From 610dd8f5a9d751ce959b848896a1fcd5d36fa3c8 Mon Sep 17 00:00:00 2001 From: Joshua Folkken Date: Fri, 27 Sep 2024 06:39:25 +0900 Subject: [PATCH] fix: auto tag workflow #164 --- .github/scripts/auto_tag.sh | 29 ++++++++++++++++++----------- .github/workflows/auto-tag.yml | 13 +++++++------ .github/workflows/deploy-web.yml | 21 +++++++++++++-------- 3 files changed, 38 insertions(+), 25 deletions(-) mode change 100644 => 100755 .github/scripts/auto_tag.sh diff --git a/.github/scripts/auto_tag.sh b/.github/scripts/auto_tag.sh old mode 100644 new mode 100755 index 285603e..0a2c224 --- a/.github/scripts/auto_tag.sh +++ b/.github/scripts/auto_tag.sh @@ -8,20 +8,27 @@ git config --global user.email "$GITHUB_ACTOR@users.noreply.github.com" cd "$(git rev-parse --show-toplevel)" || exit # Extract version from project.godot -VERSION=$(grep 'config/version=' project.godot | cut -d'=' -f2 | tr -d '"') +VERSION=v$(grep 'config/version=' project.godot | cut -d'=' -f2 | tr -d '"') +echo "VERSION: $VERSION" # Get the latest tag LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") +echo "LATEST_TAG: $LATEST_TAG" # Create a new tag if the version has changed -if [ "$VERSION" != "$LATEST_TAG" ]; then - git tag -a "v$VERSION" -m "Release $VERSION" - if git push origin "v$VERSION"; then - echo "Created and pushed new tag v$VERSION" - else - echo "Failed to push tag v$VERSION" - exit 1 - fi -else - echo "Version unchanged. Current version: $VERSION" +if [ "$VERSION" = "$LATEST_TAG" ]; then + echo "Version unchanged. No new tag will be created." + exit 0 fi + +if ! git tag -a "$VERSION" -m "Release $VERSION"; then + echo "Failed to create tag $VERSION" + exit 0 +fi + +if ! git push origin "$VERSION"; then + echo "Failed to push tag $VERSION" + exit 0 +fi + +echo "Created and pushed new tag $VERSION" diff --git a/.github/workflows/auto-tag.yml b/.github/workflows/auto-tag.yml index ed871e6..8770629 100644 --- a/.github/workflows/auto-tag.yml +++ b/.github/workflows/auto-tag.yml @@ -2,8 +2,7 @@ name: Auto Tag on Version Change on: push: - branches: - - main + branches: [main] jobs: auto-tag: @@ -11,10 +10,12 @@ jobs: permissions: contents: write steps: - - uses: actions/checkout@v4 + - name: Checkout repository + uses: actions/checkout@v4 with: fetch-depth: 0 - - name: Auto Tag + + - name: Run Auto Tag script run: | - chmod +x ./.github/scripts/auto_tag.sh - ./.github/scripts/auto_tag.sh + chmod +x .github/scripts/auto_tag.sh + .github/scripts/auto_tag.sh diff --git a/.github/workflows/deploy-web.yml b/.github/workflows/deploy-web.yml index 5853a51..689afbe 100644 --- a/.github/workflows/deploy-web.yml +++ b/.github/workflows/deploy-web.yml @@ -1,18 +1,13 @@ name: Deploy to GitHub Pages on: - # push: - # tags: - # - "v*.*.*" - workflow_run: - workflows: ["Auto Tag on Version Change"] - types: - - completed + push: + tags: + - "v*.*.*" jobs: build-and-deploy: runs-on: ubuntu-latest - if: ${{ github.event.workflow_run.conclusion == 'success' }} permissions: contents: write concurrency: @@ -21,6 +16,15 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Validate tag on main branch + run: | + if ! git branch --contains ${{ github.ref_name }} | grep -q "main"; then + echo "Tag must be on the main branch" + exit 1 + fi - name: Setup Godot uses: lihop/setup-godot@v2 @@ -35,6 +39,7 @@ jobs: - name: Deploy to GitHub Pages uses: peaceiris/actions-gh-pages@v3 + if: success() with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./build/web