-
Notifications
You must be signed in to change notification settings - Fork 34
245 lines (184 loc) · 8.5 KB
/
run-verification.yml
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
name: Run Layout Verification
on:
workflow_dispatch:
workflow_run:
workflows: ["Run Python Files"]
types:
- completed
push:
paths:
- 'submissions/**.gds'
- 'submissions/**.GDS'
- 'submissions/**.oas'
- 'submissions/**.OAS'
branches:
- '**'
pull_request:
branches:
- '**'
jobs:
verification:
runs-on: ubuntu-latest
steps:
- name: checkout repo content
uses: actions/checkout@v2
with:
fetch-depth: 0
#- name: get changed files
# uses: jitterbit/get-changed-files@v1
#- name: get changed files, list
# run: |
# for changed_file in ${{ steps.files.outputs.all }}; do
# echo "Do something with this ${changed_file}."
# done
- name: write what triggered this workflow to a txt file
run: |
echo "${{ github.event_name }}" > trigger_info.txt
cat trigger_info.txt
- name: upload trigger txt file as an artifact
uses: actions/upload-artifact@v4
with:
name: verification-trigger
path: trigger_info.txt
# can also specify python version if needed
- name: setup python
uses: actions/setup-python@v4
- name: install python packages
run: |
python -m pip install --upgrade pip
pip install klayout SiEPIC siepic_ebeam_pdk
- name: download latest python-to-oas-gds artifact from triggering workflow
uses: dawidd6/action-download-artifact@v2
with:
run_id: ${{ github.event.workflow_run.id }}
name: python-to-oas-gds
path: ./binary_files
search_artifacts: true
if: ${{ github.event_name == 'workflow_run' }}
- name: get .gds and .oas files
run: |
# if the action is being triggered after running python files, get resulting oas/gds files from artifact
# github actions is not configured to detect files pushed from another action, thus we cannot use the 'else' method below
if [ "${{ github.event_name }}" == "workflow_run" ]; then
FILES=$(ls ./binary_files)
else
if [[ "${{ github.event_name }}" == "pull_request" || "${{ github.event_name }}" == "pull_request_target" ]]; then
# triggered on pull request, get all changed / added files from forked repo
FILES=$(git diff --name-only --diff-filter=ACM origin/main...HEAD | grep -i -E '\.(gds|oas)$' | sed 's|^submissions/||')
#FILES=$(git diff --name-only --diff-filter=ACM FETCH_HEAD | grep -i -E '\.(gds|oas)$' | sed 's|^submissions/||')
else
# triggered push, locate the changed / added .gds and .oas files in the submission folder
FILES=$(git diff --name-status --diff-filter=ACM --relative=submissions ${{ github.event.before }} ${{ github.sha }} submissions | grep -i -E '\.(gds|oas)$' | awk '{print $2}')
fi
fi
# we cannot set a multiline env vars so we must change it to single line (seperated by commas) if we have more than one file
if [ $(echo "$FILES" | wc -l) -gt 1 ]; then
# Replace newlines with a delimiter (e.g., comma)
FILES_SINGLE_LINE=$(echo "$FILES" | tr '\n' ',')
else
# Keep the original content without modification
FILES_SINGLE_LINE="$FILES"
fi
echo "$FILES_SINGLE_LINE"
echo "FILES_SINGLE_LINE=$FILES_SINGLE_LINE" >> $GITHUB_ENV
- name: run layout verification
run: |
# Check if there is a comma in the variable and revert it back to a multiline var
if [[ "$FILES_SINGLE_LINE" == *","* ]]; then
# Replace the delimiter with newlines
FILES=$(echo "$FILES_SINGLE_LINE" | tr ',' '\n')
else
# No comma found, keep the original content without modification
FILES="$FILES_SINGLE_LINE"
fi
# print the names of the files
echo "Files for verification; $FILES"
files_with_errors=""
IFS=$'\n'
# run verification on all files
for file in $FILES; do
echo "Running verification on $file"
output=$(python run_verification.py "submissions/$file")
# get number of errors
errors_from_output=$(echo "$output" | tail -n 1)
echo "$errors_from_output errors detected for $file"
# if file results in verification errors add to string files_with_errors
if [[ "$errors_from_output" -ge 1 ]]; then
echo "$output"
files_with_errors+="$file, $errors_from_output errors. "
echo $files_with_errors >> $GITHUB_STEP_SUMMARY
echo $output >> $GITHUB_STEP_SUMMARY
fi
echo "Done verification on $file"
done
echo "$output" > verification_output.txt
echo "files_with_errors=$files_with_errors" >> $GITHUB_ENV
- name: move output files to new folder
run: |
export OUTPUT_FILES=$(find /home/runner/work/openEBL-2024-07-Si-Heaters/openEBL-2024-07-Si-Heaters/submissions -name "*.lyrdb")
echo "Output files: $OUTPUT_FILES"
mkdir -p verification_output
for file in $OUTPUT_FILES; do
cp "$file" verification_output/
done
- name: upload artifact
uses: actions/upload-artifact@v2
with:
name: layout-errors
path: verification_output/
- name: fail if there are errors from layout verification
run: |
if [ -z "$files_with_errors" ]; then
echo "No errors detected."
echo "No errors detected." >> $GITHUB_STEP_SUMMARY
else
echo "Errors detected: $files_with_errors"
echo "Errors detected: $files_with_errors" >> $GITHUB_STEP_SUMMARY
exit 1
fi
- name: get .gds and .oas files, run example layout verification
id: run-script
run: |
# if the action is being triggered after running python files, get resulting oas files from txt file
# github actions is not configured to detect files pushed from another action, thus we cannot use the method below
if [ -s "python-to-gds_oas.txt" ] && [ -n "$(cat python-to-gds_oas.txt)" ]; then
export FILES=$(cat python-to-gds_oas.txt)
IFS=' '
echo "" > python-to-gds_oas.txt
# push empty text file to repo
git config --local user.email "${{ github.actor }}@users.noreply.github.com"
git config --local user.name "${{ github.actor }}"
git add python-to-gds_oas.txt
git commit -m "Emptying text file"
git push
else
if [ "${{ github.event_name }}" = "pull_request" ]; then
# triggered on pull request, get all changed / added files from forked repo
export FILES=$(git diff --name-only --diff-filter=ACM FETCH_HEAD | grep -E '\.(gds|oas)$' | sed 's|^submissions/||')
else
# triggered push, locate the changed / added .gds and .oas files in the submission folder
export FILES=$(git diff --name-status --diff-filter=ACM --relative=submissions ${{ github.event.before }} ${{ github.sha }} submissions | grep -E '\.(gds|oas)$' | awk '{print $2}')
fi
IFS=$'\n'
fi
# print the names of the files
echo "Files for verification; $FILES"
files_with_errors=""
# run verification on all files
for file in $FILES; do
echo "Running verification on $file"
output=$(python run_verification.py "submissions/$file")
# get number of errors
errors_from_output=$(echo "$output" | tail -n 1)
echo "$errors_from_output errors detected for $file"
# if file results in verification errors add to string files_with_errors
if [[ "$errors_from_output" -ge 1 ]]; then
files_with_errors+="$file, $errors_from_output errors. "
echo $files_with_errors >> $GITHUB_STEP_SUMMARY
echo $output >> $GITHUB_STEP_SUMMARY
fi
echo "Done verification on $file"
done
echo "files_with_errors=$files_with_errors" >> $GITHUB_ENV
# Don't run:
if: github.repository == 'octo-org/octo-repo-prod'