-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Daniel Metzner <[email protected]>
- Loading branch information
Showing
1 changed file
with
87 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +1,149 @@ | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
# ** Release preparation ** | ||
# | ||
# This workflow create 2 pull requests branching from develop into: | ||
# - master | ||
# - develop | ||
# | ||
# The pull request contains: | ||
# - Bump release version -> .env | ||
# - .. | ||
# | ||
name: Create Release PR | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
versionCode: | ||
description: 'Version Code - [Format: "Major.Minor.Patch", Example: "3.12.1]"' | ||
required: true | ||
|
||
jobs: | ||
createRelease_01: | ||
create_release_01: | ||
name: Create Pull Request to master | ||
runs-on: ubuntu-latest | ||
|
||
# Only create release branch in case the version number is valid | ||
if: '[[ ${{ github.event.inputs.versionCode }} =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]' | ||
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 main branch | ||
- name: Create Pull Request to master branch | ||
id: cpr-main | ||
uses: peter-evans/create-pull-request@v6 | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
commit-message: Prepare release v${{ github.event.inputs.versionCode }} | ||
commit-message: create_release_01 release v${{ steps.calculate_version.outputs.new_version }} | ||
committer: Catrobot <[email protected]> | ||
title: 'Release v${{ github.event.inputs.versionCode }} into master' | ||
title: 'Release v${{ steps.calculate_version.outputs.new_version }} into master' | ||
body: | | ||
### Release v${{ github.event.inputs.versionCode }} | ||
### Release v${{ steps.calculate_version.outputs.new_version }} | ||
Release ToDo List: | ||
- [X] Bump our version code | ||
- [ ] Update Changelog | ||
- [ ] Create new Release/Tag on GitHub | ||
- [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${{ github.event.inputs.versionCode }} | ||
branch: release/v${{ steps.calculate_version.outputs.new_version }} | ||
delete-branch: true | ||
reviewers: dmetzner | ||
base: master | ||
|
||
createRelease_02: | ||
# | ||
# We have to define all of our modification in this job since the create-PR-Action uses force push and | ||
# overwrites all previous changes to the code base. | ||
# | ||
create_release_02: | ||
name: Create Pull Request to develop | ||
runs-on: ubuntu-latest | ||
needs: createRelease_01 | ||
needs: create_release_01 | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set Version Code | ||
env: | ||
NEW_VERSION: ${{ needs.create_release_01.outputs.new_version }} | ||
run: | | ||
sed -i -E "s/APP_VERSION='[0-9]+\.[0-9]+\.[0-9]+'/APP_VERSION='${{ github.event.inputs.versionCode }}'/" .env | ||
echo $NEW_VERSION | ||
sed -i -E "s/APP_VERSION='[0-9]+\.[0-9]+\.[0-9]+'/APP_VERSION='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 $NEW_VERSION" | ||
- name: Create Pull Request to develop branch | ||
id: cpr-develop | ||
uses: peter-evans/create-pull-request@v6 | ||
env: | ||
NEW_VERSION: ${{ needs.create_release_01.outputs.new_version }} | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
commit-message: Prepare release v${{ github.event.inputs.versionCode }} | ||
commit-message: create_release_01 release v${{ env.NEW_VERSION }} | ||
committer: Catrobot <[email protected]> | ||
title: 'Release v${{ github.event.inputs.versionCode }} into develop' | ||
title: "Release v$NEW_VERSION into develop" | ||
body: | | ||
### Release v${{ github.event.inputs.versionCode }} | ||
### Release v${{ env.NEW_VERSION }} | ||
Release ToDo List: | ||
- [X] Bump our version code | ||
- [ ] Update Changelog | ||
- [ ] Create new Release/Tag on GitHub | ||
- [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${{ github.event.inputs.versionCode }} | ||
branch: release/v${{ env.NEW_VERSION }} | ||
delete-branch: true | ||
reviewers: dmetzner | ||
base: develop | ||
|
||
- name: Check outputs | ||
create_release_tag: | ||
name: Create GitHub Release | ||
runs-on: ubuntu-latest | ||
needs: [create_release_01, create_release_02] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Checkout Release Branch | ||
env: | ||
NEW_VERSION: ${{ needs.create_release_01.outputs.new_version }} | ||
run: | | ||
git fetch | ||
git checkout release/v${{ env.NEW_VERSION }} | ||
- name: Generate Release Notes | ||
id: generate_notes | ||
run: | | ||
notes=$(git log --pretty=format:"* %s" `git describe --tags --abbrev=0`..HEAD) | ||
echo "release_notes=$notes" >> $GITHUB_OUTPUT | ||
- name: Create GitHub Release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
NEW_VERSION: ${{ needs.create_release_01.outputs.new_version }} | ||
run: | | ||
echo "Pull Request Number - ${{ env.PULL_REQUEST_NUMBER }}" | ||
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}" | ||
notes=$(git log --pretty=format:"* %s" `git describe --tags --abbrev=0`..HEAD) | ||
gh release create v$NEW_VERSION --target release/v$NEW_VERSION -t "v$NEW_VERSION" -n "$notes" |