Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/scripts/update-manifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const fs = require('fs');
const path = require('path');

// Get the tag from the environment variable GitHub Actions provides
const tag = process.env.GITHUB_REF_NAME;
if (!tag) {
console.error("Error: GITHUB_REF_NAME environment variable not set.");
process.exit(1);
}

const version = tag.startsWith('v') ? tag.substring(1) : tag;

if (!/^\d+\.\d+\.\d+(-[\w.-]+)?$/.test(version)) {
console.error(`Invalid version format: "${version}". Expected semver like v1.2.3 or v1.2.3-beta.1`);
process.exit(1);
}

// Path to the manifest file
const manifestPath = path.resolve(__dirname, '../../frontend/manifest.json');

// Read, update, and write the manifest file
try {
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
manifest.version = version;
fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
console.log(`Successfully updated ${manifestPath} to version ${version}`);
} catch (error) {
console.error(`Error updating manifest file: ${error.message}`);
process.exit(1);
}
63 changes: 63 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# .github/workflows/release.yml

name: Create Draft Release

on:
push:
tags:
- 'v*.*.*'
- 'v*.*.*-*' # also handle pre-releases like v1.2.3-beta.1

permissions:
contents: write
pull-requests: read

jobs:
release:
name: Create Draft Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
# Full history is required for the release notes generator
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'

- name: Install frontend dependencies
run: npm ci
working-directory: ./frontend

- name: Update manifest.json version
run: node .github/scripts/update-manifest.js

- name: Commit and Update Tag
run: |
git config --global user.name 'CodeTranslate Release Bot'
git config --global user.email 'release-bot-codetranslate@users.noreply.github.com'
git add frontend/manifest.json
# This command updates the tag to point to the new commit
git commit -m "chore: bump manifest version to ${{ github.ref_name }} [skip ci]" || echo "No changes to commit"
git push origin HEAD:main

- name: Build frontend extension
run: npm run build
working-directory: ./frontend

- name: Create ZIP archive
run: zip -r ../../CodeTranslateAI-${{ github.ref_name }}.zip .
working-directory: ./frontend/dist

- name: Create Draft GitHub Release
uses: softprops/action-gh-release@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag_name: ${{ github.ref_name }}
draft: true
generate_release_notes: true
files: CodeTranslateAI-${{ github.ref_name }}.zip
prerelease: ${{ contains(github.ref_name, '-') }}