-
Notifications
You must be signed in to change notification settings - Fork 239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a workflow for nitpicking on trailing spaces and similar issues (to discuss) #892
Open
ghost
wants to merge
1
commit into
main
Choose a base branch
from
feature/workflow-nitpicks
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
--- | ||
name: Nitpicks | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- 'DC-*' | ||
- 'xml/*' | ||
- 'adoc/*' | ||
|
||
jobs: | ||
nitpicks: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- name: Checking out relevant branches | ||
run: | | ||
git checkout $GITHUB_BASE_REF || { echo "There's a Git issue"; exit 1; } | ||
git checkout $GITHUB_HEAD_REF || { echo "There's a Git issue"; exit 1; } | ||
|
||
- name: Checking for tabs | ||
run: | | ||
tab=$(git diff -U0 $GITHUB_BASE_REF..$GITHUB_HEAD_REF | sed -n '/^+/ p' | sed -n '/\t/ p' | sed -r -e 's/\t/→/g') | ||
if [[ -n "$tab" ]]; then | ||
echo -e "\nThis pull request introduces tabs (→) on the following lines:" | ||
echo -e "\n$tab\n" | ||
exit 1 | ||
else | ||
echo "This looks aight." | ||
exit 0 | ||
fi | ||
|
||
- name: Checking for Windows/Mac line ends | ||
run: | | ||
lineends=$(git diff -U0 $GITHUB_BASE_REF..$GITHUB_HEAD_REF | sed -n '/^+/ p' | sed -n '/\r/ p' | sed -r -e 's/\r/↲/g') | ||
if [[ -n "$lineends" ]]; then | ||
echo -e "\nThis pull request introduces Windows/Mac line ends (↲) on the following lines:" | ||
echo -e "\n$lineends\n" | ||
exit 1 | ||
else | ||
echo "This looks aight." | ||
exit 0 | ||
fi | ||
|
||
- name: Checking for trailing characters | ||
run: | | ||
trail=$(git diff -U0 $GITHUB_BASE_REF..$GITHUB_HEAD_REF | sed -n '/^+/ p' | sed -n '/[ \t]$/ p' | sed -r -e 's/ *$/•/g' -e 's/\t*$/→/g' -e 's/ *$/⋄/g') | ||
if [[ -n "$trail" ]]; then | ||
echo -e "\nThis pull request introduces trailing spaces (•)/tabs (→)/protected spaces (⋄) on the following lines:" | ||
echo -e "\n$trail\n" | ||
exit 1 | ||
else | ||
echo "This looks aight." | ||
exit 0 | ||
fi | ||
|
||
- name: Checking for long lines | ||
# We exclude screens, there are legitimate reasons for them to be long. | ||
run: | | ||
potential=$(git diff -U1000 $GITHUB_BASE_REF..$GITHUB_HEAD_REF | tr '\n' '\r' | sed -r -e 's,<screen[^>]*/>,,g' -e 's,</screen[^>]*>,⋘,g' -e 's,<screen[^/>]*>[^⋘]*⋘,,g' | tr '\r' '\n' | sed -n '/^+/ p') | ||
len=$(echo -e "$potential" | wc -l) | ||
long='' | ||
for n in $(seq 1 "$len"); do | ||
line=$(echo -e "$potential" | sed -n "$n p") | ||
if [[ $(echo "$line" | wc -c) -gt 91 ]]; then | ||
long+="\n$line" | ||
fi | ||
done | ||
if [[ -n "$long" ]]; then | ||
echo -e "\nThis pull request introduces long lines (80+ characters) in at least the following spots:" | ||
echo -e "$long\n" | ||
exit 1 | ||
else | ||
echo "This looks aight." | ||
exit 0 | ||
fi |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest to use the GitHub formatted error message to make it visually distinct from other messages:
https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-error-message
Syntax
Most of these parameters are optional. So you would probably use something like this:
You may want to apply it to the other
echo
commands as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If that is true, then using two echos with
::error::
in succession as suggested here won't work, because it'd exit after the first::error::
message. I am also unsure if::error::
allows for-e
which is extremely necessary for the secondecho
.exit 1;
is 7 characters ... if anything "blows up the code", it's hardly that.^^I should probably do something like that. It could have been less work though if continue-on-error worked better though. :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, maybe I misremembered that.
It's not only this line, there are other lines. But it's probably a matter of taste, so ignore that. 😉
Right. It was just an idea. As you wrote, maybe for the future it would be better anyway to move it into a "real" GH Action. But for the time being, you could leave it as is.