Skip to content

Commit f1fcdf0

Browse files
committed
build: configure release as trusted publisher (#165)
1 parent 3367b2f commit f1fcdf0

13 files changed

Lines changed: 716 additions & 1428 deletions

.github/actions/install/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ runs:
1010
run: echo "dir=$(npm config get cache)" >> "$GITHUB_OUTPUT"
1111
shell: bash
1212

13-
- uses: actions/cache@v4
13+
- uses: actions/cache@v5
1414
with:
1515
path: ${{ steps.cache-dir.outputs.dir }}
1616
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}

.github/workflows/manual-deprecate-versions.yml

Lines changed: 0 additions & 31 deletions
This file was deleted.

.github/workflows/manual-manage-versions.yml

Lines changed: 0 additions & 37 deletions
This file was deleted.

.github/workflows/npm-service.yml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
name: NPM Service
3+
4+
on:
5+
release:
6+
types: [published]
7+
pull_request:
8+
branches: [main]
9+
types: [opened, synchronize, reopened]
10+
paths-ignore:
11+
- "**.md"
12+
13+
permissions:
14+
contents: read
15+
id-token: write
16+
17+
# Manage concurrency to stop running jobs and start new ones in case of new commit pushed
18+
concurrency:
19+
group: ${{ github.ref }}-${{ github.workflow }}
20+
cancel-in-progress: true
21+
22+
jobs:
23+
publish:
24+
if: github.event_name == 'release' || github.actor != 'dependabot[bot]'
25+
runs-on: ubuntu-latest
26+
outputs:
27+
channel: ${{ steps.publish.outputs.channel }}
28+
permissions:
29+
id-token: write
30+
contents: read
31+
pull-requests: write
32+
steps:
33+
- uses: actions/checkout@v6
34+
- uses: actions/setup-node@v6
35+
with:
36+
node-version: 20
37+
registry-url: "https://registry.npmjs.org"
38+
- run: npm install -g npm@latest
39+
- uses: ./.github/actions/install
40+
41+
# Dev version setup (PR only)
42+
- name: Compute dev version
43+
if: github.event_name == 'pull_request'
44+
id: version
45+
run: |
46+
CURRENT_VERSION=$(jq -r '.version' package.json)
47+
DEV_CHANNEL="dev-${{ github.event.pull_request.number }}"
48+
DEV_VERSION="${CURRENT_VERSION}-${DEV_CHANNEL}.${{ github.run_id }}-${{ github.run_attempt }}"
49+
echo "channel=$DEV_CHANNEL" >> "$GITHUB_OUTPUT"
50+
echo "version=$DEV_VERSION" >> "$GITHUB_OUTPUT"
51+
52+
- name: Set dev version
53+
if: github.event_name == 'pull_request'
54+
env:
55+
DEV_CHANNEL: ${{ steps.version.outputs.channel }}
56+
run: |
57+
git config --global user.email "${DEV_CHANNEL}@github.com"
58+
git config --global user.name "$DEV_CHANNEL"
59+
npm version "${{ steps.version.outputs.version }}" --no-git-tag-version
60+
61+
# Publish (unified with conditional channel)
62+
- name: Publish
63+
id: publish
64+
env:
65+
DEV_CHANNEL: ${{ steps.version.outputs.channel }}
66+
RELEASE_TAG: ${{ github.event.release.tag_name }}
67+
EVENT_NAME: ${{ github.event_name }}
68+
run: |
69+
if [ "$EVENT_NAME" = "pull_request" ]; then
70+
CHANNEL="$DEV_CHANNEL"
71+
else
72+
CHANNEL="latest-rc"
73+
fi
74+
npm publish --provenance --access public --tag "$CHANNEL"
75+
# For e2e: PR uses dev channel, release uses tag name (e.g., v1.5.0)
76+
if [ "$EVENT_NAME" = "pull_request" ]; then
77+
echo "channel=$DEV_CHANNEL" >> "$GITHUB_OUTPUT"
78+
else
79+
echo "channel=$RELEASE_TAG" >> "$GITHUB_OUTPUT"
80+
fi
81+
82+
# Comment PR (PR only)
83+
- name: Comment PR
84+
if: github.event_name == 'pull_request'
85+
uses: thollander/actions-comment-pull-request@v3
86+
env:
87+
DEV_CHANNEL: ${{ steps.version.outputs.channel }}
88+
with:
89+
message: |
90+
Published under `${{ env.DEV_CHANNEL }}` npm channel.
91+
```sh
92+
$ sf plugins install sf-git-merge-driver@${{ env.DEV_CHANNEL }}
93+
```
94+
comment-tag: dev-publish
95+
mode: recreate
96+
97+
e2e-tests:
98+
needs: [publish]
99+
uses: ./.github/workflows/run-e2e-tests.yml
100+
with:
101+
channel: ${{ needs.publish.outputs.channel }}
102+

.github/workflows/on-main-push.yml

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ on:
88
paths-ignore:
99
- "**.md"
1010

11+
permissions:
12+
contents: 'read'
13+
1114
jobs:
1215
build:
1316
uses: ./.github/workflows/reusable-build.yml
@@ -16,42 +19,11 @@ jobs:
1619
prepare-release:
1720
needs: [build]
1821
runs-on: ubuntu-latest
19-
outputs:
20-
release_created: ${{ steps.release.outputs.release_created }}
21-
prs_created: ${{ steps.release.outputs.prs_created }}
22-
version: ${{ steps.release.outputs.version }}
22+
permissions:
23+
contents: write
24+
pull-requests: write
2325
steps:
2426
- uses: googleapis/release-please-action@v4
25-
id: release
2627
with:
2728
token: ${{ secrets.RELEASE_PAT }}
2829
release-type: node
29-
30-
release:
31-
needs: [prepare-release]
32-
runs-on: ubuntu-latest
33-
if: ${{ needs.prepare-release.outputs.release_created == 'true' }}
34-
steps:
35-
- name: Checkout sources
36-
uses: actions/checkout@v6
37-
38-
- name: Setup node
39-
uses: actions/setup-node@v4
40-
with:
41-
node-version: 20
42-
registry-url: 'https://registry.npmjs.org'
43-
44-
- name: Setup dependencies, cache and install
45-
uses: ./.github/actions/install
46-
47-
- name: Publish to npm
48-
run: npm publish --access public --tag latest-rc
49-
env:
50-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
51-
52-
test-release:
53-
uses: ./.github/workflows/run-e2e-tests.yml
54-
needs: [prepare-release, release]
55-
with:
56-
channel: ${{ needs.prepare-release.outputs.version }}
57-
secrets: inherit

.github/workflows/on-merged-pull-request.yml

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)