about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-01-19T14·56+0300
committerclbot <clbot@tvl.fyi>2022-01-19T17·22+0000
commitc2e6c0719c68171a6d4902893ffb09aa8002b183 (patch)
tree7db16307fade20b3fcd98a5b45835762df659594
parentf0aa5ae3a2f519d5bdee84439fa38287818793c3 (diff)
refactor(ops/pipelines): Generalise fetch-parent-targets script r/3636
Removes all TVL-specific values in favour of environment variables
supplied by Buildkite.

This makes it possible to reuse this script outside of TVL.

Change-Id: Ic543bc41e4c81e65ee349ad241c515231e97ab30
Reviewed-on: https://cl.tvl.fyi/c/depot/+/5005
Tested-by: BuildkiteCI
Autosubmit: tazjin <tazjin@tvl.su>
Reviewed-by: ezemtsov <eugene.zemtsov@gmail.com>
-rwxr-xr-xops/pipelines/fetch-parent-targets.sh25
-rw-r--r--ops/pipelines/static-pipeline.yaml4
2 files changed, 15 insertions, 14 deletions
diff --git a/ops/pipelines/fetch-parent-targets.sh b/ops/pipelines/fetch-parent-targets.sh
index bc334fc35c..d34a826279 100755
--- a/ops/pipelines/fetch-parent-targets.sh
+++ b/ops/pipelines/fetch-parent-targets.sh
@@ -3,38 +3,39 @@ set -ueo pipefail
 
 # Each Buildkite build stores the derivation target map as a pipeline
 # artifact. This script determines the most appropriate commit (the
-# fork point of the current chain from canon) and fetches the
-# artifact.
+# fork point of the current chain from HEAD) and fetches the artifact.
 #
-# Since builds can be based on canon before the pipeline for the last
-# commit has finished, it is possible that the fork point has no
-# target map. To account for this, we will go up to 3 commits back in
-# time to find a map.
+# New builds can be based on HEAD before the pipeline for the last
+# commit has finished, in which case it is possible that the fork
+# point has no derivation map. To account for this, up to 3 commits
+# prior to HEAD are also queried to find a map.
 #
 # If no map is found, the failure mode is not critical: We simply
 # build all targets.
 
+: ${DRVMAP_PATH:=pipeline/drvmap.json}
+
 function most_relevant_builds {
-    git fetch -v origin canon
-    local FIRST=$(git merge-base --fork-point HEAD origin/canon)
+    git fetch -v origin "${BUILDKITE_PIPELINE_DEFAULT_BRANCH}"
+    local FIRST=$(git merge-base --fork-point HEAD FETCH_HEAD)
     local SECOND=$(git rev-parse "$FIRST~1")
     local THIRD=$(git rev-parse "$FIRST~2")
 
     curl 'https://graphql.buildkite.com/v1' \
          --silent \
          -H "Authorization: Bearer $(cat /run/agenix/buildkite-graphql-token)" \
-         -d "{\"query\": \"query { pipeline(slug: \\\"tvl/depot\\\") { builds(commit: [\\\"$FIRST\\\",\\\"$SECOND\\\",\\\"$THIRD\\\"]) { edges { node { uuid }}}}}\"}" | \
+         -d "{\"query\": \"query { pipeline(slug: \\\"$BUILDKITE_ORGANIZATION_SLUG/$BUILDKITE_PIPELINE_SLUG\\\") { builds(commit: [\\\"$FIRST\\\",\\\"$SECOND\\\",\\\"$THIRD\\\"]) { edges { node { uuid }}}}}\"}" | \
          jq -r '.data.pipeline.builds.edges[] | .node.uuid'
 }
 
 mkdir -p tmp
 for build in $(most_relevant_builds); do
     echo "Checking artifacts for build $build"
-    buildkite-agent artifact download --build "${build}" 'pipeline/drvmap.json' 'tmp/' || true
+    buildkite-agent artifact download --build "${build}" "${DRVMAP_PATH}" 'tmp/' || true
 
-    if [[ -f "tmp/pipeline/drvmap.json" ]]; then
+    if [[ -f "tmp/${DRVMAP_PATH}" ]]; then
         echo "Fetched target map from build ${build}"
-        mv tmp/pipeline/drvmap.json parent-target-map.json
+        mv "tmp/${DRVMAP_PATH}" tmp/parent-target-map.json
         break
     fi
 done
diff --git a/ops/pipelines/static-pipeline.yaml b/ops/pipelines/static-pipeline.yaml
index 52f9f82039..ffdb6a75c5 100644
--- a/ops/pipelines/static-pipeline.yaml
+++ b/ops/pipelines/static-pipeline.yaml
@@ -21,8 +21,8 @@ steps:
         ops/pipelines/fetch-parent-targets.sh
 
       PIPELINE_ARGS=""
-      if [[ -f ./parent-target-map.json ]]; then
-        PIPELINE_ARGS="--arg parentTargetMap ./parent-target-map.json"
+      if [[ -f tmp/parent-target-map.json ]]; then
+        PIPELINE_ARGS="--arg parentTargetMap tmp/parent-target-map.json"
       fi
 
       nix-build -A ops.pipelines.depot -o pipeline --show-trace $$PIPELINE_ARGS