forked from atteneder/glTFast
-
Notifications
You must be signed in to change notification settings - Fork 34
169 lines (151 loc) · 5.3 KB
/
dotnet-format.yml
File metadata and controls
169 lines (151 loc) · 5.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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
name: Code Format (dotnet)
on:
workflow_dispatch:
inputs:
# NOTICE: run-name seems like it might not be needed but it's necessary in order to leverage
# Yamato's `action_run_name_source` feature which ensures the right jobs gets connected when multiple
# ones are run in parallel.
run-name:
description: "Name of the job run to be presented in the UI."
default: "Code Format (dotnet)"
required: true
type: string
GIT_BRANCH:
description: "Current branch. Normally the value of the GIT_BRANCH environment variable from Yamato."
required: true
type: string
commit:
description: "Commit changes to the branch"
default: "false"
type: choice
options:
- "true"
- "false"
filter:
description: "List of glob pattern to filter files to format separated by new line."
default: "**/*.cs"
type: string
workflow_call:
inputs:
GIT_BRANCH:
description: "Current branch. Normally the value of the GIT_BRANCH environment variable from Yamato."
required: true
type: string
commit:
description: "Commit changes to the branch"
default: "false"
type: string
filter:
description: "List of glob pattern to filter files to format separated by new line."
default: "**/*.cs"
type: string
run-name: ${{ inputs.run-name }}
env:
COMMIT_CHANGES: ${{ inputs.commit }}
CURRENT_BRANCH: ${{ inputs.GIT_BRANCH }}
FILTER: ${{ inputs.filter }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_ENTERPRISE_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_HOST: "github.cds.internal.unity3d.com"
jobs:
format:
name: Format (http://go/format)
runs-on: unity-linux-runner
container:
image: europe-docker.pkg.dev/unity-cds-services-prd/ds-docker/unity-ci-format:latest@sha256:73b38fb713c2b95a142ffe870c6e130edda9d3aad61adadfda24fe985973f6b1
steps:
- name: Checkout
uses: actions/checkout@v6
with:
ref: ${{ inputs.GIT_BRANCH }}
filter: blob:none
fetch-depth: 1
sparse-checkout-cone-mode: false
sparse-checkout: |
/.github/workflows/**/*
**/.editorconfig
${{ inputs.filter }}
# A reusable workflow consumed from a different repository won't be able to access other files than the workflow itself, therefore we keep configuration embedded
- name: Create and add problem matcher
shell: bash
env:
PROBLEM_MATCHER_CONTENT: |
{
"problemMatcher": [
{
"owner": "dotnet-format",
"pattern": [
{
"regexp": "^(.*)\\((\\d+),(\\d+)\\):\\s(.*)\\[\\.\\]$",
"file": 1,
"line": 2,
"column": 3,
"message": 4
}
]
}
]
}
run: |
echo "$PROBLEM_MATCHER_CONTENT" > "$RUNNER_TEMP/problem-matcher.json"
echo "Temp file: $RUNNER_TEMP/problem-matcher.json"
cat "$RUNNER_TEMP/problem-matcher.json"
echo "::add-matcher::$RUNNER_TEMP/problem-matcher.json"
- name: Log versions
shell: bash
run: |
DOTNET_VERSION=$(dotnet --version)
echo "Read more about code formatting: [http://go/format](http://go/format)" >> $GITHUB_STEP_SUMMARY
echo "dotnet: $DOTNET_VERSION" >> $GITHUB_STEP_SUMMARY
# Create a rsp file to overcome potential issues with the command line length with a large number of files
- name: Build RSP file
shell: bash
run: |
{
echo "format "
echo "whitespace "
echo ". "
echo "--folder "
echo "--verbosity "
echo "detailed "
} >> args.rsp
if [[ "$COMMIT_CHANGES" != "true" ]];
then
echo "--verify-no-changes " >> args.rsp
fi
PR_FILES=$(gh pr view $CURRENT_BRANCH --json files --jq '.files.[].path')
printf "PR files:\n$PR_FILES\n\n"
if [[ "$PR_FILES" == "" ]];
then
echo "No files to format."
echo "No files to format." >> $GITHUB_STEP_SUMMARY
# Add a marker to the args.rsp file to avoid passing an empty list of files
PR_FILES="NOTHING_TO_FORMAT_MARKER"
fi
echo "--include " >> args.rsp
echo "$PR_FILES" >> args.rsp
echo "rsp file:"
cat args.rsp
- name: Run Format
id: format
shell: bash
run: >
DOTNET_NOLOGO=1
dotnet @args.rsp
- name: Clean-up RSP file
shell: bash
run: |
rm args.rsp
- name: Commit changes
if: |
inputs.commit == 'true'
shell: bash
env:
ACTOR: ${{ github.actor }}
ACTOR_ID: ${{ github.actor_id }}
run: |
git config user.name "$ACTOR (via GitHub Actions)"
git config user.email "$ACTOR_ID+$ACTOR@users.noreply.github.com"
git add .
git diff-index --quiet HEAD || git commit -m "[skip ci] Code format"
git push