Skip to content
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

docs: Fix example workflow #5

Merged
merged 4 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading