git/.gitlab-ci.yml
Karthik Nayak 30c4f7e350 check-whitespace: detect if no base_commit is provided
The 'check-whitespace' CI script exits gracefully if no base commit is
provided or if an invalid revision is provided. This is not good because
if a particular CI provides an incorrect base_commit, it would fail
successfully.

This is exactly the case with the GitLab CI. The CI is using the
"$CI_MERGE_REQUEST_TARGET_BRANCH_SHA" variable to get the base commit
SHA, but variable is only defined for _merged_ pipelines. So it is empty
for regular pipelines [1]. This should've failed the check-whitespace
job.

Let's fallback to 'CI_MERGE_REQUEST_DIFF_BASE_SHA' if
"CI_MERGE_REQUEST_TARGET_BRANCH_SHA" isn't available in GitLab CI,
similar to the previous commit. Let's also add a check for incorrect
base_commit in the 'check-whitespace.sh' script. While here, fix a small
typo too.

[1]: https://docs.gitlab.com/ee/ci/variables/predefined_variables.html#predefined-variables-for-merge-request-pipelines

Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-07-23 09:56:50 -07:00

157 lines
4.1 KiB
YAML

default:
timeout: 2h
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_TAG
- if: $CI_COMMIT_REF_PROTECTED == "true"
test:linux:
image: $image
variables:
CUSTOM_PATH: "/custom"
before_script:
- ./ci/install-dependencies.sh
script:
- useradd builder --create-home
- chown -R builder "${CI_PROJECT_DIR}"
- sudo --preserve-env --set-home --user=builder ./ci/run-build-and-tests.sh
after_script:
- |
if test "$CI_JOB_STATUS" != 'success'
then
sudo --preserve-env --set-home --user=builder ./ci/print-test-failures.sh
fi
parallel:
matrix:
- jobname: linux-sha256
image: ubuntu:latest
CC: clang
- jobname: linux-reftable
image: ubuntu:latest
CC: clang
- jobname: linux-gcc
image: ubuntu:20.04
CC: gcc
CC_PACKAGE: gcc-8
- jobname: linux-TEST-vars
image: ubuntu:20.04
CC: gcc
CC_PACKAGE: gcc-8
- jobname: linux-gcc-default
image: ubuntu:latest
CC: gcc
- jobname: linux-leaks
image: ubuntu:latest
CC: gcc
- jobname: linux-reftable-leaks
image: ubuntu:latest
CC: gcc
- jobname: linux-asan-ubsan
image: ubuntu:latest
CC: clang
- jobname: pedantic
image: fedora:latest
- jobname: linux-musl
image: alpine:latest
artifacts:
paths:
- t/failed-test-artifacts
when: on_failure
test:osx:
image: $image
tags:
- saas-macos-medium-m1
variables:
TEST_OUTPUT_DIRECTORY: "/Volumes/RAMDisk"
before_script:
# Create a 4GB RAM disk that we use to store test output on. This small hack
# significantly speeds up tests by more than a factor of 2 because the
# macOS runners use network-attached storage as disks, which is _really_
# slow with the many small writes that our tests do.
- sudo diskutil apfs create $(hdiutil attach -nomount ram://8192000) RAMDisk
- ./ci/install-dependencies.sh
script:
- ./ci/run-build-and-tests.sh
after_script:
- |
if test "$CI_JOB_STATUS" != 'success'
then
./ci/print-test-failures.sh
mv "$TEST_OUTPUT_DIRECTORY"/failed-test-artifacts t/
fi
parallel:
matrix:
- jobname: osx-clang
image: macos-13-xcode-14
CC: clang
- jobname: osx-reftable
image: macos-13-xcode-14
CC: clang
artifacts:
paths:
- t/failed-test-artifacts
when: on_failure
test:fuzz-smoke-tests:
image: ubuntu:latest
variables:
CC: clang
before_script:
- ./ci/install-dependencies.sh
script:
- ./ci/run-build-and-minimal-fuzzers.sh
static-analysis:
image: ubuntu:22.04
variables:
jobname: StaticAnalysis
before_script:
- ./ci/install-dependencies.sh
script:
- ./ci/run-static-analysis.sh
- ./ci/check-directional-formatting.bash
check-whitespace:
image: ubuntu:latest
before_script:
- ./ci/install-dependencies.sh
# Since $CI_MERGE_REQUEST_TARGET_BRANCH_SHA is only defined for merged
# pipelines, we fallback to $CI_MERGE_REQUEST_DIFF_BASE_SHA, which should
# be defined in all pipelines.
script:
- |
R=${CI_MERGE_REQUEST_TARGET_BRANCH_SHA-${CI_MERGE_REQUEST_DIFF_BASE_SHA:?}} || exit
./ci/check-whitespace.sh "$R"
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
check-style:
image: ubuntu:latest
allow_failure: true
variables:
CC: clang
jobname: ClangFormat
before_script:
- ./ci/install-dependencies.sh
# Since $CI_MERGE_REQUEST_TARGET_BRANCH_SHA is only defined for merged
# pipelines, we fallback to $CI_MERGE_REQUEST_DIFF_BASE_SHA, which should
# be defined in all pipelines.
script:
- |
R=${CI_MERGE_REQUEST_TARGET_BRANCH_SHA-${CI_MERGE_REQUEST_DIFF_BASE_SHA:?}} || exit
./ci/run-style-check.sh "$R"
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
documentation:
image: ubuntu:latest
variables:
jobname: Documentation
before_script:
- ./ci/install-dependencies.sh
script:
- ./ci/test-documentation.sh