Skip to content

Merge pull request #89 from DeepBlueCLtd/011-release-automation #1

Merge pull request #89 from DeepBlueCLtd/011-release-automation

Merge pull request #89 from DeepBlueCLtd/011-release-automation #1

Workflow file for this run

name: Release
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
permissions:
contents: write
jobs:
lint:
name: Lint & Format Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'
- run: npm ci
- run: npm run lint
- run: npm run format:check
test:
name: Unit & Integration Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'
- run: npm ci
- run: npm run test:unit
- run: npm run test:integration
build:
name: Build & Bundle Size Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'
- run: npm ci
- run: npm run build
- name: Check bundle size
run: npm run size-check
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: [lint, test, build]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Extract version from tag
id: version
run: |
VERSION=${GITHUB_REF_NAME#v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Releasing version: $VERSION"
- name: Check if package.json version needs update
id: check-version
run: |
CURRENT_VERSION=$(node -p "require('./package.json').version")
TAG_VERSION=${{ steps.version.outputs.version }}
if [ "$CURRENT_VERSION" = "$TAG_VERSION" ]; then
echo "needs_update=false" >> $GITHUB_OUTPUT
echo "Package.json already at version $TAG_VERSION"
else
echo "needs_update=true" >> $GITHUB_OUTPUT
echo "Package.json version $CURRENT_VERSION differs from tag $TAG_VERSION"
fi
- name: Update package.json version
if: steps.check-version.outputs.needs_update == 'true'
run: |
npm version ${{ steps.version.outputs.version }} --no-git-tag-version
echo "Updated package.json to version ${{ steps.version.outputs.version }}"
- name: Commit and push version update
if: steps.check-version.outputs.needs_update == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add package.json package-lock.json
git commit -m "chore(release): ${{ github.ref_name }}"
git push origin HEAD:main
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
generate_release_notes: true
files: |
dist/sonar-quiz.iife.js
dist/sonar-quiz.iife.js.map
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}