Skip to content

Commit 3ebd055

Browse files
committed
Update GitHub Actions workflow to handle tag overwrites and improve version extraction
1 parent e430fa0 commit 3ebd055

1 file changed

Lines changed: 10 additions & 14 deletions

File tree

.github/workflows/work-jar.yml

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ on:
44
branches:
55
- main
66
- feature/hook
7-
87
permissions:
98
contents: write
109
pages: write
1110
id-token: write
12-
1311
jobs:
1412
publish-jar:
1513
runs-on: ubuntu-latest
@@ -19,41 +17,35 @@ jobs:
1917
with:
2018
token: ${{ secrets.GITHUB_TOKEN }}
2119
fetch-depth: 0
22-
2320
- name: Set up JDK 17
2421
uses: actions/setup-java@v4
2522
with:
2623
java-version: '17'
2724
distribution: 'temurin'
28-
2925
- name: Grant execute permission for gradlew
3026
run: chmod +x gradlew
31-
3227
- name: Extract version from build.gradle.kts
3328
id: extract_version
3429
run: |
3530
VERSION=$(./gradlew -q printVersion)
3631
echo "version=$VERSION" >> $GITHUB_OUTPUT
3732
echo "Extracted version: $VERSION"
38-
3933
- name: Check if tag already exists
4034
id: check_tag
4135
run: |
4236
if git tag -l "${{ steps.extract_version.outputs.version }}" | grep -q "${{ steps.extract_version.outputs.version }}"; then
4337
echo "tag_exists=true" >> $GITHUB_OUTPUT
44-
echo "Tag ${{ steps.extract_version.outputs.version }} already exists"
38+
echo "Tag ${{ steps.extract_version.outputs.version }} already exists and will be overwritten"
4539
else
4640
echo "tag_exists=false" >> $GITHUB_OUTPUT
4741
echo "Tag ${{ steps.extract_version.outputs.version }} does not exist"
4842
fi
49-
5043
- name: Publish Maven artifacts to local repo
5144
run: ./gradlew publish
5245
env:
5346
GROUP_ID: fr.sandro642.github
5447
ARTIFACT_ID: ConnectorAPI
5548
VERSION: ${{ steps.extract_version.outputs.version }}
56-
5749
- name: Deploy to GitHub Pages
5850
uses: JamesIves/github-pages-deploy-action@v4
5951
with:
@@ -62,18 +54,22 @@ jobs:
6254
branch: main
6355
folder: build/repo
6456
target-folder: connectorapi/jar
65-
66-
- name: Create and push Git tag
67-
if: steps.check_tag.outputs.tag_exists == 'false'
57+
- name: Create and push Git tag (with override)
6858
run: |
6959
git config --local user.email "action@github.com"
7060
git config --local user.name "GitHub Action"
7161
7262
# S'assurer qu'on pousse vers le bon repository
7363
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
7464
75-
# Créer et pousser le tag
65+
# Supprimer le tag localement s'il existe
66+
git tag -d "${{ steps.extract_version.outputs.version }}" || true
67+
68+
# Supprimer le tag distant s'il existe
69+
git push origin --delete "${{ steps.extract_version.outputs.version }}" || true
70+
71+
# Créer et pousser le nouveau tag
7672
git tag -a "${{ steps.extract_version.outputs.version }}" -m "Release version ${{ steps.extract_version.outputs.version }}"
7773
git push origin "${{ steps.extract_version.outputs.version }}"
7874
env:
79-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
75+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)