Skip to content

Fix GitHub Actions workflow permissions for release creation #10

Fix GitHub Actions workflow permissions for release creation

Fix GitHub Actions workflow permissions for release creation #10

Workflow file for this run

name: package-extension
on:
push:
branches: [master, firefox]
tags: ['v*']
release:
types: [published]
workflow_dispatch:
permissions:
contents: write
jobs:
bundle:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Determine manifest version
id: manifest
run: |
VERSION=$(jq -r '.version // "0.0.0"' manifest.json)
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Determine branch and package name
id: package_info
run: |
BRANCH="${{ github.ref }}"
BASE_VERSION="${{ steps.manifest.outputs.version }}"
if [[ "$BRANCH" == "refs/heads/firefox" ]]; then
SUFFIX="firefox"
# Bump patch version for Firefox (e.g., 1.7.0 -> 1.7.1)
IFS='.' read -r MAJOR MINOR PATCH <<< "$BASE_VERSION"
FIREFOX_PATCH=$((PATCH + 1))
VERSION="${MAJOR}.${MINOR}.${FIREFOX_PATCH}"
else
SUFFIX="chrome"
VERSION="$BASE_VERSION"
fi
ARCHIVE_NAME="slactac_${SUFFIX}-v${VERSION}.zip"
echo "archive=$ARCHIVE_NAME" >> "$GITHUB_OUTPUT"
echo "suffix=$SUFFIX" >> "$GITHUB_OUTPUT"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Create distributable zip
id: package
run: |
set -euo pipefail
ARCHIVE_NAME="${{ steps.package_info.outputs.archive }}"
zip -r "$ARCHIVE_NAME" \
manifest.json \
content.js \
popup.js \
popup.html \
popup.css \
storage.js \
icons \
compat.js
echo "archive=$ARCHIVE_NAME" >> "$GITHUB_OUTPUT"
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: slactac-${{ steps.package_info.outputs.suffix }}-${{ steps.package_info.outputs.version }}
path: ${{ steps.package.outputs.archive }}
- name: Create or update release
if: startsWith(github.ref, 'refs/tags/v')
uses: softprops/action-gh-release@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
files: ${{ steps.package.outputs.archive }}
body: |
**Platform-Specific Release**
- Chrome: ${{ steps.package_info.outputs.suffix == 'chrome' && steps.package_info.outputs.version || 'N/A' }}
- Firefox: ${{ steps.package_info.outputs.suffix == 'firefox' && steps.package_info.outputs.version || 'N/A' }}
- name: Upload to existing release
if: github.event_name == 'release'
uses: softprops/action-gh-release@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
files: ${{ steps.package.outputs.archive }}