Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: auto tag workflow #164 #165

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions .github/scripts/auto_tag.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,27 @@ git config --global user.email "[email protected]"
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"
13 changes: 7 additions & 6 deletions .github/workflows/auto-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@ name: Auto Tag on Version Change

on:
push:
branches:
- main
branches: [main]

jobs:
auto-tag:
runs-on: ubuntu-latest
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
21 changes: 13 additions & 8 deletions .github/workflows/deploy-web.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand All @@ -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