Daily Tag Check #75
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Daily Tag Check | |
# Run daily at midnight UTC | |
on: | |
schedule: | |
- cron: "0 0 * * *" | |
jobs: | |
tag-check: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-tags: true | |
fetch-depth: 0 | |
token: ${{ secrets.PAT_TOKEN }} | |
- name: Get last tag | |
id: last-tag | |
run: | | |
# Fetch all tags | |
git fetch --tags | |
# Get the latest tag and output it | |
LAST_TAG=$(git describe --tags --abbrev=0 --always || echo "") | |
echo $(git describe --tags --abbrev=0 --always || echo "") | |
echo "last_tag=$(git describe --tags --abbrev=0 --always)" >> $GITHUB_ENV | |
- name: Check for new commits since last tag | |
id: new-commits | |
run: | | |
# Check for new commits since the last tag | |
if [ -z "${{ env.last_tag }}" ]; then | |
echo "No previous tags found. New tag will be created." | |
echo "new_commits=true" >> $GITHUB_ENV | |
else | |
NEW_COMMITS=$(git rev-list ${{ env.last_tag }}..HEAD --count) | |
if [ "$NEW_COMMITS" -gt 0 ]; then | |
echo "New commits detected since last tag." | |
echo "new_commits=true" >> $GITHUB_ENV | |
else | |
echo "No new commits since last tag." | |
echo "new_commits=false" >> $GITHUB_ENV | |
fi | |
fi | |
- name: Create new tag | |
if: env.new_commits == 'true' | |
run: | | |
# Generate a new tag based on the last tag | |
if [ -z "${{ env.last_tag }}" ]; then | |
NEW_TAG="v1.0.0" | |
else | |
# Bump the patch version | |
NEW_TAG=$(echo "${{ env.last_tag }}" | awk -F. '{$NF += 1;} 1' | sed 's/ /./g') | |
fi | |
echo "Creating new tag $NEW_TAG" | |
# Create and push the new tag | |
git tag "$NEW_TAG" | |
git push origin "$NEW_TAG" |