|
11 | 11 | permissions: |
12 | 12 | contents: write |
13 | 13 | pull-requests: write |
| 14 | + id-token: write |
14 | 15 | runs-on: ubuntu-latest |
15 | 16 | environment: publish |
16 | 17 | steps: |
|
20 | 21 | ref: ${{ github.ref }} |
21 | 22 | - name: Set up environment |
22 | 23 | uses: ./.github/actions/setup |
| 24 | + - name: Install npm 11 for OIDC trusted publishing |
| 25 | + run: npm install -g npm@11.12.1 |
| 26 | + - name: Check for new packages |
| 27 | + id: check-packages |
| 28 | + run: | |
| 29 | + : > "$RUNNER_TEMP/new_packages.txt" |
| 30 | + while IFS=: read -r pkg dir; do |
| 31 | + npm_stderr_file="$RUNNER_TEMP/npm-view-${pkg//[^a-zA-Z0-9]/_}.stderr" |
| 32 | + if npm view "$pkg" version > /dev/null 2> "$npm_stderr_file"; then |
| 33 | + echo "Existing package: $pkg" |
| 34 | + rm -f "$npm_stderr_file" |
| 35 | + continue |
| 36 | + fi |
| 37 | +
|
| 38 | + npm_error="$(tr '\n' ' ' < "$npm_stderr_file")" |
| 39 | + rm -f "$npm_stderr_file" |
| 40 | +
|
| 41 | + if [[ "$npm_error" == *"E404"* || "$npm_error" == *"404"* || "$npm_error" == *"Not Found"* ]]; then |
| 42 | + echo "New package detected: $pkg ($dir)" |
| 43 | + echo "$dir" >> "$RUNNER_TEMP/new_packages.txt" |
| 44 | + else |
| 45 | + echo "::error::npm view failed for $pkg: ${npm_error:-Unknown error}" |
| 46 | + exit 1 |
| 47 | + fi |
| 48 | + done < <(yarn workspaces --json info | node -e " |
| 49 | + const info = JSON.parse(JSON.parse(require('fs').readFileSync('/dev/stdin','utf8')).data); |
| 50 | + for (const [name, meta] of Object.entries(info)) { |
| 51 | + const pkgJson = require('./' + meta.location + '/package.json'); |
| 52 | + if (!pkgJson.private) console.log(name + ':' + meta.location); |
| 53 | + } |
| 54 | + ") |
| 55 | +
|
| 56 | + has_new_packages=false |
| 57 | + if [ -s "$RUNNER_TEMP/new_packages.txt" ]; then |
| 58 | + echo "::notice::New packages detected — will use NPM token for publish" |
| 59 | + has_new_packages=true |
| 60 | + else |
| 61 | + echo "All packages exist on npm — using OIDC trusted publishing" |
| 62 | + fi |
| 63 | + echo "has_new_packages=$has_new_packages" >> "$GITHUB_OUTPUT" |
| 64 | + - name: Enable NPM token publishing |
| 65 | + if: steps.check-packages.outputs.has_new_packages == 'true' |
| 66 | + run: echo "NODE_AUTH_TOKEN=${NPM_TOKEN}" >> "$GITHUB_ENV" |
| 67 | + env: |
| 68 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
23 | 69 | - name: Create Prepare Release PR or Publish |
24 | 70 | id: changesets |
25 | 71 | uses: changesets/action@e0145edc7d9d8679003495b11f87bd8ef63c0cba # v1.5.3 |
|
31 | 77 | commitMode: github-api |
32 | 78 | env: |
33 | 79 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
34 | | - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 80 | + NPM_CONFIG_PROVENANCE: true |
35 | 81 | - name: Check changesets status |
36 | 82 | if: steps.changesets.outputs.hasChangesets == 'true' |
37 | 83 | run: | |
|
0 commit comments