Skip to contentSkip to conversation

Add GitLab CI to check for whitespace errors

PATCH Superseded Justin Tobler 6 participants 42 messages Apr 30, 2024 – May 7, 2024

lore
Share & tools
lore
#0 lore raw

cover Add GitLab CI to check for whitespace errors

Hello everyone,

The currently configured GitLab pipelines do not include a CI job to check for whitespace errors. Instead of generalizing the existing GitHub action in .github/workflows/check-whitespace.yml, this change opts to create a separate generalized ci/whitespace-check.sh script to build from. The existing action does extra work to create a GitHub specific summary artifact that is markdown formatted with links to commits and blobs. If this summary feature is not considered necessary, the GitHub action could be reworked to use the general whitespace check.

He is a link to a successful execution of the CI job:
https://gitlab.com/gitlab-org/git/-/jobs/6744313860

I also added a small change to by default collapse grouped sections of CI output to reduce noise.

-Justin

Justin Tobler (2):
ci: pre-collapse GitLab CI sections
gitlab-ci: add whitespace error check

 .gitlab-ci.yml         |  9 +++++++++
 ci/check-whitespace.sh | 16 ++++++++++++++++
 ci/lib.sh              |  2 +-
 3 files changed, 26 insertions(+), 1 deletion(-)
 create mode 100755 ci/check-whitespace.sh

base-commit: 786a3e4b8d754d2b14b1208b98eeb0a554ef19a8

Signature · 1 line
2.44.0
#1 lore raw

PATCH 1/2 ci: pre-collapse GitLab CI sections

Sections of CI output defined by begin_group() and end_group() are expanded in GitLab pipelines by default. This can make CI job output rather noisy and harder to navigate. Update the behavior for GitLab pipelines to now collapse sections by default.

---
 ci/lib.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
ci/lib.sh +1 -1
index 0a73fc7bd1..02e5e058dd 100755
@@ -18,7 +18,7 @@ elif test true = "$GITLAB_CI"
 then
 	begin_group () {
 		need_to_end_group=t
-		printf "\e[0Ksection_start:$(date +%s):$(echo "$1" | tr ' ' _)\r\e[0K$1\n"
+		printf "\e[0Ksection_start:$(date +%s):$(echo "$1" | tr ' ' _)[collapsed=true]\r\e[0K$1\n"
 		trap "end_group '$1'" EXIT
 		set -x
 	}
Signature · 1 line
2.44.0
#2 lore raw

PATCH 2/2 gitlab-ci: add whitespace error check

In reply to Justin Tobler

To check for whitespace errors introduced by a set of changes, there is the .github/workflows/check-whitespace.yml GitHub action. This script executes git log --check over a range containing the new commits and parses the output to generate a markdown formatted artifact that summarizes detected errors with GitHub links to the affected commits and blobs.

Since this script is rather specific to GitHub actions, a more general and simple ci/check-whitespace.sh is added instead that functions the same, but does not generate the markdown file for the action summary. From this, a new GitLab CI job is added to support the whitespace error check.

Note that the $CI_MERGE_REQUEST_TARGET_BRANCH_SHA variable is only available in GitLab merge request pipelines and therefore the CI job is configured to only run as part of those pipelines.

---
 .gitlab-ci.yml         |  9 +++++++++
 ci/check-whitespace.sh | 16 ++++++++++++++++
 2 files changed, 25 insertions(+)
 create mode 100755 ci/check-whitespace.sh
.gitlab-ci.yml +9 -0
index c0fa2fe90b..31cf420a11 100644
@@ -102,3 +102,12 @@ static-analysis:
   script:
     - ./ci/run-static-analysis.sh
     - ./ci/check-directional-formatting.bash
+
+check-whitespace:
+  image: ubuntu:latest
+  before_script:
+    - ./ci/install-docker-dependencies.sh
+  script:
+    - ./ci/check-whitespace.sh $CI_MERGE_REQUEST_TARGET_BRANCH_SHA
+  rules:
+    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
ci/check-whitespace.sh new file +16 -0
new file mode 100755
index 0000000000..1cad2d7374
@@ -0,0 +1,16 @@
+#! /bin/sh
+#
+# Check that commits after a specified point do not contain new or modified
+# lines with whitespace errors.
+#
+
+baseSha=${1}
+
+git log --check --pretty=format:"---% h% s" ${baseSha}..
+if test $? -ne 0
+then
+	echo "A whitespace issue was found in one or more of the commits."
+	echo "Run the following command to resolve whitespace issues:"
+	echo "\tgit rebase --whitespace=fix ${baseSha}"
+	exit 2
+fi
Signature · 1 line
2.44.0
#3 lore raw

Re: [PATCH 2/2] gitlab-ci: add whitespace error check

Thanks for putting this together, Justin!

.gitlab-ci.yml static-analysis: · line 107

Quoted 2 lines
.gitlab-ci.yml +2 -0
+check-whitespace:
+  image: ubuntu:latest

I wonder if we should pin to ubuntu:22.04 and only update this for each LTS release. It seems like we've done this for the static-analysis job above.

ci/check-whitespace.sh line 1

Quoted 13 lines
.gitlab-ci.yml +6 -0
+  before_script:
+    - ./ci/install-docker-dependencies.sh
+  script:
+    - ./ci/check-whitespace.sh $CI_MERGE_REQUEST_TARGET_BRANCH_SHA
+  rules:
+    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
ci/check-whitespace.sh new file +1 -0
new file mode 100755
index 0000000000..1cad2d7374
@@ -0,0 +1,16 @@
+#! /bin/sh

nit: there seems to be extra whitespace after the shebang :D

#4 lore raw

Re: [PATCH 2/2] gitlab-ci: add whitespace error check

Quoted 8 lines · James Liu

Thanks for putting this together, Justin!

.gitlab-ci.yml static-analysis: · line 107

Quoted 2 lines
.gitlab-ci.yml +2 -0
+check-whitespace:
+  image: ubuntu:latest

I wonder if we should pin to ubuntu:22.04 and only update this for each LTS release. It seems like we've done this for the static-analysis job above.

I'm not sure if it particually matters. I know Patrick recently submitted the following also using ubuntu:latest:
https://lore.kernel.org/git/01fb94999f8e2014ba4d09ce7451a4f5d315ee72.1714371146.git.ps@pks.im/#r

I can change it though if there is strong opinion one way or the other.

Quoted 17 lines
Quoted 13 lines
.gitlab-ci.yml +6 -0
+  before_script:
+    - ./ci/install-docker-dependencies.sh
+  script:
+    - ./ci/check-whitespace.sh $CI_MERGE_REQUEST_TARGET_BRANCH_SHA
+  rules:
+    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
ci/check-whitespace.sh new file +0 -0
new file mode 100755
index 0000000000..1cad2d7374

ci/check-whitespace.sh line 1

Quoted 1 line
ci/check-whitespace.sh new file +1 -0
@@ -0,0 +1,16 @@
+#! /bin/sh

nit: there seems to be extra whitespace after the shebang :D

Whoops... I'll address this in a subsequent version.

-Justin

#5 lore raw

Re: [PATCH 2/2] gitlab-ci: add whitespace error check

Quoted 10 lines · Justin Tobler
Quoted 8 lines · James Liu

Thanks for putting this together, Justin!

.gitlab-ci.yml static-analysis: · line 107

Quoted 2 lines
.gitlab-ci.yml +2 -0
+check-whitespace:
+  image: ubuntu:latest

I wonder if we should pin to ubuntu:22.04 and only update this for each LTS release. It seems like we've done this for the static-analysis job above.

Quoted 5 lines

I'm not sure if it particually matters. I know Patrick recently submitted the following also using ubuntu:latest:
https://lore.kernel.org/git/01fb94999f8e2014ba4d09ce7451a4f5d315ee72.1714371146.git.ps@pks.im/#r

I can change it though if there is strong opinion one way or the other.

I'd say it probably doesn't matter much for this case. But using ubuntu:latest means that there's less maintenance going forward because we don't ever have to update it.

Patrick

#6 lore raw

Re: [PATCH 2/2] gitlab-ci: add whitespace error check

In reply to Justin Tobler
Quoted 7 lines · Justin Tobler

To check for whitespace errors introduced by a set of changes, there is the .github/workflows/check-whitespace.yml GitHub action. This script executes git log --check over a range containing the new commits and parses the output to generate a markdown formatted artifact that summarizes detected errors with GitHub links to the affected commits and blobs.

Quoted 5 lines

Since this script is rather specific to GitHub actions, a more general and simple ci/check-whitespace.sh is added instead that functions the same, but does not generate the markdown file for the action summary. From this, a new GitLab CI job is added to support the whitespace error check.

I still wonder whether we can unify these. Yes, the GitHub thing is quite specific. But ultimately, what it does is to generate a proper summary of where exactly the whitespaces issues are, which is something that your version doesn't do. It's useful though for consumers of a failed CI job to know exactly which commit has the issue.

So can't we pull out the logic into a script, refactor it such that it knows to print both GitHub- and GitLab-style URLs, and then also print the summary in GitLab CI?

Quoted 16 lines

Note that the $CI_MERGE_REQUEST_TARGET_BRANCH_SHA variable is only available in GitLab merge request pipelines and therefore the CI job is configured to only run as part of those pipelines.

---
 .gitlab-ci.yml         |  9 +++++++++
 ci/check-whitespace.sh | 16 ++++++++++++++++
 2 files changed, 25 insertions(+)
 create mode 100755 ci/check-whitespace.sh
.gitlab-ci.yml +0 -0
index c0fa2fe90b..31cf420a11 100644

.gitlab-ci.yml static-analysis: · line 111

Quoted 10 lines
.gitlab-ci.yml +7 -0
@@ -102,3 +102,12 @@ static-analysis:
   script:
     - ./ci/run-static-analysis.sh
     - ./ci/check-directional-formatting.bash
+
+check-whitespace:
+  image: ubuntu:latest
+  before_script:
+    - ./ci/install-docker-dependencies.sh
+  script:
+    - ./ci/check-whitespace.sh $CI_MERGE_REQUEST_TARGET_BRANCH_SHA

Let's quote this variable.

Quoted 8 lines
.gitlab-ci.yml +2 -0
+  rules:
+    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
ci/check-whitespace.sh new file +0 -0
new file mode 100755
index 0000000000..1cad2d7374

ci/check-whitespace.sh line 7

Quoted 7 lines
ci/check-whitespace.sh new file +7 -0
@@ -0,0 +1,16 @@
+#! /bin/sh
+#
+# Check that commits after a specified point do not contain new or modified
+# lines with whitespace errors.
+#
+
+baseSha=${1}

Two nits: first, I wouldn't call it "sha" because it really is a commit ID that may or may not be SHA if we were ever to grow a hash function that is not SHA. So "baseCommit" would be more descriptive.

Second, our shell variables are typically written in all-uppercase. So that'd make it "BASE_COMMIT".

ci/check-whitespace.sh line 9

Quoted 1 line
ci/check-whitespace.sh new file +1 -0
+git log --check --pretty=format:"---% h% s" ${baseSha}..

Nit: there's no need for the curly braces here. Also, let's quote the value.

Patrick

Quoted 11 lines
ci/check-whitespace.sh new file +7 -0
+if test $? -ne 0
+then
+	echo "A whitespace issue was found in one or more of the commits."
+	echo "Run the following command to resolve whitespace issues:"
+	echo "\tgit rebase --whitespace=fix ${baseSha}"
+	exit 2
+fi
Signature · 1 line
2.44.0
#7 lore raw

Re: [PATCH 2/2] gitlab-ci: add whitespace error check

Quoted 20 lines · Patrick Steinhardt
Quoted 7 lines · Justin Tobler

To check for whitespace errors introduced by a set of changes, there is the .github/workflows/check-whitespace.yml GitHub action. This script executes git log --check over a range containing the new commits and parses the output to generate a markdown formatted artifact that summarizes detected errors with GitHub links to the affected commits and blobs.

Quoted 5 lines

Since this script is rather specific to GitHub actions, a more general and simple ci/check-whitespace.sh is added instead that functions the same, but does not generate the markdown file for the action summary. From this, a new GitLab CI job is added to support the whitespace error check.

I still wonder whether we can unify these. Yes, the GitHub thing is quite specific. But ultimately, what it does is to generate a proper summary of where exactly the whitespaces issues are, which is something that your version doesn't do. It's useful though for consumers of a failed CI job to know exactly which commit has the issue.

Quoted 3 lines

So can't we pull out the logic into a script, refactor it such that it knows to print both GitHub- and GitLab-style URLs, and then also print the summary in GitLab CI?

This was my feeling as well when I read the cover letter. I don't think we should either (a) have to remove functionality from the GitHub specific version of this job, or (b) have to maintain two different but highly similar implementations of the same job.

It seems more reasonable that we'd do some third option, which is what Patrick suggests.

Thanks,
Taylor

#8 lore raw

Re: [PATCH 2/2] gitlab-ci: add whitespace error check

In reply to Patrick Steinhardt
Quoted 14 lines · Patrick Steinhardt
Quoted 7 lines · Justin Tobler

To check for whitespace errors introduced by a set of changes, there is the .github/workflows/check-whitespace.yml GitHub action. This script executes git log --check over a range containing the new commits and parses the output to generate a markdown formatted artifact that summarizes detected errors with GitHub links to the affected commits and blobs.

Quoted 5 lines

Since this script is rather specific to GitHub actions, a more general and simple ci/check-whitespace.sh is added instead that functions the same, but does not generate the markdown file for the action summary. From this, a new GitLab CI job is added to support the whitespace error check.

Quoted 5 lines

I still wonder whether we can unify these. Yes, the GitHub thing is quite specific. But ultimately, what it does is to generate a proper summary of where exactly the whitespaces issues are, which is something that your version doesn't do. It's useful though for consumers of a failed CI job to know exactly which commit has the issue.

Just to clarify, this new CI job still prints the output of git log --check which details the exact commit and file with line number of the whitespace error. The difference is that it does not write an additional markdown file with links to the commit and blob.

Here is a failed execution of the GitLab whitespace check job:
https://gitlab.com/gitlab-org/git/-/jobs/6749580210#L1289

Quoted 4 lines

So can't we pull out the logic into a script, refactor it such that it knows to print both GitHub- and GitLab-style URLs, and then also print the summary in GitLab CI?

We can do this, but for GitLab CI there probably isn't a point to generating a summary file since there is nothing that would pick it up and display it. Having links though directly in the job output would be nice. I'll give it another go.

Quoted 50 lines
Quoted 17 lines

Note that the $CI_MERGE_REQUEST_TARGET_BRANCH_SHA variable is only available in GitLab merge request pipelines and therefore the CI job is configured to only run as part of those pipelines.

---
 .gitlab-ci.yml         |  9 +++++++++
 ci/check-whitespace.sh | 16 ++++++++++++++++
 2 files changed, 25 insertions(+)
 create mode 100755 ci/check-whitespace.sh
.gitlab-ci.yml +0 -0
index c0fa2fe90b..31cf420a11 100644

.gitlab-ci.yml static-analysis: · line 111

Quoted 10 lines
.gitlab-ci.yml +7 -0
@@ -102,3 +102,12 @@ static-analysis:
   script:
     - ./ci/run-static-analysis.sh
     - ./ci/check-directional-formatting.bash
+
+check-whitespace:
+  image: ubuntu:latest
+  before_script:
+    - ./ci/install-docker-dependencies.sh
+  script:
+    - ./ci/check-whitespace.sh $CI_MERGE_REQUEST_TARGET_BRANCH_SHA

Let's quote this variable.

Quoted 8 lines
.gitlab-ci.yml +2 -0
+  rules:
+    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
ci/check-whitespace.sh new file +0 -0
new file mode 100755
index 0000000000..1cad2d7374

ci/check-whitespace.sh line 7

Quoted 7 lines
ci/check-whitespace.sh new file +7 -0
@@ -0,0 +1,16 @@
+#! /bin/sh
+#
+# Check that commits after a specified point do not contain new or modified
+# lines with whitespace errors.
+#
+
+baseSha=${1}

Two nits: first, I wouldn't call it "sha" because it really is a commit ID that may or may not be SHA if we were ever to grow a hash function that is not SHA. So "baseCommit" would be more descriptive.

Quoted 7 lines

Second, our shell variables are typically written in all-uppercase. So that'd make it "BASE_COMMIT".

ci/check-whitespace.sh line 9

Quoted 1 line
ci/check-whitespace.sh new file +1 -0
+git log --check --pretty=format:"---% h% s" ${baseSha}..

Nit: there's no need for the curly braces here. Also, let's quote the value.

Thanks for the review Patrick! I'll address these in the next version :)

-Justin

#9 lore raw

Re: [PATCH 2/2] gitlab-ci: add whitespace error check

Quoted 21 lines · Justin Tobler
Quoted 14 lines · Patrick Steinhardt
Quoted 7 lines · Justin Tobler

To check for whitespace errors introduced by a set of changes, there is the .github/workflows/check-whitespace.yml GitHub action. This script executes git log --check over a range containing the new commits and parses the output to generate a markdown formatted artifact that summarizes detected errors with GitHub links to the affected commits and blobs.

Quoted 5 lines

Since this script is rather specific to GitHub actions, a more general and simple ci/check-whitespace.sh is added instead that functions the same, but does not generate the markdown file for the action summary. From this, a new GitLab CI job is added to support the whitespace error check.

Quoted 5 lines

I still wonder whether we can unify these. Yes, the GitHub thing is quite specific. But ultimately, what it does is to generate a proper summary of where exactly the whitespaces issues are, which is something that your version doesn't do. It's useful though for consumers of a failed CI job to know exactly which commit has the issue.

Quoted 7 lines

Just to clarify, this new CI job still prints the output of git log --check which details the exact commit and file with line number of the whitespace error. The difference is that it does not write an additional markdown file with links to the commit and blob.

Here is a failed execution of the GitLab whitespace check job:
https://gitlab.com/gitlab-org/git/-/jobs/6749580210#L1289

Okay, fair enough. I'm still of the opinion that the infra here should be shared.

Quoted 8 lines
Quoted 3 lines

So can't we pull out the logic into a script, refactor it such that it knows to print both GitHub- and GitLab-style URLs, and then also print the summary in GitLab CI?

We can do this, but for GitLab CI there probably isn't a point to generating a summary file since there is nothing that would pick it up and display it. Having links though directly in the job output would be nice. I'll give it another go.

Well, we could print the output to the console so that a user can see it when they open the failed job. The nice formatting may be kind of moot, but on the other hand it doesn't hurt, either. I guess most people are used to reading plain markdown-style docs anyway.

Patrick

#10 lore raw

Re: [PATCH 2/2] gitlab-ci: add whitespace error check

Quoted 42 lines · Patrick Steinhardt
Quoted 21 lines · Justin Tobler
Quoted 14 lines · Patrick Steinhardt
Quoted 7 lines · Justin Tobler

To check for whitespace errors introduced by a set of changes, there is the .github/workflows/check-whitespace.yml GitHub action. This script executes git log --check over a range containing the new commits and parses the output to generate a markdown formatted artifact that summarizes detected errors with GitHub links to the affected commits and blobs.

Quoted 5 lines

Since this script is rather specific to GitHub actions, a more general and simple ci/check-whitespace.sh is added instead that functions the same, but does not generate the markdown file for the action summary. From this, a new GitLab CI job is added to support the whitespace error check.

Quoted 5 lines

I still wonder whether we can unify these. Yes, the GitHub thing is quite specific. But ultimately, what it does is to generate a proper summary of where exactly the whitespaces issues are, which is something that your version doesn't do. It's useful though for consumers of a failed CI job to know exactly which commit has the issue.

Quoted 7 lines

Just to clarify, this new CI job still prints the output of git log --check which details the exact commit and file with line number of the whitespace error. The difference is that it does not write an additional markdown file with links to the commit and blob.

Here is a failed execution of the GitLab whitespace check job:
https://gitlab.com/gitlab-org/git/-/jobs/6749580210#L1289

Okay, fair enough. I'm still of the opinion that the infra here should be shared.

Quoted 8 lines
Quoted 3 lines

So can't we pull out the logic into a script, refactor it such that it knows to print both GitHub- and GitLab-style URLs, and then also print the summary in GitLab CI?

We can do this, but for GitLab CI there probably isn't a point to generating a summary file since there is nothing that would pick it up and display it. Having links though directly in the job output would be nice. I'll give it another go.

Quoted 4 lines

Well, we could print the output to the console so that a user can see it when they open the failed job. The nice formatting may be kind of moot, but on the other hand it doesn't hurt, either. I guess most people are used to reading plain markdown-style docs anyway.

I'm thinking we can generalize the summary writing in some manner. When run as a GitHub action, the summary can be markdown formatted and written to $GITHUB_STEP_SUMMARY with no output to the console as done today. When run as GitLab CI, the summary can be written directly to console with links. All other runs just output normally to console.

-Justin

#11 lore raw

Re: [PATCH 2/2] gitlab-ci: add whitespace error check

Quoted 48 lines · Justin Tobler
Quoted 42 lines · Patrick Steinhardt
Quoted 21 lines · Justin Tobler
Quoted 14 lines · Patrick Steinhardt
Quoted 7 lines · Justin Tobler

To check for whitespace errors introduced by a set of changes, there is the .github/workflows/check-whitespace.yml GitHub action. This script executes git log --check over a range containing the new commits and parses the output to generate a markdown formatted artifact that summarizes detected errors with GitHub links to the affected commits and blobs.

Quoted 5 lines

Since this script is rather specific to GitHub actions, a more general and simple ci/check-whitespace.sh is added instead that functions the same, but does not generate the markdown file for the action summary. From this, a new GitLab CI job is added to support the whitespace error check.

Quoted 5 lines

I still wonder whether we can unify these. Yes, the GitHub thing is quite specific. But ultimately, what it does is to generate a proper summary of where exactly the whitespaces issues are, which is something that your version doesn't do. It's useful though for consumers of a failed CI job to know exactly which commit has the issue.

Quoted 7 lines

Just to clarify, this new CI job still prints the output of git log --check which details the exact commit and file with line number of the whitespace error. The difference is that it does not write an additional markdown file with links to the commit and blob.

Here is a failed execution of the GitLab whitespace check job:
https://gitlab.com/gitlab-org/git/-/jobs/6749580210#L1289

Okay, fair enough. I'm still of the opinion that the infra here should be shared.

Quoted 8 lines
Quoted 3 lines

So can't we pull out the logic into a script, refactor it such that it knows to print both GitHub- and GitLab-style URLs, and then also print the summary in GitLab CI?

We can do this, but for GitLab CI there probably isn't a point to generating a summary file since there is nothing that would pick it up and display it. Having links though directly in the job output would be nice. I'll give it another go.

Quoted 4 lines

Well, we could print the output to the console so that a user can see it when they open the failed job. The nice formatting may be kind of moot, but on the other hand it doesn't hurt, either. I guess most people are used to reading plain markdown-style docs anyway.

Quoted 5 lines

I'm thinking we can generalize the summary writing in some manner. When run as a GitHub action, the summary can be markdown formatted and written to $GITHUB_STEP_SUMMARY with no output to the console as done today. When run as GitLab CI, the summary can be written directly to console with links. All other runs just output normally to console.

The script can probably be generalized to take a file name as argument. For GitHub we'd then pass $GITHUB_STEP_SUMMARY, whereas for GitLab we pass in a temporary filename that we than simply cat(1) to the console. That'd allow us to move the CI-specific bits into the respective CIs whereas the script itself remains generic.

Patrick

#12 lore raw

Re: [PATCH 2/2] gitlab-ci: add whitespace error check

Quoted 55 lines · Patrick Steinhardt
Quoted 48 lines · Justin Tobler
Quoted 42 lines · Patrick Steinhardt
Quoted 21 lines · Justin Tobler
Quoted 14 lines · Patrick Steinhardt
Quoted 7 lines · Justin Tobler

To check for whitespace errors introduced by a set of changes, there is the .github/workflows/check-whitespace.yml GitHub action. This script executes git log --check over a range containing the new commits and parses the output to generate a markdown formatted artifact that summarizes detected errors with GitHub links to the affected commits and blobs.

Quoted 5 lines

Since this script is rather specific to GitHub actions, a more general and simple ci/check-whitespace.sh is added instead that functions the same, but does not generate the markdown file for the action summary. From this, a new GitLab CI job is added to support the whitespace error check.

Quoted 5 lines

I still wonder whether we can unify these. Yes, the GitHub thing is quite specific. But ultimately, what it does is to generate a proper summary of where exactly the whitespaces issues are, which is something that your version doesn't do. It's useful though for consumers of a failed CI job to know exactly which commit has the issue.

Quoted 7 lines

Just to clarify, this new CI job still prints the output of git log --check which details the exact commit and file with line number of the whitespace error. The difference is that it does not write an additional markdown file with links to the commit and blob.

Here is a failed execution of the GitLab whitespace check job:
https://gitlab.com/gitlab-org/git/-/jobs/6749580210#L1289

Okay, fair enough. I'm still of the opinion that the infra here should be shared.

Quoted 8 lines
Quoted 3 lines

So can't we pull out the logic into a script, refactor it such that it knows to print both GitHub- and GitLab-style URLs, and then also print the summary in GitLab CI?

We can do this, but for GitLab CI there probably isn't a point to generating a summary file since there is nothing that would pick it up and display it. Having links though directly in the job output would be nice. I'll give it another go.

Quoted 4 lines

Well, we could print the output to the console so that a user can see it when they open the failed job. The nice formatting may be kind of moot, but on the other hand it doesn't hurt, either. I guess most people are used to reading plain markdown-style docs anyway.

Quoted 5 lines

I'm thinking we can generalize the summary writing in some manner. When run as a GitHub action, the summary can be markdown formatted and written to $GITHUB_STEP_SUMMARY with no output to the console as done today. When run as GitLab CI, the summary can be written directly to console with links. All other runs just output normally to console.

Quoted 5 lines

The script can probably be generalized to take a file name as argument. For GitHub we'd then pass $GITHUB_STEP_SUMMARY, whereas for GitLab we pass in a temporary filename that we than simply cat(1) to the console. That'd allow us to move the CI-specific bits into the respective CIs whereas the script itself remains generic.

This sounds good, I was also considering this. We will still need CI-specific bits in the script in order to generate correctly formatted links. That is, unless we also want to pass these as arguments, but that might start to get a little messy.

-Justin

#13 lore raw

v2 cover Add GitLab CI to check for whitespace errors

In reply to Justin Tobler

Hello again,

This is the second version of my patch series to add a GitLab CI job to check for whitespace errors. The main differnece with this version is that it first generalizes the existing GitHub whitespace check CI job allowing the GitLab one to reuse it.

To validate that these changes do not break the existing GitHub CI, here are some links to a successful run and a failed run:

- https://github.com/gitgitgadget/git/actions/runs/8929081916
- https://github.com/gitgitgadget/git/actions/runs/8928887225

To validate that these changes also work on GitLab CI, here some additional links to a succdessful run and a failed run:

- https://gitlab.com/gitlab-org/git/-/jobs/6768304381
- https://gitlab.com/gitlab-org/git/-/jobs/6768282645

Thanks,
-Justin

Justin Tobler (5):
ci: pre-collapse GitLab CI sections
github-ci: fix link to whitespace error
ci: separate whitespace check script
ci: make the whitespace report optional
gitlab-ci: add whitespace error check

 .github/workflows/check-whitespace.yml | 67 ++----------------
 .gitlab-ci.yml                         |  9 +++
 ci/check-whitespace.sh                 | 95 ++++++++++++++++++++++++++
 ci/lib.sh                              |  2 +-
 4 files changed, 109 insertions(+), 64 deletions(-)
 create mode 100755 ci/check-whitespace.sh

Range-diff against v1:

1:  924d3eb23c = 1:  924d3eb23c ci: pre-collapse GitLab CI sections
-:  ---------- > 2:  c8d8b444dc github-ci: fix link to whitespace error
-:  ---------- > 3:  6b44b21dda ci: separate whitespace check script
-:  ---------- > 4:  87dfd1d5a9 ci: make the whitespace report optional
2:  624e68a8d2 ! 5:  175b300e91 gitlab-ci: add whitespace error check

@@ Metadata
## Commit message ##
gitlab-ci: add whitespace error check

- To check for whitespace errors introduced by a set of changes, there is
- the .github/workflows/check-whitespace.yml GitHub action. This script
- executes git log --check over a range containing the new commits and
- parses the output to generate a markdown formatted artifact that
- summarizes detected errors with GitHub links to the affected commits and
- blobs.
-
- Since this script is rather specific to GitHub actions, a more general
- and simple ci/check-whitespace.sh is added instead that functions the
- same, but does not generate the markdown file for the action summary.
- From this, a new GitLab CI job is added to support the whitespace error
- check.
+ GitLab CI does not have a job to check for whitespace errors introduced
+ by a set of changes. Reuse the existing generic whitespace-check.sh to
+ create the job for GitLab pipelines.

Note that the $CI_MERGE_REQUEST_TARGET_BRANCH_SHA variable is only available in GitLab merge request pipelines and therefore the CI job is
@@ .gitlab-ci.yml: static-analysis:
+ before_script:
+ - ./ci/install-docker-dependencies.sh
+ script:
-+ - ./ci/check-whitespace.sh $CI_MERGE_REQUEST_TARGET_BRANCH_SHA
++ - ./ci/check-whitespace.sh "$CI_MERGE_REQUEST_TARGET_BRANCH_SHA"
+ rules:
+ - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
-
- ## ci/check-whitespace.sh (new) ##
-@@
-+#! /bin/sh
-+#
-+# Check that commits after a specified point do not contain new or modified -+# lines with whitespace errors.
-+#
-+
-+baseSha=${1}
-+
-+git log --check --pretty=format:"---% h% s" ${baseSha}..
-+if test $? -ne 0
-+then
-+ echo "A whitespace issue was found in one or more of the commits."
-+ echo "Run the following command to resolve whitespace issues:"
-+ echo "\tgit rebase --whitespace=fix ${baseSha}"
-+ exit 2
-+fi

Signature · 1 line
2.45.0
#14 lore raw

PATCH v2 1/5 ci: pre-collapse GitLab CI sections

Sections of CI output defined by begin_group() and end_group() are expanded in GitLab pipelines by default. This can make CI job output rather noisy and harder to navigate. Update the behavior for GitLab pipelines to now collapse sections by default.

---
 ci/lib.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
ci/lib.sh +1 -1
index 0a73fc7bd1..02e5e058dd 100755
@@ -18,7 +18,7 @@ elif test true = "$GITLAB_CI"
 then
 	begin_group () {
 		need_to_end_group=t
-		printf "\e[0Ksection_start:$(date +%s):$(echo "$1" | tr ' ' _)\r\e[0K$1\n"
+		printf "\e[0Ksection_start:$(date +%s):$(echo "$1" | tr ' ' _)[collapsed=true]\r\e[0K$1\n"
 		trap "end_group '$1'" EXIT
 		set -x
 	}
Signature · 1 line
2.45.0
#15 lore raw

PATCH v2 2/5 github-ci: fix link to whitespace error

In reply to Justin Tobler

When the check-whitespace CI job detects whitespace errors, a formatted summary of the issue is generated. This summary contains links to the commits and blobs responsible for the whitespace errors. The generated links for blobs do not work and result in a 404.

Instead of using the reference name in the link, use the commit ID directly. This fixes the broken link and also helps enable future generalization of the script for other CI providers by removing one of the GitHub specific CI variables used.

---
 .github/workflows/check-whitespace.yml | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)
.github/workflows/check-whitespace.yml +12 -11
index a241a63428..a3a6913ecc 100644
@@ -31,14 +31,15 @@ jobs:
         commit=
         commitText=
         commitTextmd=
-        goodparent=
+        goodParent=
         while read dash sha etc
         do
           case "${dash}" in
-          "---")
-            if test -z "${commit}"
+          "---") # Line contains commit information.
+            if test -z "${goodParent}"
             then
-              goodparent=${sha}
+              # Assume the commit has no whitespace errors until detected otherwise.
+              goodParent=${sha}
             fi
             commit="${sha}"
             commitText="${sha} ${etc}"
@@ -46,18 +47,18 @@ jobs:
             ;;
           "")
             ;;
-          *)
-            if test -n "${commit}"
+          *) # Line contains whitespace error information for current commit.
+            if test -n "${goodParent}"
             then
               problems+=("1) --- ${commitTextmd}")
               echo ""
               echo "--- ${commitText}"
-              commit=
+              goodParent=
             fi
             case "${dash}" in
             *:[1-9]*:) # contains file and line number information
               dashend=${dash#*:}
-              problems+=("[${dash}](https://github.com/${{ github.repository }}/blob/${{github.event.pull_request.head.ref}}/${dash%%:*}#L${dashend%:}) ${sha} ${etc}")
+              problems+=("[${dash}](https://github.com/${{ github.repository }}/blob/${commit}/${dash%%:*}#L${dashend%:}) ${sha} ${etc}")
               ;;
             *)
               problems+=("\`${dash} ${sha} ${etc}\`")
@@ -70,15 +71,15 @@ jobs:
 
         if test ${#problems[*]} -gt 0
         then
-          if test -z "${commit}"
+          if test -z "${goodParent}"
           then
-            goodparent=${baseSha: 0:7}
+            goodParent=${baseSha: 0:7}
           fi
           echo "🛑 Please review the Summary output for further information."
           echo "### :x: A whitespace issue was found in one or more of the commits." >$GITHUB_STEP_SUMMARY
           echo "" >>$GITHUB_STEP_SUMMARY
           echo "Run these commands to correct the problem:" >>$GITHUB_STEP_SUMMARY
-          echo "1. \`git rebase --whitespace=fix ${goodparent}\`" >>$GITHUB_STEP_SUMMARY
+          echo "1. \`git rebase --whitespace=fix ${goodParent}\`" >>$GITHUB_STEP_SUMMARY
           echo "1. \`git push --force\`" >>$GITHUB_STEP_SUMMARY
           echo " " >>$GITHUB_STEP_SUMMARY
           echo "Errors:" >>$GITHUB_STEP_SUMMARY
Signature · 1 line
2.45.0
#16 lore raw

PATCH v2 3/5 ci: separate whitespace check script

In reply to Justin Tobler

The check-whitespace CI job is only available as a GitHub action. To help enable this job with other CI providers, first separate the logic performing the whitespace check into its own script. In subsequent commits, this script is further generalized allowing its reuse.

---
 .github/workflows/check-whitespace.yml | 68 ++---------------------
 ci/check-whitespace.sh                 | 74 ++++++++++++++++++++++++++
 2 files changed, 78 insertions(+), 64 deletions(-)
 create mode 100755 ci/check-whitespace.sh
.github/workflows/check-whitespace.yml +4 -64
index a3a6913ecc..d0a78fc426 100644
@@ -26,67 +26,7 @@ jobs:
     - name: git log --check
       id: check_out
       run: |
-        baseSha=${{github.event.pull_request.base.sha}}
-        problems=()
-        commit=
-        commitText=
-        commitTextmd=
-        goodParent=
-        while read dash sha etc
-        do
-          case "${dash}" in
-          "---") # Line contains commit information.
-            if test -z "${goodParent}"
-            then
-              # Assume the commit has no whitespace errors until detected otherwise.
-              goodParent=${sha}
-            fi
-            commit="${sha}"
-            commitText="${sha} ${etc}"
-            commitTextmd="[${sha}](https://github.com/${{ github.repository }}/commit/${sha}) ${etc}"
-            ;;
-          "")
-            ;;
-          *) # Line contains whitespace error information for current commit.
-            if test -n "${goodParent}"
-            then
-              problems+=("1) --- ${commitTextmd}")
-              echo ""
-              echo "--- ${commitText}"
-              goodParent=
-            fi
-            case "${dash}" in
-            *:[1-9]*:) # contains file and line number information
-              dashend=${dash#*:}
-              problems+=("[${dash}](https://github.com/${{ github.repository }}/blob/${commit}/${dash%%:*}#L${dashend%:}) ${sha} ${etc}")
-              ;;
-            *)
-              problems+=("\`${dash} ${sha} ${etc}\`")
-              ;;
-            esac
-            echo "${dash} ${sha} ${etc}"
-            ;;
-          esac
-        done <<< $(git log --check --pretty=format:"---% h% s" ${baseSha}..)
-
-        if test ${#problems[*]} -gt 0
-        then
-          if test -z "${goodParent}"
-          then
-            goodParent=${baseSha: 0:7}
-          fi
-          echo "🛑 Please review the Summary output for further information."
-          echo "### :x: A whitespace issue was found in one or more of the commits." >$GITHUB_STEP_SUMMARY
-          echo "" >>$GITHUB_STEP_SUMMARY
-          echo "Run these commands to correct the problem:" >>$GITHUB_STEP_SUMMARY
-          echo "1. \`git rebase --whitespace=fix ${goodParent}\`" >>$GITHUB_STEP_SUMMARY
-          echo "1. \`git push --force\`" >>$GITHUB_STEP_SUMMARY
-          echo " " >>$GITHUB_STEP_SUMMARY
-          echo "Errors:" >>$GITHUB_STEP_SUMMARY
-          for i in "${problems[@]}"
-          do
-            echo "${i}" >>$GITHUB_STEP_SUMMARY
-          done
-
-          exit 2
-        fi
+        ./ci/check-whitespace.sh \
+          "${{github.event.pull_request.base.sha}}" \
+          "$GITHUB_STEP_SUMMARY" \
+          "https://github.com/${{github.repository}}"
ci/check-whitespace.sh new file +74 -0

74 lines not on this page · raw message

Signature · 1 line
2.45.0
#17 lore raw

Re: [PATCH v2 3/5] ci: separate whitespace check script

Quoted 8 lines · Justin Tobler

The check-whitespace CI job is only available as a GitHub action. To help enable this job with other CI providers, first separate the logic performing the whitespace check into its own script. In subsequent commits, this script is further generalized allowing its reuse.

---

[snip]

ci/check-whitespace.sh line 1

Quoted 7 lines
ci/check-whitespace.sh new file +1 -0
new file mode 100755
index 0000000000..f57d1ff5f0
@@ -0,0 +1,74 @@
+#!/bin/bash

This needs to be either "/bin/sh" or "/usr/bin/env bash".

ci/check-whitespace.sh line 4

Quoted 2 lines
ci/check-whitespace.sh new file +2 -0
+baseCommit=$1
+outputFile=$2

I think the script would be more flexible if we just didn't have an output file in the first place and handle redirection of the output at the caller's side. That for example also allows you to easily append to a potential output file.

Edit: I see you change this in the next patch, so this is okay.

ci/check-whitespace.sh line 5

Quoted 1 line
ci/check-whitespace.sh new file +1 -0
+url=$3

We should check that we got 3 arguments in the first place.

Edit: I see that you add those checks in the next commit, but it does leave the reader wondering at this point. Maybe we should have a strict check here and then loosen it in the next commit where you make it optional.

Patrick

#18 lore raw

Re: [PATCH v2 3/5] ci: separate whitespace check script

Quoted 10 lines · Patrick Steinhardt
Quoted 8 lines · Justin Tobler

The check-whitespace CI job is only available as a GitHub action. To help enable this job with other CI providers, first separate the logic performing the whitespace check into its own script. In subsequent commits, this script is further generalized allowing its reuse.

---

[snip]

Quoted 9 lines

ci/check-whitespace.sh line 1

Quoted 7 lines
ci/check-whitespace.sh new file +1 -0
new file mode 100755
index 0000000000..f57d1ff5f0
@@ -0,0 +1,74 @@
+#!/bin/bash

This needs to be either "/bin/sh" or "/usr/bin/env bash".

Since the script is using some shell specific features, I'll update this to "/usr/bin/env bash" in the next version.

Quoted 11 lines

ci/check-whitespace.sh line 4

Quoted 3 lines
ci/check-whitespace.sh new file +2 -0
+baseCommit=$1
+outputFile=$2

I think the script would be more flexible if we just didn't have an output file in the first place and handle redirection of the output at the caller's side. That for example also allows you to easily append to a potential output file.

Edit: I see you change this in the next patch, so this is okay.

Quoted 8 lines

ci/check-whitespace.sh line 5

Quoted 1 line
ci/check-whitespace.sh new file +1 -0
+url=$3

We should check that we got 3 arguments in the first place.

Edit: I see that you add those checks in the next commit, but it does leave the reader wondering at this point. Maybe we should have a strict check here and then loosen it in the next commit where you make it optional.

For this patch specifically, I was trying to really only factor out the whitespace check into its own script and keep changes outside of that to a minimum. The next patch focuses on all the actual script changes and I was hoping it might be easier to review that way. :)

-Justin

#19 lore raw

Re: [PATCH v2 3/5] ci: separate whitespace check script

Quoted 21 lines · Justin Tobler
Quoted 10 lines · Patrick Steinhardt
Quoted 8 lines · Justin Tobler

The check-whitespace CI job is only available as a GitHub action. To help enable this job with other CI providers, first separate the logic performing the whitespace check into its own script. In subsequent commits, this script is further generalized allowing its reuse.

---

[snip]

Quoted 9 lines

ci/check-whitespace.sh line 1

Quoted 7 lines
ci/check-whitespace.sh new file +1 -0
new file mode 100755
index 0000000000..f57d1ff5f0
@@ -0,0 +1,74 @@
+#!/bin/bash

This needs to be either "/bin/sh" or "/usr/bin/env bash".

Quoted 2 lines

Since the script is using some shell specific features, I'll update this to "/usr/bin/env bash" in the next version.

This is a question to Patrick, but what makes it bad to assume "bash" is in "/bin" when it is OK to assume that "env" is always in "/usr/bin"?

All other comments by Patrick I found very sensible.

Thanks, both of you.

#20 lore raw

Re: [PATCH v2 3/5] ci: separate whitespace check script

Quoted 23 lines · Junio C Hamano
Quoted 21 lines · Justin Tobler
Quoted 19 lines · Patrick Steinhardt
Quoted 8 lines · Justin Tobler

The check-whitespace CI job is only available as a GitHub action. To help enable this job with other CI providers, first separate the logic performing the whitespace check into its own script. In subsequent commits, this script is further generalized allowing its reuse.

---

[snip]

ci/check-whitespace.sh line 1

Quoted 7 lines
ci/check-whitespace.sh new file +1 -0
new file mode 100755
index 0000000000..f57d1ff5f0
@@ -0,0 +1,74 @@
+#!/bin/bash

This needs to be either "/bin/sh" or "/usr/bin/env bash".

Quoted 6 lines
Quoted 2 lines

Since the script is using some shell specific features, I'll update this to "/usr/bin/env bash" in the next version.

This is a question to Patrick, but what makes it bad to assume "bash" is in "/bin" when it is OK to assume that "env" is always in "/usr/bin"?

My own bias. I know of systems without "/bin/bash" (NixOS), but I don't know of any without "/usr/bin/env". But you're right, "/usr/bin/env" is not part of POSIX and thus not really portable, either.

Ultimately I don't think there is any way to write the shebang so that it is fully POSIX compliant. So I'd rather go with the option which is supported on more systems, which is to the best of my knowlede env(1).

Patrick

#21 lore raw

Re: [PATCH v2 3/5] ci: separate whitespace check script

Quoted 6 lines · Patrick Steinhardt
Quoted 3 lines · Junio C Hamano

This is a question to Patrick, but what makes it bad to assume "bash" is in "/bin" when it is OK to assume that "env" is always in "/usr/bin"?

Quoted 7 lines

My own bias. I know of systems without "/bin/bash" (NixOS), but I don't know of any without "/usr/bin/env". But you're right, "/usr/bin/env" is not part of POSIX and thus not really portable, either.

Ultimately I don't think there is any way to write the shebang so that it is fully POSIX compliant. So I'd rather go with the option which is supported on more systems, which is to the best of my knowlede env(1).

The various BSDs mostly stick bash in /usr/local/bin; some versions of macOS did not have a /bin/bash either, as I recall, though my current mac-laptop does.

In any case, #! /usr/bin/env <program> is pretty darn common; it's found in a lot of Python scripts, for instance. It works well on old SunOS, on the various BSDs, on macOS, and on Linux, provided of course that the given <program> is installed at all.

The *most* portable method is generally to use only POSIX /bin/sh constructs, of course. :-)

Chris

#22 lore raw

PATCH v2 4/5 ci: make the whitespace report optional

In reply to Justin Tobler

The check-whitespace CI job generates a formatted output file containing whitespace error information. As not all CI providers support rendering a formatted summary, make its generation optional.

---
 ci/check-whitespace.sh | 45 +++++++++++++++++++++++++++++++-----------
 1 file changed, 33 insertions(+), 12 deletions(-)
ci/check-whitespace.sh +33 -12
index f57d1ff5f0..fabd6ecde5 100755
@@ -1,9 +1,20 @@
 #!/bin/bash
+#
+# Check that commits after a specified point do not contain new or modified
+# lines with whitespace errors. An optional formatted summary can be generated
+# by providing an output file path and url as additional arguments.
+#
 
 baseCommit=$1
 outputFile=$2
 url=$3
 
+if test "$#" -eq 0 || test "$#" -gt 3
+then
+	echo "USAGE: $0 <BASE_COMMIT> [<OUTPUT_FILE> <URL>]"
+	exit 1
+fi
+
 problems=()
 commit=
 commitText=
@@ -56,19 +67,29 @@ then
 		goodParent=${baseCommit: 0:7}
 	fi
 
-	echo "🛑 Please review the Summary output for further information."
-	echo "### :x: A whitespace issue was found in one or more of the commits." >"$outputFile"
-	echo "" >>"$outputFile"
-	echo "Run these commands to correct the problem:" >>"$outputFile"
-	echo "1. \`git rebase --whitespace=fix ${goodParent}\`" >>"$outputFile"
-	echo "1. \`git push --force\`" >>"$outputFile"
-	echo " " >>"$outputFile"
-	echo "Errors:" >>"$outputFile"
+	echo "A whitespace issue was found in onen of more of the commits."
+	echo "Run the following command to resolve whitespace issues:"
+	echo "git rebase --whitespace=fix ${goodParent}"
+
+	# If target output file is provided, write formatted ouput.
+	if test -n "$outputFile"
+	then
+		echo "🛑 Please review the Summary output for further information."
+		(
+			echo "### :x: A whitespace issue was found in one or more of the commits."
+			echo ""
+			echo "Run these commands to correct the problem:"
+			echo "1. \`git rebase --whitespace=fix ${goodParent}\`"
+			echo "1. \`git push --force\`"
+			echo ""
+			echo "Errors:"
 
-	for i in "${problems[@]}"
-	do
-		echo "${i}" >>"$outputFile"
-	done
+			for i in "${problems[@]}"
+			do
+				echo "${i}"
+			done
+		) >"$outputFile"
+	fi
 
 	exit 2
 fi
Signature · 1 line
2.45.0
#23 lore raw

Re: [PATCH v2 4/5] ci: make the whitespace report optional

Quoted 16 lines · Justin Tobler

The check-whitespace CI job generates a formatted output file containing whitespace error information. As not all CI providers support rendering a formatted summary, make its generation optional.

---
 ci/check-whitespace.sh | 45 +++++++++++++++++++++++++++++++-----------
 1 file changed, 33 insertions(+), 12 deletions(-)
ci/check-whitespace.sh +1 -0
index f57d1ff5f0..fabd6ecde5 100755
@@ -1,9 +1,20 @@
 #!/bin/bash
+#

ci/check-whitespace.sh line 12

Quoted 10 lines
ci/check-whitespace.sh +5 -0
+# Check that commits after a specified point do not contain new or modified
+# lines with whitespace errors. An optional formatted summary can be generated
+# by providing an output file path and url as additional arguments.
+#
 
 baseCommit=$1
 outputFile=$2
 url=$3
 
+if test "$#" -eq 0 || test "$#" -gt 3

That check is wrong, isn't it? Based on the usage below you either accept exactly 1 or exactly 3 arguments. But the condition here also accepts 2 arguments just fine. The following may be a bit easier to follow as it is more explicit:

    if test "$#" -ne 2 && test "$#" -ne 3
    then
        ...
    fi

ci/check-whitespace.sh line 16

Quoted 4 lines
ci/check-whitespace.sh +4 -0
+then
+	echo "USAGE: $0 <BASE_COMMIT> [<OUTPUT_FILE> <URL>]"
+	exit 1
+fi

Ah, you make the output file optional here. Fair enough, then you can scratch that comment from my preceding mail as it did serve a purpose.

Patrick

#24 lore raw

Re: [PATCH v2 4/5] ci: make the whitespace report optional

Quoted 33 lines · Patrick Steinhardt
Quoted 16 lines · Justin Tobler

The check-whitespace CI job generates a formatted output file containing whitespace error information. As not all CI providers support rendering a formatted summary, make its generation optional.

---
 ci/check-whitespace.sh | 45 +++++++++++++++++++++++++++++++-----------
 1 file changed, 33 insertions(+), 12 deletions(-)
ci/check-whitespace.sh +1 -0
index f57d1ff5f0..fabd6ecde5 100755
@@ -1,9 +1,20 @@
 #!/bin/bash
+#

ci/check-whitespace.sh line 12

Quoted 10 lines
ci/check-whitespace.sh +5 -0
+# Check that commits after a specified point do not contain new or modified
+# lines with whitespace errors. An optional formatted summary can be generated
+# by providing an output file path and url as additional arguments.
+#
 
 baseCommit=$1
 outputFile=$2
 url=$3
 
+if test "$#" -eq 0 || test "$#" -gt 3

That check is wrong, isn't it? Based on the usage below you either accept exactly 1 or exactly 3 arguments. But the condition here also accepts 2 arguments just fine. The following may be a bit easier to follow as it is more explicit:

Quoted 4 lines
    if test "$#" -ne 2 && test "$#" -ne 3
    then
        ...
    fi

Ya, good point. We should only accept 1 or 3 arguments as valid options. I'll update this. Thanks!

-Justin

Quoted 7 lines

ci/check-whitespace.sh line 16

Quoted 4 lines
ci/check-whitespace.sh +4 -0
+then
+	echo "USAGE: $0 <BASE_COMMIT> [<OUTPUT_FILE> <URL>]"
+	exit 1
+fi

Ah, you make the output file optional here. Fair enough, then you can scratch that comment from my preceding mail as it did serve a purpose.

#25 lore raw

PATCH v2 5/5 gitlab-ci: add whitespace error check

In reply to Justin Tobler

GitLab CI does not have a job to check for whitespace errors introduced by a set of changes. Reuse the existing generic whitespace-check.sh to create the job for GitLab pipelines.

Note that the $CI_MERGE_REQUEST_TARGET_BRANCH_SHA variable is only available in GitLab merge request pipelines and therefore the CI job is configured to only run as part of those pipelines.

---
 .gitlab-ci.yml | 9 +++++++++
 1 file changed, 9 insertions(+)
.gitlab-ci.yml +9 -0
index c0fa2fe90b..6d046ce409 100644
@@ -102,3 +102,12 @@ static-analysis:
   script:
     - ./ci/run-static-analysis.sh
     - ./ci/check-directional-formatting.bash
+
+check-whitespace:
+  image: ubuntu:latest
+  before_script:
+    - ./ci/install-docker-dependencies.sh
+  script:
+    - ./ci/check-whitespace.sh "$CI_MERGE_REQUEST_TARGET_BRANCH_SHA"
+  rules:
+    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
Signature · 1 line
2.45.0
#26 lore raw

Re: [PATCH v2 5/5] gitlab-ci: add whitespace error check

Quoted 20 lines · Justin Tobler

GitLab CI does not have a job to check for whitespace errors introduced by a set of changes. Reuse the existing generic whitespace-check.sh to create the job for GitLab pipelines.

Note that the $CI_MERGE_REQUEST_TARGET_BRANCH_SHA variable is only available in GitLab merge request pipelines and therefore the CI job is configured to only run as part of those pipelines.

---
 .gitlab-ci.yml | 9 +++++++++
 1 file changed, 9 insertions(+)
.gitlab-ci.yml +0 -0
index c0fa2fe90b..6d046ce409 100644
@@ -102,3 +102,12 @@ static-analysis:
   script:
     - ./ci/run-static-analysis.sh

.gitlab-ci.yml static-analysis: · line 113

Quoted 10 lines
.gitlab-ci.yml +9 -0
     - ./ci/check-directional-formatting.bash
+
+check-whitespace:
+  image: ubuntu:latest
+  before_script:
+    - ./ci/install-docker-dependencies.sh
+  script:
+    - ./ci/check-whitespace.sh "$CI_MERGE_REQUEST_TARGET_BRANCH_SHA"
+  rules:
+    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'

Nice :)

Patrick

#27 lore raw
In reply to Justin Tobler
Quoted 4 lines · Justin Tobler

This is the second version of my patch series to add a GitLab CI job to check for whitespace errors. The main differnece with this version is that it first generalizes the existing GitHub whitespace check CI job allowing the GitLab one to reuse it.

Will queue. Thanks. The extraction and reuse of a common script is excellent.

#28 lore raw
Quoted 9 lines · Junio C Hamano
Quoted 4 lines · Justin Tobler

This is the second version of my patch series to add a GitLab CI job to check for whitespace errors. The main differnece with this version is that it first generalizes the existing GitHub whitespace check CI job allowing the GitLab one to reuse it.

Will queue. Thanks. The extraction and reuse of a common script is excellent.

Thanks! I will send a V3 here shortly which makes some small suggested edits.

-Justin

#29 lore raw

v3 cover Add GitLab CI to check for whitespace errors

In reply to Justin Tobler

Hello again,

This is the third version of my patch series to add a GitLab CI job to check for whitespace errors.

Changes since V2:

- In 35e293e6 (Merge branch 'ps/ci-test-with-jgit' into next, 2024-05-01), install-docker-dependencies.sh script was merged into install-dependencies.sh and removed. Thus this patch series now depends on that change and is updated to use the other script.
- Changed the shebang to "#!/usr/bin/env bash".
- Made the argument count validation more strict.
- Fixed a typo.

GitHub CI:

- https://github.com/gitgitgadget/git/actions/runs/8941666020?pr=1727
- https://github.com/gitgitgadget/git/actions/runs/8941721282?pr=1727

GitLab CI:

- https://gitlab.com/gitlab-org/git/-/jobs/6776032414
- https://gitlab.com/gitlab-org/git/-/jobs/6776038234

Thanks for the reviews,
-Justin

Justin Tobler (5):
ci: pre-collapse GitLab CI sections
github-ci: fix link to whitespace error
ci: separate whitespace check script
ci: make the whitespace report optional
gitlab-ci: add whitespace error check

 .github/workflows/check-whitespace.yml | 67 ++----------------
 .gitlab-ci.yml                         |  9 +++
 ci/check-whitespace.sh                 | 95 ++++++++++++++++++++++++++
 ci/lib.sh                              |  2 +-
 4 files changed, 109 insertions(+), 64 deletions(-)
 create mode 100755 ci/check-whitespace.sh

Range-diff against v2:

1:  924d3eb23c = 1:  924d3eb23c ci: pre-collapse GitLab CI sections
2:  c8d8b444dc = 2:  c8d8b444dc github-ci: fix link to whitespace error
3:  6b44b21dda ! 3:  933e0c33f9 ci: separate whitespace check script
    @@ .github/workflows/check-whitespace.yml: jobs:
     
      ## ci/check-whitespace.sh (new) ##
     @@
    -+#!/bin/bash
    ++#!/usr/bin/env bash
     +
     +baseCommit=$1
     +outputFile=$2

4: 87dfd1d5a9 ! 4: 374735c60f ci: make the whitespace report optional
@@ Commit message

## ci/check-whitespace.sh ##
@@
- #!/bin/bash
+ #!/usr/bin/env bash
+#
+# Check that commits after a specified point do not contain new or modified +# lines with whitespace errors. An optional formatted summary can be generated
@@ ci/check-whitespace.sh
outputFile=$2
url=$3

-+if test "$#" -eq 0 || test "$#" -gt 3
++if test "$#" -ne 1 && test "$#" -ne 3
+then
+ echo "USAGE: $0 <BASE_COMMIT> [<OUTPUT_FILE> <URL>]"
+ exit 1
@@ ci/check-whitespace.sh: then
+ echo "Run the following command to resolve whitespace issues:"
+ echo "git rebase --whitespace=fix ${goodParent}"
+
-+ # If target output file is provided, write formatted ouput.
++ # If target output file is provided, write formatted output.
+ if test -n "$outputFile"
+ then
+ echo "🛑 Please review the Summary output for further information."
5: 175b300e91 ! 5: a7deaeadc7 gitlab-ci: add whitespace error check
@@ .gitlab-ci.yml: static-analysis:
+check-whitespace:
+ image: ubuntu:latest
+ before_script:
-+ - ./ci/install-docker-dependencies.sh
++ - ./ci/install-dependencies.sh
+ script:
+ - ./ci/check-whitespace.sh "$CI_MERGE_REQUEST_TARGET_BRANCH_SHA"
+ rules:

Signature · 1 line
2.45.0
#30 lore raw

PATCH v3 1/5 ci: pre-collapse GitLab CI sections

Sections of CI output defined by begin_group() and end_group() are expanded in GitLab pipelines by default. This can make CI job output rather noisy and harder to navigate. Update the behavior for GitLab pipelines to now collapse sections by default.

---
 ci/lib.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
ci/lib.sh +1 -1
index 0a73fc7bd1..02e5e058dd 100755
@@ -18,7 +18,7 @@ elif test true = "$GITLAB_CI"
 then
 	begin_group () {
 		need_to_end_group=t
-		printf "\e[0Ksection_start:$(date +%s):$(echo "$1" | tr ' ' _)\r\e[0K$1\n"
+		printf "\e[0Ksection_start:$(date +%s):$(echo "$1" | tr ' ' _)[collapsed=true]\r\e[0K$1\n"
 		trap "end_group '$1'" EXIT
 		set -x
 	}
Signature · 1 line
2.45.0
#31 lore raw

PATCH v3 2/5 github-ci: fix link to whitespace error

In reply to Justin Tobler

When the check-whitespace CI job detects whitespace errors, a formatted summary of the issue is generated. This summary contains links to the commits and blobs responsible for the whitespace errors. The generated links for blobs do not work and result in a 404.

Instead of using the reference name in the link, use the commit ID directly. This fixes the broken link and also helps enable future generalization of the script for other CI providers by removing one of the GitHub specific CI variables used.

---
 .github/workflows/check-whitespace.yml | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)
.github/workflows/check-whitespace.yml +12 -11
index a241a63428..a3a6913ecc 100644
@@ -31,14 +31,15 @@ jobs:
         commit=
         commitText=
         commitTextmd=
-        goodparent=
+        goodParent=
         while read dash sha etc
         do
           case "${dash}" in
-          "---")
-            if test -z "${commit}"
+          "---") # Line contains commit information.
+            if test -z "${goodParent}"
             then
-              goodparent=${sha}
+              # Assume the commit has no whitespace errors until detected otherwise.
+              goodParent=${sha}
             fi
             commit="${sha}"
             commitText="${sha} ${etc}"
@@ -46,18 +47,18 @@ jobs:
             ;;
           "")
             ;;
-          *)
-            if test -n "${commit}"
+          *) # Line contains whitespace error information for current commit.
+            if test -n "${goodParent}"
             then
               problems+=("1) --- ${commitTextmd}")
               echo ""
               echo "--- ${commitText}"
-              commit=
+              goodParent=
             fi
             case "${dash}" in
             *:[1-9]*:) # contains file and line number information
               dashend=${dash#*:}
-              problems+=("[${dash}](https://github.com/${{ github.repository }}/blob/${{github.event.pull_request.head.ref}}/${dash%%:*}#L${dashend%:}) ${sha} ${etc}")
+              problems+=("[${dash}](https://github.com/${{ github.repository }}/blob/${commit}/${dash%%:*}#L${dashend%:}) ${sha} ${etc}")
               ;;
             *)
               problems+=("\`${dash} ${sha} ${etc}\`")
@@ -70,15 +71,15 @@ jobs:
 
         if test ${#problems[*]} -gt 0
         then
-          if test -z "${commit}"
+          if test -z "${goodParent}"
           then
-            goodparent=${baseSha: 0:7}
+            goodParent=${baseSha: 0:7}
           fi
           echo "🛑 Please review the Summary output for further information."
           echo "### :x: A whitespace issue was found in one or more of the commits." >$GITHUB_STEP_SUMMARY
           echo "" >>$GITHUB_STEP_SUMMARY
           echo "Run these commands to correct the problem:" >>$GITHUB_STEP_SUMMARY
-          echo "1. \`git rebase --whitespace=fix ${goodparent}\`" >>$GITHUB_STEP_SUMMARY
+          echo "1. \`git rebase --whitespace=fix ${goodParent}\`" >>$GITHUB_STEP_SUMMARY
           echo "1. \`git push --force\`" >>$GITHUB_STEP_SUMMARY
           echo " " >>$GITHUB_STEP_SUMMARY
           echo "Errors:" >>$GITHUB_STEP_SUMMARY
Signature · 1 line
2.45.0
#32 lore raw

PATCH v3 3/5 ci: separate whitespace check script

In reply to Justin Tobler

The check-whitespace CI job is only available as a GitHub action. To help enable this job with other CI providers, first separate the logic performing the whitespace check into its own script. In subsequent commits, this script is further generalized allowing its reuse.

---
 .github/workflows/check-whitespace.yml | 68 ++---------------------
 ci/check-whitespace.sh                 | 74 ++++++++++++++++++++++++++
 2 files changed, 78 insertions(+), 64 deletions(-)
 create mode 100755 ci/check-whitespace.sh
.github/workflows/check-whitespace.yml +4 -64
index a3a6913ecc..d0a78fc426 100644
@@ -26,67 +26,7 @@ jobs:
     - name: git log --check
       id: check_out
       run: |
-        baseSha=${{github.event.pull_request.base.sha}}
-        problems=()
-        commit=
-        commitText=
-        commitTextmd=
-        goodParent=
-        while read dash sha etc
-        do
-          case "${dash}" in
-          "---") # Line contains commit information.
-            if test -z "${goodParent}"
-            then
-              # Assume the commit has no whitespace errors until detected otherwise.
-              goodParent=${sha}
-            fi
-            commit="${sha}"
-            commitText="${sha} ${etc}"
-            commitTextmd="[${sha}](https://github.com/${{ github.repository }}/commit/${sha}) ${etc}"
-            ;;
-          "")
-            ;;
-          *) # Line contains whitespace error information for current commit.
-            if test -n "${goodParent}"
-            then
-              problems+=("1) --- ${commitTextmd}")
-              echo ""
-              echo "--- ${commitText}"
-              goodParent=
-            fi
-            case "${dash}" in
-            *:[1-9]*:) # contains file and line number information
-              dashend=${dash#*:}
-              problems+=("[${dash}](https://github.com/${{ github.repository }}/blob/${commit}/${dash%%:*}#L${dashend%:}) ${sha} ${etc}")
-              ;;
-            *)
-              problems+=("\`${dash} ${sha} ${etc}\`")
-              ;;
-            esac
-            echo "${dash} ${sha} ${etc}"
-            ;;
-          esac
-        done <<< $(git log --check --pretty=format:"---% h% s" ${baseSha}..)
-
-        if test ${#problems[*]} -gt 0
-        then
-          if test -z "${goodParent}"
-          then
-            goodParent=${baseSha: 0:7}
-          fi
-          echo "🛑 Please review the Summary output for further information."
-          echo "### :x: A whitespace issue was found in one or more of the commits." >$GITHUB_STEP_SUMMARY
-          echo "" >>$GITHUB_STEP_SUMMARY
-          echo "Run these commands to correct the problem:" >>$GITHUB_STEP_SUMMARY
-          echo "1. \`git rebase --whitespace=fix ${goodParent}\`" >>$GITHUB_STEP_SUMMARY
-          echo "1. \`git push --force\`" >>$GITHUB_STEP_SUMMARY
-          echo " " >>$GITHUB_STEP_SUMMARY
-          echo "Errors:" >>$GITHUB_STEP_SUMMARY
-          for i in "${problems[@]}"
-          do
-            echo "${i}" >>$GITHUB_STEP_SUMMARY
-          done
-
-          exit 2
-        fi
+        ./ci/check-whitespace.sh \
+          "${{github.event.pull_request.base.sha}}" \
+          "$GITHUB_STEP_SUMMARY" \
+          "https://github.com/${{github.repository}}"
ci/check-whitespace.sh new file +74 -0

74 lines not on this page · raw message

Signature · 1 line
2.45.0
#33 lore raw

PATCH v3 4/5 ci: make the whitespace report optional

In reply to Justin Tobler

The check-whitespace CI job generates a formatted output file containing whitespace error information. As not all CI providers support rendering a formatted summary, make its generation optional.

---
 ci/check-whitespace.sh | 45 +++++++++++++++++++++++++++++++-----------
 1 file changed, 33 insertions(+), 12 deletions(-)
ci/check-whitespace.sh +33 -12
index 9cc496da40..db399097a5 100755
@@ -1,9 +1,20 @@
 #!/usr/bin/env bash
+#
+# Check that commits after a specified point do not contain new or modified
+# lines with whitespace errors. An optional formatted summary can be generated
+# by providing an output file path and url as additional arguments.
+#
 
 baseCommit=$1
 outputFile=$2
 url=$3
 
+if test "$#" -ne 1 && test "$#" -ne 3
+then
+	echo "USAGE: $0 <BASE_COMMIT> [<OUTPUT_FILE> <URL>]"
+	exit 1
+fi
+
 problems=()
 commit=
 commitText=
@@ -56,19 +67,29 @@ then
 		goodParent=${baseCommit: 0:7}
 	fi
 
-	echo "🛑 Please review the Summary output for further information."
-	echo "### :x: A whitespace issue was found in one or more of the commits." >"$outputFile"
-	echo "" >>"$outputFile"
-	echo "Run these commands to correct the problem:" >>"$outputFile"
-	echo "1. \`git rebase --whitespace=fix ${goodParent}\`" >>"$outputFile"
-	echo "1. \`git push --force\`" >>"$outputFile"
-	echo " " >>"$outputFile"
-	echo "Errors:" >>"$outputFile"
+	echo "A whitespace issue was found in onen of more of the commits."
+	echo "Run the following command to resolve whitespace issues:"
+	echo "git rebase --whitespace=fix ${goodParent}"
+
+	# If target output file is provided, write formatted output.
+	if test -n "$outputFile"
+	then
+		echo "🛑 Please review the Summary output for further information."
+		(
+			echo "### :x: A whitespace issue was found in one or more of the commits."
+			echo ""
+			echo "Run these commands to correct the problem:"
+			echo "1. \`git rebase --whitespace=fix ${goodParent}\`"
+			echo "1. \`git push --force\`"
+			echo ""
+			echo "Errors:"
 
-	for i in "${problems[@]}"
-	do
-		echo "${i}" >>"$outputFile"
-	done
+			for i in "${problems[@]}"
+			do
+				echo "${i}"
+			done
+		) >"$outputFile"
+	fi
 
 	exit 2
 fi
Signature · 1 line
2.45.0
#34 lore raw

PATCH v3 5/5 gitlab-ci: add whitespace error check

In reply to Justin Tobler

GitLab CI does not have a job to check for whitespace errors introduced by a set of changes. Reuse the existing generic whitespace-check.sh to create the job for GitLab pipelines.

Note that the $CI_MERGE_REQUEST_TARGET_BRANCH_SHA variable is only available in GitLab merge request pipelines and therefore the CI job is configured to only run as part of those pipelines.

---
 .gitlab-ci.yml | 9 +++++++++
 1 file changed, 9 insertions(+)
.gitlab-ci.yml +9 -0
index c0fa2fe90b..619bf729fa 100644
@@ -102,3 +102,12 @@ static-analysis:
   script:
     - ./ci/run-static-analysis.sh
     - ./ci/check-directional-formatting.bash
+
+check-whitespace:
+  image: ubuntu:latest
+  before_script:
+    - ./ci/install-dependencies.sh
+  script:
+    - ./ci/check-whitespace.sh "$CI_MERGE_REQUEST_TARGET_BRANCH_SHA"
+  rules:
+    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
Signature · 1 line
2.45.0
#35 lore raw

Re: [PATCH v3 5/5] gitlab-ci: add whitespace error check

Quoted 18 lines · Justin Tobler

GitLab CI does not have a job to check for whitespace errors introduced by a set of changes. Reuse the existing generic whitespace-check.sh to create the job for GitLab pipelines.

Note that the $CI_MERGE_REQUEST_TARGET_BRANCH_SHA variable is only available in GitLab merge request pipelines and therefore the CI job is configured to only run as part of those pipelines.

---
 .gitlab-ci.yml | 9 +++++++++
 1 file changed, 9 insertions(+)
.gitlab-ci.yml +0 -0
index c0fa2fe90b..619bf729fa 100644

.gitlab-ci.yml static-analysis: · line 109

Quoted 8 lines
.gitlab-ci.yml +5 -0
@@ -102,3 +102,12 @@ static-analysis:
   script:
     - ./ci/run-static-analysis.sh
     - ./ci/check-directional-formatting.bash
+
+check-whitespace:
+  image: ubuntu:latest
+  before_script:
+    - ./ci/install-dependencies.sh

Do we actually need to install dependencies? I imagine all that's needed would be Git.

Other than this question the patch series looks good to me, thanks!

Patrick

Quoted 8 lines
.gitlab-ci.yml +4 -0
+  script:
+    - ./ci/check-whitespace.sh "$CI_MERGE_REQUEST_TARGET_BRANCH_SHA"
+  rules:
+    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
Signature · 1 line
2.45.0
#36 lore raw

Re: [PATCH v3 5/5] gitlab-ci: add whitespace error check

Quoted 14 lines · Patrick Steinhardt
Quoted 13 lines · Justin Tobler

GitLab CI does not have a job to check for whitespace errors introduced by a set of changes. Reuse the existing generic whitespace-check.sh to create the job for GitLab pipelines.

Note that the $CI_MERGE_REQUEST_TARGET_BRANCH_SHA variable is only available in GitLab merge request pipelines and therefore the CI job is configured to only run as part of those pipelines.

---
 .gitlab-ci.yml | 9 +++++++++
 1 file changed, 9 insertions(+)
Quoted 16 lines

.gitlab-ci.yml static-analysis: · line 109

Quoted 13 lines
.gitlab-ci.yml +5 -0
index c0fa2fe90b..619bf729fa 100644
@@ -102,3 +102,12 @@ static-analysis:
   script:
     - ./ci/run-static-analysis.sh
     - ./ci/check-directional-formatting.bash
+
+check-whitespace:
+  image: ubuntu:latest
+  before_script:
+    - ./ci/install-dependencies.sh

Do we actually need to install dependencies? I imagine all that's needed would be Git.

You are correct. Git is really the only dependency we need. If we want to remove the need for the install dependencies script, we could fetch Git ourselves during the pre-script. Another option could be to use a different container image that has Git baked in.

-Justin

#37 lore raw

Re: [PATCH v3 5/5] gitlab-ci: add whitespace error check

In reply to Patrick Steinhardt
Quoted 9 lines · Patrick Steinhardt

.gitlab-ci.yml static-analysis: · line 109

Quoted 4 lines
.gitlab-ci.yml +4 -0
+check-whitespace:
+  image: ubuntu:latest
+  before_script:
+    - ./ci/install-dependencies.sh

Do we actually need to install dependencies? I imagine all that's needed would be Git.

Other than this question the patch series looks good to me, thanks!

I am a bit puzzled. Is the proposal to check our sources with a pre-built Git (which by definition would be a bit older than what is being tested)?

Not that I have serious trouble in that direction---I am just trying to make sure what is being proposed.

Thanks.

#38 lore raw

Re: [PATCH v3 5/5] gitlab-ci: add whitespace error check

Quoted 7 lines · Junio C Hamano
Quoted 5 lines · Patrick Steinhardt
Quoted 4 lines
.gitlab-ci.yml +4 -0
+check-whitespace:
+  image: ubuntu:latest
+  before_script:
+    - ./ci/install-dependencies.sh
Quoted 8 lines
Quoted 4 lines

Do we actually need to install dependencies? I imagine all that's needed would be Git.

Other than this question the patch series looks good to me, thanks!

I am a bit puzzled. Is the proposal to check our sources with a pre-built Git (which by definition would be a bit older than what is being tested)?

The GitLab check-whitespace CI job only needs Git to run and uses ci/install-dependencies.sh to download a pre-built Git package via apt-get since ubuntu:latest is the container image used. The ci/install-dependencies.sh script also fetches a bunch of other dependencies which are not needed.

I think Patrick is proposing, to further simplify, we avoid using ci/install-dependencies.sh and only fetch Git. Patrick please correct me if I misunderstand :)

-Justin

#39 lore raw

Re: [PATCH v3 5/5] gitlab-ci: add whitespace error check

Quoted 23 lines · Justin Tobler
Quoted 7 lines · Junio C Hamano
Quoted 5 lines · Patrick Steinhardt
Quoted 4 lines
.gitlab-ci.yml +4 -0
+check-whitespace:
+  image: ubuntu:latest
+  before_script:
+    - ./ci/install-dependencies.sh
Quoted 8 lines
Quoted 4 lines

Do we actually need to install dependencies? I imagine all that's needed would be Git.

Other than this question the patch series looks good to me, thanks!

I am a bit puzzled. Is the proposal to check our sources with a pre-built Git (which by definition would be a bit older than what is being tested)?

The GitLab check-whitespace CI job only needs Git to run and uses ci/install-dependencies.sh to download a pre-built Git package via apt-get since ubuntu:latest is the container image used. The ci/install-dependencies.sh script also fetches a bunch of other dependencies which are not needed.

Quoted 3 lines

I think Patrick is proposing, to further simplify, we avoid using ci/install-dependencies.sh and only fetch Git. Patrick please correct me if I misunderstand :)

I just wondered how GitHub Workflows manages without installing any dependencies at all. Is Git already part of the default images? If so, there is no need to install anything and we can just execute the script directly, which saves some time.

If there is a need to install Git we could either just manually install it in the before_script or leave it as-is. I don't mind it much either way.

Patrick

#40 lore raw

Re: [PATCH v3 5/5] gitlab-ci: add whitespace error check

Quoted 4 lines · Patrick Steinhardt

I just wondered how GitHub Workflows manages without installing any dependencies at all. Is Git already part of the default images? If so, there is no need to install anything and we can just execute the script directly, which saves some time.

Git is not bundled by default in the "ubuntu:latest" container image. We would have to install it ourselves. As for why GitHub Workflows do not have to install Git, it looks like each runner has a defined set of included software which happens to include Git.

https://github.com/actions/runner-images/blob/ubuntu22/20240422.1/images/ubuntu/Ubuntu2204-Readme.md

Quoted 3 lines

If there is a need to install Git we could either just manually install it in the before_script or leave it as-is. I don't mind it much either way.

I don't have strong opinions, but I think I would prefer to leave it as-is and reuse ci/install-dependencies.sh. I'll forgo sending another version unless there is addional feedback. Thanks

-Justin

#41 lore raw

Re: [PATCH v3 5/5] gitlab-ci: add whitespace error check

Quoted 11 lines · Justin Tobler
Quoted 4 lines · Patrick Steinhardt

I just wondered how GitHub Workflows manages without installing any dependencies at all. Is Git already part of the default images? If so, there is no need to install anything and we can just execute the script directly, which saves some time.

Git is not bundled by default in the "ubuntu:latest" container image. We would have to install it ourselves. As for why GitHub Workflows do not have to install Git, it looks like each runner has a defined set of included software which happens to include Git.

Okay.

Quoted 9 lines

https://github.com/actions/runner-images/blob/ubuntu22/20240422.1/images/ubuntu/Ubuntu2204-Readme.md

Quoted 3 lines

If there is a need to install Git we could either just manually install it in the before_script or leave it as-is. I don't mind it much either way.

I don't have strong opinions, but I think I would prefer to leave it as-is and reuse ci/install-dependencies.sh. I'll forgo sending another version unless there is addional feedback. Thanks

Fair enough. Let's not overthink this then and get this merged.

Patrick