-
Notifications
You must be signed in to change notification settings - Fork 37.7k
ci: Provide COMMIT_RANGE
variable for non-PRs
#20728
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
Conversation
759b54b
to
b1c1c4c
Compare
b1c1c4c
to
59b948c
Compare
a6fa882
to
4f1ca2a
Compare
206f455
to
c8488e0
Compare
c8488e0
to
0512c2d
Compare
Rebased on top of #20697. |
🕵️ @practicalswift has been requested to review this pull request as specified in the REVIEWERS file. |
Concept ACK |
@MarcoFalke can you take a look here. It seems this should either be straight forward to merge, or can just be closed. I think complicating our CI further, just so people can run the linter in the CI of their forked repos is very low priority, and they can always just run it locally. |
Closing for now. |
Reopened due to the recent message on IRC:
Also rebased. |
COMMIT_RANGE
variable value for cloned repos
This was reopened ~6 months ago, but has received no additional comments / interest. I still think that adding more code to our CI scripts, to make it easier for someone to run the lint job via cirrus in their own fork is ~0. |
Doesn't this also affect non-master branches in our repo? |
Thanks for bringing this PR up in my notifications. I used to run our CI on Travis before we migrated to Cirrus and it was useful to check that CI would pass before opening a PR. If this enables doing the same with no downside apart from these two lines I would be Concept ACK. |
Not sure. If it does, that should be in the PR description, and the primary reason for making this change. |
@@ -10,6 +10,8 @@ GIT_HEAD=$(git rev-parse HEAD) | |||
if [ -n "$CIRRUS_PR" ]; then | |||
COMMIT_RANGE="${CIRRUS_BASE_SHA}..$GIT_HEAD" | |||
test/lint/commit-script-check.sh "$COMMIT_RANGE" | |||
else | |||
COMMIT_RANGE="$(git fetch "$CIRRUS_REPO_CLONE_URL" "${CIRRUS_LAST_GREEN_CHANGE:-$CIRRUS_DEFAULT_BRANCH}" && git merge-base FETCH_HEAD HEAD)..$GIT_HEAD" |
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.
wouldn't it be better to skip the check if this is not a pull request? I presume this already happens when pushing to master
?
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.
Could you clarify please what code change you are suggesting?
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 don't know the code changes needed, but it seems the check currently only runs on pull requests against the base commit.
On master it is presumably skipped because the base commit is equal to the HEAD commit?
So maybe all places where COMMIT_RANGE
is used can be guarded by a check on CIRRUS_PR
? Or instead skip if the range is empty?
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.
it seems the check currently only runs on pull requests against the base commit.
ci/lint/06_script.sh
runs always except cases defined in the FILTER_TEMPLATE
.
On master it is presumably skipped because the base commit is equal to the HEAD commit?
According to Cirrus CI docs, the CIRRUS_BASE_SHA
variable is defined for PRs only. Therefore, it is natural to have distinct code paths to evaluate COMMIT_RANGE
for PRs and non-PRs.
So maybe all places where
COMMIT_RANGE
is used can be guarded by a check onCIRRUS_PR
?
Given COMMIT_RANGE
is used in two python scripts, it's okay to evaluate it before test/lint/lint-all.py
. That is the case for the current ci/lint/06_script.sh
file.
Or instead skip if the range is empty?
I cannot figure out such cases.
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.
Yes, I understand. My point is that there is no point in running COMMIT_RANGE tests on branches, only on PRs
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 CIRRUS_DEFAULT_BRANCH
is being used in the git fetch
command, which should succeed regardless of the current branch in the git tree.
CI fails in the 24.x branch because the COMMIT_RANGE
variable is not set at all, and the failed python scripts use the hardcoded "master" name of a branch. For example:
bitcoin/test/lint/lint-whitespace.py
Lines 92 to 101 in ba48fcf
if not os.getenv("COMMIT_RANGE"): | |
if args.prev_commits: | |
commit_range = "HEAD~" + args.prev_commits + "...HEAD" | |
else: | |
# This assumes that the target branch of the pull request will be master. | |
merge_base = check_output(["git", "merge-base", "HEAD", "master"], universal_newlines=True, encoding="utf8").rstrip("\n") | |
commit_range = merge_base + "..HEAD" | |
else: | |
commit_range = os.getenv("COMMIT_RANGE") | |
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 believe, such an approach won't leave un-linted commits in the commit history.
yes, maybe.
However, I still don't understand why this is needed.
If you run the linters on a branch, it is too late, because force pushing is not allowed.
For example, it is not possible to rewrite the commit subject line if test/lint/lint-git-commit-check.py
fails on a commit in a non-pull-request branch. (Same for whitespace from test/lint/lint-whitespace.py
, or the eval from test/lint/commit-script-check.sh
). There are no other uses of COMMIT_RANGE
other than those 3.
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.
If we didn't sanity check verify-commits.py
on branches, I would have already completely disabled the linters for branches.
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.
If you run the linters on a branch, it is too late, because force pushing is not allowed.
For example, it is not possible to rewrite the commit subject line if
test/lint/lint-git-commit-check.py
fails on a commit in a non-pull-request branch. (Same for whitespace fromtest/lint/lint-whitespace.py
, or the eval fromtest/lint/commit-script-check.sh
). There are no other uses ofCOMMIT_RANGE
other than those 3.
There is still a use case when running CI in personal repos though.
I would have already completely disabled the linters for branches.
That sounds reasonable. But again, this change allows to use the linter CI task in personal repos.
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.
Can you explain that use case? It seems fragile to support that, given that CIRRUS_LAST_GREEN_CHANGE
might "accidentally" be green for "broken" commits (for example if the CI was skipped, etc...). Or CIRRUS_DEFAULT_BRANCH
might be too far ahead, so that commits are "skipped".
So to summarize, I fail to see the use case, and even if there was a use case, it would be impossible to support it.
It does.
The PR description has been reworked. |
COMMIT_RANGE
variable value for cloned reposCOMMIT_RANGE
variable for non-PRs
Mind having another look into this PR? |
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process.
|
@@ -10,6 +10,8 @@ GIT_HEAD=$(git rev-parse HEAD) | |||
if [ -n "$CIRRUS_PR" ]; then | |||
COMMIT_RANGE="${CIRRUS_BASE_SHA}..$GIT_HEAD" | |||
test/lint/commit-script-check.sh "$COMMIT_RANGE" | |||
else | |||
COMMIT_RANGE="$(git fetch "$CIRRUS_REPO_CLONE_URL" "${CIRRUS_LAST_GREEN_CHANGE:-$CIRRUS_DEFAULT_BRANCH}" && git merge-base FETCH_HEAD HEAD)..$GIT_HEAD" |
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.
My suggestion would be to simply set COMMIT_RANGE="EMPTY"
and then use that to skip the affected linters
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.
This PR provides the
COMMIT_RANGE
environment variable, which is used inlint-git-commit-check.py
andlint-whitespace.py
, for non-PR cases, including our release branches and personal repos.Fixes https://github.com/bitcoin/bitcoin/runs/8664441400
Has been split out from #20697 as requested by MarcoFalke.