You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
BASELINE_COMMIT_TIME=$(git -c log.showSignature=false show --no-patch --format=%ct ${BASELINE_SHA})
79
78
if [[ ${BASELINE_COMMIT_TIME} -le ${FOUR_DAYS_BEFORE_NOW} ]]
80
79
then
81
-
echo "ERROR: Merge-base of this branch is too old for SMP. Please update your branch by merging an up-to-date main branch into your branch or by rebasing it on an up-to-date main branch."
80
+
echo "ERROR: Baseline commit (${BASELINE_SHA}) for this branch (${CI_COMMIT_BRANCH}) is too old for SMP. Please update your branch by merging or rebasing it onto an up-to-date ${SMP_BASE_BRANCH} branch."
81
+
# Updating onto ${SMP_BASE_BRANCH} makes its tip this branch's new
82
+
# merge base, so the next pipeline needs a baseline image for that
83
+
# tip. A release branch can sit idle long enough for its tip's
84
+
# image to age out of ECR, in which case that next pipeline fails
85
+
# here too -- costing another image build, which takes 40-60
86
+
# minutes once started plus unknown runner queue time. Start the
87
+
# build now so it overlaps with the update instead of following it.
88
+
#
89
+
# Release branches only: a merge base with main has almost always
90
+
# been built already by some other recent pipeline, and updating
91
+
# onto main costs one pipeline rather than two.
92
+
#
93
+
# Best-effort -- a failure to trigger is reported but does not
94
+
# change this job's outcome, which is a failure either way.
95
+
if [[ "$SMP_BASE_BRANCH" =~ ^[0-9]+\.[0-9]+\.x$ ]]
echo "WARNING: could not determine whether a baseline image exists for the ${SMP_BASE_BRANCH} tip (${SMP_BASE_TIP}), so not triggering a rebuild: ${SMP_ECR_ERROR}"
115
+
else
116
+
echo "No baseline image exists for the ${SMP_BASE_BRANCH} tip (${SMP_BASE_TIP}) - triggering a pipeline to build one now"
117
+
# Report the triggered pipeline's URL rather than an
118
+
# expected duration, which would go stale as build times
119
+
# and runner queue depths change.
120
+
#
121
+
# `POST /trigger/pipeline`, not `POST /pipeline`: GitLab
122
+
# allowlists `CI_JOB_TOKEN` for the former only, and it
123
+
# authenticates through a `token` body parameter rather
124
+
# than a header. `tasks/pipeline.py` starts child
125
+
# pipelines the same way, for the same reason.
126
+
#
127
+
# This call therefore cannot be reproduced verbatim outside
128
+
# a running job, since job tokens exist only inside one. A
129
+
# personal token minted with `dda inv auth.gitlab` works
130
+
# the other way around: it may use `POST /pipeline`, but is
131
+
# not a valid `token` value for the trigger endpoint, which
132
+
# accepts only trigger and job tokens. So the equivalent
133
+
# local command is the `PRIVATE-TOKEN` one printed below,
134
+
# aimed at a different endpoint on purpose.
135
+
#
136
+
# `CI_API_V4_URL` is https://gitlab.ddbuild.io/api/v4 and
137
+
# `CI_PROJECT_ID` is 4670 for this project.
138
+
#
139
+
# The trailing `|| true` on both lines keeps this
140
+
# best-effort. The runner runs this script under
141
+
# `set -eo pipefail`, where a bare `VAR=$(failing-cmd)`
142
+
# aborts the block -- which would skip the warning and
143
+
# self-service output below, the most useful thing this
144
+
# branch prints. `--fail` also makes curl exit nonzero on
145
+
# an HTTP error while emitting nothing, and `jq` exits
146
+
# nonzero on a non-JSON body, so the empty-string check
echo "WARNING: could not trigger a pipeline on ${SMP_BASE_BRANCH} - one may need to be started manually"
154
+
else
155
+
SMP_REBUILD_TRIGGERED="true"
156
+
echo "Triggered ${SMP_REBUILD_PIPELINE_URL} on ${SMP_BASE_BRANCH}"
157
+
# Name the job that publishes the image rather than
158
+
# linking it. Resolving its URL means listing the
159
+
# pipeline's jobs, and GitLab allowlists `CI_JOB_TOKEN`
160
+
# for only `GET /job` out of the whole Jobs API, so that
161
+
# lookup cannot succeed from here whatever it is given.
162
+
echo "The baseline image for ${SMP_BASE_TIP} is published by the single_machine_performance-full-amd64-a7 job, listed at ${SMP_REBUILD_PIPELINE_URL}/builds"
163
+
fi
164
+
echo "NOTE: this job will keep failing until that image is published to SMP's ECR registry, so wait for it before re-running this job."
165
+
# Give a self-service path to starting the build. Needed
166
+
# when the trigger above failed, and also when a triggered
167
+
# pipeline dies for reasons outside this job -- CI runners
168
+
# are taken offline for maintenance periodically, which
169
+
# kills the pipelines on them.
170
+
#
171
+
# `dda inv auth.gitlab` prints feature-flag lines to stdout
172
+
# before the token, so the `tail -1` is load-bearing: without
173
+
# it those lines land in the header value and curl fails with
174
+
# "curl: (43) bad argument".
175
+
echo "To start that pipeline yourself -- if the trigger above failed, or if the"
176
+
echo "pipeline is cancelled, e.g. by CI runner maintenance -- either open"
0 commit comments