Repository navigation
102 lines (82 loc) · 3 KB
/
Copy pathFormatCheck.yml
File metadata and controls
102 lines (82 loc) · 3 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
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
# This workflow is designed to be called from a `pull_request` trigger (NOT
# `pull_request_target`). It runs with a read-only token and no secrets, so it
# is safe to check out and inspect code from forks. It never posts comments;
# instead the required formatting changes are reported in the job summary and
# the job fails, which surfaces as a red check on the PR.
jobs:
format-check:
name: "Runic"
runs-on: ubuntu-latest
permissions:
contents: read
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 itself errored (exit code 2), bail out
[ $EXIT_CODE -eq 2 ] && exit 1 || exit 0
- name: Report formatting suggestions
if: steps.runic.outputs.exit_code == 1
run: |
cat >> "$GITHUB_STEP_SUMMARY" <<'EOF'
## :art: Formatting changes required
This PR does not meet the project's style guidelines.
Run [Runic](https://github.com/fredrikekre/Runic.jl) locally to apply the changes:
```
git runic ${{ github.base_ref }}
```
<details>
<summary>Suggested changes</summary>
```diff
${{ steps.runic.outputs.diff }}
```
</details>
EOF
- name: Report success
if: steps.runic.outputs.exit_code == 0
run: |
echo "### :white_check_mark: Formatting OK" >> "$GITHUB_STEP_SUMMARY"
- name: Propagate exit code
run: exit ${{ steps.runic.outputs.exit_code }}