Skip to content

fix(deps): bump commitizen from 3.31.0 to 4.1.1 in /pr-diff-bot #144

fix(deps): bump commitizen from 3.31.0 to 4.1.1 in /pr-diff-bot

fix(deps): bump commitizen from 3.31.0 to 4.1.1 in /pr-diff-bot #144

Workflow file for this run

name: Release
on:
workflow_dispatch:
pull_request:
types: [closed]
push:
branches:
- main
- "feature/*"
- "fix/*"
permissions:
contents: write
pull-requests: write
packages: write
jobs:
check-release:
# Skip if commit is a release commit
if: ${{ !contains(github.event.head_commit.message, 'chore(release):') }}
runs-on: ubuntu-latest
outputs:
should_release: ${{ steps.check.outputs.should_release }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.8"
cache: "pip"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install python-semantic-release==7.34.6
- name: Check if release is needed
id: check
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
# Check if there are changes that warrant a new version
NEW_VERSION=$(semantic-release version --noop)
if [ -z "$NEW_VERSION" ]; then
echo "No version bump needed"
echo "should_release=false" >> $GITHUB_OUTPUT
else
echo "Version bump needed: $NEW_VERSION"
echo "should_release=true" >> $GITHUB_OUTPUT
fi
elif [[ "${{ github.event_name }}" == "push" ]]; then
# Check if there are changes that warrant a new version
NEW_VERSION=$(semantic-release version --noop)
if [ -z "$NEW_VERSION" ]; then
echo "No version bump needed"
echo "should_release=false" >> $GITHUB_OUTPUT
else
echo "Version bump needed: $NEW_VERSION"
echo "should_release=true" >> $GITHUB_OUTPUT
fi
else
echo "should_release=false" >> $GITHUB_OUTPUT
fi
create-release-pr:
needs: check-release
if: needs.check-release.outputs.should_release == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.PAT_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.8"
cache: "pip"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install python-semantic-release==7.34.6
- name: Configure Git
run: |
git config --global user.name "github-actions"
git config --global user.email "[email protected]"
- name: Create Release PR
env:
GH_TOKEN: ${{ secrets.PAT_TOKEN }}
run: |
# Get next version
NEW_VERSION=$(semantic-release version --noop)
if [ -z "$NEW_VERSION" ]; then
echo "No version bump needed"
exit 0
fi
# Determine branch type and target
if [[ "${{ github.ref }}" == refs/heads/feature/* ]]; then
BASE_BRANCH="feature/$(echo ${{ github.ref_name }} | cut -d/ -f2-)"
PRERELEASE_TYPE="alpha"
elif [[ "${{ github.ref }}" == refs/heads/fix/* ]]; then
BASE_BRANCH="fix/$(echo ${{ github.ref_name }} | cut -d/ -f2-)"
PRERELEASE_TYPE="beta"
else
BASE_BRANCH="main"
PRERELEASE_TYPE=""
fi
# Create release branch
BRANCH="release-$NEW_VERSION"
git checkout -b $BRANCH
# Update version and create changelog
if [ -n "$PRERELEASE_TYPE" ]; then
semantic-release version --prerelease $PRERELEASE_TYPE --no-commit
else
semantic-release version --no-commit
fi
# Commit changes
git add .
git commit -m "chore(release): $NEW_VERSION"
git push -f origin $BRANCH
# Create PR
if [ -n "$PRERELEASE_TYPE" ]; then
gh pr create \
--title "chore(prerelease): $NEW_VERSION" \
--body "Automated prerelease PR to update version to $NEW_VERSION" \
--base $BASE_BRANCH \
--head $BRANCH
else
gh pr create \
--title "chore(release): $NEW_VERSION" \
--body "Automated release PR to update version to $NEW_VERSION" \
--base main \
--head $BRANCH
fi
release:
# Only run when a release PR is merged
if: |
github.event_name == 'pull_request' &&
github.event.action == 'closed' &&
github.event.pull_request.merged == true &&
startsWith(github.event.pull_request.head.ref, 'release-')
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_version.outputs.VERSION }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.PAT_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.8"
cache: "pip"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install python-semantic-release==7.34.6
- name: Configure Git
run: |
git config --global user.name "github-actions"
git config --global user.email "[email protected]"
- name: Get version from branch name
id: get_version
run: |
VERSION=$(echo "${{ github.event.pull_request.head.ref }}" | sed 's/release-//')
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
- name: Check and Create Release
env:
GH_TOKEN: ${{ secrets.PAT_TOKEN }}
run: |
# Check if release already exists
if gh release view "v${{ steps.get_version.outputs.VERSION }}" &>/dev/null; then
echo "Release v${{ steps.get_version.outputs.VERSION }} already exists. Skipping release creation."
exit 0
fi
# Create and push tag
git tag -f "v${{ steps.get_version.outputs.VERSION }}" -m "Release v${{ steps.get_version.outputs.VERSION }}"
git push --force origin "v${{ steps.get_version.outputs.VERSION }}"
# Determine if this is a prerelease
if [[ "${{ github.ref }}" == refs/heads/feature/* ]]; then
IS_PRERELEASE="--prerelease"
TARGET_BRANCH="${{ github.ref_name }}"
elif [[ "${{ github.ref }}" == refs/heads/fix/* ]]; then
IS_PRERELEASE="--prerelease"
TARGET_BRANCH="${{ github.ref_name }}"
else
IS_PRERELEASE=""
TARGET_BRANCH="main"
fi
# Create GitHub release
gh release create "v${{ steps.get_version.outputs.VERSION }}" \
--title "Release v${{ steps.get_version.outputs.VERSION }}" \
--notes "See CHANGELOG.md for details" \
--target $TARGET_BRANCH \
$IS_PRERELEASE
publish:
needs: release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get lowercase repository name
id: repo
run: |
REPO="${{ github.repository }}"
echo "name=${REPO,,}" >> $GITHUB_OUTPUT
- name: Build and push
uses: docker/build-push-action@v5
with:
push: true
platforms: linux/amd64,linux/arm64
tags: |
ghcr.io/${{ steps.repo.outputs.name }}:latest
ghcr.io/${{ steps.repo.outputs.name }}:${{ needs.release.outputs.version }}