From 84a20b6a203cb9ed28ec56fdc362e2fa2a42824a Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Wed, 3 Jan 2024 13:57:30 +0000 Subject: [PATCH] refactor: reuse template Uses a `include:local` to avoid having to copy the template for older GitLab version support. --- CONTRIBUTING.md | 39 -------------------- bazelisk/template.yml | 80 ++++++++---------------------------------- templates/bazelisk.yml | 1 + 3 files changed, 16 insertions(+), 104 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 440daaf..17c641e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,42 +5,3 @@ - [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/bazelisk/template.yml b/bazelisk/template.yml index 8c5695d..7ef288a 100644 --- a/bazelisk/template.yml +++ b/bazelisk/template.yml @@ -1,3 +1,4 @@ +# TODO: delete this file once `gitlab.arm.com` is upgraded to 16.5+ spec: inputs: image: @@ -25,68 +26,17 @@ spec: 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" +include: + - local: "/templates/bazelisk.yml" + inputs: + image: "$[[inputs.image]]" + tag: "$[[inputs.tag]]" + stage: "$[[inputs.stage]]" + src: "$[[inputs.src]]" + dst: "$[[inputs.dst]]" + bazelisk: "$[[inputs.bazelisk]]" + command: "$[[inputs.command]]" + target: "$[[inputs.target]]" + root: "$[[inputs.root]]" + key: "$[[inputs.key]]" + variables: "$[[inputs.variables]]" diff --git a/templates/bazelisk.yml b/templates/bazelisk.yml index 8c5695d..936ef07 100644 --- a/templates/bazelisk.yml +++ b/templates/bazelisk.yml @@ -1,3 +1,4 @@ +# TODO: anything added here must also be added in `bazelisk/template.yml` until `gitlab.arm.com` upgrades to 16.5+ spec: inputs: image: -- GitLab