ci: Provide COMMIT_RANGE variable for non-PRs #20728

pull hebasto wants to merge 1 commits into bitcoin:master from hebasto:201220-cirrus changing 1 files +2 −0
  1. hebasto commented at 11:12 am on December 20, 2020: member

    This PR provides the COMMIT_RANGE environment variable, which is used in lint-git-commit-check.py and lint-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 bitcoin/bitcoin#20697 as requested by MarcoFalke.

  2. hebasto force-pushed on Dec 20, 2020
  3. hebasto force-pushed on Dec 20, 2020
  4. hebasto force-pushed on Dec 20, 2020
  5. hebasto force-pushed on Dec 20, 2020
  6. hebasto renamed this:
    [DO NOT MERGE] ci: Debugging Cirrus CI
    ci: Fix COMMIT_RANGE variable value for cloned repos
    on Dec 20, 2020
  7. DrahtBot added the label Tests on Dec 20, 2020
  8. hebasto force-pushed on Dec 21, 2020
  9. hebasto marked this as a draft on Dec 21, 2020
  10. hebasto force-pushed on Dec 21, 2020
  11. hebasto force-pushed on Dec 21, 2020
  12. hebasto force-pushed on Dec 21, 2020
  13. hebasto force-pushed on Dec 21, 2020
  14. hebasto marked this as ready for review on Dec 21, 2020
  15. hebasto force-pushed on Dec 21, 2020
  16. hebasto force-pushed on Dec 21, 2020
  17. hebasto marked this as a draft on Dec 21, 2020
  18. hebasto force-pushed on Dec 21, 2020
  19. hebasto force-pushed on Dec 21, 2020
  20. hebasto force-pushed on Dec 21, 2020
  21. hebasto force-pushed on Dec 21, 2020
  22. hebasto commented at 11:27 am on December 21, 2020: member
    Rebased on top of #20697.
  23. hebasto marked this as ready for review on Dec 21, 2020
  24. DrahtBot commented at 11:46 am on January 13, 2021: contributor

    🕵️ @practicalswift has been requested to review this pull request as specified in the REVIEWERS file.

  25. decryp2kanon commented at 6:35 pm on January 19, 2021: contributor
    Concept ACK
  26. fanquake requested review from maflcko on Feb 28, 2021
  27. fanquake commented at 5:18 am on February 28, 2021: member
    @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.
  28. fanquake commented at 7:07 am on March 26, 2021: member
    Closing for now.
  29. fanquake closed this on Mar 26, 2021

  30. ci: Fix COMMIT_RANGE variable value for cloned repos d4fb89147a
  31. hebasto reopened this on May 28, 2022

  32. hebasto force-pushed on May 28, 2022
  33. hebasto commented at 9:18 am on May 28, 2022: member

    Reopened due to the recent message on IRC:

    02:52 <DavidBakin> so I am now running CI tests on a branch on my fork. lint fails in lint-git-commit-check.py with “Not a valid object name master” - is this something I did in my fork when creating my branch? or what? there isn’t any other useful information printed here, e.g., commit hash. I’ll try to run it locally to see if I can debug it but if you happen to know …

    Also rebased.

    cc @MarcoFalke @david-bakin

  34. hebasto renamed this:
    ci: Fix COMMIT_RANGE variable value for cloned repos
    ci: Fix `COMMIT_RANGE` variable value for cloned repos
    on May 28, 2022
  35. fanquake commented at 11:36 am on October 3, 2022: member
    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.
  36. maflcko commented at 11:44 am on October 3, 2022: member

    Doesn’t this also affect non-master branches in our repo?

    https://github.com/bitcoin/bitcoin/runs/8664441400

  37. jonatack commented at 11:46 am on October 3, 2022: contributor
    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.
  38. fanquake commented at 11:46 am on October 3, 2022: member

    Doesn’t this also affect non-master branches in our repo?

    Not sure. If it does, that should be in the PR description, and the primary reason for making this change.

  39. in ci/lint/06_script.sh:14 in d4fb89147a
     9@@ -10,6 +10,8 @@ GIT_HEAD=$(git rev-parse HEAD)
    10 if [ -n "$CIRRUS_PR" ]; then
    11   COMMIT_RANGE="${CIRRUS_BASE_SHA}..$GIT_HEAD"
    12   test/lint/commit-script-check.sh "$COMMIT_RANGE"
    13+else
    14+  COMMIT_RANGE="$(git fetch "$CIRRUS_REPO_CLONE_URL" "${CIRRUS_LAST_GREEN_CHANGE:-$CIRRUS_DEFAULT_BRANCH}" && git merge-base FETCH_HEAD HEAD)..$GIT_HEAD"
    


    maflcko commented at 11:49 am on October 3, 2022:
    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?

    hebasto commented at 12:01 pm on October 5, 2022:
    Could you clarify please what code change you are suggesting?

    maflcko commented at 1:36 pm on October 5, 2022:

    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?


    hebasto commented at 2:30 pm on October 5, 2022:

    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 on CIRRUS_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.


    maflcko commented at 2:41 pm on October 5, 2022:
    Yes, I understand. My point is that there is no point in running COMMIT_RANGE tests on branches, only on PRs

    hebasto commented at 2:55 pm on October 5, 2022:
    I’d keep lint-git-commit-check.py for master and release branches, no?

    hebasto commented at 2:56 pm on October 5, 2022:
    Also keeping the same set of linters for all cases is just consistent, and useful for branches in personal repos.

    maflcko commented at 3:18 pm on October 5, 2022:

    Well, for a pull request it is trivial to see which commits to check. For a branch not so.

    Does it check all commits …

    • in the history?
    • since the last push?
    • since the last green push?
    • against maser’s merge base?

    hebasto commented at 4:01 pm on October 5, 2022:
    The first commit in the commit range for a branch is a merge base between HEAD and the last green push if available or, otherwise, the default branch. I believe, such an approach won’t leave un-linted commits in the commit history.

    maflcko commented at 4:10 pm on October 5, 2022:

    Why would the default branch be available on cirrus if the ci runs on another branch?

    An alternative would be to run it from the last merge git log --merges -1


    hebasto commented at 8:25 am on October 14, 2022:

    Why would the default branch be available on cirrus if the ci runs on another branch?

    Because “the default branch” is a property of a GitHub’s repository.

    See evidences for availability of the CIRRUS_DEFAULT_BRANCH variable for any branch:


    maflcko commented at 8:27 am on October 14, 2022:
    Sorry I meant the in the git tree, not the environment variable

    maflcko commented at 8:28 am on October 14, 2022:
    0fatal: Not a valid object name master
    

    https://github.com/bitcoin/bitcoin/runs/8664441400


    hebasto commented at 11:10 am on October 14, 2022:

    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: https://github.com/bitcoin/bitcoin/blob/ba48fcf4a40c5b9888459511fb4233a1b89184cc/test/lint/lint-whitespace.py#L92-L101


    maflcko commented at 1:26 pm on November 22, 2022:

    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.


    maflcko commented at 1:33 pm on November 22, 2022:
    If we didn’t sanity check verify-commits.py on branches, I would have already completely disabled the linters for branches.

    hebasto commented at 12:32 pm on November 23, 2022:

    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 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.


    maflcko commented at 12:37 pm on November 23, 2022:

    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.


    maflcko commented at 12:45 pm on November 23, 2022:
    My suggestion would be to simply set COMMIT_RANGE="EMPTY" and then use that to skip the affected linters

    maflcko commented at 10:13 am on November 28, 2022:
  40. hebasto commented at 12:00 pm on October 5, 2022: member

    @MarcoFalke

    Doesn’t this also affect non-master branches in our repo?

    https://github.com/bitcoin/bitcoin/runs/8664441400

    It does. @fanquake

    Not sure. If it does, that should be in the PR description, and the primary reason for making this change.

    The PR description has been reworked.

  41. hebasto renamed this:
    ci: Fix `COMMIT_RANGE` variable value for cloned repos
    ci: Provide `COMMIT_RANGE` variable for non-PRs
    on Oct 5, 2022
  42. hebasto commented at 4:41 pm on October 20, 2022: member

    @MarcoFalke @fanquake

    Mind having another look into this PR?

  43. DrahtBot commented at 1:26 pm on November 22, 2022: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    Concept ACK decryp2kanon, jonatack
  44. hebasto closed this on Nov 23, 2022

  45. hebasto deleted the branch on Dec 3, 2022
  46. bitcoin locked this on Dec 3, 2023

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-17 03:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me