| 1 | name: CI |
| 2 | |
| 3 | on: [push, pull_request] |
| 4 | |
| 5 | env: |
| 6 | DEVELOPER: 1 |
| 7 | |
| 8 | # If more than one workflow run is triggered for the very same commit hash |
| 9 | # (which happens when multiple branches pointing to the same commit), only |
| 10 | # the first one is allowed to run, the second will be kept in the "queued" |
| 11 | # state. This allows a successful completion of the first run to be reused |
| 12 | # in the second run via the `skip-if-redundant` logic in the `config` job. |
| 13 | # |
| 14 | # The only caveat is that if a workflow run is triggered for the same commit |
| 15 | # hash that another run is already being held, that latter run will be |
| 16 | # canceled. For more details about the `concurrency` attribute, see: |
| 17 | # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#concurrency |
| 18 | concurrency: |
| 19 | group: ${{ github.sha }} |
| 20 | |
| 21 | jobs: |
| 22 | ci-config: |
| 23 | name: config |
| 24 | if: vars.CI_BRANCHES == '' || contains(vars.CI_BRANCHES, github.ref_name) |
| 25 | runs-on: ubuntu-latest |
| 26 | outputs: |
| 27 | enabled: ${{ steps.check-ref.outputs.enabled }}${{ steps.skip-if-redundant.outputs.enabled }} |
| 28 | skip_concurrent: ${{ steps.check-ref.outputs.skip_concurrent }} |
| 29 | steps: |
| 30 | - name: try to clone ci-config branch |
| 31 | run: | |
| 32 | git -c protocol.version=2 clone \ |
| 33 | --no-tags \ |
| 34 | --single-branch \ |
| 35 | -b ci-config \ |
| 36 | --depth 1 \ |
| 37 | --no-checkout \ |
| 38 | --filter=blob:none \ |
| 39 | https://github.com/${{ github.repository }} \ |
| 40 | config-repo && |
| 41 | cd config-repo && |
| 42 | git checkout HEAD -- ci/config || : ignore |
| 43 | - id: check-ref |
| 44 | name: check whether CI is enabled for ref |
| 45 | run: | |
| 46 | enabled=yes |
| 47 | if test -x config-repo/ci/config/allow-ref |
| 48 | then |
| 49 | echo "::warning::ci/config/allow-ref is deprecated; use CI_BRANCHES instead" |
| 50 | if ! config-repo/ci/config/allow-ref '${{ github.ref }}' |
| 51 | then |
| 52 | enabled=no |
| 53 | fi |
| 54 | fi |
| 55 | |
| 56 | skip_concurrent=yes |
| 57 | if test -x config-repo/ci/config/skip-concurrent && |
| 58 | ! config-repo/ci/config/skip-concurrent '${{ github.ref }}' |
| 59 | then |
| 60 | skip_concurrent=no |
| 61 | fi |
| 62 | echo "enabled=$enabled" >>$GITHUB_OUTPUT |
| 63 | echo "skip_concurrent=$skip_concurrent" >>$GITHUB_OUTPUT |
| 64 | - name: skip if the commit or tree was already tested |
| 65 | id: skip-if-redundant |
| 66 | uses: actions/github-script@v9 |
| 67 | if: steps.check-ref.outputs.enabled == 'yes' |
| 68 | with: |
| 69 | github-token: ${{secrets.GITHUB_TOKEN}} |
| 70 | script: | |
| 71 | try { |
| 72 | // Figure out workflow ID, commit and tree |
| 73 | const { data: run } = await github.rest.actions.getWorkflowRun({ |
| 74 | owner: context.repo.owner, |
| 75 | repo: context.repo.repo, |
| 76 | run_id: context.runId, |
| 77 | }); |
| 78 | const workflow_id = run.workflow_id; |
| 79 | const head_sha = run.head_sha; |
| 80 | const tree_id = run.head_commit.tree_id; |
| 81 | |
| 82 | // See whether there is a successful run for that commit or tree |
| 83 | const { data: runs } = await github.rest.actions.listWorkflowRuns({ |
| 84 | owner: context.repo.owner, |
| 85 | repo: context.repo.repo, |
| 86 | per_page: 500, |
| 87 | status: 'success', |
| 88 | workflow_id, |
| 89 | }); |
| 90 | for (const run of runs.workflow_runs) { |
| 91 | if (head_sha === run.head_sha) { |
| 92 | core.warning(`Successful run for the commit ${head_sha}: ${run.html_url}`); |
| 93 | core.setOutput('enabled', ' but skip'); |
| 94 | break; |
| 95 | } |
| 96 | if (run.head_commit && tree_id === run.head_commit.tree_id) { |
| 97 | core.warning(`Successful run for the tree ${tree_id}: ${run.html_url}`); |
| 98 | core.setOutput('enabled', ' but skip'); |
| 99 | break; |
| 100 | } |
| 101 | } |
| 102 | } catch (e) { |
| 103 | core.warning(e); |
| 104 | } |
| 105 | |
| 106 | regular: |
| 107 | name: ${{matrix.vector.jobname}} (${{matrix.vector.pool}}) |
| 108 | needs: ci-config |
| 109 | if: needs.ci-config.outputs.enabled == 'yes' |
| 110 | concurrency: |
| 111 | group: ${{ matrix.vector.jobname }}-${{ matrix.vector.pool }}-${{ github.ref }} |
| 112 | cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }} |
| 113 | strategy: |
| 114 | fail-fast: false |
| 115 | matrix: |
| 116 | vector: |
| 117 | - jobname: osx-clang |
| 118 | cc: clang |
| 119 | pool: macos-14 |
| 120 | - jobname: osx-reftable |
| 121 | cc: clang |
| 122 | pool: macos-14 |
| 123 | - jobname: osx-gcc |
| 124 | cc: gcc-13 |
| 125 | pool: macos-14 |
| 126 | - jobname: osx-meson |
| 127 | cc: clang |
| 128 | pool: macos-14 |
| 129 | env: |
| 130 | CC: ${{matrix.vector.cc}} |
| 131 | CC_PACKAGE: ${{matrix.vector.cc_package}} |
| 132 | jobname: ${{matrix.vector.jobname}} |
| 133 | CI_JOB_IMAGE: ${{matrix.vector.pool}} |
| 134 | TEST_OUTPUT_DIRECTORY: ${{github.workspace}}/t |
| 135 | runs-on: ${{matrix.vector.pool}} |
| 136 | steps: |
| 137 | - uses: actions/checkout@v6 |
| 138 | - run: ci/install-dependencies.sh |
| 139 | - run: ci/run-build-and-tests.sh |
| 140 | - name: print test failures |
| 141 | if: failure() && env.FAILED_TEST_ARTIFACTS != '' |
| 142 | run: ci/print-test-failures.sh |
| 143 | - name: Upload failed tests' directories |
| 144 | if: failure() && env.FAILED_TEST_ARTIFACTS != '' |
| 145 | uses: actions/upload-artifact@v7 |
| 146 | with: |
| 147 | name: failed-tests-${{matrix.vector.jobname}} |
| 148 | path: ${{env.FAILED_TEST_ARTIFACTS}} |