Skip to content

Commit

Permalink
docs: Fix example workflow (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
ginokent authored Jan 6, 2025
2 parents a852c2f + d161a07 commit 40f210d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 27 deletions.
34 changes: 21 additions & 13 deletions .github/workflows/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ on:
jobs:
missing-final-newline:
runs-on: ubuntu-latest
outputs:
missing: ${{ steps.missing-final-newline.outputs.missing }}
missing-files: ${{ steps.missing-final-newline.outputs.missing-files }}
permissions:
contents: read
pull-requests: write
steps:
- uses: hakadoriya/github-actions-missing-final-newline@develop
id: missing-final-newline
Expand All @@ -19,14 +19,22 @@ jobs:
paths: |-
^action.yml
^missing-final-newline.md
# > Note: A job that is skipped will report its status as "Success".
# > It will not prevent a pull request from merging, even if it is a required check.
# ref. https://docs.github.com/en/actions/using-jobs/using-conditions-to-control-job-execution#overview
missing:
runs-on: ubuntu-latest
needs: missing-final-newline
if: ${{ needs.missing-final-newline.outputs.missing == 'true' }}
steps:
- name: "missing final newline detected"
- name: Submit PR comment if missing final newline
if: ${{ steps.missing-final-newline.outputs.missing == 'true' }}
env:
GH_TOKEN: ${{ github.token }}
run: |
echo "needs.missing-final-newline.outputs.missing-files: ${{ needs.missing-final-newline.outputs.missing-files }}"
# Create comment body
cat <<EOF | perl -pe 's/\\n/\n/g' | tee /tmp/gh-pr-comment-body.md
## 🚨 Missing final newline
The following files are missing final newline.
\`\`\`
${{ steps.missing-final-newline.outputs.missing-files }}
\`\`\`
EOF
# Submit PR comment
gh pr comment ${{ github.event.pull_request.number }} --body-file /tmp/gh-pr-comment-body.md
# fail the workflow
exit 1
34 changes: 21 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ on:
jobs:
missing-final-newline:
runs-on: ubuntu-latest
outputs:
missing: ${{ steps.missing-final-newline.outputs.missing }}
missing-files: ${{ steps.missing-final-newline.outputs.missing-files }}
permissions:
contents: read
pull-requests: write
steps:
- uses: hakadoriya/github-actions-missing-final-newline@main
id: missing-final-newline
Expand All @@ -26,15 +26,23 @@ jobs:
paths: |-
^action.yml
^missing-final-newline.md
# > Note: A job that is skipped will report its status as "Success".
# > It will not prevent a pull request from merging, even if it is a required check.
# ref. https://docs.github.com/en/actions/using-jobs/using-conditions-to-control-job-execution#overview
missing:
runs-on: ubuntu-latest
needs: missing-final-newline
if: ${{ needs.missing-final-newline.outputs.missing == 'true' }}
steps:
- name: "missing final newline detected"
- name: Submit PR comment if missing final newline
if: ${{ steps.missing-final-newline.outputs.missing == 'true' }}
env:
GH_TOKEN: ${{ github.token }}
run: |
echo "needs.missing-final-newline.outputs.missing-files: ${{ needs.missing-final-newline.outputs.missing-files }}"
# Create comment body
cat <<EOF | perl -pe 's/\\n/\n/g' | tee /tmp/gh-pr-comment-body.md
## 🚨 Missing final newline
The following files are missing final newline.
\`\`\`
${{ steps.missing-final-newline.outputs.missing-files }}
\`\`\`
EOF
# Submit PR comment
gh pr comment ${{ github.event.pull_request.number }} --body-file /tmp/gh-pr-comment-body.md
# fail the workflow
exit 1
```
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ runs:
while read -r FILE; do
if [[ $(tail -c 1 "${FILE:?}") != $(printf '\n') ]]; then
LogshDebug "Missing final newline: ${FILE:?}"
missing_files="${missing_files:-}${FILE:?}\n"
missing_files="${missing_files:-}${missing_files:+'\n'}${FILE:?}"
fi
done <<< "${files_changed:-}"
Expand Down

0 comments on commit 40f210d

Please sign in to comment.