π Bump Version #17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
# trunk-ignore-all(checkov/CKV_GHA_7): workflow_dispatch must be configurable | |
name: π Bump Version | |
on: | |
workflow_dispatch: | |
inputs: | |
version_type: | |
description: Type of version bump | |
required: true | |
type: choice | |
options: | |
- auto | |
- major | |
- minor | |
- patch | |
permissions: | |
contents: write | |
jobs: | |
bump-version: | |
name: π Bump ${{ github.event.inputs.version_type }} version | |
runs-on: ubuntu-latest | |
steps: | |
- name: β¬οΈ Checkout repository | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
with: | |
fetch-depth: 0 | |
- name: ποΈ Setup Node.js | |
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 | |
with: | |
node-version: 20 | |
- name: π Bump version with Nyx (auto) | |
if: github.event.inputs.version_type == 'auto' | |
id: nyx | |
uses: mooltiverse/nyx@34bf14b64bd12a0ea51d92b841a6f82dc1dfb814 # v3.1.3 | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
command: infer | |
preset: extended | |
releaseLenient: true | |
- name: π Update package.json (auto) | |
if: ${{ github.event.inputs.version_type == 'auto' && (steps.nyx.outputs.newVersion == 'true') }} | |
id: auto-bump | |
run: | | |
npm version ${{ steps.nyx.outputs.version }} --no-git-tag-version | |
echo "version=${{ steps.nyx.outputs.version }}" >> "${GITHUB_OUTPUT}" | |
echo "bump_type=${{ steps.nyx.outputs.bump }}" >> "${GITHUB_OUTPUT}" | |
- name: π Manual version bump | |
if: github.event.inputs.version_type != 'auto' | |
id: manual-bump | |
run: | | |
npm version ${{ github.event.inputs.version_type }} --no-git-tag-version | |
echo "version=$(node -p "require('./package.json').version")" >> "${GITHUB_OUTPUT}" | |
echo "bump_type=${{ github.event.inputs.version_type }}" >> "${GITHUB_OUTPUT}" | |
- name: π Create signed commit | |
# Run if manual bump or if auto and new version was found | |
if: ${{ github.event.inputs.version_type != 'auto' || (steps.nyx.outputs.newVersion == 'true') }} | |
run: | | |
# Set variables based on the bump type | |
if [ "${{ github.event.inputs.version_type }}" == "auto" ]; then | |
VERSION="${{ steps.auto-bump.outputs.version }}" | |
BUMP_TYPE="${{ steps.auto-bump.outputs.bump_type }}" | |
else | |
VERSION="${{ steps.manual-bump.outputs.version }}" | |
BUMP_TYPE="${{ steps.manual-bump.outputs.bump_type }}" | |
fi | |
# Create a new commit using GitHub API (GraphQL) to get signed commit | |
gh api graphql \ | |
-f query="mutation(\$repo:String!,\$branch:String!,\$message:String!,\$path:String!,\$content:Base64String!,\$oid:GitObjectID!){ | |
createCommitOnBranch(input:{ | |
branch:{repositoryNameWithOwner:\$repo,branchName:\$branch}, | |
message:{headline:\$message}, | |
fileChanges:{additions:[{path:\$path,contents:\$content}]}, | |
expectedHeadOid:\$oid | |
}){commit{url}} | |
}" \ | |
-f repo="${{ github.repository }}" \ | |
-f branch="main" \ | |
-f message="π: bump ${BUMP_TYPE} version to ${VERSION}" \ | |
-f path="package.json" \ | |
-f content="$(base64 -w 0 package.json)" \ | |
-f oid="$(git rev-parse HEAD)" | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |