Skip to content

Release

Release #9

Workflow file for this run

---
name: Release
on:
workflow_dispatch:
permissions:
contents: write
issues: write
pull-requests: write
jobs:
github_release:
name: Github Release
runs-on: ubuntu-24.04
outputs:
new_release_version: ${{ steps.semantic.outputs.new_release_version }}
new_release_published: ${{ steps.semantic.outputs.new_release_published }}
steps:
- uses: actions/create-github-app-token@v2.0.6
id: app-token
with:
app-id: ${{ secrets.BOT_GH_APP_ID }}
private-key: ${{ secrets.BOT_GH_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: |
operator
- name: Get GitHub App User ID
id: get-user-id
run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
- name: Set up Git
run: |
git config --global user.name '${{ steps.app-token.outputs.app-slug }}[bot]'
git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com'
git config --global commit.gpgsign false
git config --global commit.signoff true
- name: Checkout code
uses: actions/checkout@v4.2.2
with:
ref: ${{ github.ref }}
fetch-depth: 0
persist-credentials: false
token: ${{ steps.app-token.outputs.token }}
- name: Set up Node.js
uses: actions/setup-node@v4.4.0
with:
node-version: 22
- name: Install semantic release and plugins
run: |
npm install -g semantic-release@v24.2.5 \
conventional-changelog-cli \
conventional-changelog-conventionalcommits \
@semantic-release/changelog \
@semantic-release/exec \
@semantic-release/git \
@semantic-release/github
- name: Create a release if needed
id: semantic
env:
CI: true
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
GIT_AUTHOR_NAME: "GitHub Actions Bot"
GIT_AUTHOR_EMAIL: ${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com
GIT_COMMITTER_NAME: "GitHub Actions Bot"
GIT_COMMITTER_EMAIL: ${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com
run: |
# Create first release if not exists using gh cli - Initial Release Version 0.1.0
# This is an HACK because semantic release doesn't support versions under 1.0.0
# But if we already have a release then it respects it and start to increment from there
if ! gh release view v0.1.0 >/dev/null 2>&1; then
gh release create v0.1.0 --title "Initial Release" --notes "Initial Release" --target main
fi
# Run semantic-release in dry-run first to capture version
DRY_OUTPUT=$(semantic-release --dry-run 2>&1 || true)
# Check if there are no changes
if $(echo "$DRY_OUTPUT" | grep -q "no new version is released"); then
echo "No new release needed"
echo "new_release_published=false" >> $GITHUB_OUTPUT
exit 0
fi
# Extract version from dry run output
VERSION=$(echo "$DRY_OUTPUT" | grep -o "The next release version is [0-9]\+\.[0-9]\+\.[0-9]\+\(-rc\.[0-9]\+\)\?" | cut -d ' ' -f6)
if [ -z "$VERSION" ]; then
echo "Error: Could not determine version"
echo "Output: $DRY_OUTPUT"
exit 1
fi
echo "new_release_version=$VERSION" >> $GITHUB_OUTPUT
# Run actual release
if semantic-release; then
echo "Successfully released version $VERSION"
echo "new_release_published=true" >> $GITHUB_OUTPUT
else
echo "Release failed"
exit 1
fi