Skip to content

Commit 0c3e9a7

Browse files
ci: harden publish workflow by switching to OIDC (#3068)
Co-authored-by: David Luna <[email protected]>
1 parent 4fbd4b9 commit 0c3e9a7

File tree

1 file changed

+48
-20
lines changed

1 file changed

+48
-20
lines changed

.github/workflows/release-please.yml

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,17 @@ permissions:
88

99
name: Run Release Please
1010
jobs:
11+
# creates the release PR, and publishes releases
1112
release-please:
13+
outputs:
14+
release_created: ${{ steps.release.outputs.release_created }}
1215
runs-on: ubuntu-latest
13-
permissions:
14-
contents: write # required for pushing changes
15-
id-token: write
1616
steps:
17-
# The logic below handles the npm publication:
1817
- name: Checkout Repository
1918
uses: actions/checkout@v5
2019
with:
2120
fetch-depth: 0
2221

23-
# If you update this version make sure to keep in sync:
24-
# - `build-and-cache` job of unit-test workflow
25-
# - `build-and-cache` job of test-all-versions workflow
2622
- name: Setup Node
2723
uses: actions/setup-node@v5
2824
with:
@@ -33,10 +29,16 @@ jobs:
3329
run: |
3430
npm ci
3531
32+
- uses: actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e # v2.0.6
33+
id: otelbot-token
34+
with:
35+
app-id: ${{ vars.OTELBOT_JS_APP_ID }}
36+
private-key: ${{ secrets.OTELBOT_JS_PRIVATE_KEY }}
37+
3638
- uses: googleapis/release-please-action@7987652d64b4581673a76e33ad5e98e3dd56832f # v4.1.3
3739
id: release
3840
with:
39-
token: ${{secrets.RELEASE_PR_TOKEN}}
41+
token: ${{ steps.otelbot-token.outputs.token }}
4042
target-branch: main
4143

4244
# get release PR as we're currently on main
@@ -47,7 +49,7 @@ jobs:
4749
with:
4850
ref: release-please--branches--main
4951
# use a token so that workflows on the PR run when we push later
50-
token: ${{ secrets.RELEASE_PR_TOKEN }}
52+
token: ${{ steps.otelbot-token.outputs.token }}
5153

5254
# release-please does not do this on its own, so we do it here instead
5355
- name: Update package-lock.json in PR
@@ -56,33 +58,59 @@ jobs:
5658
run: |
5759
npm install --ignore-scripts --package-lock-only
5860
git add package-lock.json
59-
git config user.name opentelemetrybot
60-
git config user.email 107717825+opentelemetrybot@users.noreply.github.com
61+
git config user.name otelbot
62+
git config user.email 197425009+otelbot@users.noreply.github.com
6163
git commit -m "chore: sync package-lock.json"
6264
git push
6365
64-
# get main again
66+
install-and-compile:
67+
needs: release-please
68+
# only if a release has been created
69+
if: ${{ needs.release-please.outputs.release_created }}
70+
runs-on: ubuntu-latest
71+
steps:
6572
- name: Checkout Repository
66-
# only checkout if a release has been created
67-
if: ${{ steps.release.outputs.releases_created }}
6873
uses: actions/checkout@v5
6974
with:
7075
fetch-depth: 0
71-
7276
- name: Rebuild Packages
73-
# only rebuild if a release has been created
74-
if: ${{ steps.release.outputs.releases_created }}
7577
run: |
7678
npm ci
7779
npm run compile
80+
- name: Upload contents for publish
81+
uses: actions/upload-artifact@v4
82+
with:
83+
name: publish-cache-${{ github.run_number }}
84+
path: .
85+
include-hidden-files: true
86+
if-no-files-found: error
87+
retention-days: 10
7888

89+
npm-publish:
90+
needs:
91+
- release-please
92+
- install-and-compile
93+
# only if a release has been created
94+
if: ${{ needs.release-please.outputs.release_created }}
95+
runs-on: ubuntu-latest
96+
permissions:
97+
contents: read
98+
id-token: write # to generate npm provenance statements
99+
environment: npm-publish-environment
100+
steps:
101+
- name: Setup Node
102+
uses: actions/setup-node@v4
103+
with:
104+
node-version: 24
105+
registry-url: 'https://registry.npmjs.org'
106+
- name: Download contents for publish
107+
uses: actions/download-artifact@v4
108+
with:
109+
name: publish-cache-${{ github.run_number }}
79110
# Release Please has already incremented versions and published tags, so we just
80111
# need to publish all unpublished versions to npm here
81112
# See: https://github.com/lerna/lerna/tree/main/libs/commands/publish#bump-from-package
82113
- name: Publish to npm
83-
# only publish if a release has been created
84-
if: ${{ steps.release.outputs.releases_created }}
85114
env:
86-
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
87115
NPM_CONFIG_PROVENANCE: true
88116
run: npx lerna publish from-package --no-push --no-private --no-git-tag-version --yes

0 commit comments

Comments
 (0)