Skip to content

Commit a853379

Browse files
committed
New release workflow
Signed-off-by: Daniel Metzner <daniel.metzner@niceshops.com>
1 parent 75ebb49 commit a853379

File tree

1 file changed

+77
-42
lines changed

1 file changed

+77
-42
lines changed
Lines changed: 77 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,139 @@
1-
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2-
# ** Release preparation **
3-
#
4-
# This workflow create 2 pull requests branching from develop into:
5-
# - master
6-
# - develop
7-
#
8-
# The pull request contains:
9-
# - Bump release version -> .env
10-
# - ..
11-
#
121
name: Create Release PR
132

143
on:
154
workflow_dispatch:
16-
inputs:
17-
versionCode:
18-
description: 'Version Code - [Format: "Major.Minor.Patch", Example: "3.12.1]"'
19-
required: true
205

216
jobs:
22-
createRelease_01:
7+
create_release_01:
238
name: Create Pull Request to master
249
runs-on: ubuntu-latest
25-
26-
# Only create release branch in case the version number is valid
27-
if: '[[ ${{ github.event.inputs.versionCode }} =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]'
10+
outputs:
11+
new_version: ${{ steps.calculate_version.outputs.new_version }}
2812

2913
steps:
3014
- uses: actions/checkout@v4
3115

16+
- name: Calculate new version
17+
id: calculate_version
18+
run: |
19+
# Extract the current version from the .env file
20+
current_version=$(grep -oP "(?<=APP_VERSION=')[0-9]{2}\.[0-9]{1,2}\.[0-9]{1,5}" .env)
21+
IFS=' ' read -r major minor patch <<< "$(echo $current_version | awk -F'.' '{print $1, $2, $3}')"
22+
23+
# Now you can use $year, $month, and $day
24+
#echo "current version: $current_version"
25+
#echo "major (year): $major"
26+
#echo "minor (month): $minor"
27+
#echo "patch: $patch"
28+
29+
# Increment the patch version
30+
new_patch=$((patch + 1))
31+
32+
# Get current year and month
33+
current_year=$(date +%y)
34+
current_month=$(date +%-m)
35+
36+
# If the current year or month is different, reset the patch version
37+
if [[ $major -ne $current_year || $minor -ne $current_month ]]; then
38+
new_patch=0
39+
fi
40+
41+
# Formulate the new version
42+
new_version="${current_year}.${current_month}.${new_patch}"
43+
44+
# Output the new version
45+
#echo "new version: $new_version"
46+
echo $new_version
47+
echo "new_version=$new_version" >> $GITHUB_OUTPUT
48+
3249
# The changes here will be overwritten, however we need changes, else the PR will be automatically closed by GitHub
3350
- name: Dummy Changes to keep PR open
3451
run: |
3552
echo "Dummy Change" >> .env
3653
37-
- name: Create Pull Request to main branch
54+
- name: Create Pull Request to master branch
3855
id: cpr-main
3956
uses: peter-evans/create-pull-request@v6
4057
with:
4158
token: ${{ secrets.GITHUB_TOKEN }}
42-
commit-message: Prepare release v${{ github.event.inputs.versionCode }}
59+
commit-message: create_release_01 release v${{ steps.calculate_version.outputs.new_version }}
4360
committer: Catrobot <Catrobot@catroweb.github.com>
44-
title: 'Release v${{ github.event.inputs.versionCode }} into master'
61+
title: 'Release v${{ steps.calculate_version.outputs.new_version }} into master'
4562
body: |
46-
### Release v${{ github.event.inputs.versionCode }}
63+
### Release v${{ steps.calculate_version.outputs.new_version }}
4764
4865
Release ToDo List:
4966
- [X] Bump our version code
50-
- [ ] Update Changelog
51-
- [ ] Create new Release/Tag on GitHub
67+
- [X] Create new Release/Tag on GitHub
5268
5369
This pull request is autogenerated using GitHub Actions.
5470
For more information checkout the action '.github/workflows/create_release_pull_request.yaml'
5571
labels: automated, new-release, master
56-
branch: release/v${{ github.event.inputs.versionCode }}
72+
branch: release/v${{ steps.calculate_version.outputs.new_version }}
5773
delete-branch: true
5874
reviewers: dmetzner
5975
base: master
6076

61-
createRelease_02:
62-
#
63-
# We have to define all of our modification in this job since the create-PR-Action uses force push and
64-
# overwrites all previous changes to the code base.
65-
#
77+
create_release_02:
6678
name: Create Pull Request to develop
6779
runs-on: ubuntu-latest
68-
needs: createRelease_01
80+
needs: create_release_01
81+
env:
82+
NEW_VERSION: ${{ needs.create_release_01.outputs.new_version }}
6983

7084
steps:
7185
- uses: actions/checkout@v4
7286

7387
- name: Set Version Code
7488
run: |
75-
sed -i -E "s/APP_VERSION='[0-9]+\.[0-9]+\.[0-9]+'/APP_VERSION='${{ github.event.inputs.versionCode }}'/" .env
89+
echo ${{ env.NEW_VERSION }}
90+
sed -i -E "s/APP_VERSION='[0-9]+\.[0-9]+\.[0-9]+'/APP_VERSION='${{ env.NEW_VERSION }}'/" .env
91+
92+
- name: Commit changes
93+
run: |
94+
git config --global user.name "Catrobot"
95+
git config --global user.email "Catrobot@catroweb.github.com"
96+
git commit -am "Bump version to ${{ env.NEW_VERSION }}"
7697
7798
- name: Create Pull Request to develop branch
7899
id: cpr-develop
79100
uses: peter-evans/create-pull-request@v6
80101
with:
81102
token: ${{ secrets.GITHUB_TOKEN }}
82-
commit-message: Prepare release v${{ github.event.inputs.versionCode }}
103+
commit-message: create_release_01 release v${{ env.NEW_VERSION }}
83104
committer: Catrobot <Catrobot@catroweb.github.com>
84-
title: 'Release v${{ github.event.inputs.versionCode }} into develop'
105+
title: Release v${{ env.NEW_VERSION }} into develop
85106
body: |
86-
### Release v${{ github.event.inputs.versionCode }}
107+
### Release v${{ env.NEW_VERSION }}
87108
88109
Release ToDo List:
89110
- [X] Bump our version code
90-
- [ ] Update Changelog
91-
- [ ] Create new Release/Tag on GitHub
111+
- [X] Create new Release/Tag on GitHub
92112
93113
This pull request is autogenerated using GitHub Actions.
94114
For more information checkout the action '.github/workflows/create_release_pull_request.yaml'
95115
labels: automated, new-release
96-
branch: release/v${{ github.event.inputs.versionCode }}
116+
branch: release/v${{ env.NEW_VERSION }}
97117
delete-branch: true
98118
reviewers: dmetzner
99119
base: develop
100120

101-
- name: Check outputs
121+
create_release_tag:
122+
name: Create GitHub Release
123+
runs-on: ubuntu-latest
124+
needs: [create_release_01, create_release_02]
125+
env:
126+
NEW_VERSION: ${{ needs.create_release_01.outputs.new_version }}
127+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
128+
steps:
129+
- uses: actions/checkout@v4
130+
131+
- name: Checkout Release Branch
132+
run: |
133+
git fetch
134+
git checkout release/v${{ env.NEW_VERSION }}
135+
136+
- name: Create GitHub Release
102137
run: |
103-
echo "Pull Request Number - ${{ env.PULL_REQUEST_NUMBER }}"
104-
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
138+
notes=$(git log --pretty=format:"* %s" `git describe --tags --abbrev=0`..HEAD)
139+
gh release create v${{ env.NEW_VERSION }} --target release/v${{ env.NEW_VERSION }} -t "v${{ env.NEW_VERSION }}" -n "$notes"

0 commit comments

Comments
 (0)