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