Merge branch 'jc/doc-final-resend'
[git] / .github / workflows / main.yml
1 name: CI/PR
2
3 on: [push, pull_request]
4
5 env:
6   DEVELOPER: 1
7
8 jobs:
9   ci-config:
10     runs-on: ubuntu-latest
11     outputs:
12       enabled: ${{ steps.check-ref.outputs.enabled }}${{ steps.skip-if-redundant.outputs.enabled }}
13     steps:
14       - name: try to clone ci-config branch
15         run: |
16           git -c protocol.version=2 clone \
17             --no-tags \
18             --single-branch \
19             -b ci-config \
20             --depth 1 \
21             --no-checkout \
22             --filter=blob:none \
23             https://github.com/${{ github.repository }} \
24             config-repo &&
25           cd config-repo &&
26           git checkout HEAD -- ci/config || : ignore
27       - id: check-ref
28         name: check whether CI is enabled for ref
29         run: |
30           enabled=yes
31           if test -x config-repo/ci/config/allow-ref &&
32              ! config-repo/ci/config/allow-ref '${{ github.ref }}'
33           then
34             enabled=no
35           fi
36           echo "::set-output name=enabled::$enabled"
37       - name: skip if the commit or tree was already tested
38         id: skip-if-redundant
39         uses: actions/github-script@v3
40         if: steps.check-ref.outputs.enabled == 'yes'
41         with:
42           github-token: ${{secrets.GITHUB_TOKEN}}
43           script: |
44             try {
45               // Figure out workflow ID, commit and tree
46               const { data: run } = await github.actions.getWorkflowRun({
47                 owner: context.repo.owner,
48                 repo: context.repo.repo,
49                 run_id: context.runId,
50               });
51               const workflow_id = run.workflow_id;
52               const head_sha = run.head_sha;
53               const tree_id = run.head_commit.tree_id;
54
55               // See whether there is a successful run for that commit or tree
56               const { data: runs } = await github.actions.listWorkflowRuns({
57                 owner: context.repo.owner,
58                 repo: context.repo.repo,
59                 per_page: 500,
60                 status: 'success',
61                 workflow_id,
62               });
63               for (const run of runs.workflow_runs) {
64                 if (head_sha === run.head_sha) {
65                   core.warning(`Successful run for the commit ${head_sha}: ${run.html_url}`);
66                   core.setOutput('enabled', ' but skip');
67                   break;
68                 }
69                 if (run.head_commit && tree_id === run.head_commit.tree_id) {
70                   core.warning(`Successful run for the tree ${tree_id}: ${run.html_url}`);
71                   core.setOutput('enabled', ' but skip');
72                   break;
73                 }
74               }
75             } catch (e) {
76               core.warning(e);
77             }
78
79   windows-build:
80     needs: ci-config
81     if: needs.ci-config.outputs.enabled == 'yes'
82     runs-on: windows-latest
83     steps:
84     - uses: actions/checkout@v1
85     - name: download git-sdk-64-minimal
86       shell: bash
87       run: |
88         ## Get artifact
89         urlbase=https://dev.azure.com/git-for-windows/git/_apis/build/builds
90         id=$(curl "$urlbase?definitions=22&statusFilter=completed&resultFilter=succeeded&\$top=1" |
91           jq -r ".value[] | .id")
92         download_url="$(curl "$urlbase/$id/artifacts" |
93           jq -r '.value[] | select(.name == "git-sdk-64-minimal").resource.downloadUrl')"
94         curl --connect-timeout 10 --retry 5 --retry-delay 0 --retry-max-time 240 \
95           -o artifacts.zip "$download_url"
96
97         ## Unzip and remove the artifact
98         unzip artifacts.zip
99         rm artifacts.zip
100     - name: build
101       shell: powershell
102       env:
103         HOME: ${{runner.workspace}}
104         MSYSTEM: MINGW64
105         NO_PERL: 1
106       run: |
107         & .\git-sdk-64-minimal\usr\bin\bash.exe -lc @"
108         printf '%s\n' /git-sdk-64-minimal/ >>.git/info/exclude
109
110           ci/make-test-artifacts.sh artifacts
111         "@
112     - name: upload build artifacts
113       uses: actions/upload-artifact@v1
114       with:
115         name: windows-artifacts
116         path: artifacts
117     - name: upload git-sdk-64-minimal
118       uses: actions/upload-artifact@v1
119       with:
120         name: git-sdk-64-minimal
121         path: git-sdk-64-minimal
122   windows-test:
123     runs-on: windows-latest
124     needs: [windows-build]
125     strategy:
126       matrix:
127         nr: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
128     steps:
129     - uses: actions/checkout@v1
130     - name: download build artifacts
131       uses: actions/download-artifact@v1
132       with:
133         name: windows-artifacts
134         path: ${{github.workspace}}
135     - name: extract build artifacts
136       shell: bash
137       run: tar xf artifacts.tar.gz
138     - name: download git-sdk-64-minimal
139       uses: actions/download-artifact@v1
140       with:
141         name: git-sdk-64-minimal
142         path: ${{github.workspace}}/git-sdk-64-minimal/
143     - name: test
144       shell: powershell
145       run: |
146         & .\git-sdk-64-minimal\usr\bin\bash.exe -lc @"
147           # Let Git ignore the SDK
148           printf '%s\n' /git-sdk-64-minimal/ >>.git/info/exclude
149
150           ci/run-test-slice.sh ${{matrix.nr}} 10
151         "@
152     - name: ci/print-test-failures.sh
153       if: failure()
154       shell: powershell
155       run: |
156         & .\git-sdk-64-minimal\usr\bin\bash.exe -lc ci/print-test-failures.sh
157     - name: Upload failed tests' directories
158       if: failure() && env.FAILED_TEST_ARTIFACTS != ''
159       uses: actions/upload-artifact@v1
160       with:
161         name: failed-tests-windows
162         path: ${{env.FAILED_TEST_ARTIFACTS}}
163   vs-build:
164     needs: ci-config
165     if: needs.ci-config.outputs.enabled == 'yes'
166     env:
167       MSYSTEM: MINGW64
168       NO_PERL: 1
169       GIT_CONFIG_PARAMETERS: "'user.name=CI' 'user.email=ci@git'"
170     runs-on: windows-latest
171     steps:
172     - uses: actions/checkout@v1
173     - name: download git-sdk-64-minimal
174       shell: bash
175       run: |
176         ## Get artifact
177         urlbase=https://dev.azure.com/git-for-windows/git/_apis/build/builds
178         id=$(curl "$urlbase?definitions=22&statusFilter=completed&resultFilter=succeeded&\$top=1" |
179           jq -r ".value[] | .id")
180         download_url="$(curl "$urlbase/$id/artifacts" |
181           jq -r '.value[] | select(.name == "git-sdk-64-minimal").resource.downloadUrl')"
182         curl --connect-timeout 10 --retry 5 --retry-delay 0 --retry-max-time 240 \
183           -o artifacts.zip "$download_url"
184
185         ## Unzip and remove the artifact
186         unzip artifacts.zip
187         rm artifacts.zip
188     - name: download vcpkg artifacts
189       shell: powershell
190       run: |
191         $urlbase = "https://dev.azure.com/git/git/_apis/build/builds"
192         $id = ((Invoke-WebRequest -UseBasicParsing "${urlbase}?definitions=9&statusFilter=completed&resultFilter=succeeded&`$top=1").content | ConvertFrom-JSON).value[0].id
193         $downloadUrl = ((Invoke-WebRequest -UseBasicParsing "${urlbase}/$id/artifacts").content | ConvertFrom-JSON).value[0].resource.downloadUrl
194         (New-Object Net.WebClient).DownloadFile($downloadUrl, "compat.zip")
195         Expand-Archive compat.zip -DestinationPath . -Force
196         Remove-Item compat.zip
197     - name: add msbuild to PATH
198       uses: microsoft/setup-msbuild@v1
199     - name: copy dlls to root
200       shell: powershell
201       run: |
202         & compat\vcbuild\vcpkg_copy_dlls.bat release
203         if (!$?) { exit(1) }
204     - name: generate Visual Studio solution
205       shell: bash
206       run: |
207         cmake `pwd`/contrib/buildsystems/ -DCMAKE_PREFIX_PATH=`pwd`/compat/vcbuild/vcpkg/installed/x64-windows \
208         -DIconv_LIBRARY=`pwd`/compat/vcbuild/vcpkg/installed/x64-windows/lib/libiconv.lib -DIconv_INCLUDE_DIR=`pwd`/compat/vcbuild/vcpkg/installed/x64-windows/include \
209         -DMSGFMT_EXE=`pwd`/git-sdk-64-minimal/mingw64/bin/msgfmt.exe -DPERL_TESTS=OFF -DPYTHON_TESTS=OFF -DCURL_NO_CURL_CMAKE=ON
210     - name: MSBuild
211       run: msbuild git.sln -property:Configuration=Release -property:Platform=x64 -maxCpuCount:4 -property:PlatformToolset=v142
212     - name: bundle artifact tar
213       shell: powershell
214       env:
215         MSVC: 1
216         VCPKG_ROOT: ${{github.workspace}}\compat\vcbuild\vcpkg
217       run: |
218         & git-sdk-64-minimal\usr\bin\bash.exe -lc @"
219           mkdir -p artifacts &&
220           eval \"`$(make -n artifacts-tar INCLUDE_DLLS_IN_ARTIFACTS=YesPlease ARTIFACTS_DIRECTORY=artifacts 2>&1 | grep ^tar)\"
221         "@
222     - name: upload build artifacts
223       uses: actions/upload-artifact@v1
224       with:
225         name: vs-artifacts
226         path: artifacts
227   vs-test:
228     runs-on: windows-latest
229     needs: [vs-build, windows-build]
230     strategy:
231       matrix:
232         nr: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
233     steps:
234     - uses: actions/checkout@v1
235     - name: download git-sdk-64-minimal
236       uses: actions/download-artifact@v1
237       with:
238         name: git-sdk-64-minimal
239         path: ${{github.workspace}}/git-sdk-64-minimal/
240     - name: download build artifacts
241       uses: actions/download-artifact@v1
242       with:
243         name: vs-artifacts
244         path: ${{github.workspace}}
245     - name: extract build artifacts
246       shell: bash
247       run: tar xf artifacts.tar.gz
248     - name: test
249       shell: powershell
250       env:
251         MSYSTEM: MINGW64
252         NO_SVN_TESTS: 1
253         GIT_TEST_SKIP_REBASE_P: 1
254       run: |
255         & .\git-sdk-64-minimal\usr\bin\bash.exe -lc @"
256           # Let Git ignore the SDK and the test-cache
257           printf '%s\n' /git-sdk-64-minimal/ /test-cache/ >>.git/info/exclude
258
259           ci/run-test-slice.sh ${{matrix.nr}} 10
260         "@
261     - name: ci/print-test-failures.sh
262       if: failure()
263       shell: powershell
264       run: |
265         & .\git-sdk-64-minimal\usr\bin\bash.exe -lc ci/print-test-failures.sh
266     - name: Upload failed tests' directories
267       if: failure() && env.FAILED_TEST_ARTIFACTS != ''
268       uses: actions/upload-artifact@v1
269       with:
270         name: failed-tests-windows
271         path: ${{env.FAILED_TEST_ARTIFACTS}}
272   regular:
273     needs: ci-config
274     if: needs.ci-config.outputs.enabled == 'yes'
275     strategy:
276       matrix:
277         vector:
278           - jobname: linux-clang
279             cc: clang
280             pool: ubuntu-latest
281           - jobname: linux-gcc
282             cc: gcc
283             pool: ubuntu-latest
284           - jobname: osx-clang
285             cc: clang
286             pool: macos-latest
287           - jobname: osx-gcc
288             cc: gcc
289             pool: macos-latest
290           - jobname: GETTEXT_POISON
291             cc: gcc
292             pool: ubuntu-latest
293     env:
294       CC: ${{matrix.vector.cc}}
295       jobname: ${{matrix.vector.jobname}}
296     runs-on: ${{matrix.vector.pool}}
297     steps:
298     - uses: actions/checkout@v1
299     - run: ci/install-dependencies.sh
300     - run: ci/run-build-and-tests.sh
301     - run: ci/print-test-failures.sh
302       if: failure()
303     - name: Upload failed tests' directories
304       if: failure() && env.FAILED_TEST_ARTIFACTS != ''
305       uses: actions/upload-artifact@v1
306       with:
307         name: failed-tests-${{matrix.vector.jobname}}
308         path: ${{env.FAILED_TEST_ARTIFACTS}}
309   dockerized:
310     needs: ci-config
311     if: needs.ci-config.outputs.enabled == 'yes'
312     strategy:
313       matrix:
314         vector:
315         - jobname: linux-musl
316           image: alpine
317         - jobname: Linux32
318           image: daald/ubuntu32:xenial
319     env:
320       jobname: ${{matrix.vector.jobname}}
321     runs-on: ubuntu-latest
322     container: ${{matrix.vector.image}}
323     steps:
324     - uses: actions/checkout@v1
325     - run: ci/install-docker-dependencies.sh
326     - run: ci/run-build-and-tests.sh
327     - run: ci/print-test-failures.sh
328       if: failure()
329     - name: Upload failed tests' directories
330       if: failure() && env.FAILED_TEST_ARTIFACTS != ''
331       uses: actions/upload-artifact@v1
332       with:
333         name: failed-tests-${{matrix.vector.jobname}}
334         path: ${{env.FAILED_TEST_ARTIFACTS}}
335   static-analysis:
336     needs: ci-config
337     if: needs.ci-config.outputs.enabled == 'yes'
338     env:
339       jobname: StaticAnalysis
340     runs-on: ubuntu-latest
341     steps:
342     - uses: actions/checkout@v1
343     - run: ci/install-dependencies.sh
344     - run: ci/run-static-analysis.sh
345   documentation:
346     needs: ci-config
347     if: needs.ci-config.outputs.enabled == 'yes'
348     env:
349       jobname: Documentation
350     runs-on: ubuntu-latest
351     steps:
352     - uses: actions/checkout@v1
353     - run: ci/install-dependencies.sh
354     - run: ci/test-documentation.sh