Skip to content

Commit cd23650

Browse files
authored
Add changesets based publishing (#199)
* Add changesets based publishing * Harden release workflow * Remove dependency cache from release workflow
1 parent b044c38 commit cd23650

5 files changed

Lines changed: 1328 additions & 13 deletions

File tree

.changeset/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Changesets
2+
3+
This folder is used by `@changesets/cli` to track release notes and version bumps.
4+
5+
Quick links:
6+
7+
- [Adding a changeset](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md)
8+
- [Versioning packages](https://github.com/changesets/changesets/blob/main/docs/versioning-packages.md)
9+
- [Publishing packages](https://github.com/changesets/changesets/blob/main/docs/publishing.md)

.changeset/config.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"$schema": "https://unpkg.com/@changesets/config@2.1.1/schema.json",
3+
"commit": false,
4+
"fixed": [],
5+
"linked": [],
6+
"access": "public",
7+
"baseBranch": "main",
8+
"updateInternalDependencies": "patch",
9+
"ignore": []
10+
}

.github/workflows/release.yml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
concurrency: ${{ github.workflow }}-${{ github.ref }}
9+
10+
jobs:
11+
release:
12+
name: Release
13+
outputs:
14+
has_changesets: ${{ steps.changesets.outputs.hasChangesets }}
15+
should_publish: ${{ steps.publish-check.outputs.should_publish }}
16+
permissions:
17+
contents: write
18+
issues: read
19+
pull-requests: write
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
with:
25+
persist-credentials: false
26+
27+
- name: Install Node.js
28+
uses: actions/setup-node@v4
29+
with:
30+
node-version-file: package.json
31+
registry-url: "https://registry.npmjs.org"
32+
33+
- name: Update npm
34+
run: npm install -g npm@11.11.1
35+
36+
- name: Install dependencies
37+
run: npm ci --ignore-scripts
38+
39+
- name: Create Release Pull Request
40+
id: changesets
41+
uses: changesets/action@e0145edc7d9d8679003495b11f87bd8ef63c0cba # v1.5.3
42+
with:
43+
version: npm run version
44+
commitMode: github-api
45+
env:
46+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47+
48+
- name: Check whether this version still needs publishing
49+
if: steps.changesets.outputs.hasChangesets == 'false'
50+
id: publish-check
51+
shell: bash
52+
run: |
53+
PACKAGE_NAME=$(node -p "require('./package.json').name")
54+
PACKAGE_VERSION=$(node -p "require('./package.json').version")
55+
56+
echo "Checking whether ${PACKAGE_NAME}@${PACKAGE_VERSION} is already on npm"
57+
if npm view "${PACKAGE_NAME}@${PACKAGE_VERSION}" version >/dev/null 2>&1; then
58+
echo "should_publish=false" >> "$GITHUB_OUTPUT"
59+
exit 0
60+
fi
61+
62+
echo "should_publish=true" >> "$GITHUB_OUTPUT"
63+
64+
publish:
65+
name: Publish
66+
needs: release
67+
if: needs.release.outputs.should_publish == 'true'
68+
environment:
69+
name: npm
70+
url: https://www.npmjs.com/package/@preact/preset-vite
71+
permissions:
72+
contents: write
73+
id-token: write
74+
runs-on: ubuntu-latest
75+
steps:
76+
- name: Checkout
77+
uses: actions/checkout@v4
78+
with:
79+
persist-credentials: false
80+
81+
- name: Install Node.js
82+
uses: actions/setup-node@v4
83+
with:
84+
node-version: 22
85+
registry-url: "https://registry.npmjs.org"
86+
87+
- name: Update npm
88+
run: npm install -g npm@11.11.1
89+
90+
- name: Install dependencies
91+
run: npm ci --ignore-scripts
92+
93+
- name: Build package
94+
run: npm run build
95+
96+
- name: Publish packages
97+
uses: changesets/action@e0145edc7d9d8679003495b11f87bd8ef63c0cba # v1.5.3
98+
with:
99+
publish: npm exec -- changeset publish
100+
commitMode: github-api
101+
env:
102+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)