Skip to content

build: add coverage to .gitignore #56

build: add coverage to .gitignore

build: add coverage to .gitignore #56

name: Build, Release, and Publish Chrome Extension
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:
DIRECTORY: app
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' $DIRECTORY/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' $DIRECTORY/manifest.json > temp.json && mv temp.json $DIRECTORY/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 $DIRECTORY/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 "github-actions@github.com"
git add $DIRECTORY/manifest.json
git commit -m "Increment version to $NEW_VERSION"
git push
fi
- name: Build the project
run: npm run build
- name: Zip the app directory for release
run: |
cd ${{ env.DIRECTORY }}
ZIP_NAME="release-${{ env.NEW_VERSION }}.zip"
zip -r "../${ZIP_NAME}" ./*
echo "ZIPPED_FILE=${ZIP_NAME}" >> $GITHUB_ENV
cd ..
- name: Upload zipped app as artifact
uses: actions/upload-artifact@v4
with:
name: release-zip-${{ env.NEW_VERSION }}
path: ${{ github.workspace }}/${{ env.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 zipped app artifact
uses: actions/download-artifact@v4
with:
name: release-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: "release-${{ needs.PrepareBuildAndZip.outputs.NEW_VERSION }}.zip"
token: ${{ secrets.GITHUB_TOKEN }}