Skip to content

Commit 401426e

Browse files
committed
Add gitHub workflow to create and push tag whenever we update VERSION_NAME
Trigger publish workflow if the tag creation is successful
1 parent ca52d93 commit 401426e

File tree

2 files changed

+64
-8
lines changed

2 files changed

+64
-8
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Create and push new tag
2+
#Create and push a new tag when we update the VERSION_NAME on gradle.properties file
3+
4+
on:
5+
push:
6+
branches: [ main ]
7+
paths: [ 'gradle.properties' ]
8+
9+
workflow_dispatch:
10+
11+
jobs:
12+
tag:
13+
runs-on: ubuntu-latest
14+
outputs:
15+
tag_created: ${{ steps.check_tag.outputs.exists == 'false' }}
16+
version: ${{ steps.get_version.outputs.version }}
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Get VERSION_NAME
21+
id: get_version
22+
run: |
23+
VERSION=$(grep VERSION_NAME gradle.properties | cut -d'=' -f2 | tr -d '[:space:]')
24+
echo "version=$VERSION" >> $GITHUB_OUTPUT
25+
26+
- name: Check if tag already exists
27+
id: check_tag
28+
run: |
29+
TAG="v${{ steps.get_version.outputs.version }}"
30+
if gh api repos/${{ github.repository }}/git/ref/tags/$TAG 2>/dev/null; then
31+
echo "exists=true" >> $GITHUB_OUTPUT
32+
echo "Tag $TAG already exists"
33+
else
34+
echo "exists=false" >> $GITHUB_OUTPUT
35+
echo "Tag $TAG does not exist, will create it"
36+
fi
37+
env:
38+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39+
40+
- name: Create and push tag
41+
if: steps.check_tag.outputs.exists == 'false'
42+
run: |
43+
git config user.name "github-actions[bot]"
44+
git config user.email "github-actions[bot]@users.noreply.github.com"
45+
git tag "${{ steps.get_version.outputs.version }}"
46+
git push origin "${{ steps.get_version.outputs.version }}"
47+
env:
48+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49+
50+
publish:
51+
needs: tag
52+
if: needs.tag.outputs.tag_created == 'true'
53+
uses: ./.github/workflows/publish.yml
54+
with:
55+
version: ${{ needs.tag.outputs.version }}

.github/workflows/publish.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
name: Publish to Maven Central
22

33
on:
4-
push:
5-
tags:
6-
- '*' # This triggers the workflow on any tag push'
7-
# This allows you to trigger the workflow manually from the Actions tab in GitHub
8-
workflow_dispatch:
4+
workflow_call:
5+
inputs:
6+
version:
7+
required: true
8+
type: string
99

1010
jobs:
1111
publish-to-central:
@@ -15,6 +15,8 @@ jobs:
1515
steps:
1616
- name: Checkout code
1717
uses: actions/checkout@v4
18+
with:
19+
ref: ${{ inputs.version }}
1820

1921
- name: Set up JDK 17
2022
uses: actions/setup-java@v4
@@ -45,12 +47,11 @@ jobs:
4547
run: ./gradlew publish --no-configuration-cache --info
4648

4749
- name: Create Github Release
48-
if: startsWith(github.ref, 'refs/tags/')
4950
uses: actions/create-release@v1
5051
env:
5152
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5253
with:
53-
tag_name: ${{ github.ref_name }}
54-
release_name: Release ${{ github.ref_name }}
54+
tag_name: ${{ inputs.version }}
55+
release_name: Release ${{ inputs.version }}
5556
draft: false
5657
prerelease: false

0 commit comments

Comments
 (0)