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 }}
0 commit comments