Skip to content

[Tag Scan] New tags detected — review tag-groups.js #25

[Tag Scan] New tags detected — review tag-groups.js

[Tag Scan] New tags detected — review tag-groups.js #25

Workflow file for this run

name: Weekly Tag Scan
on:
schedule:
- cron: '0 8 * * 1' # Every Monday at 08:00 UTC
workflow_dispatch:
pull_request:
types: [closed]
branches: [main]
jobs:
# ---------------------------------------------------------------------------
# scan — runs on schedule and workflow_dispatch
# Fetches fresh tags, diffs against main's tag-export.txt, and opens or
# updates a [Tag Scan] PR when 5+ new tags are found.
# ---------------------------------------------------------------------------
scan:
name: Scan for new tags
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Node
uses: actions/setup-node@v6
with:
node-version: '24'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run tag export
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: node scripts/export-tags.js
- name: Compute new tags and manage PR
env:
GH_TOKEN: ${{ secrets.PR_TOKEN }}
run: |
# Collect lines added vs main (new tags).
# grep '^+[^+]' captures added lines but not the '+++' diff header.
NEW_TAGS=$(git diff HEAD -- scripts/tag-export.txt \
| grep '^+[^+]' | sed 's/^+//' | grep -v '^[[:space:]]*$' || true)
NEW_COUNT=0
[ -n "$NEW_TAGS" ] && NEW_COUNT=$(printf '%s\n' "$NEW_TAGS" | wc -l | tr -d ' ')
echo "New tags found: $NEW_COUNT"
if [ "$NEW_COUNT" -lt 5 ]; then
echo "Below threshold (5). Nothing to do."
exit 0
fi
TODAY=$(date -u +%Y-%m-%d)
TAG_LIST=$(printf '%s\n' "$NEW_TAGS" | sed 's/^/- /')
# Build PR body into a temp file to avoid shell-quoting issues.
{
echo "## New Tags Detected"
echo ""
echo "The weekly tag scan found ${NEW_COUNT} new tags since the last baseline in \`scripts/tag-export.txt\`."
echo ""
echo "<!-- TAG_LIST_START -->"
echo "$TAG_LIST"
echo "<!-- TAG_LIST_END -->"
echo ""
echo "## How to Resolve"
echo ""
echo "See [docs/tag-grouping-process.md](docs/tag-grouping-process.md) for full instructions."
echo ""
echo "In short:"
echo "1. For each tag above, open \`public/tag-groups.js\`."
echo "2. Add the tag to an existing group, create a new group, or ignore it if it's noise."
echo "3. Once all tags are addressed, this PR can be merged."
echo ""
echo "_This PR was auto-generated by the weekly tag scan workflow. Last updated: ${TODAY}._"
} > /tmp/pr-body.md
# Set up git identity for commits.
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# If the branch already exists on remote, check it out to preserve
# any contributor commits. Otherwise create it fresh from main.
if git ls-remote --exit-code origin tag-scan/auto > /dev/null 2>&1; then
git fetch origin tag-scan/auto
git stash
git checkout tag-scan/auto
git stash pop
else
git checkout -b tag-scan/auto
fi
git add scripts/tag-export.txt
git diff --staged --quiet || \
git commit -m "chore: update tag-export.txt baseline [tag scan]"
git push origin tag-scan/auto
# Check for an existing open [Tag Scan] PR using a client-side filter
# so the '[' and ']' characters in the title don't trip up GitHub search.
EXISTING=$(gh pr list --state open --limit 100 \
--json number,body,title \
| jq '[.[] | select(.title | startswith("[Tag Scan]"))] | .[0] // empty')
PR_NUMBER=$(echo "$EXISTING" | jq -r '.number // empty')
if [ -z "$PR_NUMBER" ]; then
gh pr create \
--title "[Tag Scan] New tags detected — review tag-groups.js" \
--body-file /tmp/pr-body.md \
--base main \
--head tag-scan/auto
echo "Opened new Tag Scan PR."
else
EXISTING_BODY=$(echo "$EXISTING" | jq -r '.body' | tr -d '\r')
# Extract the tag list currently in the PR body.
EXISTING_TAGS=$(printf '%s' "$EXISTING_BODY" \
| awk '/<!-- TAG_LIST_START -->/,/<!-- TAG_LIST_END -->/' \
| grep '^- ' | sed 's/^- //')
if [ "$EXISTING_TAGS" = "$NEW_TAGS" ]; then
echo "Tag list unchanged. PR #${PR_NUMBER} is already up to date."
else
gh pr edit "$PR_NUMBER" --body-file /tmp/pr-body.md
echo "Updated PR #${PR_NUMBER} with ${NEW_COUNT} new tags."
fi
fi
# ---------------------------------------------------------------------------
# cleanup — runs when any PR targeting main is closed.
# Deletes the tag-scan/auto branch if it is the head of the closed PR.
# Uses '|| true' so it succeeds gracefully if the branch was already deleted
# (e.g. by the repo's "auto-delete head branches" setting or manually).
# ---------------------------------------------------------------------------
cleanup:
name: Delete tag-scan/auto branch
if: github.event_name == 'pull_request' && github.event.pull_request.head.ref == 'tag-scan/auto'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Delete branch
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh api --method DELETE \
"repos/${{ github.repository }}/git/refs/heads/tag-scan/auto" \
&& echo "Branch deleted." \
|| echo "Branch already deleted or does not exist."