backport https://github.com/github/copilot-sdk/pull/1483 #398
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: "Build & Test" | |
| on: | |
| schedule: | |
| # Run once a week on Sundays at 00:00 UTC | |
| - cron: '0 0 * * 0' | |
| push: | |
| branches: [main] | |
| paths-ignore: | |
| - 'README.md' | |
| - 'LICENSE' | |
| - '.github/**' | |
| pull_request: | |
| paths-ignore: | |
| - 'README.md' | |
| - 'LICENSE' | |
| - '.github/**' | |
| workflow_dispatch: | |
| merge_group: | |
| permissions: | |
| contents: read | |
| jobs: | |
| smoke-test: | |
| name: "Smoke Test" | |
| uses: ./.github/workflows/run-smoke-test.yml | |
| secrets: | |
| COPILOT_GITHUB_TOKEN: ${{ secrets.COPILOT_GITHUB_TOKEN }} | |
| java-sdk: | |
| name: "Java SDK Tests (JDK ${{ matrix.test-jdk }})" | |
| needs: smoke-test | |
| if: ${{ always() && needs.smoke-test.result != 'failure' }} | |
| permissions: | |
| contents: write | |
| checks: write | |
| pull-requests: write | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| test-jdk: ["25", "17"] | |
| defaults: | |
| run: | |
| shell: bash | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| persist-credentials: false | |
| - uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5 | |
| with: | |
| java-version: "25" | |
| distribution: "microsoft" | |
| cache: "maven" | |
| - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6 | |
| with: | |
| node-version: 22 | |
| - name: Build SDK and set up test harness | |
| run: mvn test-compile jar:jar | |
| - name: Verify Javadoc generation | |
| if: matrix.test-jdk == '25' | |
| run: mvn javadoc:javadoc -q | |
| - name: Verify CLI works | |
| run: node target/copilot-sdk/nodejs/node_modules/@github/copilot/index.js --version | |
| - name: Run spotless check | |
| if: matrix.test-jdk == '25' | |
| run: | | |
| mvn spotless:check | |
| if [ $? -ne 0 ]; then | |
| echo "❌ spotless:check failed. Please run 'mvn spotless:apply' in java" | |
| exit 1 | |
| fi | |
| echo "✅ spotless:check passed" | |
| - name: Run Java SDK tests (JDK 25) | |
| if: matrix.test-jdk == '25' | |
| env: | |
| CI: "true" | |
| run: mvn verify -Dskip.test.harness=true | |
| - name: Switch to JDK 17 | |
| if: matrix.test-jdk == '17' | |
| uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5 | |
| with: | |
| java-version: "17" | |
| distribution: "microsoft" | |
| - name: Run Java SDK tests (JDK 17, no recompilation) | |
| if: matrix.test-jdk == '17' | |
| env: | |
| CI: "true" | |
| run: | | |
| echo "Running tests against JDK 25-built classes using JDK 17 runtime..." | |
| java -version | |
| mvn jacoco:prepare-agent@wire-up-coverage-instrumentation antrun:run@print-test-jdk-banner surefire:test failsafe:integration-test failsafe:verify jacoco:report@build-coverage-report-from-tests -Denforcer.skip=true | |
| - name: Validate reference-impl-sync completeness | |
| if: >- | |
| github.event_name == 'pull_request' && | |
| contains(github.event.pull_request.labels.*.name, 'reference-impl-sync') | |
| run: | | |
| git fetch origin main --depth=1 | |
| CHANGED=$(git diff --name-only origin/main...HEAD) | |
| # 1. .lastmerge must be updated (proves finish script ran) | |
| if echo "$CHANGED" | grep -q '^\\.lastmerge$'; then | |
| echo "✅ .lastmerge was updated (finish script ran)" | |
| else | |
| echo "❌ .lastmerge was not updated. The merge-reference-impl-finish.sh script" | |
| echo " must be run before this PR can merge. This script updates .lastmerge," | |
| echo " syncs the CLI version in pom.xml, and syncs scripts/codegen/package.json." | |
| exit 1 | |
| fi | |
| # 2. If codegen inputs changed, generated output must also have changed | |
| if echo "$CHANGED" | grep -q '^scripts/codegen/'; then | |
| if echo "$CHANGED" | grep -q '^src/generated/java/'; then | |
| echo "✅ Codegen inputs changed and generated files were regenerated" | |
| else | |
| echo "❌ scripts/codegen/ was updated but src/generated/java/ has no changes." | |
| echo " The Codegen Check workflow should regenerate these files automatically." | |
| echo " If it hasn't run yet, wait for it to complete and push regenerated files." | |
| echo " Or run manually: cd scripts/codegen && npm ci && npm run generate" | |
| exit 1 | |
| fi | |
| else | |
| echo "✅ No codegen input changes — regeneration not needed" | |
| fi | |
| - name: Upload test results for site generation | |
| if: success() && github.ref == 'refs/heads/main' && matrix.test-jdk == '25' | |
| uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 | |
| with: | |
| name: test-results-for-site | |
| path: | | |
| target/jacoco-test-results/sdk-tests.exec | |
| target/surefire-reports/ | |
| target/surefire-reports-isolated/ | |
| retention-days: 1 | |
| - name: Generate JaCoCo badge | |
| if: success() && github.ref == 'refs/heads/main' && matrix.test-jdk == '25' | |
| run: .github/scripts/generate-coverage-badge.sh | |
| - name: Create PR for JaCoCo badge update | |
| if: success() && github.ref == 'refs/heads/main' && matrix.test-jdk == '25' | |
| uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v7 | |
| with: | |
| commit-message: "Update JaCoCo coverage badge" | |
| title: "Update JaCoCo coverage badge" | |
| body: "Automated JaCoCo coverage badge update from CI." | |
| branch: auto/update-jacoco-badge | |
| add-paths: .github/badges/ | |
| delete-branch: true | |
| - name: Generate Test Report Summary | |
| if: always() | |
| uses: ./.github/actions/test-report | |
| with: | |
| title: "Copilot Java SDK :: Test Results JDK ${{ matrix.test-jdk }}" | |
| - name: Upload test results on failure | |
| if: failure() | |
| uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 | |
| with: | |
| name: test-results-jdk-${{ matrix.test-jdk }} | |
| path: | | |
| target/surefire-reports/ | |
| target/surefire-reports-isolated/ | |
| target/failsafe-reports/ | |
| retention-days: 7 |