Skip to content

Commit 73889db

Browse files
oschwaldclaude
andcommitted
Use Trusted Publishing and deploy docs from GH Actions
- Add release.yml workflow for npm Trusted Publishing with provenance - Add dev-bin/release.sh automated release script - Deploy docs via peaceiris/actions-gh-pages instead of gh-pages npm package - Remove gh-pages dependency - Block manual npm publish in favor of release script 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 89d5bda commit 73889db

File tree

5 files changed

+304
-508
lines changed

5 files changed

+304
-508
lines changed

.github/workflows/release.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
push:
7+
branches:
8+
- main
9+
release:
10+
types: [published]
11+
12+
permissions: {}
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v6
19+
with:
20+
persist-credentials: false
21+
- uses: actions/setup-node@v6
22+
with:
23+
node-version: 22
24+
- run: npm ci
25+
- run: npm test
26+
- run: npm run lint
27+
- run: npm run build
28+
- run: npm run build:docs
29+
30+
publish:
31+
needs: build
32+
if: github.event_name == 'release' && github.event.action == 'published'
33+
runs-on: ubuntu-latest
34+
environment: npm
35+
permissions:
36+
contents: write
37+
id-token: write
38+
steps:
39+
- uses: actions/checkout@v6
40+
with:
41+
persist-credentials: false
42+
- uses: actions/setup-node@v6
43+
with:
44+
node-version: 22
45+
registry-url: 'https://registry.npmjs.org'
46+
- run: npm install -g npm@latest
47+
- run: npm ci
48+
- run: npm run build
49+
- run: npm publish --provenance
50+
- run: npm run build:docs
51+
- name: Deploy docs to gh-pages
52+
uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4.0.0
53+
with:
54+
github_token: ${{ secrets.GITHUB_TOKEN }}
55+
publish_dir: ./docs

README.dev.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
Steps for releasing:
1+
## Steps for releasing:
22

33
1. Review open issues and PRs to see if any can easily be fixed, closed, or
44
merged.
55
2. Bump copyright year in `README.md`, if necessary.
66
3. Consider whether any dependencies need to be updated.
77
4. Review `CHANGELOG.md` for completeness and correctness. Update its
8-
release date.
9-
5. Set the version in `package.json`.
10-
6. Run `npm publish`. You can do this from the release branch. This will
11-
generate the docs, deploy docs, and publish the module to NPM.
12-
7. Create a release PR containing the updates relating to any of the steps
13-
above.
14-
8. Create and push a git tag (e.g. `git tag -a v4.2.0 -m v4.2.0 && git push
15-
--tags`).
16-
9. Manually create a release on GitHub to include the release-specific
17-
notes found in `CHANGELOG.md`.
18-
10. Verify the release on
19-
[GitHub](https://github.com/maxmind/minfraud-api-node/releases) and
20-
[NPM](https://npmjs.com/package/@maxmind/minfraud-api-node).
8+
release date to today.
9+
5. Run `./dev-bin/release.sh`. This will:
10+
- Validate you're not on the main branch
11+
- Validate your branch is up to date with origin/main
12+
- Extract the version and date from `CHANGELOG.md`
13+
- Update the version in `package.json`
14+
- Build and test
15+
- Commit changes and push
16+
- Create a GitHub release (which triggers the npm publish workflow)
17+
6. Merge the release PR after the workflow succeeds.
18+
7. Verify the release on [npm](https://npmjs.com/package/@maxmind/minfraud-api-node).
19+
20+
Note: Publishing is done via GitHub Actions using npm Trusted Publishing
21+
(OIDC). Manual `npm publish` is not supported.
2122

2223
## Set up Precious to tidy and lint
2324

dev-bin/release.sh

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/bin/bash
2+
3+
set -eu -o pipefail
4+
5+
# Check that we're not on the main branch
6+
current_branch=$(git branch --show-current)
7+
if [ "$current_branch" = "main" ]; then
8+
echo "Error: Releases should not be done directly on the main branch."
9+
echo "Please create a release branch and run this script from there."
10+
exit 1
11+
fi
12+
13+
# Fetch latest changes and check that we're not behind origin/main
14+
echo "Fetching from origin..."
15+
git fetch origin
16+
17+
if ! git merge-base --is-ancestor origin/main HEAD; then
18+
echo "Error: Current branch is behind origin/main."
19+
echo "Please merge or rebase with origin/main before releasing."
20+
exit 1
21+
fi
22+
23+
changelog=$(cat CHANGELOG.md)
24+
25+
# minfraud-api-node format: "8.2.0 (2025-11-20)" followed by "---"
26+
regex='([0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?) \(([0-9]{4}-[0-9]{2}-[0-9]{2})\)'
27+
28+
if [[ ! $changelog =~ $regex ]]; then
29+
echo "Could not find version/date in CHANGELOG.md!"
30+
exit 1
31+
fi
32+
33+
version="${BASH_REMATCH[1]}"
34+
date="${BASH_REMATCH[3]}"
35+
36+
# Extract release notes: everything after the "---" line until the next version header
37+
notes=$(awk -v ver="$version" '
38+
$0 ~ "^" ver " \\(" { found=1; next }
39+
found && /^-+$/ { in_notes=1; next }
40+
in_notes && /^[0-9]+\.[0-9]+\.[0-9]+.* \([0-9]{4}-[0-9]{2}-[0-9]{2}\)/ { exit }
41+
in_notes { print }
42+
' CHANGELOG.md | sed -e :a -e '/^\n*$/{$d;N;ba' -e '}')
43+
44+
if [[ "$date" != "$(date +"%Y-%m-%d")" ]]; then
45+
echo "Release date $date is not today ($(date +"%Y-%m-%d"))!"
46+
exit 1
47+
fi
48+
49+
tag="v$version"
50+
51+
if [ -n "$(git status --porcelain)" ]; then
52+
echo "Working directory is not clean." >&2
53+
exit 1
54+
fi
55+
56+
# Update version in package.json
57+
current_version=$(node -p "require('./package.json').version")
58+
if [ "$current_version" != "$version" ]; then
59+
echo "Updating version in package.json from $current_version to $version..."
60+
npm version "$version" --no-git-tag-version
61+
fi
62+
63+
# Build and test
64+
echo "Running build and tests..."
65+
npm ci
66+
npm run build
67+
npm test
68+
npm run lint
69+
70+
echo $'\nDiff:'
71+
git diff
72+
73+
echo $'\nRelease notes:'
74+
echo "$notes"
75+
76+
read -e -p "Commit changes and create release? (y/n) " should_continue
77+
78+
if [ "$should_continue" != "y" ]; then
79+
echo "Aborting"
80+
exit 1
81+
fi
82+
83+
git commit -m "Prepare for $version" -a
84+
85+
git push
86+
87+
gh release create --target "$(git branch --show-current)" -t "$version" -n "$notes" "$tag"
88+
89+
echo ""
90+
echo "Release $tag created successfully!"
91+
echo "The GitHub Actions workflow will now publish to npm."
92+
echo "Monitor the release at: https://github.com/maxmind/minfraud-api-node/actions"

0 commit comments

Comments
 (0)