1+ #
2+ # Copyright 2018 ABSA Group Limited
3+ #
4+ # Licensed under the Apache License, Version 2.0 (the "License");
5+ # you may not use this file except in compliance with the License.
6+ # You may obtain a copy of the License at
7+ # http://www.apache.org/licenses/LICENSE-2.0
8+ #
9+ # Unless required by applicable law or agreed to in writing, software
10+ # distributed under the License is distributed on an "AS IS" BASIS,
11+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ # See the License for the specific language governing permissions and
13+ # limitations under the License.
14+ #
15+
16+ name : Create a new release
17+
18+ on :
19+ workflow_dispatch :
20+ inputs :
21+ release-version :
22+ description : " Define the release version (e.g., v4.7.0)"
23+ required : true
24+ default : " "
25+ development-version :
26+ description : " Define the snapshot version (e.g., v4.7.1)"
27+ required : true
28+ default : " "
29+
30+ jobs :
31+ create-release :
32+ runs-on : ubuntu-latest
33+ steps :
34+ - name : Checkout repository
35+ uses : actions/checkout@v3
36+ with :
37+ fetch-depth : 0 # Fetch all history for all tags and branches
38+
39+ - name : Validate format of received tag
40+ uses : actions/github-script@v7
41+ with :
42+ script : |
43+ const releaseVersion = core.getInput('release-version');
44+ const developmentVersion = core.getInput('development-version');
45+ const regex = /^v[0-9]+\.[0-9]+\.[0-9]+$/;
46+ if (!regex.test(releaseVersion)) {
47+ core.setFailed('Release version does not match the required format "v[0-9]+.[0-9]+.[0-9]+". Valid example: v0.5.2');
48+ return;
49+ }
50+ if (!regex.test(developmentVersion)) {
51+ core.setFailed('Development version does not match the required format "v[0-9]+.[0-9]+.[0-9]+". Valid example: v0.5.2');
52+ return;
53+ }
54+ release-version : ${{ github.event.inputs.release-version }}
55+ development-version : ${{ github.event.inputs.development-version }}
56+
57+ - name : Define semantic version number
58+ id : semantic_version
59+ run : |
60+ RELEASE_VERSION="${{ github.event.inputs.release-version }}"
61+ RELEASE_VERSION_WITHOUT_V=${RELEASE_VERSION#v}
62+
63+ DEVELOPMENT_VERSION="${{ github.event.inputs.development-version }}"
64+ DEVELOPMENT_VERSION_WITHOUT_V=${DEVELOPMENT_VERSION#v}
65+
66+ echo "RELEASE_VERSION_WITHOUT_V=${RELEASE_VERSION_WITHOUT_V}" >> "${GITHUB_ENV}"
67+ echo "DEVELOPMENT_VERSION_WITHOUT_V=${DEVELOPMENT_VERSION_WITHOUT_V}" >> "${GITHUB_ENV}"
68+ - name : Configure Git
69+ run : |
70+ git config --global user.name "${{ github.actor }}"
71+ git config --global user.email "${{ github.actor }}@users.noreply.github.com"
72+ - name : Create release branch
73+ run : |
74+ git checkout -b release/${RELEASE_VERSION_WITHOUT_V}
75+ git push origin release/${RELEASE_VERSION_WITHOUT_V}
76+ - name : Set up JDK 1.8
77+ uses : actions/setup-java@v1
78+ with :
79+ java-version : ' 1.8'
80+
81+ - name : Set Maven project version, create tag
82+ run : |
83+ git pull origin release/${RELEASE_VERSION_WITHOUT_V}
84+ mvn versions:set -DnewVersion=${RELEASE_VERSION_WITHOUT_V} --no-transfer-progress
85+ mvn versions:commit
86+ git commit -am "Set project version to ${RELEASE_VERSION_WITHOUT_V}"
87+ git push origin release/${RELEASE_VERSION_WITHOUT_V}
88+ - name : Create tag
89+ run : |
90+ git tag ${{ github.event.inputs.release-version }}
91+ git push origin ${{ github.event.inputs.release-version }}
92+ - name : Set next development version
93+ run : |
94+ # Assumes semantic versioning and increments the minor version. Adjust the awk command as needed for different versioning schemes.
95+ NEXT_VERSION=$(echo ${DEVELOPMENT_VERSION_WITHOUT_V} | awk -F. '{print $1"."$2"."$3"-SNAPSHOT"}')
96+ mvn versions:set -DnewVersion=$NEXT_VERSION --no-transfer-progress
97+ mvn versions:commit
98+ git commit -am "Set project version to $NEXT_VERSION"
99+ git push origin release/${RELEASE_VERSION_WITHOUT_V}
100+ - name : Get Default Branch
101+ id : get_default_branch
102+ uses : actions/github-script@v7
103+ with :
104+ script : |
105+ const response = await github.rest.repos.get({
106+ owner: context.repo.owner,
107+ repo: context.repo.repo
108+ });
109+ return response.data.default_branch;
110+ - name : Create Pull Request
111+ uses : actions/github-script@v7
112+ with :
113+ github-token : ${{ secrets.GITHUB_TOKEN }}
114+ script : |
115+ const branch = `release/${process.env.RELEASE_VERSION_WITHOUT_V}`;
116+ await github.rest.pulls.create({
117+ owner: context.repo.owner,
118+ repo: context.repo.repo,
119+ title: 'Release ${{ github.event.inputs.release-version }}',
120+ head: branch,
121+ base: ${{ steps.get_default_branch.outputs.result }},
122+ body: 'Pull request to merge release ${{ github.event.inputs.release-version }} into default branch',
123+ draft: false
124+ });
125+ - name : Create Draft Release
126+ uses : softprops/action-gh-release@v1
127+ env :
128+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
129+ with :
130+ name : ${{ github.event.inputs.release-version }}
131+ body : ${{ steps.generate_release_notes.outputs.releaseNotes }}
132+ tag_name : ${{ github.event.inputs.release-version }}
133+ draft : true
134+ prerelease : false
0 commit comments