Skip to content

Commit 9043f9b

Browse files
authored
Add GitHub Action to publish map-styles to npm (#61)
* Add GitHub Action to publish map-styles to npm * Testing the release action with --dry-run * Validate first the changes * Validate on push only to avoid duplicate runs * Test dry-run with OIDC * Simplify validate (OIDC already verified)
1 parent d0225b8 commit 9043f9b

3 files changed

Lines changed: 91 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Release to npm
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
bump:
7+
description: 'Version bump'
8+
type: choice
9+
options:
10+
- patch
11+
- minor
12+
- major
13+
default: patch
14+
15+
concurrency:
16+
group: release
17+
cancel-in-progress: false
18+
19+
jobs:
20+
release:
21+
if: github.ref_name == 'staging'
22+
runs-on: ubuntu-latest
23+
permissions:
24+
contents: write
25+
id-token: write
26+
steps:
27+
- name: Verify staging branch
28+
run: |
29+
if [ "${{ github.ref_name }}" != "staging" ]; then
30+
echo "::error::Releases can only be triggered from the 'staging' branch (got: ${{ github.ref_name }})"
31+
exit 1
32+
fi
33+
34+
- uses: actions/checkout@v4
35+
with:
36+
ref: staging
37+
fetch-depth: 0
38+
39+
- uses: actions/setup-node@v4
40+
with:
41+
node-version-file: '.nvmrc'
42+
registry-url: 'https://registry.npmjs.org'
43+
44+
- run: npm ci
45+
46+
- name: Configure git identity
47+
run: |
48+
git config user.name "github-actions[bot]"
49+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
50+
51+
- name: Bump version, rebuild /dist, commit and tag
52+
run: |
53+
NEW_VERSION=$(npm version ${{ inputs.bump }} --no-git-tag-version)
54+
NEW_VERSION="${NEW_VERSION#v}"
55+
npm run build
56+
git add package.json package-lock.json dist/
57+
git commit -m "Packaging ${NEW_VERSION} with rebuilt /dist"
58+
git tag "v${NEW_VERSION}"
59+
60+
- name: Push to GitHub
61+
run: git push origin staging --follow-tags
62+
63+
- name: Publish to npm with provenance
64+
run: npm publish --provenance --access public

.github/workflows/validate.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Validate build
2+
3+
on:
4+
push:
5+
branches-ignore:
6+
- staging
7+
8+
jobs:
9+
validate:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- uses: actions/setup-node@v4
15+
with:
16+
node-version-file: '.nvmrc'
17+
registry-url: 'https://registry.npmjs.org'
18+
19+
- run: npm ci
20+
21+
- name: Build /dist
22+
run: npm run build
23+
24+
- name: Validate npm package (dry-run)
25+
run: npm publish --dry-run

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ Miscellaneous notes:
7070

7171
## Versioning and publishing to npm
7272

73+
> Releases can be automated via [Actions → "Release to npm"](https://github.com/OpenHistoricalMap/map-styles/actions/workflows/release.yml) — click **Run workflow**, choose `patch` / `minor` / `major`, and it builds `/dist`, commits, tags, and publishes with provenance via npm Trusted Publishers (no token required). Manual steps below remain as a fallback.
74+
7375
1. increment the version in `package.json`, e.g., `0.9.7`
7476
1. commit your style changes, including `/dist/*` & `package.json`, push to GitHub, and [create a corresponding release](https://github.com/OpenHistoricalMap/map-styles/releases/new), e.g., `v0.9.7`
7577
1. publish to npm using `npm publish`

0 commit comments

Comments
 (0)