summaryrefslogtreecommitdiff
path: root/.github/workflows/validate-frontmatter.yml
blob: 243455d8e7d5163010bc84a012bd7ab5e3840530 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
name: Validate Frontmatter

on:
  pull_request:
    paths:
      - '**/agents/*.md'
      - '**/skills/*/SKILL.md'
      - '**/commands/*.md'

jobs:
  validate:
    # Fork PRs are auto-closed by close-external-prs.yml, so skip validation
    # for them entirely. This also prevents untrusted filenames from forks
    # from ever reaching the shell steps below.
    if: github.event.pull_request.head.repo.full_name == github.repository
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0 (sha-pinned)

      - name: Install dependencies
        run: cd .github/scripts && bun install yaml

      - name: Get changed frontmatter files
        id: changed
        env:
          GH_TOKEN: ${{ github.token }}
          PR_NUMBER: ${{ github.event.pull_request.number }}
        run: |
          # Use diff-filter=AMRC to exclude deleted files (D) - only Added, Modified, Renamed, Copied
          FILES=$(gh pr diff "$PR_NUMBER" --name-only --diff-filter=AMRC | grep -E '(agents/.*\.md|skills/.*/SKILL\.md|commands/.*\.md)$' || true)
          echo "files<<EOF" >> "$GITHUB_OUTPUT"
          echo "$FILES" >> "$GITHUB_OUTPUT"
          echo "EOF" >> "$GITHUB_OUTPUT"

      - name: Validate frontmatter
        if: steps.changed.outputs.files != ''
        env:
          FILES: ${{ steps.changed.outputs.files }}
        run: |
          printf '%s\n' "$FILES" | xargs bun .github/scripts/validate-frontmatter.ts