Skip to content

Commit 5aa8790

Browse files
Merge pull request #61 from seb-oss/feature/MCORE-201/Add-gitHub-workflow-to-publish-android-green-components-library
[MCORE-201] Add gitHub workflow to create and push tag whenever we update VERSION_NAME
2 parents ca52d93 + d04e236 commit 5aa8790

File tree

2 files changed

+67
-8
lines changed

2 files changed

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