Skip to content

Refactor release workflow to ensure steps only execute if a new tag i… #8

Refactor release workflow to ensure steps only execute if a new tag i…

Refactor release workflow to ensure steps only execute if a new tag i… #8

Workflow file for this run

name: Release Build
on:
push:
branches:
- master
tags:
- "*"
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract version from manifest
id: manifest_version
run: |
VERSION=$(grep -oP '"version":\s*"\K[^"]+' src/manifest_firefox.json)
echo "VERSION=v$VERSION" >> $GITHUB_OUTPUT
- name: Check if tag exists
id: check_tag
if: github.ref == 'refs/heads/master'
run: |
if git rev-parse ${{ steps.manifest_version.outputs.VERSION }} >/dev/null 2>&1; then
echo "TAG_EXISTS=true" >> $GITHUB_OUTPUT
else
echo "TAG_EXISTS=false" >> $GITHUB_OUTPUT
fi
- name: Create and push tag
if: github.ref == 'refs/heads/master' && steps.check_tag.outputs.TAG_EXISTS == 'false'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag ${{ steps.manifest_version.outputs.VERSION }}
git push origin ${{ steps.manifest_version.outputs.VERSION }}
- name: Get tag version
id: tag
if: github.ref_type == 'tag' || steps.check_tag.outputs.TAG_EXISTS == 'false'
run: |
if [ "${{ github.ref_type }}" == "tag" ]; then
echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
else
echo "VERSION=${{ steps.manifest_version.outputs.VERSION }}" >> $GITHUB_OUTPUT
fi
- name: Extract latest changelog
id: changelog
if: github.ref_type == 'tag' || steps.check_tag.outputs.TAG_EXISTS == 'false'
run: |
# Extract the first changelog entry (between first ## and second ##)
CHANGELOG=$(awk '/^## / {if (++count == 2) exit; if (count == 1) next} count == 1' CHANGELOG.md)
# Save to output (escape for multiline)
echo "BODY<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Build Chrome extension
if: github.ref_type == 'tag' || steps.check_tag.outputs.TAG_EXISTS == 'false'
run: |
# Create temporary build directory
mkdir -p build/chrome
# Copy src contents to build directory
cp -r src/* build/chrome/
# Remove style.scss
rm -f build/chrome/style.scss
# Replace manifest.json with manifest_chrome.json
rm -f build/chrome/manifest.json
cp src/manifest_chrome.json build/chrome/manifest.json
# Remove other manifest files
rm -f build/chrome/manifest_*.json
# Create zip
cd build/chrome
zip -r ../../SubscriptionInfo-Chrome-${{ steps.tag.outputs.VERSION }}.zip .
cd ../..
- name: Build Firefox extension
if: github.ref_type == 'tag' || steps.check_tag.outputs.TAG_EXISTS == 'false'
run: |
# Create temporary build directory
mkdir -p build/firefox
# Copy src contents to build directory
cp -r src/* build/firefox/
# Remove style.scss
rm -f build/firefox/style.scss
# Replace manifest.json with manifest_firefox.json
rm -f build/firefox/manifest.json
cp src/manifest_firefox.json build/firefox/manifest.json
# Remove other manifest files
rm -f build/firefox/manifest_*.json
# Create zip
cd build/firefox
zip -r ../../SubscriptionInfo-Firefox-${{ steps.tag.outputs.VERSION }}.zip .
cd ../..
- name: Upload Chrome artifact
if: github.ref_type == 'tag' || steps.check_tag.outputs.TAG_EXISTS == 'false'
uses: actions/upload-artifact@v4
with:
name: SubscriptionInfo-Chrome-${{ steps.tag.outputs.VERSION }}
path: SubscriptionInfo-Chrome-${{ steps.tag.outputs.VERSION }}.zip
retention-days: 90
- name: Upload Firefox artifact
if: github.ref_type == 'tag' || steps.check_tag.outputs.TAG_EXISTS == 'false'
uses: actions/upload-artifact@v4
with:
name: SubscriptionInfo-Firefox-${{ steps.tag.outputs.VERSION }}
path: SubscriptionInfo-Firefox-${{ steps.tag.outputs.VERSION }}.zip
retention-days: 90
- name: Create GitHub Release
if: github.ref_type == 'tag' || steps.check_tag.outputs.TAG_EXISTS == 'false'
uses: softprops/action-gh-release@v1
with:
files: |
SubscriptionInfo-Chrome-${{ steps.tag.outputs.VERSION }}.zip
SubscriptionInfo-Firefox-${{ steps.tag.outputs.VERSION }}.zip
body: ${{ steps.changelog.outputs.BODY }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}