|
| 1 | +name: OIDC Publish Dry Run |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - "**" |
| 7 | + tags-ignore: |
| 8 | + - "**" |
| 9 | + pull_request: |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +permissions: |
| 13 | + id-token: write # required for npm trusted publishing (OIDC) |
| 14 | + contents: read |
| 15 | + |
| 16 | +concurrency: |
| 17 | + group: oidc-publish-dry-run-${{ github.ref }} |
| 18 | + cancel-in-progress: true |
| 19 | + |
| 20 | +jobs: |
| 21 | + dry-run: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + # Avoid running in forks where npm Trusted Publisher won't match. |
| 24 | + if: ${{ github.repository == 'ringcentral/ringcentral-js' }} |
| 25 | + steps: |
| 26 | + - name: Checkout |
| 27 | + uses: actions/checkout@v4 |
| 28 | + |
| 29 | + - name: Use Node.js |
| 30 | + uses: actions/setup-node@v4 |
| 31 | + with: |
| 32 | + node-version: "22.14.0" |
| 33 | + registry-url: "https://registry.npmjs.org" |
| 34 | + |
| 35 | + - run: node --version |
| 36 | + |
| 37 | + - name: Enable Yarn (Corepack) |
| 38 | + run: | |
| 39 | + corepack enable |
| 40 | + corepack prepare yarn@1.22.22 --activate |
| 41 | + yarn --version |
| 42 | +
|
| 43 | + - name: Upgrade npm for trusted publishing compatibility |
| 44 | + run: | |
| 45 | + npm i -g npm@^11.5.1 |
| 46 | + npm --version |
| 47 | +
|
| 48 | + - run: yarn install |
| 49 | + - run: npm run build |
| 50 | + |
| 51 | + - name: Dry-run publish packages to npm (OIDC) |
| 52 | + env: |
| 53 | + NODE_AUTH_TOKEN: "" |
| 54 | + NPM_CONFIG_PROVENANCE: "true" |
| 55 | + run: | |
| 56 | + set -euo pipefail |
| 57 | +
|
| 58 | + VERSION="0.0.0-dryrun.${GITHUB_SHA:0:7}" |
| 59 | + export VERSION |
| 60 | + echo "Dry-run publishing version: ${VERSION}" |
| 61 | +
|
| 62 | + unset NODE_AUTH_TOKEN |
| 63 | +
|
| 64 | + # Informational only; may fail locally but helps debug in CI. |
| 65 | + npm whoami --registry=https://registry.npmjs.org || true |
| 66 | +
|
| 67 | + node - <<'NODE' |
| 68 | + const fs = require('fs'); |
| 69 | + const path = require('path'); |
| 70 | + const { spawnSync } = require('child_process'); |
| 71 | +
|
| 72 | + const version = process.env.VERSION; |
| 73 | + if (!version || version.trim() === '') { |
| 74 | + console.error('Missing VERSION'); |
| 75 | + process.exit(1); |
| 76 | + } |
| 77 | +
|
| 78 | + const rootPkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); |
| 79 | + const workspaces = rootPkg.workspaces || []; |
| 80 | +
|
| 81 | + function run(cmd, args, cwd) { |
| 82 | + const res = spawnSync(cmd, args, { cwd, stdio: 'inherit' }); |
| 83 | + if (res.status) process.exit(res.status); |
| 84 | + } |
| 85 | +
|
| 86 | + const publishTargets = []; |
| 87 | + for (const ws of workspaces) { |
| 88 | + const pkgJsonPath = path.join(ws, 'package.json'); |
| 89 | + if (!fs.existsSync(pkgJsonPath)) continue; |
| 90 | + const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8')); |
| 91 | + if (pkg.private) continue; |
| 92 | + if (!pkg.name) continue; |
| 93 | + publishTargets.push({ dir: ws, name: pkg.name }); |
| 94 | + } |
| 95 | +
|
| 96 | + if (publishTargets.length === 0) { |
| 97 | + console.log('No public workspaces found to dry-run publish.'); |
| 98 | + process.exit(0); |
| 99 | + } |
| 100 | +
|
| 101 | + console.log('Dry-run publish targets:'); |
| 102 | + for (const t of publishTargets) console.log(`- ${t.name} (${t.dir})`); |
| 103 | +
|
| 104 | + // Set versions consistently (no git tags/commits in CI). |
| 105 | + for (const t of publishTargets) { |
| 106 | + run('npm', ['version', version, '--no-git-tag-version'], t.dir); |
| 107 | + } |
| 108 | +
|
| 109 | + // Dry-run publish each package using npm OIDC trusted publishing. |
| 110 | + for (const t of publishTargets) { |
| 111 | + run('npm', ['publish', '--dry-run', '--provenance', '--access', 'public'], t.dir); |
| 112 | + } |
| 113 | + NODE |
| 114 | +
|
0 commit comments