Skip to content

Commit c4c4143

Browse files
committed
Add CI workflow for AssemblyScript project
Introduces a GitHub Actions workflow for CI, including testing, publishing to npm on tag pushes, automated changelog generation, and GitHub release creation. The workflow handles versioning, npm tagging, and changelog updates based on merged pull requests.
1 parent 4e0239c commit c4c4143

File tree

1 file changed

+231
-0
lines changed

1 file changed

+231
-0
lines changed

.github/workflows/ci.yml

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
name: CI for AssemblyScript
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v6
15+
with:
16+
fetch-depth: 0
17+
18+
- name: Setup Node.js
19+
uses: actions/setup-node@v6
20+
with:
21+
node-version: '24.x'
22+
23+
- name: Update npm
24+
run: npm install -g npm@latest
25+
26+
- name: Install dependencies
27+
run: npm install
28+
29+
- name: Build
30+
run: npm run build
31+
32+
- name: Run tests
33+
run: npm test
34+
35+
publish:
36+
runs-on: ubuntu-latest
37+
needs: test
38+
39+
permissions:
40+
contents: write
41+
id-token: write
42+
43+
steps:
44+
- name: Checkout code
45+
uses: actions/checkout@v6
46+
with:
47+
fetch-depth: 0
48+
49+
- name: Setup Node.js
50+
uses: actions/setup-node@v6
51+
with:
52+
node-version: '24.x'
53+
registry-url: 'https://registry.npmjs.org'
54+
55+
- name: Update npm
56+
run: npm install -g npm@latest
57+
58+
- name: Patch package.json for @btc-vision/assemblyscript
59+
run: |
60+
# Extract version from tag
61+
VERSION="${{ github.ref_name }}"
62+
VERSION="${VERSION#v}" # Remove 'v' prefix if present
63+
64+
# Update package.json: change name and version
65+
jq --arg name "@btc-vision/assemblyscript" \
66+
--arg version "$VERSION" \
67+
'.name = $name | .version = $version' \
68+
package.json > package.json.tmp
69+
mv package.json.tmp package.json
70+
71+
echo "Updated package.json:"
72+
cat package.json | head -20
73+
74+
- name: Install dependencies
75+
run: npm install
76+
77+
- name: Build
78+
run: npm run build
79+
80+
- name: Determine npm tag
81+
id: npm_tag
82+
run: |
83+
VERSION="${{ github.ref_name }}"
84+
if [[ "$VERSION" == *"-alpha"* ]]; then
85+
echo "tag=alpha" >> $GITHUB_OUTPUT
86+
elif [[ "$VERSION" == *"-beta"* ]]; then
87+
echo "tag=beta" >> $GITHUB_OUTPUT
88+
elif [[ "$VERSION" == *"-rc"* ]]; then
89+
echo "tag=rc" >> $GITHUB_OUTPUT
90+
else
91+
echo "tag=latest" >> $GITHUB_OUTPUT
92+
fi
93+
echo "Determined npm tag: $(cat $GITHUB_OUTPUT | grep tag | cut -d= -f2)"
94+
95+
- name: Publish to npm
96+
run: npm publish --access public --provenance --tag ${{ steps.npm_tag.outputs.tag }}
97+
98+
release:
99+
runs-on: ubuntu-latest
100+
needs: publish
101+
102+
permissions:
103+
contents: write
104+
105+
steps:
106+
- name: Checkout code
107+
uses: actions/checkout@v6
108+
with:
109+
fetch-depth: 0
110+
111+
- name: Generate changelog
112+
id: changelog
113+
uses: mikepenz/release-changelog-builder-action@v6
114+
with:
115+
configurationJson: |
116+
{
117+
"categories": [
118+
{
119+
"title": "### Breaking Changes",
120+
"labels": ["breaking", "breaking-change", "BREAKING-CHANGE"]
121+
},
122+
{
123+
"title": "### Features",
124+
"labels": ["feature", "feat", "enhancement"]
125+
},
126+
{
127+
"title": "### Bug Fixes",
128+
"labels": ["bug", "fix", "bugfix"]
129+
},
130+
{
131+
"title": "### Performance",
132+
"labels": ["performance", "perf"]
133+
},
134+
{
135+
"title": "### Documentation",
136+
"labels": ["documentation", "docs"]
137+
},
138+
{
139+
"title": "### Dependencies",
140+
"labels": ["dependencies", "deps"]
141+
},
142+
{
143+
"title": "### Other Changes",
144+
"labels": []
145+
}
146+
],
147+
"sort": {
148+
"order": "ASC",
149+
"on_property": "mergedAt"
150+
},
151+
"template": "#{{CHANGELOG}}",
152+
"pr_template": "- #{{TITLE}} ([##{{NUMBER}}](#{{URL}})) by @#{{AUTHOR}}",
153+
"empty_template": "- No changes",
154+
"max_tags_to_fetch": 200,
155+
"max_pull_requests": 200,
156+
"max_back_track_time_days": 365,
157+
"tag_resolver": {
158+
"method": "semver"
159+
}
160+
}
161+
env:
162+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
163+
164+
- name: Update CHANGELOG.md
165+
env:
166+
CHANGELOG_CONTENT: ${{ steps.changelog.outputs.changelog }}
167+
run: |
168+
TAG="${{ github.ref_name }}"
169+
DATE=$(date +%Y-%m-%d)
170+
NEW_HEADER="## [$TAG] - $DATE"
171+
172+
# Write changelog content to temp file using env var (avoids shell escaping)
173+
printf '%s\n' "$CHANGELOG_CONTENT" > /tmp/new_entry.md
174+
175+
if [ -f CHANGELOG.md ]; then
176+
# Create new file with entry inserted after header line
177+
{
178+
head -n 1 CHANGELOG.md
179+
echo ""
180+
echo "$NEW_HEADER"
181+
echo ""
182+
cat /tmp/new_entry.md
183+
echo ""
184+
tail -n +2 CHANGELOG.md
185+
} > /tmp/CHANGELOG_NEW.md
186+
mv /tmp/CHANGELOG_NEW.md CHANGELOG.md
187+
else
188+
# Create new CHANGELOG.md
189+
{
190+
echo "# Changelog"
191+
echo ""
192+
echo "All notable changes to this project will be documented in this file."
193+
echo ""
194+
echo "This changelog is automatically generated from merged pull requests."
195+
echo ""
196+
echo "$NEW_HEADER"
197+
echo ""
198+
cat /tmp/new_entry.md
199+
} > CHANGELOG.md
200+
fi
201+
202+
rm -f /tmp/new_entry.md
203+
204+
- name: Commit changelog
205+
run: |
206+
git config user.name "github-actions[bot]"
207+
git config user.email "github-actions[bot]@users.noreply.github.com"
208+
git add CHANGELOG.md
209+
git diff --staged --quiet || git commit -m "docs: update CHANGELOG.md for ${{ github.ref_name }}"
210+
git push origin HEAD:main || echo "No changes to push or push failed"
211+
212+
- name: Determine if prerelease
213+
id: prerelease
214+
run: |
215+
VERSION="${{ github.ref_name }}"
216+
if [[ "$VERSION" == *"-alpha"* ]] || [[ "$VERSION" == *"-beta"* ]] || [[ "$VERSION" == *"-rc"* ]]; then
217+
echo "is_prerelease=true" >> $GITHUB_OUTPUT
218+
else
219+
echo "is_prerelease=false" >> $GITHUB_OUTPUT
220+
fi
221+
222+
- name: Create GitHub Release
223+
uses: softprops/action-gh-release@v2
224+
with:
225+
tag_name: ${{ github.ref_name }}
226+
name: Release ${{ github.ref_name }}
227+
body: ${{ steps.changelog.outputs.changelog }}
228+
prerelease: ${{ steps.prerelease.outputs.is_prerelease == 'true' }}
229+
generate_release_notes: false
230+
env:
231+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)