Skip to content

Commit 5172be8

Browse files
authored
Merge pull request #906 from crazy-max/npm-publish
ci: use trusted publishing to publish our package
2 parents 9442c70 + 1ded416 commit 5172be8

File tree

3 files changed

+34
-45
lines changed

3 files changed

+34
-45
lines changed

.github/workflows/publish.yml

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
name: publish
22

3+
permissions:
4+
id-token: write # required for OIDC
5+
contents: read
6+
37
concurrency:
48
group: ${{ github.workflow }}-${{ github.ref }}
59
cancel-in-progress: true
@@ -9,17 +13,40 @@ on:
913
tags:
1014
- 'v*'
1115

16+
env:
17+
NODE_VERSION: "24" # at least Node 24 is required for Trusted Publishing with OIDC
18+
1219
jobs:
1320
publish:
1421
runs-on: ubuntu-latest
1522
steps:
1623
-
17-
name: Set up Docker Buildx
18-
uses: docker/setup-buildx-action@v3
24+
name: Checkout
25+
uses: actions/checkout@v6
1926
-
20-
name: Publish
21-
uses: docker/bake-action@v6
27+
name: Enable corepack
28+
run: |
29+
corepack enable
30+
yarn --version
31+
-
32+
name: Setup Node
33+
uses: actions/setup-node@v6
2234
with:
23-
targets: publish
24-
env:
25-
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
35+
node-version: ${{ env.NODE_VERSION }}
36+
cache: 'yarn'
37+
-
38+
name: Print versions
39+
run: |
40+
node --version
41+
npm --version
42+
yarn --version
43+
-
44+
name: Build
45+
run: |
46+
yarn install
47+
yarn run build
48+
-
49+
name: Publish
50+
run: |
51+
npm version --no-git-tag-version ${GITHUB_REF#refs/tags/v}
52+
npm publish --provenance --access public

dev.Dockerfile

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -101,24 +101,3 @@ RUN --mount=type=bind,target=.,rw \
101101

102102
FROM scratch AS test-coverage
103103
COPY --from=test /tmp/coverage /
104-
105-
FROM base AS publish
106-
ARG GITHUB_REF
107-
RUN --mount=type=bind,target=.,rw \
108-
--mount=type=cache,target=/src/.yarn/cache \
109-
--mount=type=cache,target=/src/node_modules \
110-
--mount=type=secret,id=NODE_AUTH_TOKEN,env=NODE_AUTH_TOKEN <<EOT
111-
set -e
112-
if ! [[ $GITHUB_REF =~ ^refs/tags/v ]]; then
113-
echo "GITHUB_REF is not a tag"
114-
exit 1
115-
fi
116-
yarn install
117-
yarn run build
118-
npm config set //registry.npmjs.org/:_authToken $NODE_AUTH_TOKEN
119-
npm version --no-git-tag-version ${GITHUB_REF#refs/tags/v}
120-
npm publish --access public
121-
122-
# FIXME: Can't publish with yarn berry atm: https://github.com/changesets/changesets/pull/674
123-
#yarn publish --no-git-tag-version --new-version ${GITHUB_REF#refs/tags/v}
124-
EOT

docker-bake.hcl

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -99,23 +99,6 @@ target "test-coverage" {
9999
secret = ["id=GITHUB_TOKEN,env=GITHUB_TOKEN"]
100100
}
101101

102-
# GITHUB_REF is the actual ref that triggers the workflow and used as version
103-
# when a tag is pushed: https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
104-
variable "GITHUB_REF" {
105-
default = ""
106-
}
107-
108-
target "publish" {
109-
inherits = ["_common"]
110-
dockerfile = "dev.Dockerfile"
111-
args = {
112-
GITHUB_REF = GITHUB_REF
113-
}
114-
target = "publish"
115-
output = ["type=cacheonly"]
116-
secret = ["id=NODE_AUTH_TOKEN,env=NODE_AUTH_TOKEN"]
117-
}
118-
119102
target "license-validate" {
120103
inherits = ["_common"]
121104
dockerfile = "./hack/dockerfiles/license.Dockerfile"

0 commit comments

Comments
 (0)