mirror of
https://github.com/LukeHagar/usage-statistics.git
synced 2025-12-06 04:21:55 +00:00
chore: add auto-release workflow for automated versioning and release management
This commit is contained in:
@@ -1,38 +1,31 @@
|
|||||||
name: Auto Release
|
name: Auto Release
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
paths-ignore:
|
paths-ignore:
|
||||||
- '**.md'
|
- "**.md"
|
||||||
- '.github/workflows/auto-release.yml'
|
- .github/workflows/auto-release.yml
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
auto-release:
|
auto-release:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: '20'
|
node-version: "20"
|
||||||
cache: 'npm'
|
cache: npm
|
||||||
|
|
||||||
- name: Setup Bun
|
- name: Setup Bun
|
||||||
uses: oven-sh/setup-bun@v1
|
uses: oven-sh/setup-bun@v1
|
||||||
with:
|
with:
|
||||||
bun-version: latest
|
bun-version: latest
|
||||||
|
|
||||||
- name: Install system dependencies for skia-canvas
|
- name: Install system dependencies for skia-canvas
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
@@ -49,94 +42,123 @@ jobs:
|
|||||||
make \
|
make \
|
||||||
g++ \
|
g++ \
|
||||||
libstdc++6
|
libstdc++6
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: bun install
|
run: bun install
|
||||||
|
|
||||||
- name: Rebuild native modules
|
- name: Rebuild native modules
|
||||||
env:
|
env:
|
||||||
NODE_ENV: production
|
NODE_ENV: production
|
||||||
SKIA_CANVAS_USE_SYSTEM_LIBRARIES: 1
|
SKIA_CANVAS_USE_SYSTEM_LIBRARIES: 1
|
||||||
run: |
|
run: >
|
||||||
cd node_modules/skia-canvas && npm rebuild
|
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')"
|
|
||||||
|
|
||||||
|
cd ../..
|
||||||
|
|
||||||
|
node -e "console.log('Testing skia-canvas import...');
|
||||||
|
require('skia-canvas'); console.log('✅ skia-canvas loaded
|
||||||
|
successfully')"
|
||||||
- name: Build action
|
- name: Build action
|
||||||
run: bun run build
|
run: bun run build
|
||||||
|
|
||||||
- name: Verify build
|
- name: Verify build
|
||||||
run: |
|
run: >
|
||||||
echo "Checking built files..."
|
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); })"
|
|
||||||
|
|
||||||
|
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: Get commit history
|
- name: Get commit history
|
||||||
id: commits
|
id: commits
|
||||||
uses: actions/github-script@v7
|
uses: actions/github-script@v7
|
||||||
with:
|
with:
|
||||||
script: |
|
script: >
|
||||||
const { execSync } = require('child_process');
|
const { execSync } = require('child_process');
|
||||||
|
|
||||||
|
|
||||||
// Get commits since last tag
|
// Get commits since last tag
|
||||||
const lastTag = execSync('git describe --tags --abbrev=0 2>/dev/null || echo ""', { encoding: 'utf8' }).trim();
|
|
||||||
const commits = execSync(`git log ${lastTag ? lastTag + '..HEAD' : '--oneline'} --pretty=format:"%s"`, { encoding: 'utf8' }).trim().split('\n');
|
const lastTag = execSync('git describe --tags --abbrev=0 2>/dev/null
|
||||||
|
|| echo ""', { encoding: 'utf8' }).trim();
|
||||||
|
|
||||||
|
const commits = execSync(`git log ${lastTag ? lastTag + '..HEAD' :
|
||||||
|
'--oneline'} --pretty=format:"%s"`, { encoding: 'utf8'
|
||||||
|
}).trim().split('\n');
|
||||||
|
|
||||||
|
|
||||||
console.log('Commits since last tag:', commits);
|
console.log('Commits since last tag:', commits);
|
||||||
|
|
||||||
return { commits: commits.join('\n') };
|
|
||||||
|
|
||||||
|
return { commits: commits.join('\n') };
|
||||||
- name: Determine version bump
|
- name: Determine version bump
|
||||||
id: version
|
id: version
|
||||||
run: |
|
run: |
|
||||||
# Always bump patch version for auto-releases
|
# Always bump patch version for auto-releases
|
||||||
echo "bump_type=patch" >> $GITHUB_OUTPUT
|
echo "bump_type=patch" >> $GITHUB_OUTPUT
|
||||||
echo "Bump type: ${{ steps.version.outputs.bump_type }}"
|
echo "Bump type: ${{ steps.version.outputs.bump_type }}"
|
||||||
|
|
||||||
- name: Bump version
|
- name: Bump version
|
||||||
id: bump
|
id: bump
|
||||||
run: |
|
run: >
|
||||||
# Get current version
|
# Get current version
|
||||||
|
|
||||||
CURRENT_VERSION=$(node -p "require('./package.json').version")
|
CURRENT_VERSION=$(node -p "require('./package.json').version")
|
||||||
|
|
||||||
echo "Current version: $CURRENT_VERSION"
|
echo "Current version: $CURRENT_VERSION"
|
||||||
|
|
||||||
|
|
||||||
# Bump version
|
# Bump version
|
||||||
NEW_VERSION=$(npm version ${{ steps.version.outputs.bump_type }} --no-git-tag-version)
|
|
||||||
|
NEW_VERSION=$(npm version ${{ steps.version.outputs.bump_type }}
|
||||||
|
--no-git-tag-version)
|
||||||
|
|
||||||
echo "New version: $NEW_VERSION"
|
echo "New version: $NEW_VERSION"
|
||||||
|
|
||||||
|
|
||||||
# Remove 'v' prefix if present
|
# Remove 'v' prefix if present
|
||||||
|
|
||||||
NEW_VERSION=${NEW_VERSION#v}
|
NEW_VERSION=${NEW_VERSION#v}
|
||||||
|
|
||||||
echo "Cleaned version: $NEW_VERSION"
|
echo "Cleaned version: $NEW_VERSION"
|
||||||
|
|
||||||
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
|
|
||||||
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
|
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
|
||||||
- name: Commit version bump and built files
|
- name: Commit version bump and built files
|
||||||
run: |
|
run: >
|
||||||
git config user.name "github-actions[bot]"
|
git config user.name "github-actions[bot]"
|
||||||
|
|
||||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||||
|
|
||||||
git add package.json dist/
|
git add package.json dist/
|
||||||
|
|
||||||
# Check if there are changes to commit
|
# Check if there are changes to commit
|
||||||
|
|
||||||
if git diff --staged --quiet; then
|
if git diff --staged --quiet; then
|
||||||
echo "No changes to commit, skipping commit"
|
echo "No changes to commit, skipping commit"
|
||||||
else
|
else
|
||||||
git commit -m "chore: bump version to ${{ steps.bump.outputs.new_version }} and build action"
|
git commit -m "chore: bump version to ${{ steps.bump.outputs.new_version }} and build action"
|
||||||
git push
|
git push
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Check if release exists and handle tag/release
|
- name: Check if release exists and handle tag/release
|
||||||
id: release_check
|
id: release_check
|
||||||
uses: actions/github-script@v7
|
uses: actions/github-script@v7
|
||||||
with:
|
with:
|
||||||
script: |
|
script: >
|
||||||
const { execSync } = require('child_process');
|
const { execSync } = require('child_process');
|
||||||
|
|
||||||
|
|
||||||
const tagName = 'v${{ steps.bump.outputs.new_version }}';
|
const tagName = 'v${{ steps.bump.outputs.new_version }}';
|
||||||
const tagExists = execSync(`git tag -l "${tagName}"`, { encoding: 'utf8' }).trim() === tagName;
|
|
||||||
|
const tagExists = execSync(`git tag -l "${tagName}"`, { encoding:
|
||||||
|
'utf8' }).trim() === tagName;
|
||||||
|
|
||||||
|
|
||||||
console.log(`Tag ${tagName} exists: ${tagExists}`);
|
console.log(`Tag ${tagName} exists: ${tagExists}`);
|
||||||
|
|
||||||
|
|
||||||
if (tagExists) {
|
if (tagExists) {
|
||||||
// Check if release exists for this tag
|
// Check if release exists for this tag
|
||||||
try {
|
try {
|
||||||
@@ -155,49 +177,98 @@ jobs:
|
|||||||
console.log(`Tag ${tagName} does not exist`);
|
console.log(`Tag ${tagName} does not exist`);
|
||||||
return { tagExists: false, releaseExists: false };
|
return { tagExists: false, releaseExists: false };
|
||||||
}
|
}
|
||||||
|
|
||||||
- name: Bump version again if release exists
|
- name: Bump version again if release exists
|
||||||
if: steps.release_check.outputs.tagExists == 'true' && steps.release_check.outputs.releaseExists == 'true'
|
if: steps.release_check.outputs.tagExists == 'true' &&
|
||||||
|
steps.release_check.outputs.releaseExists == 'true'
|
||||||
id: rebump
|
id: rebump
|
||||||
run: |
|
run: >
|
||||||
echo "Release already exists for v${{ steps.bump.outputs.new_version }}, bumping version again"
|
echo "Release already exists for v${{ steps.bump.outputs.new_version
|
||||||
NEW_VERSION=$(npm version patch --no-git-tag-version)
|
}}, bumping version again"
|
||||||
NEW_VERSION=${NEW_VERSION#v}
|
|
||||||
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
|
|
||||||
echo "Bumped to: $NEW_VERSION"
|
|
||||||
|
|
||||||
|
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
|
- name: Create and push tag
|
||||||
run: |
|
run: >
|
||||||
TAG_VERSION="${{ steps.release_check.outputs.releaseExists == 'true' && steps.rebump.outputs.new_version || steps.bump.outputs.new_version }}"
|
TAG_VERSION="${{ steps.release_check.outputs.releaseExists == 'true'
|
||||||
|
&& steps.rebump.outputs.new_version || steps.bump.outputs.new_version
|
||||||
|
}}"
|
||||||
|
|
||||||
echo "Creating tag: v$TAG_VERSION"
|
echo "Creating tag: v$TAG_VERSION"
|
||||||
|
|
||||||
|
|
||||||
# Check if tag already exists
|
# Check if tag already exists
|
||||||
|
|
||||||
if git tag -l "v$TAG_VERSION" | grep -q "v$TAG_VERSION"; then
|
if git tag -l "v$TAG_VERSION" | grep -q "v$TAG_VERSION"; then
|
||||||
echo "Tag v$TAG_VERSION already exists, skipping tag creation"
|
echo "Tag v$TAG_VERSION already exists, skipping tag creation"
|
||||||
else
|
else
|
||||||
git tag v$TAG_VERSION
|
git tag v$TAG_VERSION
|
||||||
git push origin v$TAG_VERSION
|
git push origin v$TAG_VERSION
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Create Release
|
- name: Create Release
|
||||||
id: create_release
|
id: create_release
|
||||||
uses: actions/create-release@v1
|
uses: actions/create-release@v1
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
with:
|
with:
|
||||||
tag_name: v${{ steps.release_check.outputs.releaseExists == 'true' && steps.rebump.outputs.new_version || steps.bump.outputs.new_version }}
|
tag_name: v${{ steps.release_check.outputs.releaseExists == 'true' &&
|
||||||
release_name: Release v${{ steps.release_check.outputs.releaseExists == 'true' && steps.rebump.outputs.new_version || steps.bump.outputs.new_version }}
|
steps.rebump.outputs.new_version || steps.bump.outputs.new_version
|
||||||
body: |
|
}}
|
||||||
## 🎉 Release 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 }}
|
||||||
|
body: >
|
||||||
|
## 🎉 Release v${{ steps.release_check.outputs.releaseExists ==
|
||||||
|
'true' && steps.rebump.outputs.new_version ||
|
||||||
|
steps.bump.outputs.new_version }}
|
||||||
|
|
||||||
|
|
||||||
### Changes:
|
### Changes:
|
||||||
|
|
||||||
${{ steps.commits.outputs.commits }}
|
${{ steps.commits.outputs.commits }}
|
||||||
|
|
||||||
|
|
||||||
### Usage:
|
### Usage:
|
||||||
|
|
||||||
Update your workflows to use:
|
Update your workflows to use:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
uses: LukeHagar/usage-statistics@v${{ steps.release_check.outputs.releaseExists == 'true' && steps.rebump.outputs.new_version || steps.bump.outputs.new_version }}
|
|
||||||
|
uses: LukeHagar/usage-statistics@v${{
|
||||||
|
steps.release_check.outputs.releaseExists == 'true' &&
|
||||||
|
steps.rebump.outputs.new_version || steps.bump.outputs.new_version
|
||||||
|
}}
|
||||||
|
|
||||||
```
|
```
|
||||||
draft: false
|
draft: false
|
||||||
prerelease: false
|
prerelease: false
|
||||||
continue-on-error: true
|
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"
|
||||||
@@ -1,43 +1,36 @@
|
|||||||
name: Release
|
name: Release
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
version:
|
version:
|
||||||
description: 'Version to release (patch, minor, major)'
|
description: Version to release (patch, minor, major)
|
||||||
required: true
|
required: true
|
||||||
default: 'patch'
|
default: patch
|
||||||
type: choice
|
type: choice
|
||||||
options:
|
options:
|
||||||
- patch
|
- patch
|
||||||
- minor
|
- minor
|
||||||
- major
|
- major
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
release:
|
release:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: '20'
|
node-version: "20"
|
||||||
cache: 'npm'
|
cache: npm
|
||||||
|
|
||||||
- name: Setup Bun
|
- name: Setup Bun
|
||||||
uses: oven-sh/setup-bun@v1
|
uses: oven-sh/setup-bun@v1
|
||||||
with:
|
with:
|
||||||
bun-version: latest
|
bun-version: latest
|
||||||
|
|
||||||
- name: Install system dependencies for skia-canvas
|
- name: Install system dependencies for skia-canvas
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
@@ -54,72 +47,95 @@ jobs:
|
|||||||
make \
|
make \
|
||||||
g++ \
|
g++ \
|
||||||
libstdc++6
|
libstdc++6
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: bun install
|
run: bun install
|
||||||
|
|
||||||
- name: Rebuild native modules
|
- name: Rebuild native modules
|
||||||
env:
|
env:
|
||||||
NODE_ENV: production
|
NODE_ENV: production
|
||||||
SKIA_CANVAS_USE_SYSTEM_LIBRARIES: 1
|
SKIA_CANVAS_USE_SYSTEM_LIBRARIES: 1
|
||||||
run: |
|
run: >
|
||||||
cd node_modules/skia-canvas && npm rebuild
|
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')"
|
|
||||||
|
|
||||||
|
cd ../..
|
||||||
|
|
||||||
|
node -e "console.log('Testing skia-canvas import...');
|
||||||
|
require('skia-canvas'); console.log('✅ skia-canvas loaded
|
||||||
|
successfully')"
|
||||||
- name: Build action
|
- name: Build action
|
||||||
run: bun run build
|
run: bun run build
|
||||||
|
|
||||||
- name: Verify build
|
- name: Verify build
|
||||||
run: |
|
run: >
|
||||||
echo "Checking built files..."
|
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); })"
|
|
||||||
|
|
||||||
|
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
|
- name: Bump version
|
||||||
id: bump
|
id: bump
|
||||||
run: |
|
run: >
|
||||||
# Get current version
|
# Get current version
|
||||||
|
|
||||||
CURRENT_VERSION=$(node -p "require('./package.json').version")
|
CURRENT_VERSION=$(node -p "require('./package.json').version")
|
||||||
|
|
||||||
echo "Current version: $CURRENT_VERSION"
|
echo "Current version: $CURRENT_VERSION"
|
||||||
|
|
||||||
|
|
||||||
# Bump version
|
# Bump version
|
||||||
NEW_VERSION=$(npm version ${{ github.event.inputs.version }} --no-git-tag-version)
|
|
||||||
|
NEW_VERSION=$(npm version ${{ github.event.inputs.version }}
|
||||||
|
--no-git-tag-version)
|
||||||
|
|
||||||
echo "New version: $NEW_VERSION"
|
echo "New version: $NEW_VERSION"
|
||||||
|
|
||||||
|
|
||||||
# Remove 'v' prefix if present
|
# Remove 'v' prefix if present
|
||||||
|
|
||||||
NEW_VERSION=${NEW_VERSION#v}
|
NEW_VERSION=${NEW_VERSION#v}
|
||||||
|
|
||||||
echo "Cleaned version: $NEW_VERSION"
|
echo "Cleaned version: $NEW_VERSION"
|
||||||
|
|
||||||
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
|
|
||||||
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
|
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
|
||||||
- name: Commit version bump and built files
|
- name: Commit version bump and built files
|
||||||
run: |
|
run: >
|
||||||
git config user.name "github-actions[bot]"
|
git config user.name "github-actions[bot]"
|
||||||
|
|
||||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||||
|
|
||||||
git add package.json dist/
|
git add package.json dist/
|
||||||
|
|
||||||
# Check if there are changes to commit
|
# Check if there are changes to commit
|
||||||
|
|
||||||
if git diff --staged --quiet; then
|
if git diff --staged --quiet; then
|
||||||
echo "No changes to commit, skipping commit"
|
echo "No changes to commit, skipping commit"
|
||||||
else
|
else
|
||||||
git commit -m "chore: bump version to ${{ steps.bump.outputs.new_version }} and build action"
|
git commit -m "chore: bump version to ${{ steps.bump.outputs.new_version }} and build action"
|
||||||
git push
|
git push
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Check if release exists and handle tag/release
|
- name: Check if release exists and handle tag/release
|
||||||
id: release_check
|
id: release_check
|
||||||
uses: actions/github-script@v7
|
uses: actions/github-script@v7
|
||||||
with:
|
with:
|
||||||
script: |
|
script: >
|
||||||
const { execSync } = require('child_process');
|
const { execSync } = require('child_process');
|
||||||
|
|
||||||
|
|
||||||
const tagName = 'v${{ steps.bump.outputs.new_version }}';
|
const tagName = 'v${{ steps.bump.outputs.new_version }}';
|
||||||
const tagExists = execSync(`git tag -l "${tagName}"`, { encoding: 'utf8' }).trim() === tagName;
|
|
||||||
|
const tagExists = execSync(`git tag -l "${tagName}"`, { encoding:
|
||||||
|
'utf8' }).trim() === tagName;
|
||||||
|
|
||||||
|
|
||||||
console.log(`Tag ${tagName} exists: ${tagExists}`);
|
console.log(`Tag ${tagName} exists: ${tagExists}`);
|
||||||
|
|
||||||
|
|
||||||
if (tagExists) {
|
if (tagExists) {
|
||||||
// Check if release exists for this tag
|
// Check if release exists for this tag
|
||||||
try {
|
try {
|
||||||
@@ -138,61 +154,117 @@ jobs:
|
|||||||
console.log(`Tag ${tagName} does not exist`);
|
console.log(`Tag ${tagName} does not exist`);
|
||||||
return { tagExists: false, releaseExists: false };
|
return { tagExists: false, releaseExists: false };
|
||||||
}
|
}
|
||||||
|
|
||||||
- name: Bump version again if release exists
|
- name: Bump version again if release exists
|
||||||
if: steps.release_check.outputs.tagExists == 'true' && steps.release_check.outputs.releaseExists == 'true'
|
if: steps.release_check.outputs.tagExists == 'true' &&
|
||||||
|
steps.release_check.outputs.releaseExists == 'true'
|
||||||
id: rebump
|
id: rebump
|
||||||
run: |
|
run: >
|
||||||
echo "Release already exists for v${{ steps.bump.outputs.new_version }}, bumping version again"
|
echo "Release already exists for v${{ steps.bump.outputs.new_version
|
||||||
NEW_VERSION=$(npm version patch --no-git-tag-version)
|
}}, bumping version again"
|
||||||
NEW_VERSION=${NEW_VERSION#v}
|
|
||||||
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
|
|
||||||
echo "Bumped to: $NEW_VERSION"
|
|
||||||
|
|
||||||
|
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
|
- name: Create and push tag
|
||||||
run: |
|
run: >
|
||||||
TAG_VERSION="${{ steps.release_check.outputs.releaseExists == 'true' && steps.rebump.outputs.new_version || steps.bump.outputs.new_version }}"
|
TAG_VERSION="${{ steps.release_check.outputs.releaseExists == 'true'
|
||||||
|
&& steps.rebump.outputs.new_version || steps.bump.outputs.new_version
|
||||||
|
}}"
|
||||||
|
|
||||||
echo "Creating tag: v$TAG_VERSION"
|
echo "Creating tag: v$TAG_VERSION"
|
||||||
|
|
||||||
|
|
||||||
# Check if tag already exists
|
# Check if tag already exists
|
||||||
|
|
||||||
if git tag -l "v$TAG_VERSION" | grep -q "v$TAG_VERSION"; then
|
if git tag -l "v$TAG_VERSION" | grep -q "v$TAG_VERSION"; then
|
||||||
echo "Tag v$TAG_VERSION already exists, skipping tag creation"
|
echo "Tag v$TAG_VERSION already exists, skipping tag creation"
|
||||||
else
|
else
|
||||||
git tag v$TAG_VERSION
|
git tag v$TAG_VERSION
|
||||||
git push origin v$TAG_VERSION
|
git push origin v$TAG_VERSION
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Create Release
|
- name: Create Release
|
||||||
id: create_release
|
id: create_release
|
||||||
uses: actions/create-release@v1
|
uses: actions/create-release@v1
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
with:
|
with:
|
||||||
tag_name: v${{ steps.release_check.outputs.releaseExists == 'true' && steps.rebump.outputs.new_version || steps.bump.outputs.new_version }}
|
tag_name: v${{ steps.release_check.outputs.releaseExists == 'true' &&
|
||||||
release_name: Release v${{ steps.release_check.outputs.releaseExists == 'true' && steps.rebump.outputs.new_version || steps.bump.outputs.new_version }}
|
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
|
draft: false
|
||||||
prerelease: false
|
prerelease: false
|
||||||
continue-on-error: true
|
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
|
- name: Update action.yml version reference
|
||||||
run: |
|
run: >
|
||||||
# Update the action.yml to reference the new version
|
# 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
|
|
||||||
|
|
||||||
|
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
|
- name: Comment on release
|
||||||
run: |
|
run: >
|
||||||
echo "## 🎉 Release v${{ steps.bump.outputs.new_version }} Published!"
|
echo "## 🎉 Release v${{ steps.bump.outputs.new_version }} Published!"
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
echo "### What's New:"
|
echo "### What's New:"
|
||||||
echo "- Version bumped from ${{ steps.bump.outputs.current_version }} to ${{ steps.bump.outputs.new_version }}"
|
|
||||||
|
echo "- Version bumped from ${{ steps.bump.outputs.current_version }}
|
||||||
|
to ${{ steps.bump.outputs.new_version }}"
|
||||||
|
|
||||||
echo "- Action built and tested successfully"
|
echo "- Action built and tested successfully"
|
||||||
|
|
||||||
echo "- Release assets uploaded"
|
echo "- Release assets uploaded"
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
echo "### Usage:"
|
echo "### Usage:"
|
||||||
|
|
||||||
echo "Update your workflows to use:"
|
echo "Update your workflows to use:"
|
||||||
|
|
||||||
echo "```yaml"
|
echo "```yaml"
|
||||||
echo "uses: LukeHagar/usage-statistics@v${{ steps.bump.outputs.new_version }}"
|
|
||||||
|
echo "uses: LukeHagar/usage-statistics@v${{
|
||||||
|
steps.bump.outputs.new_version }}"
|
||||||
|
|
||||||
echo "```"
|
echo "```"
|
||||||
@@ -97,7 +97,7 @@ export async function createGitHubReleaseChart(platformMetrics: MetricResult[],
|
|||||||
function groupByReleaseCumulative(releaseRange: { day: string, downloads: number, tagName?: string }[]){
|
function groupByReleaseCumulative(releaseRange: { day: string, downloads: number, tagName?: string }[]){
|
||||||
const releases: Record<string, {downloads: number, tagName: string}> = {}
|
const releases: Record<string, {downloads: number, tagName: string}> = {}
|
||||||
for (const release of releaseRange.sort((a, b) => {
|
for (const release of releaseRange.sort((a, b) => {
|
||||||
return semver.compare(a.tagName || '0.0.0', b.tagName || '0.0.0')
|
return semver.compare((a.tagName || '0.0.0').trim(), (b.tagName || '0.0.0').trim())
|
||||||
})) {
|
})) {
|
||||||
if (!release.tagName) {
|
if (!release.tagName) {
|
||||||
continue
|
continue
|
||||||
@@ -112,7 +112,7 @@ function groupByReleaseCumulative(releaseRange: { day: string, downloads: number
|
|||||||
let cumulativeDownloads = 0
|
let cumulativeDownloads = 0
|
||||||
|
|
||||||
for (const release of Object.keys(releases).sort((a, b) => {
|
for (const release of Object.keys(releases).sort((a, b) => {
|
||||||
return semver.compare(a, b)
|
return semver.compare(a.trim(), b.trim())
|
||||||
})) {
|
})) {
|
||||||
cumulativeDownloads += releases[release].downloads
|
cumulativeDownloads += releases[release].downloads
|
||||||
releases[release].downloads = cumulativeDownloads
|
releases[release].downloads = cumulativeDownloads
|
||||||
@@ -126,7 +126,7 @@ export async function createDownloadsPerReleaseChart(metric: MetricResult, outpu
|
|||||||
const svgOutputPath = `${outputPath}/${metric.name.replace('/', '-')}-release-downloads.svg`
|
const svgOutputPath = `${outputPath}/${metric.name.replace('/', '-')}-release-downloads.svg`
|
||||||
|
|
||||||
const sortedReleases = downloadsRange.sort((a: { tagName?: string }, b: { tagName?: string }) => {
|
const sortedReleases = downloadsRange.sort((a: { tagName?: string }, b: { tagName?: string }) => {
|
||||||
return semver.compare(a.tagName || '0.0.0', b.tagName || '0.0.0')
|
return semver.compare((a.tagName || '0.0.0').trim(), (b.tagName || '0.0.0').trim())
|
||||||
})
|
})
|
||||||
|
|
||||||
const canvas = new Canvas(1000, 800);
|
const canvas = new Canvas(1000, 800);
|
||||||
@@ -191,7 +191,7 @@ export async function createCumulativeDownloadsChart(metric: MetricResult, outpu
|
|||||||
|
|
||||||
// Sort months chronologically
|
// Sort months chronologically
|
||||||
const semVerSortedReleases = Object.keys(groupedDownloads).sort((a, b) => {
|
const semVerSortedReleases = Object.keys(groupedDownloads).sort((a, b) => {
|
||||||
return semver.compare(a, b)
|
return semver.compare(a.trim(), b.trim())
|
||||||
})
|
})
|
||||||
|
|
||||||
const canvas = new Canvas(1000, 800);
|
const canvas = new Canvas(1000, 800);
|
||||||
@@ -259,7 +259,7 @@ export async function createReleaseDownloadsChart(metric: MetricResult, outputPa
|
|||||||
.filter((release: { tagName?: string; downloads: number; day: string }) => release.tagName && release.downloads > 0)
|
.filter((release: { tagName?: string; downloads: number; day: string }) => release.tagName && release.downloads > 0)
|
||||||
.sort((a: { downloads: number }, b: { downloads: number }) => b.downloads - a.downloads)
|
.sort((a: { downloads: number }, b: { downloads: number }) => b.downloads - a.downloads)
|
||||||
.slice(0, 10) // Show top 10 releases
|
.slice(0, 10) // Show top 10 releases
|
||||||
.sort((a: { tagName?: string }, b: { tagName?: string }) => semver.compare(a.tagName || '0.0.0', b.tagName || '0.0.0'))
|
.sort((a: { tagName?: string }, b: { tagName?: string }) => semver.compare((a.tagName || '0.0.0').trim(), (b.tagName || '0.0.0').trim()))
|
||||||
|
|
||||||
if (sortedReleases.length === 0) {
|
if (sortedReleases.length === 0) {
|
||||||
// Return empty chart if no releases
|
// Return empty chart if no releases
|
||||||
|
|||||||
Reference in New Issue
Block a user