diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 62d6935dd28aeaa538552aaf460ac65b93693c9d..5d8ef062dca119cef59e9ed71b29d37fdde73528 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,5 @@ include: - - component: "${CI_SERVER_HOST}/${CI_PROJECT_PATH}@${CI_COMMIT_SHA}" + - component: "${CI_SERVER_HOST}/${CI_PROJECT_PATH}/bazelisk@${CI_COMMIT_SHA}" inputs: tag: "${CI_COMMIT_SHA}" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 17c641ecdb871441591076c04ffd8689ffaac4e5..440daafeaeccba18e9cfe7ebd5916564ef9c0099 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,3 +5,42 @@ - [Install](https://github.com/bazelbuild/bazelisk#installation) `bazelisk` - Run `bazelisk test //...` - Run `bazelisk test $(bazelisk query "attr(tags, '\bmanual\b', //...)")` + +## GitLab Compatibility + +GitLab CI components were experimental for a while. + +In [GitLab 16.3][16.3] the folder structure for a named component looked like so: + +``` +├── template.yml +├── README.md +├── .gitlab-ci.yml +├── unit/ +│ └── template.yml +└── integration/ + └── template.yml +``` + +In [16.5], the directory structure changed to: + +``` +├── README.md +├── .gitlab-ci.yml +└── templates/ + └── all-scans.yml + └── secret-detection.yml +``` + +The old structure was [deprecated]. + +Until the GitLab instance is upgraded past 16.5 both structures need to be supported. + +_Unfortunately_, a GitLab CI component **cannot be a symlink** so we must copy the content between +`templates/bazelisk.yml` and `bazelisk/template.yml`. + +TODO: when gitlab.arm.com upgrades to 16.5+ remove this section and `bazelisk/template.yml` + +[16.3]: https://archives.docs.gitlab.com/16.3/ee/ci/components/#directory-structure +[16.5]: https://docs.gitlab.com/16.5/ee/ci/components/#directory-structure +[deprecated]: https://docs.gitlab.com/16.5/ee/ci/components/#component-configurations-saved-in-any-directory-deprecated diff --git a/README.md b/README.md index 46c947e0b896ddbb73fbb18e16731f245889af3f..9af07c9a1140d8ee00743249ffce8c58a5a6ecd3 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Add the CI component to the `.gitlab-ci.yml`: ```yaml include: - - component: gitlab.arm.com/ci/component/bazelisk@ + - component: "${CI_SERVER_HOST}/ci/component/bazelisk/bazelisk@" ``` Add a job that extends the `.bazelisk` template to recursively test the project: diff --git a/template.yml b/bazelisk/template.yml similarity index 98% rename from template.yml rename to bazelisk/template.yml index 30b718e9714611481f93725558e9a7b97909b0c2..8c5695d739238238dfd53572cd796cea3b6ed9ec 100644 --- a/template.yml +++ b/bazelisk/template.yml @@ -64,6 +64,7 @@ spec: .bazelisk: image: "$[[inputs.image]]:$[[inputs.tag]]" needs: [] + stage: "$[[inputs.stage]]" variables: ROOT: "$[[inputs.root]]" BAZELISK_HOME: "${CI_PROJECT_DIR}/.cache/bazelisk" diff --git a/templates/bazelisk.yml b/templates/bazelisk.yml new file mode 100644 index 0000000000000000000000000000000000000000..8c5695d739238238dfd53572cd796cea3b6ed9ec --- /dev/null +++ b/templates/bazelisk.yml @@ -0,0 +1,92 @@ +spec: + inputs: + image: + default: registry.gitlab.arm.com/ci/component/bazelisk + tag: + default: latest + stage: + default: test + src: + default: .bazelrc.ci + dst: + default: .bazelrc.user + bazelisk: + default: bazelisk + command: + default: test + target: + default: //... + root: + default: . + key: + default: "bazelisk-1" + variables: + default: | + CI_PROJECT_DIR + CI_PROJECT_ID +--- +.bazelisk-fragment: + rc: + - pushd "${ROOT}" + - | + # Copying Bazel run commands + set -euo pipefail + VARIABLES="${VARIABLES-$[[inputs.variables]]}" + while IFS= read -r LINE; do + for VARIABLE in ${VARIABLES}; do + LINE="${LINE//\$\{${VARIABLE}\}/${!VARIABLE}}" + done + printf '%s\n' "${LINE}" >> "$[[inputs.dst]]" + done < "$[[inputs.src]]" + - popd + execute: + - pushd "${ROOT}" + - > + "$[[inputs.bazelisk]]" "$[[inputs.command]]" "$[[inputs.target]]" + - popd + testlogs: # https://gitlab.com/gitlab-org/gitlab/-/issues/19746 + - | + # Copying test logs to workaround gitlab#19746 + set -euo pipefail + pushd "${ROOT}" + shopt -s extglob globstar nullglob + for SRC in bazel-testlogs/**/test.@(xml|log); do + DST="bazel-testlogs~/${SRC#bazel-testlogs}" + mkdir -p "${DST%/*}" + cp "${SRC}" "${DST}" + done + if test -d bazel-testlogs~; then + rm bazel-testlogs + mv bazel-testlogs{~,} + fi + popd + +.bazelisk: + image: "$[[inputs.image]]:$[[inputs.tag]]" + needs: [] + stage: "$[[inputs.stage]]" + variables: + ROOT: "$[[inputs.root]]" + BAZELISK_HOME: "${CI_PROJECT_DIR}/.cache/bazelisk" + cache: + key: "$[[inputs.key]]" + paths: + - ".cache" + when: always + script: + - !reference [.bazelisk-fragment, rc] + - !reference [.bazelisk-fragment, execute] + after_script: + - !reference [.bazelisk-fragment, testlogs] + artifacts: + paths: + - "${ROOT}/bazel-testlogs/**/test.log" + when: always + reports: + junit: "${ROOT}/bazel-testlogs/**/test.xml" + rules: + - if: $CI_MERGE_REQUEST_IID + - if: $CI_COMMIT_TAG + - if: $CI_COMMIT_REF_PROTECTED == "true" + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + - if: $CI_FORCE == "true"