|
| 1 | +name: Publish Runtime Adapter |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + dist_tag: |
| 7 | + description: "npm dist-tag" |
| 8 | + required: true |
| 9 | + default: "latest" |
| 10 | + type: choice |
| 11 | + options: |
| 12 | + - latest |
| 13 | + - next |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: write |
| 17 | + |
| 18 | +concurrency: |
| 19 | + group: runtime-angular-release |
| 20 | + cancel-in-progress: false |
| 21 | + |
| 22 | +jobs: |
| 23 | + publish: |
| 24 | + runs-on: ubuntu-latest |
| 25 | + env: |
| 26 | + FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true |
| 27 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 28 | + steps: |
| 29 | + - name: Checkout |
| 30 | + uses: actions/checkout@v5 |
| 31 | + with: |
| 32 | + ref: main |
| 33 | + |
| 34 | + - name: Setup Node.js |
| 35 | + uses: actions/setup-node@v5 |
| 36 | + with: |
| 37 | + node-version: "24" |
| 38 | + cache: npm |
| 39 | + |
| 40 | + - name: Install dependencies |
| 41 | + run: npm ci |
| 42 | + |
| 43 | + - name: Build package |
| 44 | + run: npm run build |
| 45 | + |
| 46 | + - name: Resolve package metadata |
| 47 | + id: meta |
| 48 | + run: | |
| 49 | + NAME="$(node -p "require('./projects/runtime-adapter/package.json').name")" |
| 50 | + VERSION="$(node -p "require('./projects/runtime-adapter/package.json').version")" |
| 51 | + TAG="v${VERSION}" |
| 52 | + echo "name=${NAME}" >> "$GITHUB_OUTPUT" |
| 53 | + echo "version=${VERSION}" >> "$GITHUB_OUTPUT" |
| 54 | + echo "tag=${TAG}" >> "$GITHUB_OUTPUT" |
| 55 | +
|
| 56 | + - name: Ensure version is not already published |
| 57 | + run: | |
| 58 | + if npm view "${{ steps.meta.outputs.name }}@${{ steps.meta.outputs.version }}" version --registry https://registry.npmjs.org >/dev/null 2>&1; then |
| 59 | + echo "Version already published: ${{ steps.meta.outputs.name }}@${{ steps.meta.outputs.version }}" |
| 60 | + echo "Please bump projects/runtime-adapter/package.json version and rerun release." |
| 61 | + exit 1 |
| 62 | + fi |
| 63 | +
|
| 64 | + - name: Configure npm auth |
| 65 | + run: | |
| 66 | + if [[ -z "${NODE_AUTH_TOKEN}" ]]; then |
| 67 | + echo "NPM_TOKEN is not configured." |
| 68 | + exit 1 |
| 69 | + fi |
| 70 | + cat > ~/.npmrc <<EOF |
| 71 | + //registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN} |
| 72 | + EOF |
| 73 | +
|
| 74 | + - name: Publish package |
| 75 | + run: | |
| 76 | + npm publish ./dist/runtime-adapter --access public --tag "${{ github.event.inputs.dist_tag }}" |
| 77 | +
|
| 78 | + - name: Upsert GitHub release |
| 79 | + uses: actions/github-script@v8 |
| 80 | + with: |
| 81 | + script: | |
| 82 | + const tag = '${{ steps.meta.outputs.tag }}'; |
| 83 | + const name = '${{ steps.meta.outputs.name }}'; |
| 84 | + const version = '${{ steps.meta.outputs.version }}'; |
| 85 | + const distTag = '${{ github.event.inputs.dist_tag }}'; |
| 86 | + const body = [ |
| 87 | + `Published ${name}@${version}`, |
| 88 | + '', |
| 89 | + `- npm dist-tag: ${distTag}`, |
| 90 | + `- package path: dist/runtime-adapter` |
| 91 | + ].join('\n'); |
| 92 | +
|
| 93 | + const releases = await github.paginate(github.rest.repos.listReleases, { |
| 94 | + owner: context.repo.owner, |
| 95 | + repo: context.repo.repo |
| 96 | + }); |
| 97 | + const existing = releases.find((r) => r.tag_name === tag); |
| 98 | +
|
| 99 | + if (existing) { |
| 100 | + await github.rest.repos.updateRelease({ |
| 101 | + owner: context.repo.owner, |
| 102 | + repo: context.repo.repo, |
| 103 | + release_id: existing.id, |
| 104 | + draft: false, |
| 105 | + prerelease: distTag === 'next', |
| 106 | + name: tag, |
| 107 | + body |
| 108 | + }); |
| 109 | + core.info(`Updated release ${tag}`); |
| 110 | + } else { |
| 111 | + await github.rest.repos.createRelease({ |
| 112 | + owner: context.repo.owner, |
| 113 | + repo: context.repo.repo, |
| 114 | + tag_name: tag, |
| 115 | + target_commitish: context.sha, |
| 116 | + name: tag, |
| 117 | + draft: false, |
| 118 | + prerelease: distTag === 'next', |
| 119 | + body |
| 120 | + }); |
| 121 | + core.info(`Created release ${tag}`); |
| 122 | + } |
0 commit comments