|
| 1 | +name: Refresh issue template version dropdown |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + refresh: |
| 14 | + name: Refresh integration_version options |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - name: Checkout main |
| 18 | + uses: actions/checkout@v4 |
| 19 | + with: |
| 20 | + fetch-depth: 0 |
| 21 | + ref: main |
| 22 | + |
| 23 | + - name: Regenerate version options block |
| 24 | + env: |
| 25 | + MAX_TAGS: "20" |
| 26 | + run: | |
| 27 | + python3 - <<'PY' |
| 28 | + import os |
| 29 | + import re |
| 30 | + import subprocess |
| 31 | +
|
| 32 | + MAX_TAGS = int(os.environ.get("MAX_TAGS", "20")) |
| 33 | +
|
| 34 | + tags = subprocess.check_output( |
| 35 | + ["git", "tag", "--sort=-creatordate"], |
| 36 | + text=True, |
| 37 | + ).strip().splitlines() |
| 38 | + tags = [t for t in tags if t.startswith("v")][:MAX_TAGS] |
| 39 | + if not tags: |
| 40 | + raise SystemExit("No v-prefixed tags found; aborting.") |
| 41 | +
|
| 42 | + path = ".github/ISSUE_TEMPLATE/bug_report.yml" |
| 43 | + with open(path, "r", encoding="utf-8") as f: |
| 44 | + original = f.read() |
| 45 | +
|
| 46 | + # Indentation matches the existing options: block in the dropdown |
| 47 | + # (siblings: label, description, options). See bug_report.yml. |
| 48 | + indent = " " |
| 49 | + item_indent = " " |
| 50 | +
|
| 51 | + new_block_lines = [ |
| 52 | + f"{indent}# BEGIN AUTO-GENERATED VERSION LIST (refreshed by .github/workflows/update-issue-template.yml — do not hand-edit)", |
| 53 | + f"{indent}options:", |
| 54 | + ] |
| 55 | + for tag in tags: |
| 56 | + new_block_lines.append(f"{item_indent}- {tag}") |
| 57 | + new_block_lines.append(f"{item_indent}- Older / not listed (specify in description)") |
| 58 | + new_block_lines.append(f"{indent}# END AUTO-GENERATED VERSION LIST") |
| 59 | + new_block = "\n".join(new_block_lines) |
| 60 | +
|
| 61 | + pattern = re.compile( |
| 62 | + re.escape(f"{indent}# BEGIN AUTO-GENERATED VERSION LIST") |
| 63 | + + r".*?" |
| 64 | + + re.escape(f"{indent}# END AUTO-GENERATED VERSION LIST"), |
| 65 | + re.DOTALL, |
| 66 | + ) |
| 67 | + if not pattern.search(original): |
| 68 | + raise SystemExit( |
| 69 | + "Could not find AUTO-GENERATED VERSION LIST markers in bug_report.yml" |
| 70 | + ) |
| 71 | +
|
| 72 | + updated = pattern.sub(new_block, original) |
| 73 | + if updated == original: |
| 74 | + print("No change.") |
| 75 | + raise SystemExit(0) |
| 76 | +
|
| 77 | + with open(path, "w", encoding="utf-8") as f: |
| 78 | + f.write(updated) |
| 79 | + print(f"Updated dropdown with {len(tags)} tag(s); newest: {tags[0]}") |
| 80 | + PY |
| 81 | +
|
| 82 | + - name: Commit and push if changed |
| 83 | + run: | |
| 84 | + if git diff --quiet -- .github/ISSUE_TEMPLATE/bug_report.yml; then |
| 85 | + echo "No changes to commit." |
| 86 | + exit 0 |
| 87 | + fi |
| 88 | + git config user.name "github-actions[bot]" |
| 89 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 90 | + git add .github/ISSUE_TEMPLATE/bug_report.yml |
| 91 | + git commit -m "chore: refresh issue template version dropdown" |
| 92 | + git push origin main |
0 commit comments