mirror of
https://github.com/LukeHagar/usage-statistics.git
synced 2025-12-06 04:21:55 +00:00
271 lines
8.1 KiB
YAML
271 lines
8.1 KiB
YAML
name: Release
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
version:
|
|
description: Version to release (patch, minor, major)
|
|
required: true
|
|
default: patch
|
|
type: choice
|
|
options:
|
|
- patch
|
|
- minor
|
|
- major
|
|
permissions:
|
|
contents: write
|
|
jobs:
|
|
release:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
token: ${{ secrets.GITHUB_TOKEN }}
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: "20"
|
|
cache: npm
|
|
- name: Setup Bun
|
|
uses: oven-sh/setup-bun@v1
|
|
with:
|
|
bun-version: latest
|
|
- name: Install system dependencies for skia-canvas
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y \
|
|
build-essential \
|
|
libcairo2-dev \
|
|
libpango1.0-dev \
|
|
libjpeg-dev \
|
|
libgif-dev \
|
|
librsvg2-dev \
|
|
libpixman-1-dev \
|
|
pkg-config \
|
|
python3 \
|
|
make \
|
|
g++ \
|
|
libstdc++6
|
|
- name: Install dependencies
|
|
run: bun install
|
|
- name: Rebuild native modules
|
|
env:
|
|
NODE_ENV: production
|
|
SKIA_CANVAS_USE_SYSTEM_LIBRARIES: 1
|
|
run: >
|
|
cd node_modules/skia-canvas && npm rebuild
|
|
|
|
cd ../..
|
|
|
|
node -e "console.log('Testing skia-canvas import...');
|
|
require('skia-canvas'); console.log('✅ skia-canvas loaded
|
|
successfully')"
|
|
- name: Build action
|
|
run: bun run build
|
|
- name: Verify build
|
|
run: >
|
|
echo "Checking built files..."
|
|
|
|
ls -la dist/
|
|
|
|
echo "Testing action execution..."
|
|
|
|
node -e "console.log('Testing action import...');
|
|
import('./dist/action.js').then(() => console.log('✅ Action loaded
|
|
successfully')).catch(err => { console.error('❌ Action load failed:',
|
|
err.message); process.exit(1); })"
|
|
- name: Bump version
|
|
id: bump
|
|
run: >
|
|
# Get current version
|
|
|
|
CURRENT_VERSION=$(node -p "require('./package.json').version")
|
|
|
|
echo "Current version: $CURRENT_VERSION"
|
|
|
|
|
|
# Bump version
|
|
|
|
NEW_VERSION=$(npm version ${{ github.event.inputs.version }}
|
|
--no-git-tag-version)
|
|
|
|
echo "New version: $NEW_VERSION"
|
|
|
|
|
|
# Remove 'v' prefix if present
|
|
|
|
NEW_VERSION=${NEW_VERSION#v}
|
|
|
|
echo "Cleaned version: $NEW_VERSION"
|
|
|
|
|
|
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
|
|
|
|
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
|
|
- name: Commit version bump and built files
|
|
run: >
|
|
git config user.name "github-actions[bot]"
|
|
|
|
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
|
|
git add package.json dist/
|
|
|
|
# Check if there are changes to commit
|
|
|
|
if git diff --staged --quiet; then
|
|
echo "No changes to commit, skipping commit"
|
|
else
|
|
git commit -m "chore: bump version to ${{ steps.bump.outputs.new_version }} and build action"
|
|
git push
|
|
fi
|
|
- name: Check if release exists and handle tag/release
|
|
id: release_check
|
|
uses: actions/github-script@v7
|
|
with:
|
|
script: >
|
|
const { execSync } = require('child_process');
|
|
|
|
|
|
const tagName = 'v${{ steps.bump.outputs.new_version }}';
|
|
|
|
const tagExists = execSync(`git tag -l "${tagName}"`, { encoding:
|
|
'utf8' }).trim() === tagName;
|
|
|
|
|
|
console.log(`Tag ${tagName} exists: ${tagExists}`);
|
|
|
|
|
|
if (tagExists) {
|
|
// Check if release exists for this tag
|
|
try {
|
|
const release = await github.rest.repos.getReleaseByTag({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
tag: tagName
|
|
});
|
|
console.log(`Release for ${tagName} exists: true`);
|
|
return { tagExists: true, releaseExists: true };
|
|
} catch (error) {
|
|
console.log(`Release for ${tagName} exists: false`);
|
|
return { tagExists: true, releaseExists: false };
|
|
}
|
|
} else {
|
|
console.log(`Tag ${tagName} does not exist`);
|
|
return { tagExists: false, releaseExists: false };
|
|
}
|
|
- name: Bump version again if release exists
|
|
if: steps.release_check.outputs.tagExists == 'true' &&
|
|
steps.release_check.outputs.releaseExists == 'true'
|
|
id: rebump
|
|
run: >
|
|
echo "Release already exists for v${{ steps.bump.outputs.new_version
|
|
}}, bumping version again"
|
|
|
|
NEW_VERSION=$(npm version patch --no-git-tag-version)
|
|
|
|
NEW_VERSION=${NEW_VERSION#v}
|
|
|
|
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
|
|
|
|
echo "Bumped to: $NEW_VERSION"
|
|
- name: Create and push tag
|
|
run: >
|
|
TAG_VERSION="${{ steps.release_check.outputs.releaseExists == 'true'
|
|
&& steps.rebump.outputs.new_version || steps.bump.outputs.new_version
|
|
}}"
|
|
|
|
echo "Creating tag: v$TAG_VERSION"
|
|
|
|
|
|
# Check if tag already exists
|
|
|
|
if git tag -l "v$TAG_VERSION" | grep -q "v$TAG_VERSION"; then
|
|
echo "Tag v$TAG_VERSION already exists, skipping tag creation"
|
|
else
|
|
git tag v$TAG_VERSION
|
|
git push origin v$TAG_VERSION
|
|
fi
|
|
- name: Create Release
|
|
id: create_release
|
|
uses: actions/create-release@v1
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
with:
|
|
tag_name: v${{ steps.release_check.outputs.releaseExists == 'true' &&
|
|
steps.rebump.outputs.new_version || steps.bump.outputs.new_version
|
|
}}
|
|
release_name: Release v${{ steps.release_check.outputs.releaseExists == 'true'
|
|
&& steps.rebump.outputs.new_version ||
|
|
steps.bump.outputs.new_version }}
|
|
draft: false
|
|
prerelease: false
|
|
continue-on-error: true
|
|
- name: Update latest tag
|
|
run: >
|
|
RELEASE_VERSION="${{ steps.release_check.outputs.releaseExists ==
|
|
'true' && steps.rebump.outputs.new_version ||
|
|
steps.bump.outputs.new_version }}"
|
|
|
|
echo "Updating latest tag to point to v$RELEASE_VERSION"
|
|
|
|
|
|
# Delete existing latest tag if it exists
|
|
|
|
if git tag -l "latest" | grep -q "latest"; then
|
|
git tag -d latest
|
|
git push origin :refs/tags/latest || echo "Latest tag didn't exist remotely"
|
|
fi
|
|
|
|
|
|
# Create new latest tag pointing to the current release
|
|
|
|
git tag latest v$RELEASE_VERSION
|
|
|
|
git push origin latest
|
|
|
|
|
|
echo "✅ Latest tag updated to v$RELEASE_VERSION"
|
|
- name: Update action.yml version reference
|
|
run: >
|
|
# Update the action.yml to reference the new version
|
|
|
|
sed -i "s/uses:
|
|
LukeHagar\/usage-statistics@v[0-9]*\.[0-9]*\.[0-9]*/uses:
|
|
LukeHagar\/usage-statistics@v${{ steps.bump.outputs.new_version }}/g"
|
|
.github/workflows/test-action-local.yml
|
|
|
|
git add .github/workflows/test-action-local.yml
|
|
|
|
git commit -m "chore: update test workflow to use v${{
|
|
steps.bump.outputs.new_version }}" || echo "No changes to commit"
|
|
|
|
git push
|
|
- name: Comment on release
|
|
run: >
|
|
echo "## 🎉 Release v${{ steps.bump.outputs.new_version }} Published!"
|
|
|
|
echo ""
|
|
|
|
echo "### What's New:"
|
|
|
|
echo "- Version bumped from ${{ steps.bump.outputs.current_version }}
|
|
to ${{ steps.bump.outputs.new_version }}"
|
|
|
|
echo "- Action built and tested successfully"
|
|
|
|
echo "- Release assets uploaded"
|
|
|
|
echo ""
|
|
|
|
echo "### Usage:"
|
|
|
|
echo "Update your workflows to use:"
|
|
|
|
echo "```yaml"
|
|
|
|
echo "uses: LukeHagar/usage-statistics@v${{
|
|
steps.bump.outputs.new_version }}"
|
|
|
|
echo "```"
|