Skip to content

Create Release PR

Create Release PR #78

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ** Release preparation **
#
# This workflow create 2 pull requests branching from develop into:
# - master
# - develop
#
# The pull request contains:
# - Bump release version -> .env
#
# Additionally, a tag and gitHub release is created for the new release version
# After merging the newly created PRs, start the deployment
#
name: Create Release PR
on:
workflow_dispatch:
jobs:
create_release_01:
name: Create Pull Request to master
runs-on: ubuntu-latest
outputs:
new_version: ${{ steps.calculate_version.outputs.new_version }}
steps:
- uses: actions/checkout@v4
- name: Calculate new version
id: calculate_version
run: |
# Extract the current version from the .env file
current_version=$(grep -oP "(?<=APP_VERSION=')[0-9]{2}\.[0-9]{1,2}\.[0-9]{1,5}" .env)
IFS=' ' read -r major minor patch <<< "$(echo $current_version | awk -F'.' '{print $1, $2, $3}')"
# Now you can use $year, $month, and $day
#echo "current version: $current_version"
#echo "major (year): $major"
#echo "minor (month): $minor"
#echo "patch: $patch"
# Increment the patch version
new_patch=$((patch + 1))
# Get current year and month
current_year=$(date +%y)
current_month=$(date +%-m)
# If the current year or month is different, reset the patch version
if [[ $major -ne $current_year || $minor -ne $current_month ]]; then
new_patch=0
fi
# Formulate the new version
new_version="${current_year}.${current_month}.${new_patch}"
# Output the new version
#echo "new version: $new_version"
echo $new_version
echo "new_version=$new_version" >> $GITHUB_OUTPUT
# The changes here will be overwritten, however we need changes, else the PR will be automatically closed by GitHub
- name: Dummy Changes to keep PR open
run: |
echo "Dummy Change" >> .env
- name: Create Pull Request to master branch
id: cpr-main
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: create_release_01 release v${{ steps.calculate_version.outputs.new_version }}
committer: Catrobot <[email protected]>
title: 'Release v${{ steps.calculate_version.outputs.new_version }} into master'
body: |
### Release v${{ steps.calculate_version.outputs.new_version }}
Release ToDo List:
- [X] Bump our version code
- [X] Create new Release/Tag on GitHub
This pull request is autogenerated using GitHub Actions.
For more information checkout the action '.github/workflows/create_release_pull_request.yaml'
labels: automated, new-release, master
branch: release/v${{ steps.calculate_version.outputs.new_version }}
delete-branch: true
reviewers: dmetzner
base: master
create_release_02:
name: Create Pull Request to develop
runs-on: ubuntu-latest
needs: create_release_01
env:
NEW_VERSION: ${{ needs.create_release_01.outputs.new_version }}
steps:
- uses: actions/checkout@v4
- name: Set Version Code
run: |
echo ${{ env.NEW_VERSION }}
sed -i -E "s/APP_VERSION='[0-9]+\.[0-9]+\.[0-9]+'/APP_VERSION='${{ env.NEW_VERSION }}'/" .env
- name: Commit changes
run: |
git config --global user.name "Catrobot"
git config --global user.email "[email protected]"
git commit -am "Bump version to ${{ env.NEW_VERSION }}"
- name: Create Pull Request to develop branch
id: cpr-develop
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: create_release_01 release v${{ env.NEW_VERSION }}
committer: Catrobot <[email protected]>
title: Release v${{ env.NEW_VERSION }} into develop
body: |
### Release v${{ env.NEW_VERSION }}
Release ToDo List:
- [X] Bump our version code
- [X] Create new Release/Tag on GitHub
This pull request is autogenerated using GitHub Actions.
For more information checkout the action '.github/workflows/create_release_pull_request.yaml'
labels: automated, new-release
branch: release/v${{ env.NEW_VERSION }}
delete-branch: true
reviewers: dmetzner
base: develop
create_release_tag:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: [create_release_01, create_release_02]
env:
NEW_VERSION: ${{ needs.create_release_01.outputs.new_version }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4
- name: Checkout Release Branch
run: |
git fetch
git checkout release/v${{ env.NEW_VERSION }}
- name: Create GitHub Release
run: |
notes=$(git log --pretty=format:"* %s" `git describe --tags --abbrev=0`..HEAD)
gh release create v${{ env.NEW_VERSION }} --target release/v${{ env.NEW_VERSION }} -t "v${{ env.NEW_VERSION }}" -n "$notes"