validate-registry.yml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. name: Validate Registry on PR
  2. # This workflow validates the registry.json and prompt library structure on all PRs.
  3. #
  4. # For bot-created PRs (like automated version bumps), the workflow won't trigger automatically
  5. # due to GitHub's security restrictions. In those cases, you can manually trigger this workflow:
  6. #
  7. # Option 1 - Run Validation:
  8. # 1. Go to Actions > Validate Registry on PR > Run workflow
  9. # 2. Enter the PR number (e.g., 106)
  10. # 3. Leave "skip_validation" unchecked
  11. # 4. Click "Run workflow"
  12. #
  13. # Option 2 - Admin Bypass (for trusted bot PRs):
  14. # 1. Go to Actions > Validate Registry on PR > Run workflow
  15. # 2. Enter the PR number (e.g., 106)
  16. # 3. Check "skip_validation" checkbox
  17. # 4. Click "Run workflow"
  18. # 5. The check will pass immediately without running validation
  19. on:
  20. pull_request:
  21. branches:
  22. - main
  23. - dev
  24. # Removed paths filter - this check is required by repository ruleset
  25. # so it must run on ALL PRs to prevent blocking merges
  26. pull_request_target:
  27. branches:
  28. - main
  29. - dev
  30. # pull_request_target allows workflows to run on bot-created PRs
  31. workflow_dispatch:
  32. inputs:
  33. pr_number:
  34. description: 'PR number to validate (for manual runs on bot-created PRs)'
  35. required: false
  36. type: number
  37. skip_validation:
  38. description: 'Skip validation checks (maintainer override)'
  39. required: false
  40. type: boolean
  41. default: false
  42. permissions:
  43. contents: write
  44. pull-requests: write
  45. jobs:
  46. validate-and-update:
  47. runs-on: ubuntu-latest
  48. steps:
  49. - name: Admin bypass check
  50. if: github.event_name == 'workflow_dispatch' && github.event.inputs.skip_validation == 'true'
  51. run: |
  52. echo "## ✅ Validation Bypassed (Admin Override)" >> $GITHUB_STEP_SUMMARY
  53. echo "" >> $GITHUB_STEP_SUMMARY
  54. echo "Validation checks skipped by maintainer." >> $GITHUB_STEP_SUMMARY
  55. echo "PR: #${{ github.event.inputs.pr_number }}" >> $GITHUB_STEP_SUMMARY
  56. echo "" >> $GITHUB_STEP_SUMMARY
  57. echo "The workflow will complete successfully without running validation steps." >> $GITHUB_STEP_SUMMARY
  58. - name: Checkout repository (for manual runs)
  59. if: github.event_name == 'workflow_dispatch' && github.event.inputs.skip_validation != 'true'
  60. uses: actions/checkout@v4
  61. with:
  62. fetch-depth: 0
  63. token: ${{ secrets.GITHUB_TOKEN }}
  64. - name: Get PR details (for manual runs)
  65. if: github.event_name == 'workflow_dispatch' && github.event.inputs.pr_number != '' && github.event.inputs.skip_validation != 'true'
  66. id: get_pr
  67. run: |
  68. PR_DATA=$(gh pr view ${{ github.event.inputs.pr_number }} --json headRefName,headRepository,headRepositoryOwner)
  69. echo "head_ref=$(echo $PR_DATA | jq -r '.headRefName')" >> $GITHUB_OUTPUT
  70. echo "head_repo=$(echo $PR_DATA | jq -r '.headRepositoryOwner.login + "/" + .headRepository.name')" >> $GITHUB_OUTPUT
  71. env:
  72. GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  73. - name: Checkout PR branch
  74. if: github.event.inputs.skip_validation != 'true'
  75. uses: actions/checkout@v4
  76. with:
  77. # For manual runs: use PR details from get_pr step
  78. # For PR events: use event data
  79. repository: ${{ github.event_name == 'workflow_dispatch' && steps.get_pr.outputs.head_repo || github.event.pull_request.head.repo.full_name }}
  80. ref: ${{ github.event_name == 'workflow_dispatch' && steps.get_pr.outputs.head_ref || github.event.pull_request.head.ref }}
  81. fetch-depth: 0
  82. token: ${{ secrets.GITHUB_TOKEN }}
  83. - name: Detect fork PR
  84. if: github.event.inputs.skip_validation != 'true'
  85. id: fork_check
  86. run: |
  87. # For manual runs, use the fetched PR data
  88. if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
  89. HEAD_REPO="${{ steps.get_pr.outputs.head_repo }}"
  90. else
  91. HEAD_REPO="${{ github.event.pull_request.head.repo.full_name }}"
  92. fi
  93. if [ "$HEAD_REPO" != "${{ github.repository }}" ]; then
  94. echo "is_fork=true" >> $GITHUB_OUTPUT
  95. echo "🔀 Fork PR detected from: $HEAD_REPO"
  96. else
  97. echo "is_fork=false" >> $GITHUB_OUTPUT
  98. echo "📝 Internal PR detected"
  99. fi
  100. - name: Install dependencies
  101. if: github.event.inputs.skip_validation != 'true'
  102. run: |
  103. sudo apt-get update
  104. sudo apt-get install -y jq
  105. - name: Make scripts executable
  106. if: github.event.inputs.skip_validation != 'true'
  107. run: |
  108. chmod +x scripts/registry/validate-registry.sh
  109. chmod +x scripts/registry/auto-detect-components.sh
  110. chmod +x scripts/registry/register-component.sh
  111. chmod +x scripts/prompts/validate-pr.sh
  112. - name: Auto-detect new components
  113. if: github.event.inputs.skip_validation != 'true'
  114. id: auto_detect
  115. run: |
  116. echo "## 🔍 Auto-Detection Results" >> $GITHUB_STEP_SUMMARY
  117. echo "" >> $GITHUB_STEP_SUMMARY
  118. # Run auto-detect in dry-run mode first to see what would be added
  119. if ./scripts/registry/auto-detect-components.sh --dry-run > /tmp/detect-output.txt 2>&1; then
  120. cat /tmp/detect-output.txt >> $GITHUB_STEP_SUMMARY
  121. # Check if new components were found
  122. if grep -q "Found.*new component" /tmp/detect-output.txt; then
  123. echo "new_components=true" >> $GITHUB_OUTPUT
  124. echo "" >> $GITHUB_STEP_SUMMARY
  125. echo "⚠️ New components detected - will auto-add to registry" >> $GITHUB_STEP_SUMMARY
  126. else
  127. echo "new_components=false" >> $GITHUB_OUTPUT
  128. echo "✅ No new components found" >> $GITHUB_STEP_SUMMARY
  129. fi
  130. else
  131. echo "new_components=false" >> $GITHUB_OUTPUT
  132. echo "❌ Auto-detection failed" >> $GITHUB_STEP_SUMMARY
  133. fi
  134. - name: Add new components to registry
  135. if: steps.auto_detect.outputs.new_components == 'true' && github.event.inputs.skip_validation != 'true'
  136. run: |
  137. echo "## 📝 Adding New Components" >> $GITHUB_STEP_SUMMARY
  138. echo "" >> $GITHUB_STEP_SUMMARY
  139. ./scripts/registry/auto-detect-components.sh --auto-add | tee -a $GITHUB_STEP_SUMMARY
  140. - name: Validate prompt library structure
  141. if: github.event.inputs.skip_validation != 'true'
  142. id: validate_prompts
  143. run: |
  144. echo "## 🔍 Prompt Library Validation" >> $GITHUB_STEP_SUMMARY
  145. echo "" >> $GITHUB_STEP_SUMMARY
  146. if ./scripts/prompts/validate-pr.sh > /tmp/prompt-validation.txt 2>&1; then
  147. echo "prompt_validation=passed" >> $GITHUB_OUTPUT
  148. echo "✅ Prompt library structure is valid!" >> $GITHUB_STEP_SUMMARY
  149. echo "" >> $GITHUB_STEP_SUMMARY
  150. echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
  151. cat /tmp/prompt-validation.txt >> $GITHUB_STEP_SUMMARY
  152. echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
  153. else
  154. echo "prompt_validation=failed" >> $GITHUB_OUTPUT
  155. echo "❌ Prompt library validation failed!" >> $GITHUB_STEP_SUMMARY
  156. echo "" >> $GITHUB_STEP_SUMMARY
  157. echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
  158. cat /tmp/prompt-validation.txt >> $GITHUB_STEP_SUMMARY
  159. echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
  160. echo "" >> $GITHUB_STEP_SUMMARY
  161. echo "**Architecture:**" >> $GITHUB_STEP_SUMMARY
  162. echo "- Agent files (.opencode/agent/**/*.md) = Canonical defaults" >> $GITHUB_STEP_SUMMARY
  163. echo "- Prompt variants (.opencode/prompts/<agent>/<model>.md) = Model-specific" >> $GITHUB_STEP_SUMMARY
  164. echo "- default.md files should NOT exist" >> $GITHUB_STEP_SUMMARY
  165. echo "- Agents organized in category subdirectories (core/, development/, content/, etc.)" >> $GITHUB_STEP_SUMMARY
  166. echo "" >> $GITHUB_STEP_SUMMARY
  167. echo "See [CONTRIBUTING.md](docs/contributing/CONTRIBUTING.md) for details" >> $GITHUB_STEP_SUMMARY
  168. exit 1
  169. fi
  170. - name: Validate registry
  171. if: github.event.inputs.skip_validation != 'true'
  172. id: validate
  173. run: |
  174. echo "## ✅ Registry Validation" >> $GITHUB_STEP_SUMMARY
  175. echo "" >> $GITHUB_STEP_SUMMARY
  176. if ./scripts/registry/validate-registry.sh -v > /tmp/validation-output.txt 2>&1; then
  177. echo "validation=passed" >> $GITHUB_OUTPUT
  178. echo "✅ All registry paths are valid!" >> $GITHUB_STEP_SUMMARY
  179. echo "" >> $GITHUB_STEP_SUMMARY
  180. echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
  181. tail -20 /tmp/validation-output.txt >> $GITHUB_STEP_SUMMARY
  182. echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
  183. else
  184. echo "validation=failed" >> $GITHUB_OUTPUT
  185. echo "❌ Registry validation failed!" >> $GITHUB_STEP_SUMMARY
  186. echo "" >> $GITHUB_STEP_SUMMARY
  187. echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
  188. cat /tmp/validation-output.txt >> $GITHUB_STEP_SUMMARY
  189. echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
  190. exit 1
  191. fi
  192. - name: Commit registry updates (Internal PRs only)
  193. if: |
  194. github.event.inputs.skip_validation != 'true' &&
  195. steps.fork_check.outputs.is_fork == 'false' &&
  196. steps.auto_detect.outputs.new_components == 'true' &&
  197. steps.validate_prompts.outputs.prompt_validation == 'passed' &&
  198. steps.validate.outputs.validation == 'passed'
  199. run: |
  200. git config --local user.email "github-actions[bot]@users.noreply.github.com"
  201. git config --local user.name "github-actions[bot]"
  202. if ! git diff --quiet registry.json; then
  203. git add registry.json
  204. git commit -m "chore: auto-update registry with new components [skip ci]"
  205. # For manual runs, use the fetched branch name
  206. BRANCH_NAME="${{ github.event_name == 'workflow_dispatch' && steps.get_pr.outputs.head_ref || github.event.pull_request.head.ref }}"
  207. git push origin "$BRANCH_NAME"
  208. echo "## 🚀 Registry Updated" >> $GITHUB_STEP_SUMMARY
  209. echo "" >> $GITHUB_STEP_SUMMARY
  210. echo "Registry has been automatically updated with new components." >> $GITHUB_STEP_SUMMARY
  211. echo "Changes have been pushed to this PR branch." >> $GITHUB_STEP_SUMMARY
  212. else
  213. echo "## ℹ️ No Changes to Commit" >> $GITHUB_STEP_SUMMARY
  214. echo "" >> $GITHUB_STEP_SUMMARY
  215. echo "Registry is already up to date." >> $GITHUB_STEP_SUMMARY
  216. fi
  217. - name: Fork PR notice
  218. if: |
  219. github.event.inputs.skip_validation != 'true' &&
  220. steps.fork_check.outputs.is_fork == 'true' &&
  221. steps.auto_detect.outputs.new_components == 'true' &&
  222. steps.validate_prompts.outputs.prompt_validation == 'passed' &&
  223. steps.validate.outputs.validation == 'passed'
  224. uses: actions/github-script@v7
  225. with:
  226. script: |
  227. github.rest.issues.createComment({
  228. issue_number: context.issue.number,
  229. owner: context.repo.owner,
  230. repo: context.repo.repo,
  231. body: `## 📝 Registry Update Needed
  232. Hi @${{ github.event.pull_request.user.login }}! 👋
  233. New components were detected in your PR. Since this is a fork PR, I can't auto-commit the registry updates for security reasons.
  234. **Please run these commands locally:**
  235. \`\`\`bash
  236. ./scripts/registry/auto-detect-components.sh --auto-add
  237. git add registry.json
  238. git commit -m "chore: update registry"
  239. git push
  240. \`\`\`
  241. Once you push the updated registry, the checks will pass! ✅`
  242. });
  243. - name: Fork PR summary
  244. if: steps.fork_check.outputs.is_fork == 'true' && github.event.inputs.skip_validation != 'true'
  245. run: |
  246. echo "## 🔀 Fork PR Detected" >> $GITHUB_STEP_SUMMARY
  247. echo "" >> $GITHUB_STEP_SUMMARY
  248. echo "This is an external contribution - thank you! 🎉" >> $GITHUB_STEP_SUMMARY
  249. echo "" >> $GITHUB_STEP_SUMMARY
  250. if [ "${{ steps.auto_detect.outputs.new_components }}" == "true" ]; then
  251. echo "⚠️ **Action Required:** New components detected" >> $GITHUB_STEP_SUMMARY
  252. echo "" >> $GITHUB_STEP_SUMMARY
  253. echo "A comment has been posted with instructions to update the registry." >> $GITHUB_STEP_SUMMARY
  254. else
  255. echo "✅ No registry updates needed" >> $GITHUB_STEP_SUMMARY
  256. fi
  257. - name: Post validation summary
  258. if: always()
  259. run: |
  260. echo "" >> $GITHUB_STEP_SUMMARY
  261. echo "---" >> $GITHUB_STEP_SUMMARY
  262. echo "" >> $GITHUB_STEP_SUMMARY
  263. PROMPT_VALID="${{ steps.validate_prompts.outputs.prompt_validation }}"
  264. REGISTRY_VALID="${{ steps.validate.outputs.validation }}"
  265. if [ "$PROMPT_VALID" = "passed" ] && [ "$REGISTRY_VALID" = "passed" ]; then
  266. echo "### ✅ All Validations Passed" >> $GITHUB_STEP_SUMMARY
  267. echo "" >> $GITHUB_STEP_SUMMARY
  268. echo "- ✅ Prompt library structure is valid" >> $GITHUB_STEP_SUMMARY
  269. echo "- ✅ Registry paths are valid" >> $GITHUB_STEP_SUMMARY
  270. echo "" >> $GITHUB_STEP_SUMMARY
  271. echo "This PR is ready for review!" >> $GITHUB_STEP_SUMMARY
  272. else
  273. echo "### ❌ Validation Failed" >> $GITHUB_STEP_SUMMARY
  274. echo "" >> $GITHUB_STEP_SUMMARY
  275. if [ "$PROMPT_VALID" != "passed" ]; then
  276. echo "- ❌ Prompt library validation failed" >> $GITHUB_STEP_SUMMARY
  277. else
  278. echo "- ✅ Prompt library validation passed" >> $GITHUB_STEP_SUMMARY
  279. fi
  280. if [ "$REGISTRY_VALID" != "passed" ]; then
  281. echo "- ❌ Registry validation failed" >> $GITHUB_STEP_SUMMARY
  282. else
  283. echo "- ✅ Registry validation passed" >> $GITHUB_STEP_SUMMARY
  284. fi
  285. echo "" >> $GITHUB_STEP_SUMMARY
  286. echo "Please fix the issues above before merging." >> $GITHUB_STEP_SUMMARY
  287. fi
  288. - name: Fail if validation failed
  289. if: |
  290. (steps.validate_prompts.outputs.prompt_validation == 'failed' || steps.validate.outputs.validation == 'failed') &&
  291. github.event.inputs.skip_validation != 'true'
  292. run: |
  293. echo "❌ Validation failed - blocking PR merge"
  294. echo "Maintainer can override by running workflow manually with 'skip_validation' enabled"
  295. exit 1