Skip to content

Commit 7508027

Browse files
rubenmarcusclaude
andcommitted
feat(ci): add automated GitHub releases on tag push
Add GitHub Action workflow that automatically creates releases when version tags are pushed. The workflow: - Triggers on any v* tag push - Runs tests and build to verify the tag is valid - Detects prerelease versions (alpha, beta, rc) - Generates release notes from commits since last tag - Creates GitHub release with appropriate prerelease flag - Includes npm installation instructions in release notes The npm publish step is included but commented out - can be enabled when ready to automate npm publishing by adding NPM_TOKEN secret. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 3d714ee commit 7508027

File tree

1 file changed

+147
-0
lines changed

1 file changed

+147
-0
lines changed

.github/workflows/release.yml

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
release:
13+
name: Create Release
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Setup Node.js
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: '20'
25+
cache: 'npm'
26+
registry-url: 'https://registry.npmjs.org'
27+
28+
- name: Install dependencies
29+
run: npm ci
30+
31+
- name: Build
32+
run: npm run build
33+
34+
- name: Run tests
35+
run: npm test
36+
37+
- name: Extract version info
38+
id: version
39+
run: |
40+
TAG_NAME=${GITHUB_REF#refs/tags/}
41+
VERSION=${TAG_NAME#v}
42+
43+
# Determine if this is a prerelease
44+
if [[ "$VERSION" == *"-"* ]]; then
45+
echo "prerelease=true" >> $GITHUB_OUTPUT
46+
# Extract prerelease type (alpha, beta, rc)
47+
PRERELEASE_TYPE=$(echo "$VERSION" | sed 's/.*-\([a-z]*\).*/\1/')
48+
echo "prerelease_type=$PRERELEASE_TYPE" >> $GITHUB_OUTPUT
49+
else
50+
echo "prerelease=false" >> $GITHUB_OUTPUT
51+
echo "prerelease_type=" >> $GITHUB_OUTPUT
52+
fi
53+
54+
echo "tag=$TAG_NAME" >> $GITHUB_OUTPUT
55+
echo "version=$VERSION" >> $GITHUB_OUTPUT
56+
57+
- name: Generate release notes
58+
id: notes
59+
run: |
60+
TAG_NAME=${{ steps.version.outputs.tag }}
61+
VERSION=${{ steps.version.outputs.version }}
62+
PRERELEASE=${{ steps.version.outputs.prerelease }}
63+
PRERELEASE_TYPE=${{ steps.version.outputs.prerelease_type }}
64+
65+
# Get previous tag
66+
PREV_TAG=$(git describe --tags --abbrev=0 $TAG_NAME^ 2>/dev/null || echo "")
67+
68+
# Build release notes
69+
NOTES="## What's Changed\n\n"
70+
71+
if [ -n "$PREV_TAG" ]; then
72+
# Get commits since last tag
73+
COMMITS=$(git log --pretty=format:"- %s (%h)" $PREV_TAG..$TAG_NAME --no-merges 2>/dev/null || echo "")
74+
if [ -n "$COMMITS" ]; then
75+
NOTES+="$COMMITS\n\n"
76+
fi
77+
fi
78+
79+
# Add installation instructions
80+
if [ "$PRERELEASE" == "true" ]; then
81+
NOTES+="## Installation\n\n"
82+
NOTES+="\`\`\`bash\n"
83+
NOTES+="npm install -g ralph-starter@$PRERELEASE_TYPE\n"
84+
NOTES+="\`\`\`\n\n"
85+
NOTES+="Or install this specific version:\n\n"
86+
NOTES+="\`\`\`bash\n"
87+
NOTES+="npm install -g ralph-starter@$VERSION\n"
88+
NOTES+="\`\`\`\n"
89+
else
90+
NOTES+="## Installation\n\n"
91+
NOTES+="\`\`\`bash\n"
92+
NOTES+="npm install -g ralph-starter\n"
93+
NOTES+="\`\`\`\n"
94+
fi
95+
96+
# Write to file (multiline handling)
97+
echo -e "$NOTES" > release_notes.md
98+
99+
- name: Create GitHub Release
100+
uses: softprops/action-gh-release@v1
101+
with:
102+
tag_name: ${{ steps.version.outputs.tag }}
103+
name: ${{ steps.version.outputs.tag }}
104+
body_path: release_notes.md
105+
prerelease: ${{ steps.version.outputs.prerelease }}
106+
generate_release_notes: true
107+
env:
108+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
109+
110+
# Optional: Publish to npm
111+
# Uncomment this job when ready to auto-publish
112+
# publish:
113+
# name: Publish to npm
114+
# needs: release
115+
# runs-on: ubuntu-latest
116+
# steps:
117+
# - name: Checkout
118+
# uses: actions/checkout@v4
119+
#
120+
# - name: Setup Node.js
121+
# uses: actions/setup-node@v4
122+
# with:
123+
# node-version: '20'
124+
# cache: 'npm'
125+
# registry-url: 'https://registry.npmjs.org'
126+
#
127+
# - name: Install dependencies
128+
# run: npm ci
129+
#
130+
# - name: Build
131+
# run: npm run build
132+
#
133+
# - name: Extract version info
134+
# id: version
135+
# run: |
136+
# TAG_NAME=${GITHUB_REF#refs/tags/}
137+
# VERSION=${TAG_NAME#v}
138+
# if [[ "$VERSION" == *"-"* ]]; then
139+
# echo "npm_tag=beta" >> $GITHUB_OUTPUT
140+
# else
141+
# echo "npm_tag=latest" >> $GITHUB_OUTPUT
142+
# fi
143+
#
144+
# - name: Publish to npm
145+
# run: npm publish --tag ${{ steps.version.outputs.npm_tag }}
146+
# env:
147+
# NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

0 commit comments

Comments
 (0)