Skip to content

Commit efa406f

Browse files
Merge pull request #49 from singhxabhijeet/feat/add-release-workflow
feat: Add GitHub Action to automate releases
2 parents 013555e + d31e8f0 commit efa406f

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

.github/scripts/update-manifest.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
// Get the tag from the environment variable GitHub Actions provides
5+
const tag = process.env.GITHUB_REF_NAME;
6+
if (!tag) {
7+
console.error("Error: GITHUB_REF_NAME environment variable not set.");
8+
process.exit(1);
9+
}
10+
11+
const version = tag.startsWith('v') ? tag.substring(1) : tag;
12+
13+
if (!/^\d+\.\d+\.\d+(-[\w.-]+)?$/.test(version)) {
14+
console.error(`Invalid version format: "${version}". Expected semver like v1.2.3 or v1.2.3-beta.1`);
15+
process.exit(1);
16+
}
17+
18+
// Path to the manifest file
19+
const manifestPath = path.resolve(__dirname, '../../frontend/manifest.json');
20+
21+
// Read, update, and write the manifest file
22+
try {
23+
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
24+
manifest.version = version;
25+
fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
26+
console.log(`Successfully updated ${manifestPath} to version ${version}`);
27+
} catch (error) {
28+
console.error(`Error updating manifest file: ${error.message}`);
29+
process.exit(1);
30+
}

.github/workflows/release.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# .github/workflows/release.yml
2+
3+
name: Create Draft Release
4+
5+
on:
6+
push:
7+
tags:
8+
- 'v*.*.*'
9+
- 'v*.*.*-*' # also handle pre-releases like v1.2.3-beta.1
10+
11+
permissions:
12+
contents: write
13+
pull-requests: read
14+
15+
jobs:
16+
release:
17+
name: Create Draft Release
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
with:
23+
# Full history is required for the release notes generator
24+
fetch-depth: 0
25+
26+
- name: Setup Node.js
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version: '18'
30+
31+
- name: Install frontend dependencies
32+
run: npm ci
33+
working-directory: ./frontend
34+
35+
- name: Update manifest.json version
36+
run: node .github/scripts/update-manifest.js
37+
38+
- name: Commit and Update Tag
39+
run: |
40+
git config --global user.name 'CodeTranslate Release Bot'
41+
git config --global user.email 'release-bot-codetranslate@users.noreply.github.com'
42+
git add frontend/manifest.json
43+
# This command updates the tag to point to the new commit
44+
git commit -m "chore: bump manifest version to ${{ github.ref_name }} [skip ci]" || echo "No changes to commit"
45+
git push origin HEAD:main
46+
47+
- name: Build frontend extension
48+
run: npm run build
49+
working-directory: ./frontend
50+
51+
- name: Create ZIP archive
52+
run: zip -r ../../CodeTranslateAI-${{ github.ref_name }}.zip .
53+
working-directory: ./frontend/dist
54+
55+
- name: Create Draft GitHub Release
56+
uses: softprops/action-gh-release@v2
57+
with:
58+
token: ${{ secrets.GITHUB_TOKEN }}
59+
tag_name: ${{ github.ref_name }}
60+
draft: true
61+
generate_release_notes: true
62+
files: CodeTranslateAI-${{ github.ref_name }}.zip
63+
prerelease: ${{ contains(github.ref_name, '-') }}

0 commit comments

Comments
 (0)