The eleventh batch
[git/gitster.git] / .github / workflows / main.yml
blob9301a1edd6d8496c8d1bc799f6a33d6041688392
1 name: CI
3 on: [push, pull_request]
5 env:
6   DEVELOPER: 1
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.
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 }}
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
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@v7
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;
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             }
106   windows-build:
107     name: win build
108     needs: ci-config
109     if: needs.ci-config.outputs.enabled == 'yes'
110     runs-on: windows-latest
111     concurrency:
112       group: windows-build-${{ github.ref }}
113       cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }}
114     steps:
115     - uses: actions/checkout@v4
116     - name: setup SDK
117       shell: powershell
118       run: ci/install-sdk.ps1
119     - name: build
120       shell: powershell
121       env:
122         HOME: ${{runner.workspace}}
123         NO_PERL: 1
124       run: git-sdk/usr/bin/bash.exe -l -c 'ci/make-test-artifacts.sh artifacts'
125     - name: zip up tracked files
126       run: git archive -o artifacts/tracked.tar.gz HEAD
127     - name: upload tracked files and build artifacts
128       uses: actions/upload-artifact@v4
129       with:
130         name: windows-artifacts
131         path: artifacts
132   windows-test:
133     name: win test
134     runs-on: windows-latest
135     needs: [ci-config, windows-build]
136     strategy:
137       fail-fast: false
138       matrix:
139         nr: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
140     concurrency:
141       group: windows-test-${{ matrix.nr }}-${{ github.ref }}
142       cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }}
143     steps:
144     - name: download tracked files and build artifacts
145       uses: actions/download-artifact@v4
146       with:
147         name: windows-artifacts
148         path: ${{github.workspace}}
149     - name: extract tracked files and build artifacts
150       shell: bash
151       run: tar xf artifacts.tar.gz && tar xf tracked.tar.gz
152     - name: setup SDK
153       shell: powershell
154       run: ci/install-sdk.ps1
155     - name: test
156       shell: powershell
157       run: git-sdk/usr/bin/bash.exe -l -c 'ci/run-test-slice.sh ${{matrix.nr}} 10'
158     - name: print test failures
159       if: failure() && env.FAILED_TEST_ARTIFACTS != ''
160       shell: bash
161       run: ci/print-test-failures.sh
162     - name: Upload failed tests' directories
163       if: failure() && env.FAILED_TEST_ARTIFACTS != ''
164       uses: actions/upload-artifact@v4
165       with:
166         name: failed-tests-windows-${{ matrix.nr }}
167         path: ${{env.FAILED_TEST_ARTIFACTS}}
168   vs-build:
169     name: win+VS build
170     needs: ci-config
171     if: github.event.repository.owner.login == 'git-for-windows' && needs.ci-config.outputs.enabled == 'yes'
172     env:
173       NO_PERL: 1
174       GIT_CONFIG_PARAMETERS: "'user.name=CI' 'user.email=ci@git'"
175     runs-on: windows-latest
176     concurrency:
177       group: vs-build-${{ github.ref }}
178       cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }}
179     steps:
180     - uses: actions/checkout@v4
181     - uses: git-for-windows/setup-git-for-windows-sdk@v1
182     - name: initialize vcpkg
183       uses: actions/checkout@v4
184       with:
185         repository: 'microsoft/vcpkg'
186         path: 'compat/vcbuild/vcpkg'
187     - name: download vcpkg artifacts
188       uses: git-for-windows/get-azure-pipelines-artifact@v0
189       with:
190         repository: git/git
191         definitionId: 9
192     - name: add msbuild to PATH
193       uses: microsoft/setup-msbuild@v2
194     - name: copy dlls to root
195       shell: cmd
196       run: compat\vcbuild\vcpkg_copy_dlls.bat release
197     - name: generate Visual Studio solution
198       shell: bash
199       run: |
200         cmake `pwd`/contrib/buildsystems/ -DCMAKE_PREFIX_PATH=`pwd`/compat/vcbuild/vcpkg/installed/x64-windows \
201         -DNO_GETTEXT=YesPlease -DPERL_TESTS=OFF -DPYTHON_TESTS=OFF -DCURL_NO_CURL_CMAKE=ON
202     - name: MSBuild
203       run: msbuild git.sln -property:Configuration=Release -property:Platform=x64 -maxCpuCount:4 -property:PlatformToolset=v142
204     - name: bundle artifact tar
205       shell: bash
206       env:
207         MSVC: 1
208         VCPKG_ROOT: ${{github.workspace}}\compat\vcbuild\vcpkg
209       run: |
210         mkdir -p artifacts &&
211         eval "$(make -n artifacts-tar INCLUDE_DLLS_IN_ARTIFACTS=YesPlease ARTIFACTS_DIRECTORY=artifacts NO_GETTEXT=YesPlease 2>&1 | grep ^tar)"
212     - name: zip up tracked files
213       run: git archive -o artifacts/tracked.tar.gz HEAD
214     - name: upload tracked files and build artifacts
215       uses: actions/upload-artifact@v4
216       with:
217         name: vs-artifacts
218         path: artifacts
219   vs-test:
220     name: win+VS test
221     runs-on: windows-latest
222     needs: [ci-config, vs-build]
223     strategy:
224       fail-fast: false
225       matrix:
226         nr: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
227     concurrency:
228       group: vs-test-${{ matrix.nr }}-${{ github.ref }}
229       cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }}
230     steps:
231     - uses: git-for-windows/setup-git-for-windows-sdk@v1
232     - name: download tracked files and build artifacts
233       uses: actions/download-artifact@v4
234       with:
235         name: vs-artifacts
236         path: ${{github.workspace}}
237     - name: extract tracked files and build artifacts
238       shell: bash
239       run: tar xf artifacts.tar.gz && tar xf tracked.tar.gz
240     - name: test
241       shell: bash
242       env:
243         NO_SVN_TESTS: 1
244       run: . /etc/profile && ci/run-test-slice.sh ${{matrix.nr}} 10
245     - name: print test failures
246       if: failure() && env.FAILED_TEST_ARTIFACTS != ''
247       shell: bash
248       run: ci/print-test-failures.sh
249     - name: Upload failed tests' directories
250       if: failure() && env.FAILED_TEST_ARTIFACTS != ''
251       uses: actions/upload-artifact@v4
252       with:
253         name: failed-tests-windows-vs-${{ matrix.nr }}
254         path: ${{env.FAILED_TEST_ARTIFACTS}}
255   regular:
256     name: ${{matrix.vector.jobname}} (${{matrix.vector.pool}})
257     needs: ci-config
258     if: needs.ci-config.outputs.enabled == 'yes'
259     concurrency:
260       group: ${{ matrix.vector.jobname }}-${{ matrix.vector.pool }}-${{ github.ref }}
261       cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }}
262     strategy:
263       fail-fast: false
264       matrix:
265         vector:
266           - jobname: linux-sha256
267             cc: clang
268             pool: ubuntu-latest
269           - jobname: linux-reftable
270             cc: clang
271             pool: ubuntu-latest
272           - jobname: linux-gcc
273             cc: gcc
274             cc_package: gcc-8
275             pool: ubuntu-20.04
276           - jobname: linux-TEST-vars
277             cc: gcc
278             cc_package: gcc-8
279             pool: ubuntu-20.04
280           - jobname: osx-clang
281             cc: clang
282             pool: macos-13
283           - jobname: osx-reftable
284             cc: clang
285             pool: macos-13
286           - jobname: osx-gcc
287             cc: gcc-13
288             pool: macos-13
289           - jobname: linux-gcc-default
290             cc: gcc
291             pool: ubuntu-latest
292           - jobname: linux-leaks
293             cc: gcc
294             pool: ubuntu-latest
295           - jobname: linux-reftable-leaks
296             cc: gcc
297             pool: ubuntu-latest
298           - jobname: linux-asan-ubsan
299             cc: clang
300             pool: ubuntu-latest
301     env:
302       CC: ${{matrix.vector.cc}}
303       CC_PACKAGE: ${{matrix.vector.cc_package}}
304       jobname: ${{matrix.vector.jobname}}
305       distro: ${{matrix.vector.pool}}
306     runs-on: ${{matrix.vector.pool}}
307     steps:
308     - uses: actions/checkout@v4
309     - run: ci/install-dependencies.sh
310     - run: ci/run-build-and-tests.sh
311     - name: print test failures
312       if: failure() && env.FAILED_TEST_ARTIFACTS != ''
313       run: ci/print-test-failures.sh
314     - name: Upload failed tests' directories
315       if: failure() && env.FAILED_TEST_ARTIFACTS != ''
316       uses: actions/upload-artifact@v4
317       with:
318         name: failed-tests-${{matrix.vector.jobname}}
319         path: ${{env.FAILED_TEST_ARTIFACTS}}
320   fuzz-smoke-test:
321     name: fuzz smoke test
322     needs: ci-config
323     if: needs.ci-config.outputs.enabled == 'yes'
324     env:
325       CC: clang
326     runs-on: ubuntu-latest
327     steps:
328     - uses: actions/checkout@v4
329     - run: ci/install-dependencies.sh
330     - run: ci/run-build-and-minimal-fuzzers.sh
331   dockerized:
332     name: ${{matrix.vector.jobname}} (${{matrix.vector.image}})
333     needs: ci-config
334     if: needs.ci-config.outputs.enabled == 'yes'
335     concurrency:
336       group: dockerized-${{ matrix.vector.jobname }}-${{ matrix.vector.image }}-${{ github.ref }}
337       cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }}
338     strategy:
339       fail-fast: false
340       matrix:
341         vector:
342         - jobname: linux-musl
343           image: alpine
344           distro: alpine-latest
345         - jobname: linux32
346           image: i386/ubuntu:focal
347           distro: ubuntu32-20.04
348         - jobname: pedantic
349           image: fedora
350           distro: fedora-latest
351     env:
352       jobname: ${{matrix.vector.jobname}}
353       distro: ${{matrix.vector.distro}}
354     runs-on: ubuntu-latest
355     container: ${{matrix.vector.image}}
356     steps:
357     - name: prepare libc6 for actions
358       if: matrix.vector.jobname == 'linux32'
359       run: apt -q update && apt -q -y install libc6-amd64 lib64stdc++6
360     - uses: actions/checkout@v4
361     - run: ci/install-dependencies.sh
362     - run: ci/run-build-and-tests.sh
363     - name: print test failures
364       if: failure() && env.FAILED_TEST_ARTIFACTS != ''
365       run: ci/print-test-failures.sh
366     - name: Upload failed tests' directories
367       if: failure() && env.FAILED_TEST_ARTIFACTS != ''
368       uses: actions/upload-artifact@v4
369       with:
370         name: failed-tests-${{matrix.vector.jobname}}
371         path: ${{env.FAILED_TEST_ARTIFACTS}}
372   static-analysis:
373     needs: ci-config
374     if: needs.ci-config.outputs.enabled == 'yes'
375     env:
376       jobname: StaticAnalysis
377     runs-on: ubuntu-22.04
378     concurrency:
379       group: static-analysis-${{ github.ref }}
380       cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }}
381     steps:
382     - uses: actions/checkout@v4
383     - run: ci/install-dependencies.sh
384     - run: ci/run-static-analysis.sh
385     - run: ci/check-directional-formatting.bash
386   sparse:
387     needs: ci-config
388     if: needs.ci-config.outputs.enabled == 'yes'
389     env:
390       jobname: sparse
391     runs-on: ubuntu-20.04
392     concurrency:
393       group: sparse-${{ github.ref }}
394       cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }}
395     steps:
396     - name: Download a current `sparse` package
397       # Ubuntu's `sparse` version is too old for us
398       uses: git-for-windows/get-azure-pipelines-artifact@v0
399       with:
400         repository: git/git
401         definitionId: 10
402         artifact: sparse-20.04
403     - name: Install the current `sparse` package
404       run: sudo dpkg -i sparse-20.04/sparse_*.deb
405     - uses: actions/checkout@v4
406     - name: Install other dependencies
407       run: ci/install-dependencies.sh
408     - run: make sparse
409   documentation:
410     name: documentation
411     needs: ci-config
412     if: needs.ci-config.outputs.enabled == 'yes'
413     concurrency:
414       group: documentation-${{ github.ref }}
415       cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }}
416     env:
417       jobname: Documentation
418     runs-on: ubuntu-latest
419     steps:
420     - uses: actions/checkout@v4
421     - run: ci/install-dependencies.sh
422     - run: ci/test-documentation.sh