Skip to content

Commit 27d4820

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 27d4820

File tree

2 files changed

+112
-20
lines changed

2 files changed

+112
-20
lines changed

.github/workflows/release.yml

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

48-
- name: Build
107+
- name: 'Build'
49108
run: pnpm build
50109

51-
- name: Run tests
110+
- name: 'Run tests'
52111
run: pnpm test
53112

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

57-
- name: Create GitHub Release
133+
- name: '◆ Create GitHub Release'
134+
if: ${{ !inputs.dry_run }}
58135
uses: softprops/action-gh-release@v2
59136
with:
137+
tag_name: v${{ steps.version.outputs.version }}
60138
generate_release_notes: true
61139

62-
- name: Summary
140+
- name: 'Summary'
63141
run: |
64-
echo "## Release Published" >> $GITHUB_STEP_SUMMARY
65-
echo "" >> $GITHUB_STEP_SUMMARY
66-
echo "**Tag:** \`${{ github.ref_name }}\`" >> $GITHUB_STEP_SUMMARY
142+
echo "## Release ${{ inputs.dry_run && '[DRY RUN] ' || '' }}v${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
67143
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
144+
if [[ "${{ inputs.dry_run }}" == "true" ]]; then
145+
echo "✓ Build and tests passed. Ready to release." >> $GITHUB_STEP_SUMMARY
146+
else
147+
echo "✓ Successfully released" >> $GITHUB_STEP_SUMMARY
148+
echo "" >> $GITHUB_STEP_SUMMARY
149+
echo "- [npm](https://www.npmjs.com/package/next-dynenv/v/${{ steps.version.outputs.version }})" >> $GITHUB_STEP_SUMMARY
150+
echo "- [GitHub Release](https://github.com/${{ github.repository }}/releases/tag/v${{ steps.version.outputs.version }})" >> $GITHUB_STEP_SUMMARY
151+
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)