Skip to content

Commit 3dda8f9

Browse files
committed
chore(ci): use explicit publishing
Since changeset doesn't support trusted publishing, we use it to bump the version, and then use regular workflows to publish to NPM and GitHub releases. Signed-off-by: JP-Ellis <josh@jpellis.me>
1 parent 94121a2 commit 3dda8f9

3 files changed

Lines changed: 53 additions & 18 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ jobs:
3838
run: npm run typecheck
3939
- name: Test
4040
run: npm run test
41-
call-workflow:
41+
42+
publish:
4243
uses: ./.github/workflows/publish.yaml
4344
if: ${{ github.repository_owner == 'pactflow' && github.event_name == 'push' }}
4445
needs: test

.github/workflows/publish.yaml

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,73 @@ name: Publish
22

33
on:
44
workflow_call:
5+
push:
6+
branches:
7+
- chore/use-explicit-publishing
8+
9+
concurrency:
10+
group: publish
11+
cancel-in-progress: false
512

613
jobs:
714
publish:
815
runs-on: ubuntu-latest
16+
environment: npm
17+
18+
permissions:
19+
contents: write
20+
id-token: write
21+
922
steps:
1023
- name: Checkout code
1124
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
25+
with:
26+
fetch-depth: 0
27+
1228
- name: Setup node
1329
uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6
1430
with:
1531
node-version: 24
1632
cache: npm
17-
cache-dependency-path: "patches/*.patch"
33+
cache-dependency-path: |
34+
package-lock.json
35+
patches/*.patch
1836
registry-url: "https://registry.npmjs.org"
37+
1938
- name: Install dependencies
2039
run: npm ci --ignore-scripts && npm run patch-package
21-
- name: Creating .npmrc
40+
41+
- name: Version packages with changeset
42+
id: version
2243
run: |
23-
cat << EOF > "$HOME/.npmrc"
24-
//registry.npmjs.org/:_authToken=$NPM_TOKEN
25-
EOF
26-
env:
27-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
28-
- name: Release
29-
id: changesets
30-
uses: changesets/action@v1
44+
git config user.name "github-actions[bot]"
45+
git config user.email "github-actions[bot]@users.noreply.github.com"
46+
npx changeset version
47+
if [ -n "$(git status --porcelain)" ]; then
48+
git add .
49+
git commit -m "[ci] release"
50+
git push
51+
echo "has_changes=true" >> $GITHUB_OUTPUT
52+
VERSION=$(node -p "require('./package.json').version")
53+
echo "version=${VERSION}" >> $GITHUB_OUTPUT
54+
else
55+
echo "has_changes=false" >> $GITHUB_OUTPUT
56+
fi
57+
58+
- name: Build package
59+
if: steps.version.outputs.has_changes == 'true'
60+
run: npm run build
61+
62+
- name: Publish to npm
63+
if: steps.version.outputs.has_changes == 'true'
64+
run: npm publish --provenance --access public
65+
66+
- name: Create GitHub Release
67+
if: steps.version.outputs.has_changes == 'true'
68+
uses: softprops/action-gh-release@v2
3169
with:
32-
version: npm run changeset:version
33-
publish: npm run changeset:publish
34-
commit: "[ci] release"
35-
title: "[ci] release"
70+
tag_name: v${{ steps.version.outputs.version }}
71+
name: v${{ steps.version.outputs.version }}
72+
generate_release_notes: true
3673
env:
3774
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
"scripts": {
2121
"build": "rollup --config",
2222
"build:watch": "rollup --config --watch",
23-
"changeset:add": "changeset add",
24-
"changeset:publish": "changeset publish",
25-
"changeset:version": "changeset version",
2623
"lint": "eslint --max-warnings=0",
2724
"patch-package": "patch-package",
2825
"prepare": "npm run build",

0 commit comments

Comments
 (0)