From 461d7ec6c4501066c9479c7fdcb03e93f1775ba4 Mon Sep 17 00:00:00 2001 From: Abhijeet Singh Date: Thu, 2 Oct 2025 21:30:15 +0530 Subject: [PATCH 1/4] feat: Add GitHub Action to automate releases --- .github/workflows/release.yml | 62 +++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..31ebf92 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,62 @@ +# .github/workflows/release.yml + +name: Create Draft Release + +on: + push: + tags: + - 'v*.*.*' + +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: + 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 -e "let manifest = require('./frontend/manifest.json'); manifest.version = '${{ github.ref_name }}'.substring(1); require('fs').writeFileSync('./frontend/manifest.json', JSON.stringify(manifest, null, 2));" + echo "frontend/manifest.json updated to version ${{ github.ref_name }}" + + - name: Commit and Update Tag + run: | + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' + git add frontend/manifest.json + git commit -m "chore: Bump frontend version to ${{ github.ref_name }}" + # This command updates the tag to point to the new commit + git push origin --force ${{ github.ref_name }} + + - 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 \ No newline at end of file From 0a3d534397dfd4164d775cf28e48da2342f9fd81 Mon Sep 17 00:00:00 2001 From: Abhijeet Singh Date: Tue, 7 Oct 2025 17:07:12 +0530 Subject: [PATCH 2/4] refactor: Address feedback on release workflow --- .github/scripts/update-manifest.js | 26 ++++++++++++++++++++++++++ .github/workflows/release.yml | 9 +++++---- 2 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 .github/scripts/update-manifest.js diff --git a/.github/scripts/update-manifest.js b/.github/scripts/update-manifest.js new file mode 100644 index 0000000..0cc31a0 --- /dev/null +++ b/.github/scripts/update-manifest.js @@ -0,0 +1,26 @@ +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); +} + +// The version is the tag name without the 'v' prefix +const version = tag.substring(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); +} \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 31ebf92..e77ce14 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,6 +19,7 @@ jobs: - name: Checkout code uses: actions/checkout@v4 with: + # Full history is required for the release notes generator fetch-depth: 0 - name: Setup Node.js @@ -31,17 +32,17 @@ jobs: working-directory: ./frontend - name: Update manifest.json version - run: | - node -e "let manifest = require('./frontend/manifest.json'); manifest.version = '${{ github.ref_name }}'.substring(1); require('fs').writeFileSync('./frontend/manifest.json', JSON.stringify(manifest, null, 2));" - echo "frontend/manifest.json updated to version ${{ github.ref_name }}" + run: node .github/scripts/update-manifest.js - name: Commit and Update Tag run: | git config --global user.name 'github-actions[bot]' git config --global user.email 'github-actions[bot]@users.noreply.github.com' git add frontend/manifest.json - git commit -m "chore: Bump frontend version to ${{ github.ref_name }}" # This command updates the tag to point to the new commit + git commit -m "chore: Bump frontend version to ${{ github.ref_name }}" + # Force push is required to move the tag to the new commit, + # which includes the manifest.json version bump. git push origin --force ${{ github.ref_name }} - name: Build frontend extension From 5dfa300436a000d4220d66c98ea955cbdb692bf1 Mon Sep 17 00:00:00 2001 From: Dinesh Kumar Sutihar <110833165+dineshsutihar@users.noreply.github.com> Date: Tue, 7 Oct 2025 22:17:07 +0530 Subject: [PATCH 3/4] Fix version extraction to handle non-prefixed tags --- .github/scripts/update-manifest.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/scripts/update-manifest.js b/.github/scripts/update-manifest.js index 0cc31a0..6a7fd71 100644 --- a/.github/scripts/update-manifest.js +++ b/.github/scripts/update-manifest.js @@ -8,8 +8,12 @@ if (!tag) { process.exit(1); } -// The version is the tag name without the 'v' prefix -const version = tag.substring(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'); @@ -23,4 +27,4 @@ try { } catch (error) { console.error(`Error updating manifest file: ${error.message}`); process.exit(1); -} \ No newline at end of file +} From d31e8f09cced9f4fc841d2554680c445f70594ae Mon Sep 17 00:00:00 2001 From: Dinesh Kumar Sutihar <110833165+dineshsutihar@users.noreply.github.com> Date: Tue, 7 Oct 2025 22:25:00 +0530 Subject: [PATCH 4/4] Update release workflow for pre-releases handling --- .github/workflows/release.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e77ce14..faf315d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -6,6 +6,7 @@ on: push: tags: - 'v*.*.*' + - 'v*.*.*-*' # also handle pre-releases like v1.2.3-beta.1 permissions: contents: write @@ -36,14 +37,12 @@ jobs: - name: Commit and Update Tag run: | - git config --global user.name 'github-actions[bot]' - git config --global user.email 'github-actions[bot]@users.noreply.github.com' + 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 frontend version to ${{ github.ref_name }}" - # Force push is required to move the tag to the new commit, - # which includes the manifest.json version bump. - git push origin --force ${{ github.ref_name }} + 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 @@ -60,4 +59,5 @@ jobs: tag_name: ${{ github.ref_name }} draft: true generate_release_notes: true - files: CodeTranslateAI-${{ github.ref_name }}.zip \ No newline at end of file + files: CodeTranslateAI-${{ github.ref_name }}.zip + prerelease: ${{ contains(github.ref_name, '-') }}