diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index f86b8747..945c6daa 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -27,6 +27,7 @@ jobs: permissions: contents: write packages: write + id-token: write # The OIDC ID token is used for authentication with JSR. steps: - name: Checkout repository uses: actions/checkout@v3 @@ -58,6 +59,12 @@ jobs: GH_RELEASE: 1 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: node scripts/publish.js ${{ steps.find.outputs.modified }} + - uses: denoland/setup-deno@v1 + - name: Build packages and publish to JSR + env: + JSR: 1 + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: node scripts/publish.js ${{ steps.find.outputs.modified }} - name: Commit version bumps run: | git commit -am "v${{ steps.bump.outputs.version }}" diff --git a/scripts/build-package.js b/scripts/build-package.js index 7f98bfce..d548f2d4 100644 --- a/scripts/build-package.js +++ b/scripts/build-package.js @@ -607,7 +607,7 @@ if (!IS_JSR) { } Promise.resolve(buildConfig.final()).then(() => { - if (IS_JSR) { + if (IS_JSR && !process.env.CI) { console.log('[i] Trying to publish with --dry-run') exec('deno publish --dry-run --allow-dirty --quiet', { cwd: outDir }) console.log('[v] All good!') diff --git a/scripts/publish.js b/scripts/publish.js index f6454788..465c730a 100644 --- a/scripts/publish.js +++ b/scripts/publish.js @@ -4,7 +4,7 @@ const cp = require('child_process') const stc = require('@teidesu/slow-types-compiler') const IS_JSR = process.env.JSR === '1' -const MAIN_REGISTRY = IS_JSR ? 'http://jsr.test/' : 'https://registry.npmjs.org' +const MAIN_REGISTRY = IS_JSR ? 'https://jsr.io/' : 'https://registry.npmjs.org' let REGISTRY = process.env.REGISTRY || MAIN_REGISTRY exports.REGISTRY = REGISTRY if (!REGISTRY.endsWith('/')) REGISTRY += '/' @@ -97,7 +97,7 @@ async function publishSinglePackage(name) { if (IS_JSR) { // publish to jsr const params = process.env.JSR_TOKEN ? `--token ${process.env.JSR_TOKEN}` : '' - cp.execSync(`deno publish --allow-dirty ${params}`, { + cp.execSync(`deno publish --allow-dirty --quiet ${params}`, { cwd: path.join(packageDir, 'dist/jsr'), stdio: 'inherit', }) @@ -179,7 +179,28 @@ async function main(arg = process.argv[2]) { } } } else { - for (const pkg of arg.split(',')) { + let pkgs = arg.split(',') + + const deps = {} + // determine the order of packages to publish + + for (const pkg of pkgs) { + if (IS_JSR && JSR_EXCEPTIONS[pkg] === 'never') continue + if (!IS_JSR && JSR_EXCEPTIONS[pkg] === 'only') continue + + if (IS_JSR) { + const pkgDeps = require(`../packages/${pkg}/package.json`).dependencies || {} + deps[pkg] = Object.keys(pkgDeps) + .filter((d) => d.startsWith('@mtcute/')) + .map((d) => d.slice(8)) + } + } + + if (IS_JSR) { + pkgs = stc.determinePublishOrder(deps) + } + + for (const pkg of pkgs) { try { await publishSinglePackage(pkg) publishedPkgs.push(pkg)