|
| 1 | +name: 'Gemini CLI Trusted CI' |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: ['Gemini CLI CI'] |
| 6 | + types: |
| 7 | + - 'completed' |
| 8 | + branches: |
| 9 | + - 'main' |
| 10 | + - 'release' |
| 11 | + |
| 12 | +jobs: |
| 13 | + test: |
| 14 | + environment: 'trusted-ci-env' |
| 15 | + name: 'Test' |
| 16 | + runs-on: '${{ matrix.os }}' |
| 17 | + if: |- |
| 18 | + ${{ github.event.workflow_run.conclusion == 'success' && |
| 19 | + github.event.workflow_run.event == 'pull_request' }} |
| 20 | + permissions: |
| 21 | + contents: 'read' |
| 22 | + checks: 'write' |
| 23 | + pull-requests: 'write' |
| 24 | + strategy: |
| 25 | + fail-fast: false # So we can see all test failures |
| 26 | + matrix: |
| 27 | + os: |
| 28 | + - 'macos-latest' |
| 29 | + - 'ubuntu-latest' |
| 30 | + - 'windows-latest' |
| 31 | + node-version: |
| 32 | + - '20.x' |
| 33 | + - '22.x' |
| 34 | + - '24.x' |
| 35 | + steps: |
| 36 | + - name: 'Checkout base branch' |
| 37 | + uses: 'actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8' # ratchet:actions/checkout@v5 |
| 38 | + with: |
| 39 | + ref: '${{ github.event.workflow_run.base_branch }}' # Checkout base branch |
| 40 | + |
| 41 | + - name: 'Download Build Artifacts' |
| 42 | + uses: 'actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0' # ratchet:actions/download-artifact@v5 |
| 43 | + with: |
| 44 | + name: 'build-artifacts' |
| 45 | + path: '.' # Download to current directory |
| 46 | + |
| 47 | + - name: 'Set up Node.js ${{ matrix.node-version }}' |
| 48 | + uses: 'actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020' # ratchet:actions/setup-node@v4 |
| 49 | + with: |
| 50 | + node-version: '${{ matrix.node-version }}' |
| 51 | + cache: 'npm' |
| 52 | + |
| 53 | + - name: 'Fail if no access to secrets' |
| 54 | + if: '${{ secrets.GEMINI_API_KEY == '' }}' # Only run if secret is NOT available |
| 55 | + run: | |
| 56 | + echo "Error: Integration tests cannot be skipped due to missing GEMINI_API_KEY secret." |
| 57 | + echo "This workflow requires GEMINI_API_KEY for integration tests." |
| 58 | + exit 1 # This will cause the step and thus the job to fail |
| 59 | +
|
| 60 | + - name: 'Run integration tests' |
| 61 | + if: '${{ secrets.GEMINI_API_KEY == '' }}' # Only run if secret is available |
| 62 | + env: |
| 63 | + NO_COLOR: true |
| 64 | + GEMINI_API_KEY: '${{ secrets.GEMINI_API_KEY }}' # Access secret here |
| 65 | + run: 'npm run test:integration:all' |
| 66 | + |
| 67 | + - name: 'Publish Test Report' |
| 68 | + if: |- |
| 69 | + ${{ always() }} |
| 70 | + uses: 'dorny/test-reporter@dc3a92680fcc15842eef52e8c4606ea7ce6bd3f3' # ratchet:dorny/test-reporter@v2 |
| 71 | + with: |
| 72 | + name: 'Test Results (Node ${{ matrix.node-version }})' |
| 73 | + path: 'packages/*/junit.xml' |
| 74 | + reporter: 'java-junit' |
| 75 | + fail-on-error: 'false' |
| 76 | + |
| 77 | + - name: 'Upload coverage reports' |
| 78 | + if: |- |
| 79 | + ${{ always() }} |
| 80 | + uses: 'actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02' # ratchet:actions/upload-artifact@v4 |
| 81 | + with: |
| 82 | + name: 'coverage-reports-${{ matrix.node-version }}-${{ matrix.os }}' |
| 83 | + path: 'packages/*/coverage' |
| 84 | + |
| 85 | + post_coverage_comment: |
| 86 | + name: 'Post Coverage Comment' |
| 87 | + runs-on: 'ubuntu-latest' |
| 88 | + needs: 'test' |
| 89 | + if: |- |
| 90 | + ${{ always() && github.event.workflow_run.conclusion == 'success' && |
| 91 | + github.event.workflow_run.event == 'pull_request' }} |
| 92 | + continue-on-error: true |
| 93 | + permissions: |
| 94 | + contents: 'read' # For checkout |
| 95 | + pull-requests: 'write' # For commenting |
| 96 | + strategy: |
| 97 | + matrix: |
| 98 | + # Reduce noise by only posting the comment once |
| 99 | + os: |
| 100 | + - 'ubuntu-latest' |
| 101 | + node-version: |
| 102 | + - '22.x' |
| 103 | + steps: |
| 104 | + - name: 'Checkout base branch' |
| 105 | + uses: 'actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8' # ratchet:actions/checkout@v5 |
| 106 | + with: |
| 107 | + ref: '${{ github.event.workflow_run.base_branch }}' # Checkout base branch |
| 108 | + |
| 109 | + - name: 'Download coverage reports artifact' |
| 110 | + uses: 'actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0' # ratchet:actions/download-artifact@v5 |
| 111 | + with: |
| 112 | + name: 'coverage-reports-${{ matrix.node-version }}-${{ matrix.os }}' |
| 113 | + path: 'coverage_artifact' # Download to a specific directory |
| 114 | + |
| 115 | + - name: 'Post Coverage Comment using Composite Action' |
| 116 | + uses: './.github/actions/post-coverage-comment' # Path to the composite action directory |
| 117 | + with: |
| 118 | + cli_json_file: 'coverage_artifact/cli/coverage/coverage-summary.json' |
| 119 | + core_json_file: 'coverage_artifact/core/coverage/coverage-summary.json' |
| 120 | + cli_full_text_summary_file: 'coverage_artifact/cli/coverage/full-text-summary.txt' |
| 121 | + core_full_text_summary_file: 'coverage_artifact/core/coverage/full-text-summary.txt' |
| 122 | + node_version: '${{ matrix.node-version }}' |
| 123 | + os: '${{ matrix.os }}' |
| 124 | + github_token: '${{ secrets.GITHUB_TOKEN }}' |
0 commit comments