From f7891c513d810fc6e92361f43f2ec57816ae1197 Mon Sep 17 00:00:00 2001 From: Lukasz Okraszewski Date: Wed, 3 Jan 2024 09:39:30 +0000 Subject: [PATCH 1/4] chore: update dir structure As of gitlab 16.5 the component dir structure has changed. Updates the name of component to match the updated docs. --- .gitlab-ci.yml | 1 + templates/bazelisk.yml | 1 + 2 files changed, 2 insertions(+) create mode 120000 templates/bazelisk.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 62d6935..e8f40f6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,5 @@ include: + # In 16.5 onwards use "${CI_SERVER_HOST}/${CI_PROJECT_PATH}/bazelisk@${CI_COMMIT_SHA}" - component: "${CI_SERVER_HOST}/${CI_PROJECT_PATH}@${CI_COMMIT_SHA}" inputs: tag: "${CI_COMMIT_SHA}" diff --git a/templates/bazelisk.yml b/templates/bazelisk.yml new file mode 120000 index 0000000..44afddd --- /dev/null +++ b/templates/bazelisk.yml @@ -0,0 +1 @@ +../template.yml \ No newline at end of file -- GitLab From 8282d7129fad6a36d28f1c7dc78364161a109562 Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Wed, 3 Jan 2024 11:51:41 +0000 Subject: [PATCH 2/4] fix: add stage to `.bazelisk` job --- template.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/template.yml b/template.yml index 30b718e..8c5695d 100644 --- a/template.yml +++ b/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" -- GitLab From c5ced293dbed2c4371f544c529130a1b14c86f1d Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Wed, 3 Jan 2024 11:30:13 +0000 Subject: [PATCH 3/4] fix: commit to new component directory structure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes the component include path consistent on 16.3/16.5+. They changed the template structure from: ``` ├── template.yml ├── README.md ├── .gitlab-ci.yml ├── unit/ │ └── template.yml └── integration/ └── template.yml ``` To: ``` ├── README.md ├── .gitlab-ci.yml └── templates/ └── all-scans.yml └── secret-detection.yml ``` Unfortunately, symlinks are *not* supported so until we can drop support for 16.3, we'll have to copy over changes. BREAKING CHANGE: The component must be included via the `bazelisk` name. The nameless include in `1.0.0-beta.1` is no longer supported. ``` include: - component: "${CI_SERVER_HOST}/ci/component/bazelisk@1.0.0-beta.1" ``` Add the `/bazelisk` named CI component: ``` include: - component: "${CI_SERVER_HOST}/ci/component/bazelisk/bazelisk@1.0.0-beta.2" ``` This is due to GitLab CI components being stabilised and the nameless component support being removed. --- .gitlab-ci.yml | 3 +- README.md | 2 +- template.yml => bazelisk/template.yml | 0 templates/bazelisk.yml | 93 ++++++++++++++++++++++++++- 4 files changed, 94 insertions(+), 4 deletions(-) rename template.yml => bazelisk/template.yml (100%) mode change 120000 => 100644 templates/bazelisk.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e8f40f6..5d8ef06 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,6 +1,5 @@ include: - # In 16.5 onwards use "${CI_SERVER_HOST}/${CI_PROJECT_PATH}/bazelisk@${CI_COMMIT_SHA}" - - 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/README.md b/README.md index 46c947e..9af07c9 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 100% rename from template.yml rename to bazelisk/template.yml diff --git a/templates/bazelisk.yml b/templates/bazelisk.yml deleted file mode 120000 index 44afddd..0000000 --- a/templates/bazelisk.yml +++ /dev/null @@ -1 +0,0 @@ -../template.yml \ No newline at end of file diff --git a/templates/bazelisk.yml b/templates/bazelisk.yml new file mode 100644 index 0000000..8c5695d --- /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" -- GitLab From 106febbae0943bf08aaff1d52bc1777a0968dd8f Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Wed, 3 Jan 2024 13:41:30 +0000 Subject: [PATCH 4/4] docs(contributing): describe version compatibility --- CONTRIBUTING.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 17c641e..440daaf 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 -- GitLab