2021-08-29 14:25:59 +02:00
|
|
|
# This file defines the static Buildkite pipeline which attempts to
|
|
|
|
# create the dynamic pipeline of all depot targets.
|
|
|
|
#
|
|
|
|
# If something fails during the creation of the pipeline, the fallback
|
|
|
|
# is executed instead which will simply report an error to Gerrit.
|
2020-11-17 23:27:38 +01:00
|
|
|
---
|
|
|
|
steps:
|
|
|
|
- label: ":llama:"
|
2021-10-01 12:43:53 +02:00
|
|
|
key: "pipeline-gen"
|
2020-11-17 23:27:38 +01:00
|
|
|
command: |
|
2021-12-10 08:10:02 +01:00
|
|
|
set -ue
|
2021-12-19 17:24:04 +01:00
|
|
|
|
|
|
|
if test -n "$${GERRIT_CHANGE_URL-}"; then
|
|
|
|
echo "This is a build of [cl/$$GERRIT_CHANGE_ID]($$GERRIT_CHANGE_URL) (at patchset #$$GERRIT_PATCHSET)" | \
|
|
|
|
buildkite-agent annotate
|
|
|
|
fi
|
|
|
|
|
2021-12-15 12:28:15 +01:00
|
|
|
nix-build -A ops.pipelines.depot -o pipeline --show-trace
|
|
|
|
|
|
|
|
# Steps need to be uploaded in reverse order because pipeline
|
|
|
|
# upload prepends instead of appending.
|
|
|
|
ls pipeline/chunk-*.json | tac | while read chunk; do
|
|
|
|
buildkite-agent pipeline upload $$chunk
|
|
|
|
done
|
2020-11-17 23:27:38 +01:00
|
|
|
|
2021-10-01 12:43:53 +02:00
|
|
|
buildkite-agent artifact upload pipeline/drvmap.json
|
|
|
|
|
2022-01-07 01:53:51 +01:00
|
|
|
# Wait for all previous steps to complete.
|
|
|
|
- wait: null
|
|
|
|
continue_on_failure: true
|
|
|
|
|
2021-12-10 08:10:02 +01:00
|
|
|
# Exit with success or failure depending on whether any other steps
|
|
|
|
# failed.
|
|
|
|
#
|
|
|
|
# This information is checked by querying the Buildkite GraphQL API
|
|
|
|
# and fetching the count of failed steps.
|
|
|
|
#
|
|
|
|
# This step must be :duck: (yes, really!) because the post-command
|
|
|
|
# hook will inspect this name.
|
|
|
|
#
|
|
|
|
# Note that this step has requirements for the agent environment, which
|
|
|
|
# are enforced in our NixOS configuration:
|
|
|
|
#
|
|
|
|
# * curl and jq must be on the $PATH of build agents
|
|
|
|
# * besadii configuration must be readable to the build agents
|
|
|
|
- label: ":duck:"
|
|
|
|
key: ":duck:"
|
|
|
|
command: |
|
|
|
|
set -ueo pipefail
|
|
|
|
|
|
|
|
readonly FAILED_JOBS=$(curl 'https://graphql.buildkite.com/v1' \
|
|
|
|
--silent \
|
2021-12-10 21:14:41 +01:00
|
|
|
-H "Authorization: Bearer $(cat /run/agenix/buildkite-graphql-token)" \
|
2021-12-10 08:10:02 +01:00
|
|
|
-d "{\"query\": \"query BuildStatusQuery { build(uuid: \\\"$BUILDKITE_BUILD_ID\\\") { jobs(passed: false) { count } } }\"}" | \
|
|
|
|
jq -r '.data.build.jobs.count')
|
|
|
|
|
|
|
|
echo "$$FAILED_JOBS build jobs failed."
|
|
|
|
|
|
|
|
if (( $$FAILED_JOBS > 0 )); then
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-11-05 13:59:57 +01:00
|
|
|
|
2021-12-10 09:01:21 +01:00
|
|
|
# After duck, on success, create a gcroot if the build branch is
|
|
|
|
# canon.
|
|
|
|
#
|
|
|
|
# We care that this anchors *most* of the depot, in practice it's
|
|
|
|
# unimportant if there is a build race and we get +-1 of the
|
|
|
|
# targets.
|
|
|
|
#
|
|
|
|
# Unfortunately this requires a third evaluation of the graph, but
|
|
|
|
# since it happens after :duck: it should not affect the timing of
|
|
|
|
# status reporting back to Gerrit.
|
|
|
|
- label: ":anchor:"
|
|
|
|
if: "build.branch == 'refs/heads/canon'"
|
|
|
|
command: |
|
2022-01-01 16:37:58 +01:00
|
|
|
nix-build -A ci.gcroot --out-link /nix/var/nix/gcroots/depot/canon
|
2021-12-10 09:01:21 +01:00
|
|
|
depends_on:
|
|
|
|
- step: ":duck:"
|
|
|
|
allow_failure: false
|
|
|
|
|
2021-11-05 13:59:57 +01:00
|
|
|
# Create a revision number for the current commit for builds on
|
|
|
|
# canon.
|
|
|
|
#
|
|
|
|
# This writes data back to Gerrit using the Buildkite agent
|
|
|
|
# credentials injected through a git credentials helper.
|
|
|
|
#
|
|
|
|
# Revision numbers are defined as the number of commits in the
|
|
|
|
# lineage of HEAD, following only the first parent of merges.
|
|
|
|
- label: ":git:"
|
|
|
|
if: "build.branch == 'refs/heads/canon'"
|
|
|
|
command: |
|
2021-12-10 21:14:41 +01:00
|
|
|
git -c 'credential.helper=gerrit-creds' \
|
2021-11-05 15:31:21 +01:00
|
|
|
push origin "HEAD:refs/r/$(git rev-list --count --first-parent HEAD)"
|