Skip to content

Commit 6c1042a

Browse files
committed
Formatter: use comments instead of code suggestions.
[ci skip]
1 parent d435670 commit 6c1042a

File tree

1 file changed

+60
-14
lines changed

1 file changed

+60
-14
lines changed

.github/workflows/Format.yml

Lines changed: 60 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,16 @@ on:
77

88
permissions:
99
contents: read
10-
11-
# needed for julia-actions/cache to delete old caches
1210
actions: write
13-
14-
# needed for googleapis/code-suggester
1511
pull-requests: write
1612

1713
jobs:
1814
runic:
1915
runs-on: ubuntu-latest
2016
if: github.event.pull_request.draft == false
2117
steps:
22-
- uses: actions/checkout@v4
18+
- name: Check out repository
19+
uses: actions/checkout@v4
2320
with:
2421
ref: ${{github.event.pull_request.head.ref}}
2522
repository: ${{github.event.pull_request.head.repo.full_name}}
@@ -40,16 +37,65 @@ jobs:
4037
sudo mv git-runic /usr/local/bin
4138
4239
- name: Run Runic
40+
id: runic
4341
run: |
4442
set +e
45-
git runic origin/master
46-
[ $? -eq 2 ] && exit 1 || exit 0
43+
MERGE_BASE=$(git merge-base origin/${{ github.base_ref }} HEAD) || exit 2
44+
DIFF=$(git runic --diff $MERGE_BASE)
45+
EXIT_CODE=$?
46+
47+
echo "exit_code=$EXIT_CODE" >> $GITHUB_OUTPUT
48+
echo "diff<<EOF" >> $GITHUB_OUTPUT
49+
echo "$DIFF" >> $GITHUB_OUTPUT
50+
echo "EOF" >> $GITHUB_OUTPUT
51+
52+
# if Runic failed, bail out
53+
[ $EXIT_CODE -eq 2 ] && exit 1 || exit 0
54+
55+
- name: Find comment
56+
if: steps.runic.outputs.exit_code == 1
57+
uses: peter-evans/find-comment@v3
58+
id: find-comment
59+
with:
60+
issue-number: ${{ github.event.pull_request.number }}
61+
comment-author: 'github-actions[bot]'
62+
body-includes: '<!-- runic-format-summary -->'
63+
64+
- name: Comment formatting suggestions
65+
if: steps.runic.outputs.exit_code == 1
66+
uses: peter-evans/create-or-update-comment@v4
67+
with:
68+
comment-id: ${{ steps.find-comment.outputs.comment-id }}
69+
issue-number: ${{ github.event.pull_request.number }}
70+
body: |
71+
<!-- runic-format-summary -->
72+
73+
Your PR requires formatting changes to meet the project's style guidelines.
74+
Please consider running [Runic](https://github.com/fredrikekre/Runic.jl) (`git runic ${{ github.base_ref }}`) to apply these changes.
75+
76+
<details>
77+
<summary>Click here to view the suggested changes.</summary>
78+
79+
```diff
80+
${{ steps.runic.outputs.diff }}
81+
```
4782
48-
- name: Suggest changes
49-
uses: googleapis/code-suggester@v2
50-
env:
51-
ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
83+
</details>
84+
edit-mode: replace
85+
86+
- name: Update stale comment
87+
if: steps.runic.outputs.exit_code == 0 && steps.find-comment.outputs.comment-id
88+
uses: peter-evans/create-or-update-comment@v4
5289
with:
53-
command: review
54-
pull_number: ${{ github.event.pull_request.number }}
55-
git_dir: '.'
90+
comment-id: ${{ steps.find-comment.outputs.comment-id }}
91+
issue-number: ${{ github.event.pull_request.number }}
92+
body: |
93+
<!-- runic-format-summary -->
94+
95+
Your PR no longer requires formatting changes. Thank you for your contribution!
96+
edit-mode: replace
97+
98+
# XXX: if Github ever supports allow-failure (actions/runner#2347)
99+
#- name: Propagate exit code
100+
# run: |
101+
# exit ${{ steps.runic.outputs.exit_code }}

0 commit comments

Comments
 (0)