release.ymlā¢4.76 kB
name: Create Release
on:
workflow_dispatch:
inputs:
version_bump:
description: 'Version bump type'
required: true
type: choice
options:
- patch
- minor
- major
default: 'patch'
release_name:
description: 'Release name (optional - leave blank for auto-generated)'
required: false
type: string
permissions:
contents: write
pull-requests: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.RELEASE_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Get current version
id: current_version
run: |
CURRENT_VERSION=$(node -p "require('./package.json').version")
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "Current version: $CURRENT_VERSION"
- name: Calculate new version
id: new_version
run: |
CURRENT_VERSION="${{ steps.current_version.outputs.version }}"
IFS='.' read -ra VERSION_PARTS <<< "$CURRENT_VERSION"
MAJOR="${VERSION_PARTS[0]}"
MINOR="${VERSION_PARTS[1]}"
PATCH="${VERSION_PARTS[2]}"
case "${{ inputs.version_bump }}" in
major)
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
;;
minor)
MINOR=$((MINOR + 1))
PATCH=0
;;
patch)
PATCH=$((PATCH + 1))
;;
esac
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "New version: $NEW_VERSION"
- name: Update package.json version
run: |
npm version ${{ steps.new_version.outputs.version }} --no-git-tag-version
- name: Update package-lock.json
run: |
npm install --package-lock-only
- name: Commit version bump
run: |
set -e
git add package.json package-lock.json
git commit -m "chore: bump version to ${{ steps.new_version.outputs.version }}"
git push
- name: Create Git tag
run: |
set -e
git tag -a "v${{ steps.new_version.outputs.version }}" -m "Release v${{ steps.new_version.outputs.version }}"
git push origin "v${{ steps.new_version.outputs.version }}"
- name: Determine release name
id: release_name
run: |
if [ -z "${{ inputs.release_name }}" ]; then
echo "name=v${{ steps.new_version.outputs.version }}" >> $GITHUB_OUTPUT
else
echo "name=${{ inputs.release_name }}" >> $GITHUB_OUTPUT
fi
- name: Create GitHub Release
uses: actions/github-script@v7
with:
script: |
const tagName = 'v${{ steps.new_version.outputs.version }}';
// Check if release already exists
try {
await github.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: tagName
});
core.info(`Release ${tagName} already exists. Skipping creation.`);
return;
} catch (error) {
if (error.status !== 404) {
throw error;
}
}
// Create the release
await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: tagName,
name: '${{ steps.release_name.outputs.name }}',
draft: false,
prerelease: false,
generate_release_notes: true
});
- name: Summary
run: |
echo "## Release Created Successfully! š" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Version:** v${{ steps.new_version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "**Bump Type:** ${{ inputs.version_bump }}" >> $GITHUB_STEP_SUMMARY
echo "**Previous Version:** v${{ steps.current_version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Release URL:** https://github.com/${{ github.repository }}/releases/tag/v${{ steps.new_version.outputs.version }}" >> $GITHUB_STEP_SUMMARY