Skip to content

Bump Version

Bump Version #313

Workflow file for this run

name: Bump Version
on:
workflow_run:
workflows: ["Prepare Version Bump"]
types:
- completed
jobs:
check-previous-workflow:
runs-on: ubuntu-latest
steps:
- name: Check if previous workflow was successful
run: |
if [[ "${{ github.event.workflow_run.conclusion }}" != "success" ]]; then
echo "### ❌ Previous Workflow Failed" >> $GITHUB_STEP_SUMMARY
echo "The triggering workflow did not complete successfully, please review the workflow run details." >> $GITHUB_STEP_SUMMARY
exit 1
else
echo "### ✅ Previous Workflow Succeeded" >> $GITHUB_STEP_SUMMARY
fi
shell: bash
check-token:
runs-on: ubuntu-latest
steps:
- name: Check GH_PUSH_TOKEN
run: |
if [[ -z "${{ secrets.GH_PUSH_TOKEN }}" ]]; then
echo "### ❌ GH_PUSH_TOKEN Error" >> $GITHUB_STEP_SUMMARY
echo "The \`GH_PUSH_TOKEN\` secret is not set, which is required for git operations." >> $GITHUB_STEP_SUMMARY
exit 1
else
echo "### ✅ GH_PUSH_TOKEN Found" >> $GITHUB_STEP_SUMMARY
fi
shell: bash
download-artifact:
needs: [check-previous-workflow, check-token]
runs-on: ubuntu-latest
steps:
# No need to retry this logic, the previous workflow will fail if
# the artifact isn't uploaded
- name: Download version artifact
uses: actions/github-script@v7
env:
WORKFLOW_RUN_ID: ${{ github.event.workflow_run.id }}
with:
script: |
const artifact_name = `version-${process.env.WORKFLOW_RUN_ID}`;
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: process.env.WORKFLOW_RUN_ID,
});
const matchArtifact = artifacts.data.artifacts.find((artifact) =>
artifact.name === artifact_name
);
if (!matchArtifact) {
console.log(`### ❌ Artifact ${artifact_name} is not available`);
process.exit(1);
}
console.log(`Artifact ${artifact_name} with ID ${matchArtifact.id} is available`);
const download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
const fs = require('fs');
fs.writeFileSync('./version-artifact.zip', Buffer.from(download.data));
const unzip = require('child_process').execSync('unzip -j "version-artifact.zip" "version.txt" -d .');
if (!fs.existsSync('version.txt')) {
console.log('### ❌ Failed to extract version.txt');
process.exit(1);
}
- name: Read BUMP_TYPE from version file and set as output
id: read_bump_type
run: |
BUMP_TYPE=$(cat version.txt)
echo "### 📄 Bump Type" >> $GITHUB_STEP_SUMMARY
echo "The BUMP_TYPE set for this run is \`${BUMP_TYPE}\`." >> $GITHUB_STEP_SUMMARY
echo "BUMP_TYPE=${BUMP_TYPE}" >> $GITHUB_OUTPUT
shell: bash
outputs:
BUMP_TYPE: ${{ steps.read_bump_type.outputs.BUMP_TYPE }}
bump-and-push-version:
needs: download-artifact
runs-on: ubuntu-latest
steps:
- name: Check out code with token
uses: actions/checkout@v4
with:
token: ${{ secrets.GH_PUSH_TOKEN }}
- name: Configure Git
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
- name: Bump Version, create tag and commit
id: bump_version
run: |
BUMP_TYPE=${{ needs.download-artifact.outputs.BUMP_TYPE }}
echo "Current BUMP_TYPE: $BUMP_TYPE"
npm version "$BUMP_TYPE" --no-git-tag-version
VERSION=$(node -p "require('./package.json').version")
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
git commit -am "Bump version to $VERSION"
git tag "$VERSION"
git push origin HEAD:main
git push origin "$VERSION"
shell: bash
- name: Version Bump Summary
run: |
VERSION=${{ steps.bump_version.outputs.VERSION }}
echo "### 🚀 Version Bumped" >> $GITHUB_STEP_SUMMARY
echo "The project version has been increased to **$VERSION**." >> $GITHUB_STEP_SUMMARY
echo "This includes a new Git tag and commit for **$VERSION** which has been pushed to the repository." >> $GITHUB_STEP_SUMMARY
echo "Check out the [commit history](https://github.com/${{ github.repository }}/commits/main) to see the changes." >> $GITHUB_STEP_SUMMARY
shell: bash
outputs:
VERSION: ${{ steps.bump_version.outputs.VERSION }}
create-release:
needs: bump-and-push-version
runs-on: ubuntu-latest
steps:
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ needs.bump-and-push-version.outputs.VERSION }}
name: ${{ needs.bump-and-push-version.outputs.VERSION }}
env:
GITHUB_TOKEN: ${{ secrets.GH_PUSH_TOKEN }}
- name: Release Summary
run: |
echo "### 🎉 New Release Created" >> $GITHUB_STEP_SUMMARY
echo "A new release version \`${{ needs.bump-and-push-version.outputs.VERSION }}\` has been published!" >> $GITHUB_STEP_SUMMARY
echo "[View the new release](https://github.com/${{ github.repository }}/releases/tag/v${{ needs.bump-and-push-version.outputs.VERSION }})" >> $GITHUB_STEP_SUMMARY