|
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 | | -# |
12 | 1 | name: Create Release PR |
13 | 2 |
|
14 | 3 | on: |
15 | 4 | workflow_dispatch: |
16 | | - inputs: |
17 | | - versionCode: |
18 | | - description: 'Version Code - [Format: "Major.Minor.Patch", Example: "3.12.1]"' |
19 | | - required: true |
20 | 5 |
|
21 | 6 | jobs: |
22 | | - createRelease_01: |
| 7 | + create_release_01: |
23 | 8 | name: Create Pull Request to master |
24 | 9 | 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 }} |
28 | 12 |
|
29 | 13 | steps: |
30 | 14 | - uses: actions/checkout@v4 |
31 | 15 |
|
| 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 | +
|
32 | 49 | # The changes here will be overwritten, however we need changes, else the PR will be automatically closed by GitHub |
33 | 50 | - name: Dummy Changes to keep PR open |
34 | 51 | run: | |
35 | 52 | echo "Dummy Change" >> .env |
36 | 53 |
|
37 | | - - name: Create Pull Request to main branch |
| 54 | + - name: Create Pull Request to master branch |
38 | 55 | id: cpr-main |
39 | 56 | uses: peter-evans/create-pull-request@v6 |
40 | 57 | with: |
41 | 58 | 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 }} |
43 | 60 | 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' |
45 | 62 | body: | |
46 | | - ### Release v${{ github.event.inputs.versionCode }} |
| 63 | + ### Release v${{ steps.calculate_version.outputs.new_version }} |
47 | 64 |
|
48 | 65 | Release ToDo List: |
49 | 66 | - [X] Bump our version code |
50 | | - - [ ] Update Changelog |
51 | | - - [ ] Create new Release/Tag on GitHub |
| 67 | + - [X] Create new Release/Tag on GitHub |
52 | 68 |
|
53 | 69 | This pull request is autogenerated using GitHub Actions. |
54 | 70 | For more information checkout the action '.github/workflows/create_release_pull_request.yaml' |
55 | 71 | labels: automated, new-release, master |
56 | | - branch: release/v${{ github.event.inputs.versionCode }} |
| 72 | + branch: release/v${{ steps.calculate_version.outputs.new_version }} |
57 | 73 | delete-branch: true |
58 | 74 | reviewers: dmetzner |
59 | 75 | base: master |
60 | 76 |
|
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: |
66 | 78 | name: Create Pull Request to develop |
67 | 79 | 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 }} |
69 | 83 |
|
70 | 84 | steps: |
71 | 85 | - uses: actions/checkout@v4 |
72 | 86 |
|
73 | 87 | - name: Set Version Code |
74 | 88 | 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 }}" |
76 | 97 |
|
77 | 98 | - name: Create Pull Request to develop branch |
78 | 99 | id: cpr-develop |
79 | 100 | uses: peter-evans/create-pull-request@v6 |
80 | 101 | with: |
81 | 102 | 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 }} |
83 | 104 | 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 |
85 | 106 | body: | |
86 | | - ### Release v${{ github.event.inputs.versionCode }} |
| 107 | + ### Release v${{ env.NEW_VERSION }} |
87 | 108 |
|
88 | 109 | Release ToDo List: |
89 | 110 | - [X] Bump our version code |
90 | | - - [ ] Update Changelog |
91 | | - - [ ] Create new Release/Tag on GitHub |
| 111 | + - [X] Create new Release/Tag on GitHub |
92 | 112 |
|
93 | 113 | This pull request is autogenerated using GitHub Actions. |
94 | 114 | For more information checkout the action '.github/workflows/create_release_pull_request.yaml' |
95 | 115 | labels: automated, new-release |
96 | | - branch: release/v${{ github.event.inputs.versionCode }} |
| 116 | + branch: release/v${{ env.NEW_VERSION }} |
97 | 117 | delete-branch: true |
98 | 118 | reviewers: dmetzner |
99 | 119 | base: develop |
100 | 120 |
|
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 |
102 | 137 | 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