Merge branch 'main' of github.com:KarimAziev/chrome-emacs #73
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build, Release, and Publish Chrome and Firefox Extensions | |
on: | |
workflow_dispatch: | |
inputs: | |
logLevel: | |
description: 'Log level' | |
required: true | |
default: 'warning' | |
tags: | |
description: 'Test scenario tags' | |
versionType: | |
description: 'Version Increment Type (major, minor, patch) - Leave empty for auto detection based on commit message' | |
required: false | |
default: '' | |
newVersion: | |
description: 'New Version (e.g., 1.2.3) - Overrides versionType if set' | |
required: false | |
default: '' | |
push: | |
branches: | |
- main | |
env: | |
PROJECT_NAME: chrome-emacs | |
jobs: | |
RunTests: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version-file: '.nvmrc' | |
- name: Install dependencies | |
run: npm ci | |
- name: Run Test Suite | |
run: npm run test | |
PrepareBuildAndZip: | |
needs: [RunTests] | |
runs-on: ubuntu-latest | |
outputs: | |
NEW_VERSION: ${{ steps.update-version.outputs.NEW_VERSION }} | |
OLD_VERSION: ${{ steps.update-version.outputs.OLD_VERSION }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version-file: '.nvmrc' | |
- name: Install dependencies | |
run: npm ci | |
- name: Update manifest version | |
id: update-version | |
run: | | |
VERSION_FILE=version.env | |
CURRENT_VERSION=$(jq -r '.version' chrome/manifest.json) | |
echo "OLD_VERSION=$CURRENT_VERSION" >> $GITHUB_OUTPUT | |
MANUAL_VERSION_TYPE="${{ github.event.inputs.versionType }}" | |
MANUAL_NEW_VERSION="${{ github.event.inputs.newVersion }}" | |
if [[ -n "$MANUAL_NEW_VERSION" ]]; then | |
NEW_VERSION="$MANUAL_NEW_VERSION" | |
else | |
IFS='.' read -ra VERSION <<< "$CURRENT_VERSION" | |
if [[ "$MANUAL_VERSION_TYPE" == "major" || "${{ github.event.head_commit.message }}" =~ ^major: ]]; then | |
VERSION[0]=$((VERSION[0]+1)) | |
VERSION[1]=0 | |
VERSION[2]=0 | |
elif [[ "$MANUAL_VERSION_TYPE" == "minor" || "${{ github.event.head_commit.message }}" =~ ^minor: ]]; then | |
VERSION[1]=$((VERSION[1]+1)) | |
VERSION[2]=0 | |
elif [[ "$MANUAL_VERSION_TYPE" == "patch" || "${{ github.event.head_commit.message }}" =~ ^patch: ]]; then | |
VERSION[2]=$((VERSION[2]+1)) | |
else | |
echo "No version increment specified, skipping." | |
NEW_VERSION="$CURRENT_VERSION" | |
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV | |
echo "NEW_VERSION=$NEW_VERSION" >> $VERSION_FILE | |
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_OUTPUT | |
exit 0 | |
fi | |
NEW_VERSION="${VERSION[0]}.${VERSION[1]}.${VERSION[2]}" | |
fi | |
echo "New version: $NEW_VERSION" | |
jq --arg v "$NEW_VERSION" '.version = $v' chrome/manifest.json > temp.json && mv temp.json chrome/manifest.json | |
jq --arg v "$NEW_VERSION" '.version = $v' firefox/manifest.json > temp.json && mv temp.json firefox/manifest.json | |
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV | |
echo "NEW_VERSION=$NEW_VERSION" >> $VERSION_FILE | |
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_OUTPUT | |
# Check if there are any changes | |
if git diff --quiet --exit-code chrome/manifest.json && git diff --quiet --exit-code firefox/manifest.json; then | |
echo "No changes in manifest.json. Skipping commit and push." | |
else | |
# If there are changes, configure git, commit, and push | |
git config user.name "github-actions" | |
git config user.email "[email protected]" | |
git add chrome/manifest.json firefox/manifest.json | |
git commit -m "Increment version to $NEW_VERSION" | |
git push | |
fi | |
- name: Build the project | |
run: npm run build | |
- name: Zip the Chrome app directory for release | |
run: | | |
cd chrome | |
ZIP_NAME="chrome-release-${{ steps.update-version.outputs.NEW_VERSION }}.zip" | |
zip -r "../${ZIP_NAME}" ./* | |
echo "CHROME_ZIPPED_FILE=${ZIP_NAME}" >> $GITHUB_ENV | |
cd .. | |
- name: Zip the Firefox app directory for release | |
run: | | |
cd firefox | |
ZIP_NAME="firefox-release-${{ steps.update-version.outputs.NEW_VERSION }}.zip" | |
zip -r "../${ZIP_NAME}" ./* | |
echo "FIREFOX_ZIPPED_FILE=${ZIP_NAME}" >> $GITHUB_ENV | |
cd .. | |
- name: Zip the source code for submission | |
run: | | |
SOURCE_ZIP_NAME="source-code-${{ steps.update-version.outputs.NEW_VERSION }}.zip" | |
zip -r "${SOURCE_ZIP_NAME}" . \ | |
-x ".git/*" \ | |
-x ".github/*" \ | |
-x "node_modules/*" \ | |
-x "*.zip" \ | |
-x "chrome/scripts/*" \ | |
-x "firefox/scripts/*" \ | |
-x "chrome/images/*" \ | |
-x "firefox/images/*" | |
echo "SOURCE_ZIPPED_FILE=${SOURCE_ZIP_NAME}" >> $GITHUB_ENV | |
- name: Upload Chrome zipped app as artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: chrome-release-zip-${{ steps.update-version.outputs.NEW_VERSION }} | |
path: ${{ github.workspace }}/${{ env.CHROME_ZIPPED_FILE }} | |
- name: Upload Firefox zipped app as artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: firefox-release-zip-${{ steps.update-version.outputs.NEW_VERSION }} | |
path: ${{ github.workspace }}/${{ env.FIREFOX_ZIPPED_FILE }} | |
- name: Upload source code zip as artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: source-code-zip-${{ steps.update-version.outputs.NEW_VERSION }} | |
path: ${{ github.workspace }}/${{ env.SOURCE_ZIPPED_FILE }} | |
CreateAndUploadRelease: | |
needs: [PrepareBuildAndZip] | |
runs-on: ubuntu-latest | |
if: ${{ needs.PrepareBuildAndZip.outputs.NEW_VERSION != needs.PrepareBuildAndZip.outputs.OLD_VERSION || github.event_name == 'workflow_dispatch' }} | |
steps: | |
- name: Download Chrome zipped app artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: chrome-release-zip-${{ needs.PrepareBuildAndZip.outputs.NEW_VERSION }} | |
- name: Download Firefox zipped app artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: firefox-release-zip-${{ needs.PrepareBuildAndZip.outputs.NEW_VERSION }} | |
- name: Download source code zip artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: source-code-zip-${{ needs.PrepareBuildAndZip.outputs.NEW_VERSION }} | |
- name: Create or Update Release | |
id: create-release | |
uses: ncipollo/release-action@v1 | |
with: | |
allowUpdates: true | |
tag: ${{ needs.PrepareBuildAndZip.outputs.NEW_VERSION }} | |
name: Release ${{ needs.PrepareBuildAndZip.outputs.NEW_VERSION }} | |
draft: false | |
prerelease: false | |
artifacts: | | |
chrome-release-${{ needs.PrepareBuildAndZip.outputs.NEW_VERSION }}.zip | |
firefox-release-${{ needs.PrepareBuildAndZip.outputs.NEW_VERSION }}.zip | |
source-code-${{ needs.PrepareBuildAndZip.outputs.NEW_VERSION }}.zip | |
token: ${{ secrets.GITHUB_TOKEN }} |