Skip to content

Commit 55b9f32

Browse files
committed
🔧 Convert release workflow to manual dispatch with version input
Replace tag-triggered releases with workflow_dispatch for more control: - Add version input parameter with semver validation - Add dry_run option to test builds without publishing - Automate version bump, commit, and tag creation in workflow - Add integration tests step before publishing - Add git configuration for automated commits - Improve step labels with decorative prefixes - Update summary to reflect dry run status and new version format
1 parent fecb6c3 commit 55b9f32

File tree

2 files changed

+108
-19
lines changed

2 files changed

+108
-19
lines changed

.github/workflows/release.yml

Lines changed: 97 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,33 @@
11
name: Release
22

33
on:
4-
push:
5-
tags:
6-
- 'v*'
74
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'Version to release (leave empty for patch bump)'
8+
required: false
9+
default: ''
10+
bump:
11+
description: 'Version bump type (if version not specified)'
12+
required: false
13+
type: choice
14+
default: 'patch'
15+
options:
16+
- patch
17+
- minor
18+
- major
19+
dry_run:
20+
description: 'Dry run (skip publish & tag)'
21+
required: false
22+
type: boolean
23+
default: false
824

925
permissions:
1026
contents: write
1127
id-token: write
1228

1329
concurrency:
14-
group: release-${{ github.ref }}
30+
group: release
1531
cancel-in-progress: false
1632

1733
env:
@@ -25,44 +41,108 @@ jobs:
2541
timeout-minutes: 15
2642

2743
steps:
28-
- name: Checkout
44+
- name: 'Checkout'
2945
uses: actions/checkout@v4
3046
with:
3147
fetch-depth: 0
48+
token: ${{ secrets.GITHUB_TOKEN }}
3249

33-
- name: Setup pnpm
50+
- name: 'Setup pnpm'
3451
uses: pnpm/action-setup@v4
3552
with:
3653
version: ${{ env.PNPM_VERSION }}
3754

38-
- name: Setup Node.js
55+
- name: 'Setup Node.js'
3956
uses: actions/setup-node@v4
4057
with:
4158
node-version: ${{ env.NODE_VERSION }}
4259
cache: 'pnpm'
4360
registry-url: 'https://registry.npmjs.org'
4461

45-
- name: Install dependencies
62+
- name: '◇ Configure git'
63+
run: |
64+
git config user.name "github-actions[bot]"
65+
git config user.email "github-actions[bot]@users.noreply.github.com"
66+
67+
- name: '△ Determine version'
68+
id: version
69+
run: |
70+
CURRENT=$(node -p "require('./package.json').version")
71+
echo "Current version: $CURRENT"
72+
73+
if [[ -n "${{ inputs.version }}" ]]; then
74+
VERSION="${{ inputs.version }}"
75+
else
76+
IFS='.' read -r MAJOR MINOR PATCH <<< "${CURRENT%%-*}"
77+
case "${{ inputs.bump }}" in
78+
major) VERSION="$((MAJOR + 1)).0.0" ;;
79+
minor) VERSION="${MAJOR}.$((MINOR + 1)).0" ;;
80+
patch) VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))" ;;
81+
esac
82+
fi
83+
84+
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?$ ]]; then
85+
echo "::error::Invalid version format: $VERSION"
86+
exit 1
87+
fi
88+
89+
if git tag -l "v$VERSION" | grep -q "v$VERSION"; then
90+
echo "::error::Tag v$VERSION already exists"
91+
exit 1
92+
fi
93+
94+
echo "version=$VERSION" >> $GITHUB_OUTPUT
95+
echo "Releasing version: $VERSION"
96+
97+
- name: '△ Update version → ${{ steps.version.outputs.version }}'
98+
run: |
99+
npm version ${{ steps.version.outputs.version }} --no-git-tag-version
100+
101+
- name: '◈ Install dependencies'
46102
run: pnpm install --frozen-lockfile
47103

48-
- name: Build
104+
- name: 'Build'
49105
run: pnpm build
50106

51-
- name: Run tests
107+
- name: 'Run tests'
52108
run: pnpm test
53109

54-
- name: Publish to npm
110+
- name: '● Run integration tests'
111+
run: pnpm test:integration
112+
113+
- name: '◆ Commit version bump'
114+
if: ${{ !inputs.dry_run }}
115+
run: |
116+
git add package.json
117+
git commit -m "🔖 v${{ steps.version.outputs.version }}"
118+
119+
- name: '◆ Create and push tag'
120+
if: ${{ !inputs.dry_run }}
121+
run: |
122+
git tag -a "v${{ steps.version.outputs.version }}" -m "Release v${{ steps.version.outputs.version }}"
123+
git push origin HEAD:${{ github.ref_name }}
124+
git push origin "v${{ steps.version.outputs.version }}"
125+
126+
- name: '▲ Publish to npm'
127+
if: ${{ !inputs.dry_run }}
55128
run: pnpm publish --access public --no-git-checks
56129

57-
- name: Create GitHub Release
130+
- name: '◆ Create GitHub Release'
131+
if: ${{ !inputs.dry_run }}
58132
uses: softprops/action-gh-release@v2
59133
with:
134+
tag_name: v${{ steps.version.outputs.version }}
60135
generate_release_notes: true
61136

62-
- name: Summary
137+
- name: 'Summary'
63138
run: |
64-
echo "## Release Published" >> $GITHUB_STEP_SUMMARY
65-
echo "" >> $GITHUB_STEP_SUMMARY
66-
echo "**Tag:** \`${{ github.ref_name }}\`" >> $GITHUB_STEP_SUMMARY
139+
echo "## Release ${{ inputs.dry_run && '[DRY RUN] ' || '' }}v${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
67140
echo "" >> $GITHUB_STEP_SUMMARY
68-
echo "[npm](https://www.npmjs.com/package/next-dynenv) · [Release](https://github.com/${{ github.repository }}/releases/tag/${{ github.ref_name }})" >> $GITHUB_STEP_SUMMARY
141+
if [[ "${{ inputs.dry_run }}" == "true" ]]; then
142+
echo "✓ Build and tests passed. Ready to release." >> $GITHUB_STEP_SUMMARY
143+
else
144+
echo "✓ Successfully released" >> $GITHUB_STEP_SUMMARY
145+
echo "" >> $GITHUB_STEP_SUMMARY
146+
echo "- [npm](https://www.npmjs.com/package/next-dynenv/v/${{ steps.version.outputs.version }})" >> $GITHUB_STEP_SUMMARY
147+
echo "- [GitHub Release](https://github.com/${{ github.repository }}/releases/tag/v${{ steps.version.outputs.version }})" >> $GITHUB_STEP_SUMMARY
148+
fi

.npmignore

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# testing
22
/coverage
3+
/test-app
4+
vitest.config.ts
35

4-
# server
6+
# config
57
.audit-ci.json
68
.env.sample
79
.eslintignore
@@ -10,16 +12,23 @@
1012
codecov.yml
1113
jest.config.js
1214
prettier.config.js
15+
.prettierrc
1316
tsconfig.json
17+
biome.jsonc
18+
pnpm-workspace.yaml
19+
pnpm-lock.yaml
1420
/.github
1521
/.vscode
1622

1723
# source
1824
/src
1925

20-
# expamples
26+
# examples
2127
/examples
2228

29+
# docs
30+
/docs
31+
2332
# misc
2433
.DS_Store
2534
.env

0 commit comments

Comments
 (0)