validate-registry.yml 11 KB

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