Skip to content

Commit c34149a

Browse files
authored
Github Action - Create Release and Deploy (#312)
Github Action - Create Release and Deploy (#312)
1 parent e6c2ad8 commit c34149a

File tree

2 files changed

+199
-0
lines changed

2 files changed

+199
-0
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
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

.github/workflows/deploy.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
21+
jobs:
22+
deploy:
23+
runs-on: ubuntu-latest
24+
strategy:
25+
fail-fast: false
26+
matrix:
27+
scala: [ 2.11, 2.12 ]
28+
spark: [ 2, 3 ]
29+
exclude:
30+
- scala: 2.11
31+
spark: 3
32+
steps:
33+
- name: Checkout repository
34+
uses: actions/checkout@v3
35+
with:
36+
fetch-tags: true
37+
fetch-depth: 0 # Fetch all history for all tags and branches
38+
39+
- name: Set up JDK 1.8
40+
uses: actions/setup-java@v1
41+
with:
42+
java-version: '1.8'
43+
44+
- name: Import GPG keys
45+
run: |
46+
echo "${{ secrets.MAVEN_GPG_PRIVATE_KEY }}" | base64 --decode | gpg --batch --import --keyserver https://keyserver.ubuntu.com/
47+
echo "${{ secrets.MAVEN_GPG_PASSPHRASE }}" | gpg --passphrase-fd 0 --batch --pinentry-mode loopback --import-ownertrust <<< .
48+
- name: Create settings.xml
49+
run: |
50+
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\">
51+
<servers>
52+
<server>
53+
<id>ossrh</id>
54+
<username>${{ secrets.OSSRH_USERNAME }}</username>
55+
<password>${{ secrets.OSSRH_TOKEN }}</password>
56+
</server>
57+
</servers>
58+
</settings>" > $HOME/.m2/settings.xml
59+
- name: Build and deploy artifact
60+
env:
61+
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
62+
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
63+
run: |
64+
mvn scala-cross-build:change-version -Pscala-${{ matrix.scala }},spark-${{ matrix.spark }}
65+
mvn -B -e -DskipTests -Dmanual-release -Pdeploy,scala-${{ matrix.scala }},spark-${{ matrix.spark }} -Dossrh clean deploy -Dossrh.username=${{ secrets.OSSRH_USERNAME }} -Dossrh.password=${{ secrets.OSSRH_TOKEN }} -Dgpg.passphrase=${{ secrets.MAVEN_GPG_PASSPHRASE }}

0 commit comments

Comments
 (0)