validate-registry.yml 14 KB

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