mirror of
https://github.com/Lucaslhm/Flipper-IRDB.git
synced 2024-12-23 20:07:08 +00:00
ci: add linter comment on pull request (#817)
This commit is contained in:
parent
1a33994705
commit
ce2f20eb6b
104
.github/workflows/pr-lint.yaml
vendored
104
.github/workflows/pr-lint.yaml
vendored
@ -2,63 +2,101 @@ name: "🧐 Checking IR Files"
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
paths: '**.ir'
|
paths:
|
||||||
|
- '**/*.ir'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
lint:
|
lint:
|
||||||
name: "🐛 Looking for issues"
|
name: "🐛 Looking for issues"
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
# checkout IRDB
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/checkout@v3
|
|
||||||
with:
|
with:
|
||||||
ref: ${{ github.event.pull_request.head.sha }}
|
ref: ${{ github.event.pull_request.head.sha }}
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
# checkout Linter
|
|
||||||
- name: Clean Script Directory
|
- name: Clean Script Directory
|
||||||
run: rm -rf fff-ir-lint
|
run: rm -rf fff-ir-lint
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
repository: 'darmiel/fff-ir-lint'
|
repository: 'darmiel/fff-ir-lint'
|
||||||
path: fff-ir-lint
|
path: fff-ir-lint
|
||||||
|
|
||||||
# only check files changed in the PR
|
- name: Get changed files
|
||||||
- name: Get Changed Files
|
|
||||||
id: changed-files
|
id: changed-files
|
||||||
uses: tj-actions/changed-files@v37.1.1
|
uses: tj-actions/changed-files@v45
|
||||||
with:
|
with:
|
||||||
files: "**/*.ir"
|
files: "**/*.ir"
|
||||||
separator: "\n"
|
json: true
|
||||||
|
write_output_files: true
|
||||||
sha: ${{ github.event.pull_request.head.sha }}
|
sha: ${{ github.event.pull_request.head.sha }}
|
||||||
|
|
||||||
- name: Save changed file names to file
|
- name: Verify the contents of the .github/outputs/added_files.json file
|
||||||
run: echo '${{ steps.changed-files.outputs.all_changed_files }}' > changed_file_list.txt
|
run: cat .github/outputs/added_files.json
|
||||||
|
|
||||||
- uses: actions/setup-python@v4
|
|
||||||
with:
|
|
||||||
python-version: '3.10'
|
|
||||||
|
|
||||||
- name: Run Linter if at least 1 IR File Changed
|
- uses: actions/setup-python@v5
|
||||||
uses: mathiasvr/command-output@v2.0.0
|
with:
|
||||||
id: run
|
python-version: '3.10'
|
||||||
|
|
||||||
|
- name: Run Linter
|
||||||
|
id: run-linter
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
|
run: LINTER_CONFIG=.fff-ir-lint.json python fff-ir-lint/main.py github2 json:.github/outputs/added_files.json > .github/outputs/linter_output.txt
|
||||||
|
|
||||||
|
- name: Verify the contents of the .github/outputs/linter_output.txt file
|
||||||
|
run: cat .github/outputs/linter_output.txt
|
||||||
|
|
||||||
|
- name: Find Comment from Linter
|
||||||
|
uses: peter-evans/find-comment@v3
|
||||||
|
if: ${{ github.event.pull_request.head.repo.full_name == 'Lucaslhm/Flipper-IRDB' }} # does not work in forks
|
||||||
|
id: fc
|
||||||
with:
|
with:
|
||||||
run: 'LINTER_CONFIG=.fff-ir-lint.json python fff-ir-lint/main.py github2 file:changed_file_list.txt'
|
issue-number: ${{ github.event.pull_request.number }}
|
||||||
|
comment-author: 'github-actions[bot]'
|
||||||
|
body-includes: '<!-- [lint] -->'
|
||||||
|
|
||||||
|
- name: Create or update comment if linter found no errors
|
||||||
|
uses: peter-evans/create-or-update-comment@v4
|
||||||
|
if: ${{ steps.run-linter.outcome == 'success' && github.event.pull_request.head.repo.full_name == 'Lucaslhm/Flipper-IRDB' }} # does not work in forks
|
||||||
|
with:
|
||||||
|
comment-id: ${{ steps.fc.outputs.comment-id }}
|
||||||
|
issue-number: ${{ github.event.pull_request.number }}
|
||||||
|
body: |
|
||||||
|
<!-- [lint] -->
|
||||||
|
Thank you for your contribution! ❤️
|
||||||
|
|
||||||
#- uses: ntsd/auto-request-changes-action@v2
|
**The linter found no issues. 🎉**
|
||||||
# name: "Request Changes"
|
edit-mode: replace
|
||||||
# if: ${{ steps.run.outputs.stderr }}
|
|
||||||
# with:
|
- name: Create comment body if linter found errors
|
||||||
# github-token: "${{ secrets.GITHUB_TOKEN }}"
|
if: ${{ steps.run-linter.outcome != 'success' }}
|
||||||
# comment-body: |
|
run: |
|
||||||
# <details>
|
cat <<EOF > .github/outputs/comment_body.txt
|
||||||
# <summary>🐛 Linter Result</summary>
|
<!-- [lint] -->
|
||||||
#
|
Thank you for your contribution! ❤️
|
||||||
# ${{ steps.run.outputs.stdout }}
|
|
||||||
#
|
We use an automated linter to ensure consistency. During the review of the \`.ir\` files in your pull request, it found the following issue(s):
|
||||||
# </details>
|
|
||||||
|
<details>
|
||||||
|
<summary><strong>🐛 Linter Result</strong> <i>(Click to open)</i></summary>
|
||||||
|
|
||||||
|
$(cat .github/outputs/linter_output.txt)
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
Please address these issues and update your pull request. Once the problems are resolved, the linter will re-check your changes.
|
||||||
|
EOF
|
||||||
|
|
||||||
|
- name: Create or update comment if linter found errors
|
||||||
|
uses: peter-evans/create-or-update-comment@v4
|
||||||
|
if: ${{ steps.run-linter.outcome != 'success' && github.event.pull_request.head.repo.full_name == 'Lucaslhm/Flipper-IRDB' }} # does not work in forks
|
||||||
|
with:
|
||||||
|
comment-id: ${{ steps.fc.outputs.comment-id }}
|
||||||
|
issue-number: ${{ github.event.pull_request.number }}
|
||||||
|
body-path: .github/outputs/comment_body.txt
|
||||||
|
edit-mode: replace
|
||||||
|
|
||||||
- name: Fail Pipeline
|
- name: Fail Pipeline if Linter Found Issues
|
||||||
if: ${{ steps.run.outputs.stderr }}
|
if: ${{ steps.run-linter.outcome == 'failure' }}
|
||||||
run: exit 1
|
run: exit 1
|
||||||
|
Loading…
Reference in New Issue
Block a user