Skip to content

Commit 42c5fc8

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 42c5fc8

3 files changed

Lines changed: 48 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: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,67 @@ name: Publish
33
on:
44
workflow_call:
55

6+
concurrency:
7+
group: publish
8+
cancel-in-progress: false
9+
610
jobs:
711
publish:
812
runs-on: ubuntu-latest
13+
environment: npm
14+
15+
permissions:
16+
contents: write
17+
id-token: write
18+
919
steps:
1020
- name: Checkout code
1121
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
22+
with:
23+
fetch-depth: 0
24+
1225
- name: Setup node
1326
uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6
1427
with:
1528
node-version: 24
1629
cache: npm
17-
cache-dependency-path: "patches/*.patch"
30+
cache-dependency-path: "patches/*.patch, package-lock.json"
1831
registry-url: "https://registry.npmjs.org"
32+
1933
- name: Install dependencies
2034
run: npm ci --ignore-scripts && npm run patch-package
21-
- name: Creating .npmrc
35+
36+
- name: Version packages with changeset
37+
id: version
2238
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
39+
git config user.name "github-actions[bot]"
40+
git config user.email "github-actions[bot]@users.noreply.github.com"
41+
npx changeset version
42+
if [ -n "$(git status --porcelain)" ]; then
43+
git add .
44+
git commit -m "[ci] release"
45+
git push
46+
echo "has_changes=true" >> $GITHUB_OUTPUT
47+
VERSION=$(node -p "require('./package.json').version")
48+
echo "version=${VERSION}" >> $GITHUB_OUTPUT
49+
else
50+
echo "has_changes=false" >> $GITHUB_OUTPUT
51+
fi
52+
53+
- name: Build package
54+
if: steps.version.outputs.has_changes == 'true'
55+
run: npm run build
56+
57+
- name: Publish to npm
58+
if: steps.version.outputs.has_changes == 'true'
59+
run: npm publish --provenance --access public
60+
61+
- name: Create GitHub Release
62+
if: steps.version.outputs.has_changes == 'true'
63+
uses: softprops/action-gh-release@v2
3164
with:
32-
version: npm run changeset:version
33-
publish: npm run changeset:publish
34-
commit: "[ci] release"
35-
title: "[ci] release"
65+
tag_name: v${{ steps.version.outputs.version }}
66+
name: v${{ steps.version.outputs.version }}
67+
generate_release_notes: true
3668
env:
3769
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)