-
Notifications
You must be signed in to change notification settings - Fork 2
130 lines (118 loc) · 4.24 KB
/
FormatCheck.yml
File metadata and controls
130 lines (118 loc) · 4.24 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: "FormatCheck"
# Parse phase of the format-check pipeline. Designed to run on
# `pull_request:` (no secrets, read-only `GITHUB_TOKEN` for fork PRs)
# so that PR-controlled content the formatter touches can never reach
# secrets. The check status this workflow emits is what branch
# protection should require.
#
# Companion: FormatCheckComment.yml runs on `workflow_run:` after this
# workflow finishes, downloads the artifact uploaded here, and posts /
# updates the format-suggestion comment. The comment workflow runs in the base
# repo's trusted context so it can use `FORMATPULLREQUEST_PAT` without
# exposing it to the parse phase.
on:
workflow_call:
inputs:
directory:
description: "The directory on which ITensorFormatter needs to be run"
default: "."
required: false
type: string
julia-version:
description: "Julia version"
default: "1"
required: false
type: string
concurrent-jobs:
description: "Run jobs concurrently"
default: false
required: false
type: boolean
cancel-in-progress:
description: "Cancel jobs in-progress in favor of a new one in the same concurrency group"
default: true
required: false
type: boolean
concurrency:
# Key on the PR number so each PR has its own concurrency group;
# falling back to `github.ref` for non-PR triggers.
group: "${{ inputs.concurrent-jobs && github.run_id || github.event.pull_request.number || github.ref }}:${{ github.workflow }}"
cancel-in-progress: ${{ !inputs.concurrent-jobs && inputs.cancel-in-progress }}
jobs:
format-check:
name: "FormatCheck"
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: "Check out PR head"
uses: actions/checkout@v6
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: "Setup Julia"
uses: julia-actions/setup-julia@v3
with:
version: "${{ inputs.julia-version }}"
arch: "x64"
- uses: julia-actions/cache@v2
- name: "Install ITensorFormatter"
run: |
julia -e '
using Pkg
Pkg.Registry.add("General")
Pkg.Registry.add(; url = "https://github.com/ITensor/ITensorRegistry")
Pkg.Apps.add("ITensorFormatter")
'
echo "$HOME/.julia/bin" >> $GITHUB_PATH
- name: "Run ITensorFormatter"
id: format
env:
DIRECTORY: ${{ inputs.directory }}
run: |
set +e
echo "Formatter will run on: $DIRECTORY"
itpkgfmt "$DIRECTORY"
FORMAT_EXIT=$?
if [ $FORMAT_EXIT -ne 0 ]; then
: > diff.patch
echo "exit_code=2" >> "$GITHUB_OUTPUT"
exit 0
fi
# `git add -N .` makes new (untracked) files visible to `git diff`
# so the diff captured below covers added files as well.
git add -N .
git diff > diff.patch
if [ -s diff.patch ]; then
echo "exit_code=1" >> "$GITHUB_OUTPUT"
else
echo "exit_code=0" >> "$GITHUB_OUTPUT"
fi
- name: "Save metadata for comment workflow"
if: ${{ always() }}
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
EXIT_CODE: ${{ steps.format.outputs.exit_code }}
run: |
{
echo "pr_number=$PR_NUMBER"
echo "pr_head_sha=$PR_HEAD_SHA"
echo "exit_code=${EXIT_CODE:-2}"
} > metadata.txt
- name: "Upload artifact for comment workflow"
if: ${{ always() }}
uses: actions/upload-artifact@v7
with:
name: "format-check"
path: |
metadata.txt
diff.patch
if-no-files-found: ignore
- name: "Propagate exit code"
run: |
# exit 0 -> already formatted; exit 1 -> formatting needed;
# exit 2 -> formatter itself errored. The check status reflects
# this directly so branch protection can require it.
exit ${{ steps.format.outputs.exit_code }}