git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 1/3] ci (check-whitespace): suggest fixes for errors

From
Đoàn Trần Công Danh <congdanhqx@gmail.com>
Date
Dec 20, 2022, 07:34 UTC
Message-ID
<Y6Fle8gzVU5si3T/@danh.dev>
In-Reply-To
<a2b5f3e87d6ef62d8005cff5568ad3afc4af3771.1671496548.git.gitgitgadget@gmail.com>
On 2022-12-20 00:35:45+0000, "Chris. Webster via GitGitGadget" <gitgitgadget@gmail.com> wrote:
Show 7 quoted lines
> From: "Chris. Webster" <chris@webstech.net>
> 
> Make the errors more visible by adding them to the job summary and
> display the git commands that will usually fix the problem.
> 
> Signed-off-by: Chris. Webster <chris@webstech.net>
> ---

I think this change is getting too long to be embeded in a yaml file. I think it's better to move the shell code into its own script, so we can have better code highlight in editor and a proper shebang (/bin/bash).

Show 60 quoted lines
>  .github/workflows/check-whitespace.yml | 37 +++++++++++++++++++-------
>  1 file changed, 28 insertions(+), 9 deletions(-)
> 
> diff --git a/.github/workflows/check-whitespace.yml b/.github/workflows/check-whitespace.yml
> index ad3466ad16e..a0871489b24 100644
> --- a/.github/workflows/check-whitespace.yml
> +++ b/.github/workflows/check-whitespace.yml
> @@ -20,31 +20,50 @@ jobs:
>      - name: git log --check
>        id: check_out
>        run: |
> -        log=
> +        problems=()
>          commit=
> -        while read dash etc
> +        commitText=
> +        lastcommit=
> +        while read dash sha etc
>          do
>            case "${dash}" in
>            "---")
> -            commit="${etc}"
> +            if test -z "${commit}"
> +            then
> +              lastcommit=${sha}
> +            fi
> +            commit="${sha}"
> +            commitText="${sha} ${etc}"
>              ;;
>            "")
>              ;;
>            *)
>              if test -n "${commit}"
>              then
> -              log="${log}\n${commit}"
> +              problems+=("" "--- ${commitText}")
>                echo ""
> -              echo "--- ${commit}"
> +              echo "--- ${commitText}"
> +              commit=
>              fi
> -            commit=
> -            log="${log}\n${dash} ${etc}"
> -            echo "${dash} ${etc}"
> +            problems+=("${dash} ${sha} ${etc}")
> +            echo "${problems[-1]}"
>              ;;
>            esac
>          done <<< $(git log --check --pretty=format:"---% h% s" ${{github.event.pull_request.base.sha}}..)
>  
> -        if test -n "${log}"
> +        if test ${#problems[*]} -gt 0
>          then
> +          if test -z "${commit}"
> +          then
> +            lastcommit=${{github.event.pull_request.base.sha}}
> +          fi
> +          echo "A whitespace issue was found in one or more of the commits." >$GITHUB_STEP_SUMMARY
> +          echo "" >>$GITHUB_STEP_SUMMARY
> +          echo "Run \`git rebase --whitespace=fix ${lastcommit}\` and \`git push --force\` to correct the problem." >>$GITHUB_STEP_SUMMARY

When move this block into its own script, we can use single quote string here, too.

Show 10 quoted lines
> +          for i in "${problems[@]}"
> +          do
> +            echo "${i}" >>$GITHUB_STEP_SUMMARY
> +          done
> +
>            exit 2
>          fi
> -- 
> gitgitgadget
> 
-- 
Danh
Previous: Chris. Webster via GitGitGadgetNext: Chris Webster
Message 12 of 18 in “Make check-whitespace failures more helpful”
  1. 0/2 Make check-whitespace failures more helpfulChris. Webster via GitGitGadget, Dec 16, 2022
  2. 2/2 Improve check-whitespace outputChris. Webster via GitGitGadget, Dec 16, 2022
  3. Junio C HamanoDec 16, 2022
  4. Chris WebsterDec 20, 2022
  5. 1/2 Make `check-whitespace` failures more helpfulChris. Webster via GitGitGadget, Dec 16, 2022
  6. Junio C HamanoDec 16, 2022
  7. Chris WebsterDec 20, 2022
  8. Junio C HamanoDec 20, 2022
  9. Chris WebsterDec 20, 2022
  10. 0/3 Make check-whitespace failures more helpfulChris. Webster via GitGitGadget, Dec 20, 2022
  11. 1/3 ci (check-whitespace): suggest fixes for errorsChris. Webster via GitGitGadget, Dec 20, 2022
  12. Đoàn Trần Công DanhDec 20, 2022
  13. Chris WebsterDec 20, 2022
  14. Đoàn Trần Công DanhDec 21, 2022
  15. Chris WebsterDec 21, 2022
  16. Đoàn Trần Công DanhDec 21, 2022
  17. 2/3 ci (check-whitespace): add links to job outputChris. Webster via GitGitGadget, Dec 20, 2022
  18. 3/3 ci (check-whitespace): move to actions/checkout@v3Chris. Webster via GitGitGadget, Dec 20, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.