test-agents.yml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. name: Test Agents
  2. on:
  3. pull_request:
  4. branches: [ main, dev ]
  5. paths:
  6. - '.opencode/**'
  7. - 'evals/**'
  8. - '.github/workflows/test-agents.yml'
  9. push:
  10. branches: [ main ]
  11. workflow_dispatch:
  12. inputs:
  13. skip_tests:
  14. description: 'Skip tests (maintainer override)'
  15. required: false
  16. type: boolean
  17. default: false
  18. jobs:
  19. # Check if this is a PR merge commit (skip tests if so - they already ran on PR)
  20. check-trigger:
  21. name: Check Trigger Type
  22. runs-on: ubuntu-latest
  23. outputs:
  24. should_test: ${{ steps.check.outputs.should_test }}
  25. should_bump: ${{ steps.check.outputs.should_bump }}
  26. steps:
  27. - name: Determine if tests should run
  28. id: check
  29. run: |
  30. # For PRs, always run tests
  31. if [ "${{ github.event_name }}" == "pull_request" ]; then
  32. echo "should_test=true" >> $GITHUB_OUTPUT
  33. echo "should_bump=false" >> $GITHUB_OUTPUT
  34. echo "PR detected - will run tests"
  35. exit 0
  36. fi
  37. # For workflow_dispatch, check skip_tests input
  38. if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
  39. if [ "${{ github.event.inputs.skip_tests }}" == "true" ]; then
  40. echo "should_test=false" >> $GITHUB_OUTPUT
  41. echo "should_bump=false" >> $GITHUB_OUTPUT
  42. echo "Manual trigger - tests skipped by maintainer"
  43. else
  44. echo "should_test=true" >> $GITHUB_OUTPUT
  45. echo "should_bump=false" >> $GITHUB_OUTPUT
  46. echo "Manual trigger - will run tests"
  47. fi
  48. exit 0
  49. fi
  50. # For push events, check if it's a PR merge
  51. COMMIT_MSG="${{ github.event.head_commit.message }}"
  52. # PR merges have messages like "Merge pull request #123" or contain (#123)
  53. if echo "$COMMIT_MSG" | grep -qE "^Merge pull request #|^.*\(#[0-9]+\)$"; then
  54. echo "should_test=false" >> $GITHUB_OUTPUT
  55. echo "should_bump=true" >> $GITHUB_OUTPUT
  56. echo "PR merge detected - skipping tests, will bump version"
  57. # Skip version bump commits
  58. elif echo "$COMMIT_MSG" | grep -qE "^\[skip ci\]|chore: bump version"; then
  59. echo "should_test=false" >> $GITHUB_OUTPUT
  60. echo "should_bump=false" >> $GITHUB_OUTPUT
  61. echo "Version bump commit - skipping everything"
  62. else
  63. echo "should_test=true" >> $GITHUB_OUTPUT
  64. echo "should_bump=true" >> $GITHUB_OUTPUT
  65. echo "Direct push detected - will run tests and bump version"
  66. fi
  67. test-openagent:
  68. name: Test OpenAgent
  69. runs-on: ubuntu-latest
  70. needs: check-trigger
  71. if: needs.check-trigger.outputs.should_test == 'true'
  72. timeout-minutes: 15
  73. steps:
  74. - name: Checkout code
  75. uses: actions/checkout@v4
  76. - name: Setup Node.js
  77. uses: actions/setup-node@v4
  78. with:
  79. node-version: '20'
  80. cache: 'npm'
  81. cache-dependency-path: 'evals/framework/package-lock.json'
  82. # Install the OpenCode CLI (from opencode.ai, NOT our install.sh)
  83. # Our install.sh only installs agents/commands/tools, not the CLI binary
  84. # The @opencode-ai/sdk spawns `opencode serve` internally, so CLI is required
  85. - name: Install OpenCode CLI
  86. run: |
  87. npm install -g opencode-ai
  88. which opencode
  89. opencode --version
  90. # Install our OpenAgents components (agents, commands, tools)
  91. - name: Install OpenAgents Components
  92. run: bash install.sh essential --install-dir .opencode
  93. - name: Install dependencies
  94. working-directory: evals/framework
  95. run: npm install
  96. - name: Build framework
  97. working-directory: evals/framework
  98. run: npm run build
  99. - name: Run OpenAgent smoke test
  100. run: npm run test:ci:openagent
  101. env:
  102. CI: true
  103. - name: Upload test results
  104. if: always()
  105. uses: actions/upload-artifact@v4
  106. with:
  107. name: openagent-results
  108. path: evals/results/
  109. retention-days: 30
  110. test-opencoder:
  111. name: Test OpenCoder
  112. runs-on: ubuntu-latest
  113. needs: check-trigger
  114. if: needs.check-trigger.outputs.should_test == 'true'
  115. timeout-minutes: 15
  116. steps:
  117. - name: Checkout code
  118. uses: actions/checkout@v4
  119. - name: Setup Node.js
  120. uses: actions/setup-node@v4
  121. with:
  122. node-version: '20'
  123. cache: 'npm'
  124. cache-dependency-path: 'evals/framework/package-lock.json'
  125. # Install the OpenCode CLI (from opencode.ai, NOT our install.sh)
  126. # Our install.sh only installs agents/commands/tools, not the CLI binary
  127. # The @opencode-ai/sdk spawns `opencode serve` internally, so CLI is required
  128. - name: Install OpenCode CLI
  129. run: |
  130. npm install -g opencode-ai
  131. which opencode
  132. opencode --version
  133. # Install our OpenAgents components (agents, commands, tools)
  134. - name: Install OpenAgents Components
  135. run: bash install.sh essential --install-dir .opencode
  136. - name: Install dependencies
  137. working-directory: evals/framework
  138. run: npm install
  139. - name: Build framework
  140. working-directory: evals/framework
  141. run: npm run build
  142. - name: Run OpenCoder smoke test
  143. run: npm run test:ci:opencoder
  144. env:
  145. CI: true
  146. - name: Upload test results
  147. if: always()
  148. uses: actions/upload-artifact@v4
  149. with:
  150. name: opencoder-results
  151. path: evals/results/
  152. retention-days: 30
  153. report-results:
  154. name: Report Test Results
  155. runs-on: ubuntu-latest
  156. needs: [check-trigger, test-openagent, test-opencoder]
  157. if: always() && needs.check-trigger.outputs.should_test == 'true'
  158. steps:
  159. - name: Download OpenAgent results
  160. uses: actions/download-artifact@v4
  161. with:
  162. name: openagent-results
  163. path: results/openagent
  164. continue-on-error: true
  165. - name: Download OpenCoder results
  166. uses: actions/download-artifact@v4
  167. with:
  168. name: opencoder-results
  169. path: results/opencoder
  170. continue-on-error: true
  171. - name: Display results summary
  172. run: |
  173. echo "## Test Results Summary" >> $GITHUB_STEP_SUMMARY
  174. echo "" >> $GITHUB_STEP_SUMMARY
  175. if [ -f results/openagent/latest.json ]; then
  176. echo "### OpenAgent" >> $GITHUB_STEP_SUMMARY
  177. cat results/openagent/latest.json | jq -r '"- Passed: \(.passed)\n- Failed: \(.failed)\n- Total: \(.total)"' >> $GITHUB_STEP_SUMMARY
  178. fi
  179. if [ -f results/opencoder/latest.json ]; then
  180. echo "" >> $GITHUB_STEP_SUMMARY
  181. echo "### OpenCoder" >> $GITHUB_STEP_SUMMARY
  182. cat results/opencoder/latest.json | jq -r '"- Passed: \(.passed)\n- Failed: \(.failed)\n- Total: \(.total)"' >> $GITHUB_STEP_SUMMARY
  183. fi
  184. auto-version-bump:
  185. name: Auto Version Bump
  186. runs-on: ubuntu-latest
  187. needs: [check-trigger, test-openagent, test-opencoder]
  188. # Run version bump if:
  189. # 1. Tests ran and passed, OR
  190. # 2. This is a PR merge (tests already passed on PR)
  191. if: |
  192. github.event_name == 'push' &&
  193. github.ref == 'refs/heads/main' &&
  194. needs.check-trigger.outputs.should_bump == 'true' &&
  195. (needs.check-trigger.outputs.should_test == 'false' ||
  196. (needs.test-openagent.result == 'success' && needs.test-opencoder.result == 'success'))
  197. permissions:
  198. contents: write
  199. steps:
  200. - name: Checkout code
  201. uses: actions/checkout@v4
  202. with:
  203. fetch-depth: 0
  204. token: ${{ secrets.GITHUB_TOKEN }}
  205. - name: Setup Node.js
  206. uses: actions/setup-node@v4
  207. with:
  208. node-version: '20'
  209. - name: Configure Git
  210. run: |
  211. git config user.name "github-actions[bot]"
  212. git config user.email "github-actions[bot]@users.noreply.github.com"
  213. - name: Determine version bump type
  214. id: bump-type
  215. run: |
  216. # Get the last commit message
  217. COMMIT_MSG=$(git log -1 --pretty=%B)
  218. # Determine bump type from commit message
  219. if echo "$COMMIT_MSG" | grep -qiE "^(feat|feature)\(.*\)!:|^BREAKING CHANGE:|^[a-z]+!:"; then
  220. echo "type=major" >> $GITHUB_OUTPUT
  221. echo "Detected BREAKING CHANGE - bumping major version"
  222. elif echo "$COMMIT_MSG" | grep -qiE "^(feat|feature)(\(.*\))?:"; then
  223. echo "type=minor" >> $GITHUB_OUTPUT
  224. echo "Detected feature - bumping minor version"
  225. elif echo "$COMMIT_MSG" | grep -qiE "^(fix|bugfix)(\(.*\))?:"; then
  226. echo "type=patch" >> $GITHUB_OUTPUT
  227. echo "Detected fix - bumping patch version"
  228. elif echo "$COMMIT_MSG" | grep -qiE "^\[alpha\]"; then
  229. echo "type=alpha" >> $GITHUB_OUTPUT
  230. echo "Detected [alpha] tag - bumping alpha version"
  231. elif echo "$COMMIT_MSG" | grep -qiE "^\[beta\]"; then
  232. echo "type=beta" >> $GITHUB_OUTPUT
  233. echo "Detected [beta] tag - bumping beta version"
  234. elif echo "$COMMIT_MSG" | grep -qiE "^\[rc\]"; then
  235. echo "type=rc" >> $GITHUB_OUTPUT
  236. echo "Detected [rc] tag - bumping rc version"
  237. else
  238. echo "type=patch" >> $GITHUB_OUTPUT
  239. echo "No specific type detected - defaulting to patch version bump"
  240. fi
  241. - name: Bump version
  242. run: |
  243. BUMP_TYPE="${{ steps.bump-type.outputs.type }}"
  244. # Get current version
  245. CURRENT_VERSION=$(cat VERSION)
  246. echo "Current version: $CURRENT_VERSION"
  247. # Bump version in package.json
  248. npm run version:bump:$BUMP_TYPE
  249. # Get new version
  250. NEW_VERSION=$(cat VERSION)
  251. echo "New version: $NEW_VERSION"
  252. # Update CHANGELOG.md
  253. DATE=$(date +%Y-%m-%d)
  254. COMMIT_MSG=$(git log -1 --pretty=%B)
  255. # Create changelog entry
  256. cat > /tmp/changelog_entry.md << EOF
  257. ## [$NEW_VERSION] - $DATE
  258. ### Changes
  259. - $COMMIT_MSG
  260. EOF
  261. # Prepend to CHANGELOG.md (after the header)
  262. if [ -f CHANGELOG.md ]; then
  263. # Insert after the first occurrence of "## ["
  264. awk '/^## \[/ && !found {print; system("cat /tmp/changelog_entry.md"); found=1; next} 1' CHANGELOG.md > /tmp/changelog_new.md
  265. mv /tmp/changelog_new.md CHANGELOG.md
  266. fi
  267. - name: Commit version bump
  268. run: |
  269. NEW_VERSION=$(cat VERSION)
  270. git add VERSION package.json CHANGELOG.md
  271. git commit -m "chore: bump version to v$NEW_VERSION [skip ci]"
  272. git tag "v$NEW_VERSION"
  273. - name: Push changes
  274. run: |
  275. git push origin main --tags
  276. env:
  277. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  278. - name: Create GitHub Release
  279. run: |
  280. NEW_VERSION=$(cat VERSION)
  281. # Extract changelog entry for this version
  282. RELEASE_NOTES=$(awk '/^## \['"$NEW_VERSION"'\]/{flag=1; next} /^## \[/{flag=0} flag' CHANGELOG.md)
  283. # If no specific notes found, use commit message
  284. if [ -z "$RELEASE_NOTES" ]; then
  285. RELEASE_NOTES="Release v$NEW_VERSION"
  286. fi
  287. # Create the release
  288. gh release create "v$NEW_VERSION" \
  289. --title "v$NEW_VERSION" \
  290. --notes "$RELEASE_NOTES" \
  291. --latest
  292. env:
  293. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}