forked from ITensor/ITensorActions
-
Notifications
You must be signed in to change notification settings - Fork 0
114 lines (93 loc) · 3.47 KB
/
Copy pathFormatCheck.yml
File metadata and controls
114 lines (93 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
name: "Reusable Format Checking Workflow"
on:
workflow_call:
inputs:
julia-version:
description: "Julia version"
default: "1"
required: false
type: string
concurrency:
group: "${{ github.run_id || github.ref }}:${{ github.workflow }}"
cancel-in-progress: true
jobs:
format-check:
name: "Runic"
runs-on: ubuntu-latest
permissions:
contents: read
actions: write
pull-requests: write
steps:
- name: Check out repository
uses: actions/checkout@v5
with:
ref: ${{github.event.pull_request.head.ref}}
repository: ${{github.event.pull_request.head.repo.full_name}}
fetch-depth: 0
- name: Add upstream remote
run: |
git remote add upstream https://github.com/${{ github.repository }}
git fetch upstream
- name: Setup Julia
uses: julia-actions/setup-julia@v2
with:
version: ${{ inputs.julia-version }}
arch: 'x64'
- uses: julia-actions/cache@v2
- name: Install Runic
run: |
julia --project=@runic -e 'using Pkg; Pkg.add("Runic")'
curl -o git-runic https://raw.githubusercontent.com/fredrikekre/Runic.jl/master/bin/git-runic
chmod +x git-runic
sudo mv git-runic /usr/local/bin
- name: Run Runic
id: runic
run: |
set +e
MERGE_BASE=$(git merge-base upstream/${{ github.base_ref }} HEAD) || exit 1
DIFF=$(git runic --diff $MERGE_BASE)
EXIT_CODE=$?
echo "exit_code=$EXIT_CODE" >> $GITHUB_OUTPUT
echo "diff<<EOF" >> $GITHUB_OUTPUT
echo "$DIFF" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
# if Runic failed, bail out
[ $EXIT_CODE -eq 2 ] && exit 1 || exit 0
- name: Find comment
uses: peter-evans/find-comment@v3
id: find-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: '<!-- runic-format-summary -->'
- name: Comment formatting suggestions
if: steps.runic.outputs.exit_code == 1
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
<!-- runic-format-summary -->
Your PR requires formatting changes to meet the project's style guidelines.
Please consider running [Runic](https://github.com/fredrikekre/Runic.jl) (`git runic ${{ github.base_ref }}`) to apply these changes.
<details>
<summary>Click here to view the suggested changes.</summary>
~~~diff
${{ steps.runic.outputs.diff }}
~~~
</details>
edit-mode: replace
- name: Update stale comment
if: steps.runic.outputs.exit_code == 0 && steps.find-comment.outputs.comment-id
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
<!-- runic-format-summary -->
Your PR no longer requires formatting changes. Thank you for your contribution!
edit-mode: replace
- name: Propagate exit code
run: |
exit ${{ steps.runic.outputs.exit_code }}