Skip to content

Commit b79be33

Browse files
Add GitHub Actions for publishing packages to NPM registry (#692)
* chore: add GitHub workflows for automated npm publishing - Add publish-radfish.yml workflow for @nmfs-radfish/radfish package - Add publish-react-radfish.yml workflow for @nmfs-radfish/react-radfish package - Include admin permission checks, version bumping, testing, and publishing steps - Add rollback mechanisms for failed publishes * refactor: migrate radfish package from Jest to Vitest - Remove babel.config.js and jest.config.js - Update package.json to use vitest instead of jest - Replace jest imports with vitest imports in all test files - Remove Jest-related dependencies and add vitest dependencies - Clean up unnecessary dependencies from radfish package * chore: update react-radfish package configuration - Add publishConfig for npm registry publishing - Add React as peer dependency - Configure package for public access * chore: update git tag format to use shorter package names - Change tag format from @nmfs-radfish/[package]@[version] to [package]@[version] - Update both radfish and react-radfish workflows - Cleaner tag names since repository is already nmfs-radfish namespaced * feat: add latest tags for packages in publishing workflows - Add [package-name]@latest tags that get updated with each new version - Force push latest tags to always point to the most recent release - Provides a stable reference for the current version of each package * fix: implement proper tag logic for prerelease vs stable releases - For prereleases: only create/update beta tag - For stable releases: only create/update latest tag - Prevents latest tag from being updated by prereleases - Allows beta tag to become stale between prerelease cycles * chore: add npm tag support for prerelease vs stable releases - For prereleases: npm publish --tag beta - For stable releases: npm publish (defaults to latest tag) - Ensures npm registry tags match git tag behavior * chore: Register workflows on GitHub * chore: Remove push trigger * fix: checkout current branch instead of hardcoded main - Update workflows to use github.ref instead of hardcoded main branch - Change step name from 'Checkout main branch' to 'Checkout repository' - Ensures workflows run against the current branch's code and dependencies - Fixes Jest vs Vitest test runner issue when running from feature branches * fix: use broader peer dependency range for radfish - Change from ^1.0.0 to >=1.0.0 <2.0.0 for @nmfs-radfish/radfish - Allows independent versioning of packages within major version - Prevents npm version bump conflicts in monorepo workspace - Commits to semantic versioning within v1.x.x releases * chore: update package-lock.json for new peer dependency range - Regenerate lockfile to reflect peer dependency change from ^1.0.0 to >=1.0.0 <2.0.0 - Should resolve npm version bump conflicts in workspace * fix: update peer dependency to support prereleases - Change from >=1.0.0 <2.0.0 to ^1.0.0-0 for @nmfs-radfish/radfish - ^1.0.0-0 allows prereleases like 1.1.2-rc.1 while maintaining semver compatibility - Should resolve npm version bump issues with prerelease versions * chore: add --legacy-peer-deps flag to version bump steps - Add --legacy-peer-deps to npm version commands in both workflows - Resolves peer dependency conflicts when bumping prerelease versions - Allows using standard ^1.0.0 peer dependency format * refactor: simplify workflow inputs and logic for version bumping - Replace separate version + prerelease inputs with single version_type dropdown - Remove complex conditional logic for determining version bump type - Auto-detect prerelease status from resulting version for npm publish tags - Remove redundant 'Navigate to package directory' steps - Eliminate ambiguity: users now explicitly choose exact version bump behavior Examples: - prerelease: 1.1.2-rc.1 → 1.1.2-rc.2 - preminor: 1.1.2-rc.1 → 1.2.0-rc.1 - minor: 1.1.2 → 1.2.0 * fix: use jq to parse version from package.json instead of npm output - npm version command outputs multiline content that breaks GitHub Actions - Now run npm version to update package.json, then use jq to get clean version - Eliminates multiline output issues and removes 'v' prefix automatically - Results in clean version strings like '1.1.2-rc.3' instead of 'v1.1.2-rc.3\n...' - Fixes 'Unable to process file command output successfully' error * fix: push to current branch instead of hardcoded main - Workflows were failing when run on feature branches because they tried to push to 'main' - Changed 'git push origin main' to 'git push origin HEAD' to push current branch - Now workflows work correctly on any branch, including feature branches for testing * chore: reset radfish version to last published version (1.1.2-rc.0) - Ready to run workflow with prerelease version type - npm version prerelease will increment to 1.1.2-rc.1 * fix: add --legacy-peer-deps to install step in workflows - Resolves peer dependency conflicts during npm install - react-radfish has peer dependency ^1.0.0 but workspace has 1.1.1 - --legacy-peer-deps allows npm to proceed with installation * chore(release): bump @nmfs-radfish/radfish to 1.1.3-rc.0 * chore(release): bump @nmfs-radfish/radfish to 1.1.4-rc.0 * fix: add --legacy-peer-deps to test workflow scripts --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 557abb5 commit b79be33

File tree

11 files changed

+1607
-279
lines changed

11 files changed

+1607
-279
lines changed
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
name: Publish @nmfs-radfish/radfish to NPM
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version_type:
7+
description: 'Version bump type'
8+
required: true
9+
type: choice
10+
options:
11+
- patch # 1.1.2 → 1.1.3
12+
- minor # 1.1.2 → 1.2.0
13+
- major # 1.1.2 → 2.0.0
14+
- prerelease # 1.1.2-rc.1 → 1.1.2-rc.2
15+
- prepatch # 1.1.2 → 1.1.3-rc.1
16+
- preminor # 1.1.2 → 1.2.0-rc.1
17+
- premajor # 1.1.2 → 2.0.0-rc.1
18+
19+
permissions:
20+
contents: write
21+
22+
jobs:
23+
publish:
24+
runs-on: ubuntu-latest
25+
26+
steps:
27+
- name: Check admin permissions
28+
uses: actions/github-script@v7
29+
with:
30+
script: |
31+
const { data: { permission } } = await github.rest.repos.getCollaboratorPermissionLevel({
32+
owner: context.repo.owner,
33+
repo: context.repo.repo,
34+
username: context.actor
35+
});
36+
37+
if (permission !== 'admin') {
38+
core.setFailed(`User ${context.actor} does not have admin permissions. Current permission: ${permission}`);
39+
}
40+
41+
- name: Checkout repository
42+
uses: actions/checkout@v4
43+
with:
44+
ref: ${{ github.ref }}
45+
token: ${{ secrets.GITHUB_TOKEN }}
46+
47+
- name: Configure Git
48+
run: |
49+
git config --global user.name "github-actions[bot]"
50+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
51+
52+
- name: Setup Node.js
53+
uses: actions/setup-node@v4
54+
with:
55+
node-version: '18'
56+
registry-url: 'https://registry.npmjs.org'
57+
58+
- name: Install dependencies
59+
run: npm install --legacy-peer-deps
60+
61+
- name: Run tests
62+
run: |
63+
set -e
64+
npm test -- --run
65+
working-directory: packages/radfish
66+
67+
- name: Bump version (no git operations)
68+
id: bump-version
69+
run: |
70+
set -e
71+
# Bump version (ignore output)
72+
npm version ${{ inputs.version_type }} --preid=rc --no-git-tag-version --legacy-peer-deps
73+
# Query the updated package.json for clean version
74+
NEW_VERSION=$(jq -r '.version' package.json)
75+
echo "new_version=${NEW_VERSION}" >> $GITHUB_OUTPUT
76+
working-directory: packages/radfish
77+
78+
- name: Publish to NPM
79+
id: npm-publish
80+
run: |
81+
set -e
82+
if [[ "${{ steps.bump-version.outputs.new_version }}" == *"-rc."* ]]; then
83+
npm publish --tag beta
84+
else
85+
npm publish
86+
fi
87+
working-directory: packages/radfish
88+
env:
89+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
90+
91+
- name: Commit version bump
92+
if: success()
93+
run: |
94+
set -e
95+
git add packages/radfish/package.json
96+
git commit -m "chore(release): bump @nmfs-radfish/radfish to ${{ steps.bump-version.outputs.new_version }}"
97+
98+
- name: Create and push tags
99+
if: success()
100+
run: |
101+
set -e
102+
git tag "radfish@${{ steps.bump-version.outputs.new_version }}"
103+
git push origin HEAD
104+
if [[ "${{ steps.bump-version.outputs.new_version }}" == *"-rc."* ]]; then
105+
# For prereleases, only tag and push beta
106+
git tag -f "radfish@beta"
107+
git push origin "radfish@${{ steps.bump-version.outputs.new_version }}" "radfish@beta" --force
108+
else
109+
# For regular releases, only tag and push latest
110+
git tag -f "radfish@latest"
111+
git push origin "radfish@${{ steps.bump-version.outputs.new_version }}" "radfish@latest" --force
112+
fi
113+
114+
- name: Create GitHub Release
115+
if: success()
116+
uses: actions/create-release@v1
117+
env:
118+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
119+
with:
120+
tag_name: "radfish@${{ steps.bump-version.outputs.new_version }}"
121+
release_name: "radfish@${{ steps.bump-version.outputs.new_version }}"
122+
body: |
123+
Release of @nmfs-radfish/radfish version ${{ steps.bump-version.outputs.new_version }}
124+
125+
## Changes
126+
See [commit history](https://github.com/${{ github.repository }}/commits/radfish@${{ steps.bump-version.outputs.new_version }}) for detailed changes.
127+
draft: false
128+
prerelease: ${{ contains(steps.bump-version.outputs.new_version, '-rc.') }}
129+
130+
- name: Rollback version on failure
131+
if: failure() && steps.bump-version.conclusion == 'success'
132+
run: |
133+
set -e
134+
git checkout -- packages/radfish/package.json
135+
echo "Version bump rolled back due to publish failure"
136+
working-directory: .
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
name: Publish @nmfs-radfish/react-radfish to NPM
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version_type:
7+
description: 'Version bump type'
8+
required: true
9+
type: choice
10+
options:
11+
- patch # 1.1.2 → 1.1.3
12+
- minor # 1.1.2 → 1.2.0
13+
- major # 1.1.2 → 2.0.0
14+
- prerelease # 1.1.2-rc.1 → 1.1.2-rc.2
15+
- prepatch # 1.1.2 → 1.1.3-rc.1
16+
- preminor # 1.1.2 → 1.2.0-rc.1
17+
- premajor # 1.1.2 → 2.0.0-rc.1
18+
19+
permissions:
20+
contents: write
21+
22+
jobs:
23+
publish:
24+
runs-on: ubuntu-latest
25+
26+
steps:
27+
- name: Check admin permissions
28+
uses: actions/github-script@v7
29+
with:
30+
script: |
31+
const { data: { permission } } = await github.rest.repos.getCollaboratorPermissionLevel({
32+
owner: context.repo.owner,
33+
repo: context.repo.repo,
34+
username: context.actor
35+
});
36+
37+
if (permission !== 'admin') {
38+
core.setFailed(`User ${context.actor} does not have admin permissions. Current permission: ${permission}`);
39+
}
40+
41+
- name: Checkout repository
42+
uses: actions/checkout@v4
43+
with:
44+
ref: ${{ github.ref }}
45+
token: ${{ secrets.GITHUB_TOKEN }}
46+
47+
- name: Configure Git
48+
run: |
49+
git config --global user.name "github-actions[bot]"
50+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
51+
52+
- name: Setup Node.js
53+
uses: actions/setup-node@v4
54+
with:
55+
node-version: '18'
56+
registry-url: 'https://registry.npmjs.org'
57+
58+
- name: Install dependencies
59+
run: npm install --legacy-peer-deps
60+
61+
- name: Run tests
62+
run: |
63+
set -e
64+
npm test -- --run
65+
working-directory: packages/react-radfish
66+
67+
- name: Bump version (no git operations)
68+
id: bump-version
69+
run: |
70+
set -e
71+
# Bump version (ignore output)
72+
npm version ${{ inputs.version_type }} --preid=rc --no-git-tag-version --legacy-peer-deps
73+
# Query the updated package.json for clean version
74+
NEW_VERSION=$(jq -r '.version' package.json)
75+
echo "new_version=${NEW_VERSION}" >> $GITHUB_OUTPUT
76+
working-directory: packages/react-radfish
77+
78+
- name: Build package
79+
run: |
80+
set -e
81+
npm run build
82+
working-directory: packages/react-radfish
83+
84+
- name: Publish to NPM
85+
id: npm-publish
86+
run: |
87+
set -e
88+
if [[ "${{ steps.bump-version.outputs.new_version }}" == *"-rc."* ]]; then
89+
npm publish --tag beta
90+
else
91+
npm publish
92+
fi
93+
working-directory: packages/react-radfish
94+
env:
95+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
96+
97+
- name: Commit version bump
98+
if: success()
99+
run: |
100+
set -e
101+
git add packages/react-radfish/package.json
102+
git commit -m "chore(release): bump @nmfs-radfish/react-radfish to ${{ steps.bump-version.outputs.new_version }}"
103+
104+
- name: Create and push tags
105+
if: success()
106+
run: |
107+
set -e
108+
git tag "react-radfish@${{ steps.bump-version.outputs.new_version }}"
109+
git push origin HEAD
110+
if [[ "${{ steps.bump-version.outputs.new_version }}" == *"-rc."* ]]; then
111+
# For prereleases, only tag and push beta
112+
git tag -f "react-radfish@beta"
113+
git push origin "react-radfish@${{ steps.bump-version.outputs.new_version }}" "react-radfish@beta" --force
114+
else
115+
# For regular releases, only tag and push latest
116+
git tag -f "react-radfish@latest"
117+
git push origin "react-radfish@${{ steps.bump-version.outputs.new_version }}" "react-radfish@latest" --force
118+
fi
119+
120+
- name: Create GitHub Release
121+
if: success()
122+
uses: actions/create-release@v1
123+
env:
124+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
125+
with:
126+
tag_name: "react-radfish@${{ steps.bump-version.outputs.new_version }}"
127+
release_name: "react-radfish@${{ steps.bump-version.outputs.new_version }}"
128+
body: |
129+
Release of @nmfs-radfish/react-radfish version ${{ steps.bump-version.outputs.new_version }}
130+
131+
## Changes
132+
See [commit history](https://github.com/${{ github.repository }}/commits/react-radfish@${{ steps.bump-version.outputs.new_version }}) for detailed changes.
133+
draft: false
134+
prerelease: ${{ contains(steps.bump-version.outputs.new_version, '-rc.') }}
135+
136+
- name: Rollback version on failure
137+
if: failure() && steps.bump-version.conclusion == 'success'
138+
run: |
139+
set -e
140+
git checkout -- packages/react-radfish/package.json
141+
echo "Version bump rolled back due to publish failure"
142+
working-directory: .

.github/workflows/run-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ jobs:
3131
ref: ${{ github.event.pull_request.head.sha }}
3232

3333
- name: Install workspace dependencies
34-
run: npm install
34+
run: npm install --legacy-peer-deps
3535
working-directory: .
3636

3737
- name: Install dependencies
38-
run: npm install
38+
run: npm install --legacy-peer-deps
3939
working-directory: templates/react-javascript
4040

4141
- name: Build project

0 commit comments

Comments
 (0)