Skip to content

Commit 9196ab5

Browse files
committed
Add: update work-jar.yml to include permissions and check for existing tags before creating a new tag
1 parent 6e63c3c commit 9196ab5

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

.github/workflows/work-jar.yml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ on:
33
push:
44
branches:
55
- main
6+
7+
permissions:
8+
contents: write
9+
pages: write
10+
id-token: write
11+
612
jobs:
713
publish-jar:
814
runs-on: ubuntu-latest
@@ -11,6 +17,7 @@ jobs:
1117
uses: actions/checkout@v4
1218
with:
1319
token: ${{ secrets.GITHUB_TOKEN }}
20+
fetch-depth: 0
1421

1522
- name: Set up JDK 17
1623
uses: actions/setup-java@v4
@@ -28,6 +35,17 @@ jobs:
2835
echo "version=$VERSION" >> $GITHUB_OUTPUT
2936
echo "Extracted version: $VERSION"
3037
38+
- name: Check if tag already exists
39+
id: check_tag
40+
run: |
41+
if git tag -l "${{ steps.extract_version.outputs.version }}" | grep -q "${{ steps.extract_version.outputs.version }}"; then
42+
echo "tag_exists=true" >> $GITHUB_OUTPUT
43+
echo "Tag ${{ steps.extract_version.outputs.version }} already exists"
44+
else
45+
echo "tag_exists=false" >> $GITHUB_OUTPUT
46+
echo "Tag ${{ steps.extract_version.outputs.version }} does not exist"
47+
fi
48+
3149
- name: Publish Maven artifacts to local repo
3250
run: ./gradlew publish
3351
env:
@@ -44,14 +62,11 @@ jobs:
4462
folder: build/repo
4563
target-folder: connectorapi/jar
4664

47-
- name: Configure Git for tagging
65+
- name: Create and push Git tag
66+
if: steps.check_tag.outputs.tag_exists == 'false'
4867
run: |
4968
git config --local user.email "action@github.com"
5069
git config --local user.name "GitHub Action"
51-
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
52-
53-
- name: Create and push Git tag
54-
run: |
5570
git tag -a "${{ steps.extract_version.outputs.version }}" -m "Release version ${{ steps.extract_version.outputs.version }}"
5671
git push origin "${{ steps.extract_version.outputs.version }}"
5772
env:

0 commit comments

Comments
 (0)