Skip to content

Commit 3776007

Browse files
authored
Formatter: use comments instead of code suggestions. (#2313)
1 parent a8c1ae5 commit 3776007

File tree

1 file changed

+64
-14
lines changed

1 file changed

+64
-14
lines changed

.github/workflows/Format.yml

Lines changed: 64 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,26 @@ 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}}
2623
fetch-depth: 0
2724

25+
- name: Add upstream remote
26+
run: |
27+
git remote add upstream https://github.com/${{ github.repository }}
28+
git fetch upstream
29+
2830
- name: Setup Julia
2931
uses: julia-actions/setup-julia@v2
3032
with:
@@ -40,16 +42,64 @@ jobs:
4042
sudo mv git-runic /usr/local/bin
4143
4244
- name: Run Runic
45+
id: runic
4346
run: |
4447
set +e
45-
git runic origin/main
46-
[ $? -eq 2 ] && exit 1 || exit 0
48+
MERGE_BASE=$(git merge-base upstream/${{ github.base_ref }} HEAD) || exit 1
49+
DIFF=$(git runic --diff $MERGE_BASE)
50+
EXIT_CODE=$?
51+
52+
echo "exit_code=$EXIT_CODE" >> $GITHUB_OUTPUT
53+
echo "diff<<EOF" >> $GITHUB_OUTPUT
54+
echo "$DIFF" >> $GITHUB_OUTPUT
55+
echo "EOF" >> $GITHUB_OUTPUT
56+
57+
# if Runic failed, bail out
58+
[ $EXIT_CODE -eq 2 ] && exit 1 || exit 0
59+
60+
- name: Find comment
61+
uses: peter-evans/find-comment@v3
62+
id: find-comment
63+
with:
64+
issue-number: ${{ github.event.pull_request.number }}
65+
comment-author: 'github-actions[bot]'
66+
body-includes: '<!-- runic-format-summary -->'
4767

48-
- name: Suggest changes
49-
uses: googleapis/code-suggester@v4
50-
env:
51-
ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
68+
- name: Comment formatting suggestions
69+
if: steps.runic.outputs.exit_code == 1
70+
uses: peter-evans/create-or-update-comment@v4
5271
with:
53-
command: review
54-
pull_number: ${{ github.event.pull_request.number }}
55-
git_dir: '.'
72+
comment-id: ${{ steps.find-comment.outputs.comment-id }}
73+
issue-number: ${{ github.event.pull_request.number }}
74+
body: |
75+
<!-- runic-format-summary -->
76+
77+
Your PR requires formatting changes to meet the project's style guidelines.
78+
Please consider running [Runic](https://github.com/fredrikekre/Runic.jl) (`git runic ${{ github.base_ref }}`) to apply these changes.
79+
80+
<details>
81+
<summary>Click here to view the suggested changes.</summary>
82+
83+
```diff
84+
${{ steps.runic.outputs.diff }}
85+
```
86+
87+
</details>
88+
edit-mode: replace
89+
90+
- name: Update stale comment
91+
if: steps.runic.outputs.exit_code == 0 && steps.find-comment.outputs.comment-id
92+
uses: peter-evans/create-or-update-comment@v4
93+
with:
94+
comment-id: ${{ steps.find-comment.outputs.comment-id }}
95+
issue-number: ${{ github.event.pull_request.number }}
96+
body: |
97+
<!-- runic-format-summary -->
98+
99+
Your PR no longer requires formatting changes. Thank you for your contribution!
100+
edit-mode: replace
101+
102+
# XXX: if Github ever supports allow-failure (actions/runner#2347)
103+
#- name: Propagate exit code
104+
# run: |
105+
# exit ${{ steps.runic.outputs.exit_code }}

0 commit comments

Comments
 (0)