-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🏗 Persist merge commit for reuse with later CI jobs #33165
Conversation
778cb10
to
0f8d04b
Compare
First run forked from d110566, and CircleCI is "merging" it with c6b122b. Results:
Success so far! |
The rebase failed, but for a surprising reason! After the build, but before bundle-size, a new commit was merged onto master. So we built from c2f0984 (https://app.circleci.com/pipelines/github/ampproject/amphtml/4038/workflows/dfff0a99-8d4a-400a-a39a-f5065b1fdb7b/jobs/51946/parallel-runs/0/steps/0-107), but diffed size against cfe8f2f (https://app.circleci.com/pipelines/github/ampproject/amphtml/4038/workflows/dfff0a99-8d4a-400a-a39a-f5065b1fdb7b/jobs/51966/parallel-runs/0/steps/0-107). |
One way to avoid this is to report bundle sizes immediately after building in the same job (i.e., the old way). This probably means we'll need to merge the module and nomodule size reports on the server side instead of consolidating binaries during CI. |
Hey @rsimha! These files were changed:
|
e6259bd
to
fbebb49
Compare
fbebb49
to
0841e3d
Compare
The new persist logic worked! You can see we consistently used merge commit ba9a167, even though I purposefully merged #33062 after the build started (but before bundle-size started). This is proven by the changed commit log lines: * ba9a1678e Justin Ridgewell - (HEAD -> pull/33165) Merge 0841e3d4929c06f6f0cbfa5938fe7594239e449d into 32a411de53fde79e349c6b636d8134acf070199d (4 minutes ago)
|\
| * 0841e3d49 Justin Ridgewell - (origin/pull/33165) Fetch and store merge_commit at the beginning of the build (4 minutes ago)
- * | 32a411de5 Dima Voytenko - (origin/master, origin/HEAD, master) Multi-version: signal when extensions are known (#33162) (19 minutes ago)
+ * | 32a411de5 Dima Voytenko - Multi-version: signal when extensions are known (#33162) (27 minutes ago) From that, we generated https://app.circleci.com/pipelines/github/ampproject/amphtml/4060/workflows/e50d7ea6-898d-455e-9c1e-ba6619708486/jobs/52305, and https://github.com/ampproject/amphtml/pull/33165/checks?check_run_id=2071240440. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for investigating this and prototyping a solution! You've managed to discover the elusive crux of the problem: a commit sneaking into master
between build stages of a CI build.
However, I think the solution can be made more efficient at the minimum, and potentially be done without adding a new CI stage. Posting an initial comment inline, will follow up after doing some homework.
The "compare" link on this check #33165 (checks) shows code from other PRs, I believe it too needs to use the merge commit SHA instead of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "compare" link on this check #33165 (checks) shows code from other PRs, I believe it too needs to use the merge commit SHA instead of gitCommitHash().
I agree partially. The comparison is definitely wrong, but I think the HEAD and BASE are should be reported as they are. We should instead change the code changes link to MERGE?
d67174f
to
d891e84
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree partially. The comparison is definitely wrong, but I think the HEAD and BASE are should be reported as they are. We should instead change the code changes link to MERGE?
Today, CI builds only report the base SHA to the bundle-size app (along with the actual sizes).
amphtml/build-system/tasks/bundle-size/index.js
Lines 188 to 191 in c121292
body: { | |
baseSha, | |
bundleSizes: await getBrotliBundleSizes(), | |
}, |
The app infers the head SHA and constructs the comparison link. We'll likely need to change this API to properly fix the comparison link.
Added a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few comments based on your latest changes.
build-system/common/ci.js
Outdated
/** | ||
* Returns the merge commits SHA when running a CI Pull Request build. | ||
* @return {string} | ||
*/ | ||
function ciMergeSha() { | ||
// CIRCLE_MERGE_SHA is populated by .circleci/fetch_merge_commit.sh. | ||
return isCircleci ? env('CIRCLE_MERGE_SHA') : ''; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thumb-rule for every function in this file is that it should be usable on GH actions if ever required, and that it is based on well-known env vars from each platform.
amphtml/build-system/common/ci.js
Lines 18 to 24 in c121292
/** | |
* @fileoverview Provides various kinds of CI state. | |
* | |
* References: | |
* GitHub Actions: https://docs.github.com/en/free-pro-team@latest/actions/reference/environment-variables#default-environment-variables | |
* CircleCI: https://circleci.com/docs/2.0/env-vars/#built-in-environment-variables | |
*/ |
For CIRCLE_MERGE_SHA
, I wonder if we should just add a util function within bundle-size/index.js
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's not an equivalent GH env.
For CIRCLE_MERGE_SHA, I wonder if we should just add a util function within bundle-size/index.js.
I wanted to avoid tying the setup scripts to the actual JS code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SG. Let's just rename this function to circleciPrMergeSha
to clearly indicate that it's not a generic CI function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request, the GITHUB_SHA
is actually the merge commit! And we're mixing up the CCI SHA (which is the HEAD SHA) with the GH SHA (which is the merge SHA) in ciCommitSha
above.
I'll rename this for now, and leave it to you to cleanup the env vars.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ciCommitSha
is only used during push builds, and according to these docs, GITHUB_SHA
is the correct variable.
I will admit that ci.js
has gotten confusing due to all the individual use cases, and could do with a separate cleanup.
Other cleanup is coming up in #33215.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for patiently dealing with all my review comments!
build-system/common/ci.js
Outdated
/** | ||
* Returns the merge commits SHA when running a CI Pull Request build. | ||
* @return {string} | ||
*/ | ||
function ciMergeSha() { | ||
// CIRCLE_MERGE_SHA is populated by .circleci/fetch_merge_commit.sh. | ||
return isCircleci ? env('CIRCLE_MERGE_SHA') : ''; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SG. Let's just rename this function to circleciPrMergeSha
to clearly indicate that it's not a generic CI function.
*/ | ||
function ciMergeSha() { | ||
// CIRCLE_MERGE_SHA is populated by .circleci/fetch_merge_commit.sh. | ||
return isCircleci ? env('CIRCLE_MERGE_SHA') : ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this condition be isPullRequestBuild() && isCircleciBuild()
to guarantee an empty value during push builds?
Lol, deleting my branch borked master. I restored it until #33176 can be merged. |
* bundle-size: Use mergeSha when showing code changes Uses the [new `mergeSha` field](https://github.com/ampproject/amphtml/pull/33165/files#diff-c141453bcbdbe03ca8414e5b4d425c5b7323e43d524b614455ce13770633509eR191), which resolves ampproject/amphtml#33165 (comment). * Review updates * Add todo
This commit is purposefully forked several commits before (768808e) the current master (d110566). I'm going to rebase and merge to see what happens.