FMHY-SafeGuard/.github/workflows/release.yml
Kenneth Hendricks 807b77c781
Update release workflow to manage Firefox updates.json
Adds a step to update Firefox updates.json and commit changes.
2026-01-25 16:42:14 -05:00

133 lines
4.5 KiB
YAML

name: Release Extensions
on:
push:
tags:
- 'v*.*.*'
workflow_dispatch: # Allows manual triggering from GitHub UI
permissions:
contents: write # Required to write contents and create releases
jobs:
build-and-release:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install -y zip jq
# Step to get the version, or use a default if no tag exists (manual trigger)
- name: Get Version from Tag or Default
id: get_version
run: |
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
echo "VERSION=${VERSION}" >> $GITHUB_ENV
else
echo "No tag found, using default version"
echo "VERSION=dev-version" >> $GITHUB_ENV
fi
- name: Assemble Release Notes
id: release_notes
run: |
VERSION=${{ env.VERSION }}
echo "## Release $VERSION" > release_notes.md
echo "" >> release_notes.md
if [[ "$VERSION" != "dev-version" ]]; then
awk "/^## \\[$VERSION\\]/, /^## \\[/" CHANGELOG.md >> release_notes.md || cat RELEASE.HEAD.md >> release_notes.md
else
echo "Manual run, no release notes extracted from CHANGELOG.md" >> release_notes.md
cat RELEASE.HEAD.md >> release_notes.md
fi
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.VERSION }}
release_name: Release ${{ env.VERSION }}
body_path: release_notes.md
draft: false
prerelease: false
- name: Build Chrome Extension
run: |
mkdir -p dist/chromium
cp -r src/* dist/chromium/
cp platform/chromium/manifest.json dist/chromium/manifest.json
cd dist/chromium
zip -r ../FMHY-SafeGuard_${{ env.VERSION }}.chromium.zip ./*
cd ../..
- name: Build Firefox Extension
run: |
mkdir -p dist/firefox
cp -r src/* dist/firefox/
cp platform/firefox/manifest.json dist/firefox/manifest.json
cd dist/firefox
zip -r ../FMHY-SafeGuard_${{ env.VERSION }}.firefox.zip ./*
cd ..
mv FMHY-SafeGuard_${{ env.VERSION }}.firefox.zip FMHY-SafeGuard_${{ env.VERSION }}.firefox.xpi
- name: Upload Chrome Extension
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: dist/FMHY-SafeGuard_${{ env.VERSION }}.chromium.zip
asset_name: FMHY-SafeGuard_${{ env.VERSION }}.chromium.zip
asset_content_type: application/zip
- name: Upload Firefox Extension
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: dist/FMHY-SafeGuard_${{ env.VERSION }}.firefox.xpi
asset_name: FMHY-SafeGuard_${{ env.VERSION }}.firefox.xpi
asset_content_type: application/x-xpinstall
- name: Update Firefox updates.json
if: env.VERSION != 'dev-version'
run: |
cat > updates.json << EOF
{
"addons": {
"{5d554479-7cc4-487f-bd25-d8fc67a42602}": {
"updates": [
{
"version": "${VERSION#v}",
"update_link": "https://github.com/fmhy/FMHY-SafeGuard/releases/download/${{ env.VERSION }}/FMHY-SafeGuard_${{ env.VERSION }}.firefox.xpi"
}
]
}
}
}
EOF
- name: Commit and Push updates.json
if: env.VERSION != 'dev-version'
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add updates.json
git commit -m "Update Firefox updates.json for ${{ env.VERSION }}" || echo "No changes to commit"
git push origin HEAD:main