Skip to content

Commit caee37a

Browse files
authored
Github release, deploy actions (#839)
1 parent f71e4af commit caee37a

File tree

2 files changed

+228
-0
lines changed

2 files changed

+228
-0
lines changed

.github/workflows/create_release.yml

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
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., v0.5.2)"
23+
required: true
24+
default: ""
25+
development-version:
26+
description: "Define the snapshot version (e.g., v0.5.2)"
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+
47+
if (!regex.test(releaseVersion)) {
48+
core.setFailed('Release version does not match the required format "v[0-9]+.[0-9]+.[0-9]+". Valid example: v0.5.2');
49+
return;
50+
}
51+
if (!regex.test(developmentVersion)) {
52+
core.setFailed('Development version does not match the required format "v[0-9]+.[0-9]+.[0-9]+". Valid example: v0.5.2');
53+
return;
54+
}
55+
release-version: ${{ github.event.inputs.release-version }}
56+
development-version: ${{ github.event.inputs.development-version }}
57+
58+
- name: Define semantic version number
59+
id: semantic_version
60+
run: |
61+
RELEASE_VERSION="${{ github.event.inputs.release-version }}"
62+
RELEASE_VERSION_WITHOUT_V=${RELEASE_VERSION#v}
63+
64+
DEVELOPMENT_VERSION="${{ github.event.inputs.development-version }}"
65+
DEVELOPMENT_VERSION_WITHOUT_V=${DEVELOPMENT_VERSION#v}
66+
67+
echo "RELEASE_VERSION_WITHOUT_V=${RELEASE_VERSION_WITHOUT_V}" >> "${GITHUB_ENV}"
68+
echo "DEVELOPMENT_VERSION_WITHOUT_V=${DEVELOPMENT_VERSION_WITHOUT_V}" >> "${GITHUB_ENV}"
69+
70+
- name: Configure Git
71+
run: |
72+
git config --global user.name "${{ github.actor }}"
73+
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
74+
75+
- name: Create release branch
76+
run: |
77+
git checkout -b release/${RELEASE_VERSION_WITHOUT_V}
78+
git push origin release/${RELEASE_VERSION_WITHOUT_V}
79+
80+
- name: Set up JDK 1.8
81+
uses: actions/setup-java@v1
82+
with:
83+
java-version: '1.8'
84+
85+
- name: Set Maven project version, create tag
86+
run: |
87+
git pull origin release/${RELEASE_VERSION_WITHOUT_V}
88+
mvn versions:set -DnewVersion=${RELEASE_VERSION_WITHOUT_V} --no-transfer-progress
89+
mvn versions:commit
90+
git commit -am "Set project version to ${RELEASE_VERSION_WITHOUT_V}"
91+
git push origin release/${RELEASE_VERSION_WITHOUT_V}
92+
93+
- name: Create tag
94+
run: |
95+
git tag ${{ github.event.inputs.release-version }}
96+
git push origin ${{ github.event.inputs.release-version }}
97+
98+
- name: Set next development version
99+
run: |
100+
# Assumes semantic versioning and increments the minor version. Adjust the awk command as needed for different versioning schemes.
101+
NEXT_VERSION=$(echo ${DEVELOPMENT_VERSION_WITHOUT_V} | awk -F. '{print $1"."$2"."$3"-SNAPSHOT"}')
102+
mvn versions:set -DnewVersion=$NEXT_VERSION --no-transfer-progress
103+
mvn versions:commit
104+
git commit -am "Set project version to $NEXT_VERSION"
105+
git push origin release/${RELEASE_VERSION_WITHOUT_V}
106+
107+
- name: Get Default Branch
108+
id: get_default_branch
109+
uses: actions/github-script@v7
110+
with:
111+
script: |
112+
const response = await github.rest.repos.get({
113+
owner: context.repo.owner,
114+
repo: context.repo.repo
115+
});
116+
return response.data.default_branch;
117+
118+
- name: Create Pull Request
119+
uses: actions/github-script@v7
120+
with:
121+
github-token: ${{ secrets.GITHUB_TOKEN }}
122+
script: |
123+
const branch = `release/${process.env.RELEASE_VERSION_WITHOUT_V}`;
124+
await github.rest.pulls.create({
125+
owner: context.repo.owner,
126+
repo: context.repo.repo,
127+
title: 'Release ${{ github.event.inputs.release-version }}',
128+
head: branch,
129+
base: ${{ steps.get_default_branch.outputs.result }},
130+
body: 'Pull request to merge release ${{ github.event.inputs.release-version }} into default branch',
131+
draft: false
132+
});
133+
134+
- name: Create Draft Release
135+
uses: softprops/action-gh-release@v1
136+
env:
137+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
138+
with:
139+
name: ${{ github.event.inputs.release-version }}
140+
body: ${{ steps.generate_release_notes.outputs.releaseNotes }}
141+
tag_name: ${{ github.event.inputs.release-version }}
142+
draft: true
143+
prerelease: false

.github/workflows/deploy.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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: Deploy
17+
18+
on:
19+
workflow_dispatch:
20+
inputs:
21+
tag-name:
22+
description: 'Tag for deployment (e.g., v0.5.2)'
23+
required: true
24+
25+
jobs:
26+
deploy:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- name: Checkout repository
30+
uses: actions/checkout@v3
31+
with:
32+
fetch-depth: 0 # Fetch all history for all tags and branches
33+
34+
- name: Validate format of received tag
35+
uses: actions/github-script@v7
36+
with:
37+
script: |
38+
const newTag = core.getInput('tag-name');
39+
const regex = /^v[0-9]+\.[0-9]+\.[0-9]+$/;
40+
41+
if (!regex.test(newTag)) {
42+
core.setFailed('Tag does not match the required format "v[0-9]+.[0-9]+.[0-9]+". Valid example: v0.5.2');
43+
return;
44+
}
45+
tag-name: ${{ github.event.inputs.tag-name }}
46+
47+
- name: Define semantic version number
48+
id: semantic_version
49+
run: |
50+
TAG_NAME="${{ github.event.inputs.tag-name }}"
51+
VERSION=${TAG_NAME#v}
52+
echo "VERSION=${VERSION}" >> "${GITHUB_ENV}"
53+
54+
- name: Checkout to tag
55+
run: |
56+
git checkout ${{ github.event.inputs.tag-name }}
57+
58+
- name: Set up JDK 1.8
59+
uses: actions/setup-java@v1
60+
with:
61+
java-version: '1.8'
62+
63+
- name: Import GPG keys
64+
run: |
65+
echo "${{ secrets.MAVEN_GPG_PRIVATE_KEY }}" | base64 --decode | gpg --batch --import --keyserver https://keyserver.ubuntu.com/
66+
echo "${{ secrets.MAVEN_GPG_PASSPHRASE }}" | gpg --passphrase-fd 0 --batch --pinentry-mode loopback --import-ownertrust <<< .
67+
68+
69+
- name: Create settings.xml
70+
run: |
71+
echo "<settings xmlns=\"http://maven.apache.org/SETTINGS/1.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd\">
72+
<servers>
73+
<server>
74+
<id>ossrh</id>
75+
<username>${{ secrets.OSSRH_USERNAME }}</username>
76+
<password>${{ secrets.OSSRH_TOKEN }}</password>
77+
</server>
78+
</servers>
79+
</settings>" > $HOME/.m2/settings.xml
80+
81+
- name: Build and deploy artifact
82+
env:
83+
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
84+
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
85+
run: mvn -B -e -DskipTests -Dmanual-release -Ddeploy -Dossrh clean deploy -Dossrh.username=${{ secrets.OSSRH_USERNAME }} -Dossrh.password=${{ secrets.OSSRH_TOKEN }} -Dgpg.passphrase=${{ secrets.MAVEN_GPG_PASSPHRASE }}

0 commit comments

Comments
 (0)