|
| 1 | +name: "Challenge 16: Capstone Agent File Validation" |
| 2 | +# Validates that the student's agent file has valid YAML frontmatter, |
| 3 | +# responsibilities, and guardrails sections |
| 4 | +# NOTE: This workflow runs in the accessibility-agents repo, not learning-room |
| 5 | + |
| 6 | +on: |
| 7 | + pull_request: |
| 8 | + types: [opened, synchronize, reopened] |
| 9 | + paths: |
| 10 | + - "agents/**/*.md" |
| 11 | + - "community-agents/**/*.md" |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: read |
| 15 | + pull-requests: write |
| 16 | + |
| 17 | +jobs: |
| 18 | + validate-agent: |
| 19 | + name: Verify Agent File |
| 20 | + runs-on: ubuntu-latest |
| 21 | + |
| 22 | + steps: |
| 23 | + - name: Checkout PR branch |
| 24 | + uses: actions/checkout@v4 |
| 25 | + |
| 26 | + - name: Find and validate agent files |
| 27 | + id: check |
| 28 | + run: | |
| 29 | + # Find new/modified .md files in agents/ or community-agents/ |
| 30 | + AGENTS=$(find agents community-agents -name '*.md' 2>/dev/null || true) |
| 31 | +
|
| 32 | + if [ -z "$AGENTS" ]; then |
| 33 | + echo "found=false" >> "$GITHUB_OUTPUT" |
| 34 | + exit 0 |
| 35 | + fi |
| 36 | +
|
| 37 | + echo "found=true" >> "$GITHUB_OUTPUT" |
| 38 | + FIRST=$(echo "$AGENTS" | head -1) |
| 39 | + echo "file=$FIRST" >> "$GITHUB_OUTPUT" |
| 40 | + CHECK_FILE="/tmp/capstone-agent.md" |
| 41 | + sed '1s/^\xEF\xBB\xBF//' "$FIRST" > "$CHECK_FILE" |
| 42 | +
|
| 43 | + ERRORS="" |
| 44 | +
|
| 45 | + # Check YAML frontmatter exists (starts with ---) |
| 46 | + if head -1 "$CHECK_FILE" | grep -q '^---'; then |
| 47 | + echo "has_frontmatter=true" >> "$GITHUB_OUTPUT" |
| 48 | + else |
| 49 | + echo "has_frontmatter=false" >> "$GITHUB_OUTPUT" |
| 50 | + ERRORS="missing YAML frontmatter" |
| 51 | + fi |
| 52 | +
|
| 53 | + # Check for responsibilities section |
| 54 | + if grep -qi '## responsibilities\|## what this agent does' "$CHECK_FILE"; then |
| 55 | + echo "has_responsibilities=true" >> "$GITHUB_OUTPUT" |
| 56 | + else |
| 57 | + echo "has_responsibilities=false" >> "$GITHUB_OUTPUT" |
| 58 | + ERRORS="$ERRORS${ERRORS:+, }missing responsibilities section" |
| 59 | + fi |
| 60 | +
|
| 61 | + # Check for guardrails section |
| 62 | + if grep -qi '## guardrails\|## limitations\|## boundaries' "$CHECK_FILE"; then |
| 63 | + echo "has_guardrails=true" >> "$GITHUB_OUTPUT" |
| 64 | + else |
| 65 | + echo "has_guardrails=false" >> "$GITHUB_OUTPUT" |
| 66 | + ERRORS="$ERRORS${ERRORS:+, }missing guardrails section" |
| 67 | + fi |
| 68 | +
|
| 69 | + echo "errors=$ERRORS" >> "$GITHUB_OUTPUT" |
| 70 | +
|
| 71 | + - name: Post result |
| 72 | + if: always() |
| 73 | + uses: actions/github-script@v7 |
| 74 | + with: |
| 75 | + script: | |
| 76 | + const found = '${{ steps.check.outputs.found }}' === 'true'; |
| 77 | + const file = '${{ steps.check.outputs.file }}'; |
| 78 | + const errors = '${{ steps.check.outputs.errors }}'; |
| 79 | + let body; |
| 80 | + if (!found) { |
| 81 | + body = [ |
| 82 | + '## Challenge 16: No agent file found', |
| 83 | + '', |
| 84 | + 'Create an `.md` file in the `agents/` or `community-agents/` directory ', |
| 85 | + 'with YAML frontmatter, a responsibilities section, and a guardrails section.', |
| 86 | + '', |
| 87 | + 'See [Chapter 20: Build Your Agent](https://github.com/Community-Access/git-going-with-github/blob/main/docs/20-build-your-agent.md) for the template.' |
| 88 | + ].join('\n'); |
| 89 | + } else if (errors) { |
| 90 | + body = [ |
| 91 | + '## Challenge 16: Agent file needs work', |
| 92 | + '', |
| 93 | + 'Found `' + file + '` but it has issues: ' + errors + '.', |
| 94 | + '', |
| 95 | + 'Your agent file should have:', |
| 96 | + '- YAML frontmatter (between `---` markers)', |
| 97 | + '- A responsibilities/purpose section', |
| 98 | + '- A guardrails/limitations section', |
| 99 | + ].join('\n'); |
| 100 | + } else { |
| 101 | + body = [ |
| 102 | + '## Challenge 16: Agent file looks great!', |
| 103 | + '', |
| 104 | + 'Found `' + file + '` with valid frontmatter, responsibilities, and guardrails. ', |
| 105 | + 'Excellent capstone work!' |
| 106 | + ].join('\n'); |
| 107 | + } |
| 108 | + try { |
| 109 | + await github.rest.issues.createComment({ |
| 110 | + owner: context.repo.owner, |
| 111 | + repo: context.repo.repo, |
| 112 | + issue_number: context.issue.number, |
| 113 | + body |
| 114 | + }); |
| 115 | + } catch (error) { |
| 116 | + console.error('Could not post Challenge 16 result:', error.message); |
| 117 | + } |
0 commit comments