Skip to content

Commit f32504b

Browse files
authored
Add semi-automated tagging and generating GH Release draft to CICD (#37)
1 parent a9e5246 commit f32504b

File tree

2 files changed

+98
-4
lines changed

2 files changed

+98
-4
lines changed

.github/workflows/release_draft.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#
2+
# Copyright 2023 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+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
name: Release - create draft release
18+
on:
19+
workflow_dispatch:
20+
inputs:
21+
tagName:
22+
description: 'Name of git tag to be created, and then draft release created. Syntax: "v[0-9]+.[0-9]+.[0-9]+".'
23+
required: true
24+
25+
jobs:
26+
tag:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: actions/checkout@v4
30+
with:
31+
fetch-depth: 0
32+
- name: Validate format of received tag
33+
uses: actions/github-script@v7
34+
with:
35+
script: |
36+
const newTag = core.getInput('tag-name');
37+
const regex = /^v[0-9]+\.[0-9]+\.[0-9]+$/;
38+
39+
if (!regex.test(newTag)) {
40+
core.setFailed('Tag does not match the required format "v[0-9]+.[0-9]+.[0-9]+"');
41+
return;
42+
}
43+
tag-name: ${{ github.event.inputs.tagName }}
44+
- name: Create and push tag
45+
uses: actions/github-script@v7
46+
with:
47+
script: |
48+
const tag = core.getInput('tag-name')
49+
const ref = `refs/tags/${tag}`;
50+
const sha = context.sha; // The SHA of the commit to tag
51+
52+
await github.rest.git.createRef({
53+
owner: context.repo.owner,
54+
repo: context.repo.repo,
55+
ref: ref,
56+
sha: sha
57+
});
58+
59+
console.log(`Tag created: ${tag}`);
60+
github-token: ${{ secrets.GITHUB_TOKEN }}
61+
tag-name: ${{ github.event.inputs.tagName }}
62+
63+
release:
64+
needs: tag
65+
runs-on: ubuntu-latest
66+
steps:
67+
- uses: actions/checkout@v4
68+
with:
69+
fetch-depth: 0
70+
ref: refs/tags/${{ github.event.inputs.tagName }}
71+
- name: Generate release notes
72+
id: generate_release_notes
73+
uses: AbsaOSS/[email protected]
74+
env:
75+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
76+
with:
77+
chapters: |
78+
[
79+
{"title": "Breaking Changes 💥", "label": "breaking-change"},
80+
{"title": "New Features 🎉", "label": "enhancement"},
81+
{"title": "Bugfixes 🛠", "label": "bug"}
82+
]
83+
warnings: true
84+
- name: Create draft release
85+
uses: softprops/action-gh-release@v1
86+
env:
87+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
88+
with:
89+
name: ${{ github.event.inputs.tagName }}
90+
body: ${{ steps.generate_release_notes.outputs.releaseNotes }}
91+
draft: true
92+
prerelease: false

.github/workflows/release.yml renamed to .github/workflows/release_publish.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
# limitations under the License.
1515
#
1616

17-
name: Release
17+
name: Release - publish artifacts
1818
on:
19-
workflow_dispatch:
19+
release:
20+
types: [released]
2021

2122
jobs:
2223
publish:
@@ -27,8 +28,9 @@ jobs:
2728
fetch-depth: 0
2829
- uses: olafurpg/setup-scala@v14
2930
with:
30-
java-version: "[email protected]"
31-
- run: sbt ci-release
31+
java-version: "[email protected]"
32+
- name: Build and release to Sonatype and Maven Central
33+
run: sbt ci-release
3234
env:
3335
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
3436
PGP_SECRET: ${{ secrets.PGP_SECRET }}

0 commit comments

Comments
 (0)