Skip to content

Commit 04e6e07

Browse files
committed
MinorChange: Add automated release workflow with semantic versioning
Implement GitHub Actions workflow to automatically create releases and publish to VS Code Marketplace based on commit message keywords (MajorChange:, MinorChange:, Patch:, Refactor:)
1 parent 5c52dd4 commit 04e6e07

File tree

2 files changed

+211
-0
lines changed

2 files changed

+211
-0
lines changed

.github/workflows/README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# GitHub Actions Workflows
2+
3+
## Auto Release and Publish
4+
5+
This workflow automatically creates releases and publishes the extension to the VS Code Marketplace based on commit message keywords.
6+
7+
### Version Bump Keywords
8+
9+
Use these keywords in your commit messages to trigger automatic version bumps following semantic versioning:
10+
11+
- **MajorChange:** - Increments major version (x.0.0)
12+
- Use for breaking changes or major new features
13+
- Example: `MajorChange: Complete rewrite of memory calculation engine`
14+
15+
- **MinorChange:** - Increments minor version (0.x.0)
16+
- Use for new features that are backward compatible
17+
- Example: `MinorChange: Add support for nested struct analysis`
18+
19+
- **Patch:** or **Refactor:** - Increments patch version (0.0.x)
20+
- Use for bug fixes, performance improvements, or refactoring
21+
- Example: `Patch: Fix padding calculation for ARM64 architecture`
22+
- Example: `Refactor: Simplify struct parsing logic`
23+
24+
### How It Works
25+
26+
1. On push to `master` branch, the workflow analyzes commit messages
27+
2. If a version keyword is found, it:
28+
- Determines the appropriate version bump
29+
- Updates `package.json` with the new version
30+
- Builds and packages the extension
31+
- Creates a GitHub release with the `.vsix` file
32+
- Publishes to VS Code Marketplace (if `VSCE_PAT` secret is configured)
33+
3. If no keywords are found, the workflow skips the release
34+
35+
### Setup Requirements
36+
37+
To enable marketplace publishing, add a `VSCE_PAT` secret to your repository:
38+
1. Create a Personal Access Token at https://marketplace.visualstudio.com/manage
39+
2. Go to repository Settings → Secrets → Actions
40+
3. Add new secret named `VSCE_PAT` with your token
41+
42+
### Examples
43+
44+
```bash
45+
# Patch release
46+
git commit -m "Patch: Fix memory leak in hover provider"
47+
48+
# Minor release
49+
git commit -m "MinorChange: Add cache line boundary visualization"
50+
51+
# Major release
52+
git commit -m "MajorChange: Redesign extension API for plugin support"
53+
54+
# No release (normal commit)
55+
git commit -m "Update documentation for installation steps"
56+
```

.github/workflows/release.yml

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
name: Auto Release and Publish
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Setup Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: '20.x'
24+
25+
- name: Install dependencies
26+
run: npm install
27+
28+
- name: Determine version bump
29+
id: version
30+
run: |
31+
# Get the latest tag or default to 0.0.0
32+
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
33+
echo "Latest tag: $LATEST_TAG"
34+
35+
# Remove 'v' prefix if present
36+
CURRENT_VERSION=${LATEST_TAG#v}
37+
echo "Current version: $CURRENT_VERSION"
38+
39+
# Split version into components
40+
IFS='.' read -r -a VERSION_PARTS <<< "$CURRENT_VERSION"
41+
MAJOR="${VERSION_PARTS[0]:-0}"
42+
MINOR="${VERSION_PARTS[1]:-0}"
43+
PATCH="${VERSION_PARTS[2]:-0}"
44+
45+
# Get commit messages since last tag
46+
if git describe --tags --abbrev=0 2>/dev/null; then
47+
COMMITS=$(git log $(git describe --tags --abbrev=0)..HEAD --pretty=%B)
48+
else
49+
COMMITS=$(git log --pretty=%B)
50+
fi
51+
52+
echo "Analyzing commits..."
53+
54+
# Check for version bump keywords
55+
if echo "$COMMITS" | grep -qi "MajorChange:"; then
56+
MAJOR=$((MAJOR + 1))
57+
MINOR=0
58+
PATCH=0
59+
BUMP_TYPE="major"
60+
echo "Major version bump detected"
61+
elif echo "$COMMITS" | grep -qi "MinorChange:"; then
62+
MINOR=$((MINOR + 1))
63+
PATCH=0
64+
BUMP_TYPE="minor"
65+
echo "Minor version bump detected"
66+
elif echo "$COMMITS" | grep -qi "Patch:\|Refactor:"; then
67+
PATCH=$((PATCH + 1))
68+
BUMP_TYPE="patch"
69+
echo "Patch version bump detected"
70+
else
71+
echo "No version bump keywords found, skipping release"
72+
echo "skip=true" >> $GITHUB_OUTPUT
73+
exit 0
74+
fi
75+
76+
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
77+
echo "New version: $NEW_VERSION"
78+
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
79+
echo "bump_type=$BUMP_TYPE" >> $GITHUB_OUTPUT
80+
echo "skip=false" >> $GITHUB_OUTPUT
81+
82+
- name: Update package.json version
83+
if: steps.version.outputs.skip != 'true'
84+
run: |
85+
NEW_VERSION="${{ steps.version.outputs.version }}"
86+
npm version $NEW_VERSION --no-git-tag-version
87+
git config user.name "github-actions[bot]"
88+
git config user.email "github-actions[bot]@users.noreply.github.com"
89+
git add package.json package-lock.json
90+
git commit -m "chore: bump version to $NEW_VERSION [skip ci]" || echo "No changes to commit"
91+
92+
- name: Build extension
93+
if: steps.version.outputs.skip != 'true'
94+
run: |
95+
npm run compile
96+
97+
- name: Package extension
98+
if: steps.version.outputs.skip != 'true'
99+
run: |
100+
npm install -g @vscode/vsce
101+
vsce package
102+
103+
- name: Create Release
104+
if: steps.version.outputs.skip != 'true'
105+
id: create_release
106+
uses: actions/create-release@v1
107+
env:
108+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
109+
with:
110+
tag_name: v${{ steps.version.outputs.version }}
111+
release_name: Release v${{ steps.version.outputs.version }}
112+
body: |
113+
## Release v${{ steps.version.outputs.version }}
114+
115+
### Changes
116+
This is a ${{ steps.version.outputs.bump_type }} release.
117+
118+
### Installation
119+
Download the `.vsix` file below and install it in VS Code:
120+
1. Open VS Code
121+
2. Press `Ctrl+Shift+P` (Windows/Linux) or `Cmd+Shift+P` (Mac)
122+
3. Type "Extensions: Install from VSIX"
123+
4. Select the downloaded `.vsix` file
124+
125+
Or install directly from the [VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=RhinoSoftware.go-memory-visualizer)
126+
draft: false
127+
prerelease: false
128+
129+
- name: Upload Release Asset
130+
if: steps.version.outputs.skip != 'true'
131+
uses: actions/upload-release-asset@v1
132+
env:
133+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
134+
with:
135+
upload_url: ${{ steps.create_release.outputs.upload_url }}
136+
asset_path: ./go-memory-visualizer-${{ steps.version.outputs.version }}.vsix
137+
asset_name: go-memory-visualizer-${{ steps.version.outputs.version }}.vsix
138+
asset_content_type: application/octet-stream
139+
140+
- name: Publish to VS Code Marketplace
141+
if: steps.version.outputs.skip != 'true' && github.event_name == 'push'
142+
env:
143+
VSCE_PAT: ${{ secrets.VSCE_PAT }}
144+
run: |
145+
if [ -n "$VSCE_PAT" ]; then
146+
vsce publish -p $VSCE_PAT
147+
echo "Published to VS Code Marketplace"
148+
else
149+
echo "VSCE_PAT not set, skipping marketplace publish"
150+
fi
151+
152+
- name: Push version update
153+
if: steps.version.outputs.skip != 'true'
154+
run: |
155+
git push origin master --follow-tags || echo "Failed to push, may need manual intervention"

0 commit comments

Comments
 (0)