Skip to content

Commit b5eda60

Browse files
gkalpakmatsko
authored andcommitted
ci: work around CIRCLE_COMPARE_URL not being available wih CircleCI Pipelines (angular#32537)
The commit range that is associated with a CI build is used for a couple of things (mostly related to payload-size tracking): - Determine whether a size change was caused by application code or dependencies (or both). - Add the messages of the commits associated with the build (and thus the payload-size change). NOTE: The commit range is only used on push builds. Previously, the commit range was computed based on the `CIRCLE_COMPARE_URL` environment variable. With [CircleCI Pipelines][1] enabled, `CIRCLE_COMPARE_URL` is no longer available and the commit range cannot be reliably detected. This commit switches `CI_COMMIT_RANGE` to only include the last commit. This can be less accurate in some rare cases, but is true in the majority of cases (on push builds). Additionally, it stores the CircleCI build URL in the database along with the payload data, so the relevant info can be retrieved when needed. [1]: https://circleci.com/docs/2.0/build-processing PR Close angular#32537
1 parent df5924a commit b5eda60

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

.circleci/env.sh

+8-4
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,20 @@ setPublicVar PROJECT_ROOT "$projectDir";
1919
setPublicVar CI_AIO_MIN_PWA_SCORE "95";
2020
# This is the branch being built; e.g. `pull/12345` for PR builds.
2121
setPublicVar CI_BRANCH "$CIRCLE_BRANCH";
22+
setPublicVar CI_BUILD_URL "$CIRCLE_BUILD_URL";
2223
# ChromeDriver version compatible with the Chrome version included in the docker image used in
2324
# `.circleci/config.yml`. See http://chromedriver.chromium.org/downloads for a list of versions.
2425
# This variable is intended to be passed as an arg to the `webdriver-manager update` command (e.g.
2526
# `"postinstall": "webdriver-manager update $CI_CHROMEDRIVER_VERSION_ARG"`).
2627
setPublicVar CI_CHROMEDRIVER_VERSION_ARG "--versions.chrome 75.0.3770.90";
2728
setPublicVar CI_COMMIT "$CIRCLE_SHA1";
28-
# `CI_COMMIT_RANGE` will only be available when `CIRCLE_COMPARE_URL` is also available (or can be
29-
# retrieved via `get-compare-url.js`), i.e. on push builds (a.k.a. non-PR, non-scheduled builds and
30-
# rerun workflows of such builds). That is fine, since we only need it in push builds.
31-
setPublicVar CI_COMMIT_RANGE "`[[ ${CIRCLE_PR_NUMBER:-false} != false ]] && echo "" || node $getCommitRangePath "$CIRCLE_BUILD_NUM" "$CIRCLE_COMPARE_URL"`";
29+
# `CI_COMMIT_RANGE` is only used on push builds (a.k.a. non-PR, non-scheduled builds and rerun
30+
# workflows of such builds).
31+
# NOTE: With [CircleCI Pipelines](https://circleci.com/docs/2.0/build-processing) enabled,
32+
# `CIRCLE_COMPARE_URL` is no longer available and the commit range cannot be reliably
33+
# detected. Fall back to only considering the last commit (which is accurate in the majority
34+
# of cases for push builds).
35+
setPublicVar CI_COMMIT_RANGE "`[[ ${CIRCLE_PR_NUMBER:-false} != false ]] && echo "" || echo "$CIRCLE_SHA1~1...$CIRCLE_SHA1"`";
3236
setPublicVar CI_PULL_REQUEST "${CIRCLE_PR_NUMBER:-false}";
3337
setPublicVar CI_REPO_NAME "$CIRCLE_PROJECT_REPONAME";
3438
setPublicVar CI_REPO_OWNER "$CIRCLE_PROJECT_USERNAME";

.circleci/get-commit-range.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
* format of the `CIRCLE_COMPARE_URL` environment variable, or by retrieving the equivalent of
1111
* `CIRCLE_COMPARE_URL` for jobs that are part of a rerun workflow and extracting it from there.
1212
*
13+
* > !!! WARNING !!!
14+
* > !!
15+
* > !! When [CircleCI Pipelines](https://circleci.com/docs/2.0/build-processing) is enabled, the
16+
* > !! `CIRCLE_COMPARE_URL` environment variable is not available at all and this script does not
17+
* > !! work.
18+
* > !!!!!!!!!!!!!!!
19+
*
1320
* **Context:**
1421
* CircleCI sets the `CIRCLE_COMPARE_URL` environment variable (from which we can extract the commit
1522
* range) on push builds (a.k.a. non-PR, non-scheduled builds). Yet, when a workflow is rerun
@@ -21,7 +28,7 @@
2128
* (undocumented) fact that the workspace ID happens to be the same as the workflow ID that first
2229
* created it.
2330
*
24-
* For example, for a job on push build workflow, the CircleCI API will return data that look like:
31+
* For example, for a job on push build workflows, the CircleCI API will return data that look like:
2532
* ```js
2633
* {
2734
* compare: 'THE_COMPARE_URL_WE_ARE_LOOKING_FOR',

scripts/ci/payload-size.sh

+10
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ addTimestamp() {
5151
payloadData="$payloadData\"timestamp\": $timestamp, "
5252
}
5353

54+
# Write the current CI build URL to global variable `$payloadData`.
55+
# This allows mapping the data stored in the database to the CI build job that generated it, which
56+
# might contain more info/context.
57+
# $1: string - The CI build URL.
58+
addBuildUrl() {
59+
buildUrl="$1"
60+
payloadData="$payloadData\"buildUrl\": \"$buildUrl\", "
61+
}
62+
5463
# Write the commit message for the current CI commit range to global variable `$payloadData`.
5564
# $1: string - The commit range for this build (in `<SHA-1>...<SHA-2>` format).
5665
addMessage() {
@@ -142,6 +151,7 @@ trackPayloadSize() {
142151
addChangeType $CI_COMMIT_RANGE
143152
fi
144153
addTimestamp
154+
addBuildUrl $CI_BUILD_URL
145155
addMessage $CI_COMMIT_RANGE
146156
uploadData $name
147157
fi

0 commit comments

Comments
 (0)