Skip to content

New Version PR

New Version PR #46

name: New Version PR
on:
workflow_dispatch:
inputs:
semver_input:
description: "Enter a version (optional)"
required: false
default: ""
jobs:
new_version_pr:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Get the latest tag
id: get_latest_tag
run: |
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
echo "Latest tag: $LATEST_TAG"
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV
- name: Parse the latest tag and bump minor version if no input provided
id: set_version
run: |
if [ "${{ github.event.inputs.semver_input }}" != "" ]; then
NEW_VERSION=${{ github.event.inputs.semver_input }}
else
VERSION_REGEX="^v([0-9]+)\.([0-9]+)\.([0-9]+)$"
echo "Latest tag: $LATEST_TAG"
if [[ $LATEST_TAG =~ $VERSION_REGEX ]]; then
MAJOR="${BASH_REMATCH[1]}"
MINOR="${BASH_REMATCH[2]}"
PATCH="${BASH_REMATCH[3]}"
PATCH=$((PATCH + 1))
NEW_VERSION="v${MAJOR}.${MINOR}.${PATCH}"
else
echo "Latest tag $LATEST_TAG does not follow semantic versioning. Using fallback v0.0.0."
NEW_VERSION="v0.0.0"
fi
fi
echo "New version: $NEW_VERSION"
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
- name: Check if branch already exists
run: |
BRANCH_NAME="release/$NEW_VERSION"
if git ls-remote --exit-code --heads origin "$BRANCH_NAME"; then
echo "Branch $BRANCH_NAME already exists. Exiting."
exit 1
fi
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
- name: Check if tag already exists
run: |
git fetch --tags
if git rev-parse "$NEW_VERSION" >/dev/null 2>&1; then
echo "Tag $NEW_VERSION already exists. Exiting."
exit 1
fi
- name: Create a new branch
run: |
git checkout -b release/$NEW_VERSION
- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true
trust_level: 5
git_config_global: true
- name: Create VERSION file with new version
run: |
git config user.name "GitHub Actions"
git config user.email "[email protected]"
echo "$NEW_VERSION" > VERSION
git add VERSION
git commit -m "Release version $NEW_VERSION"
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.0"
- name: Install GitHub Changelog Generator
run: gem install github_changelog_generator
- name: Generate Changelog
run: |
github_changelog_generator \
-u cvele \
-p playnite_web_mqtt \
--since-tag $(git describe --tags --abbrev=0) \
--output CHANGELOG.md
git add CHANGELOG.md
git commit -m "CHANGELOG.md $NEW_VERSION"
env:
CHANGELOG_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Push new branch
run: |
git push origin release/$NEW_VERSION
- name: Create pull request using GitHub CLI
run: |
gh pr create -B main -H release/$NEW_VERSION \
--title '$NEW_VERSION @sourcery-ai' \
--body '@sourcery-ai summary @sourcery-ai review'
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
- name: Enable auto-merge for the pull request
run: |
pr_number=$(gh pr list --head "release/$NEW_VERSION" --json number --jq '.[0].number')
gh pr merge $pr_number --auto --squash
env:
GITHUB_TOKEN: ${{ secrets.PAT }}