Skip to content
Merged
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
69 changes: 18 additions & 51 deletions .github/workflows/auto-tags.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: Auto tag from PR labels

on:
pull_request:
pull_request_target:
types: [closed]
branches: [main]
workflow_dispatch: {}

permissions:
contents: write
Expand All @@ -13,9 +14,10 @@ jobs:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: Checkout
- name: Checkout base (main)
uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0

- name: Fetch tags
Expand All @@ -27,20 +29,26 @@ jobs:
env:
PR_LABELS: ${{ toJson(github.event.pull_request.labels) }}
run: |
labels=$(echo "$PR_LABELS" | jq -r '.[].name' | tr '[:upper:]' '[:lower:]')
# Normalize labels to lowercase array using jq
labels=$(echo "$PR_LABELS" | jq -r 'map(.name | ascii_downcase)')
echo "PR labels: $labels"

# If 'no-tag' present, skip tagging entirely.
if echo "$labels" | grep -q '\bno-tag\b'; then
# Skip if 'no-tag' is present
if echo "$labels" | jq -e 'index("no-tag") != null' >/dev/null; then
echo "skip=true" >> "$GITHUB_OUTPUT"
echo "Tagging skipped due to 'no-tag' label."
exit 0
fi

level="patch" # default
if echo "$labels" | grep -q '\bmajor\b'; then level="major"
elif echo "$labels" | grep -q '\bminor\b'; then level="minor"
elif echo "$labels" | grep -q '\bpatch\b'; then level="patch"
# Precedence: major > minor > patch (default patch)
if echo "$labels" | jq -e 'index("major") != null' >/dev/null; then
level=major
elif echo "$labels" | jq -e 'index("minor") != null' >/dev/null; then
level=minor
elif echo "$labels" | jq -e 'index("patch") != null' >/dev/null; then
level=patch
else
level=patch
fi

echo "level=$level" >> "$GITHUB_OUTPUT"
Expand All @@ -58,6 +66,7 @@ jobs:
latest="v0.1.0"
echo "No previous tag; starting at $latest"
fi

ver="${latest#v}"
IFS='.' read -r MA MI PA <<<"$ver"

Expand All @@ -68,45 +77,3 @@ jobs:
esac

next="v${MA}.${MI}.${PA}"
echo "next=$next" >> "$GITHUB_OUTPUT"
echo "latest=$latest -> next=$next"

- name: Tag and push
if: steps.bump.outputs.skip != 'true'
env:
NEXT: ${{ steps.next.outputs.next }}
run: |
if git rev-parse -q --verify "refs/tags/${NEXT}" >/dev/null; then
echo "Tag ${NEXT} already exists; nothing to do."
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag -a "$NEXT" -m "chore(release): $NEXT"
git push origin "$NEXT"

- name: Comment with result
if: steps.bump.outputs.skip != 'true'
uses: actions/github-script@v7
with:
script: |
const next = '${{ steps.next.outputs.next }}';
const level = '${{ steps.bump.outputs.level }}';
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: `🔖 Released **${next}** (bump: \`${level}\`).`
});

- name: Comment: tagging skipped
if: steps.bump.outputs.skip == 'true'
uses: actions/github-script@v7
with:
script: |
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: `⏭️ Tag creation skipped due to \`no-tag\` label.`
});