forked from SiEPIC/openEBL-2025-10
-
Notifications
You must be signed in to change notification settings - Fork 0
168 lines (129 loc) · 5.4 KB
/
python-to-oas_gds.yml
File metadata and controls
168 lines (129 loc) · 5.4 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: Run Python Files
on:
workflow_dispatch:
push:
paths:
- "submissions/KLayout Python/**.py"
branches:
- '**'
pull_request:
paths:
- "submissions/KLayout Python/**.py"
branches:
- '**'
jobs:
run-python:
runs-on: ubuntu-latest
steps:
- name: checkout repo content
uses: actions/checkout@v4
with:
fetch-depth: 0
# can also specify python version if needed
- name: setup python 3.11
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
- name: install python packages
run: |
pip install siepic_ebeam_pdk IPython
- name: run python scripts and get output gds / oas file
run: |
# get added/modified py files
if [ "${{ github.event_name }}" == "push" ]; then
FILES=$(git diff --name-only --diff-filter=ACM ${{ github.event.before }} ${{ github.sha }} -- "submissions/KLayout Python" | grep -E '\.py$' | sed 's|^submissions/KLayout Python/||')
else
FILES=$(git diff --name-only --diff-filter=ACM FETCH_HEAD -- "submissions/KLayout Python" | grep -i -E '\.py$' | sed 's|^submissions/KLayout Python/||')
fi
echo "Added / modified Python files; $FILES"
# delete .oas and .gds files in the runner's submissions folder
# this is needed in the case where someone already has file_name.gds and is now trying to generate file_name.oas (or vice versa)
rm -rf submissions/*.gds submissions/*.oas
IFS=$'\n'
OUTPUT_FILES=""
for file in $FILES; do
echo "Getting oas/gds output for $file"
# run file and generate a gds / oas output
python "submissions/KLayout Python/$file"
# Lukas: for some reason, the "submissions/KLayout" part was showing up twice, and now it isn't.
# python "$file"
# get output and save to OUTPUT_FILES
gds_files=$(find submissions -type f -name "*.gds" -exec basename {} .gds \;)
oas_files=$(find submissions -type f -name "*.oas" -exec basename {} .oas \;)
file_name=$(basename "$file")
file_name_no_py=$(basename "$file_name" .py)
output_files=""
if echo "$gds_files" | grep -q "$file_name_no_py"; then
output_file="${file_name_no_py}.gds"
else
output_file="${file_name_no_py}.oas"
fi
OUTPUT_FILES+="$output_file "
echo "Done for $file"
done
echo "output files; $OUTPUT_FILES"
echo "OUTPUT_FILES=$OUTPUT_FILES" >> $GITHUB_ENV
- name: move oas and gds files to a new folder
run: |
mkdir -p python_to_oas_gds
for file in $OUTPUT_FILES; do
cp "submissions/$file" python_to_oas_gds/
done
- name: upload .oas and .gds as an artifact
uses: actions/upload-artifact@v4
with:
name: python-to-oas-gds
path: python_to_oas_gds/
- name: Debug fork info
run: |
echo "PR fork repo: ${{ github.event.pull_request.head.repo.full_name }}"
echo "PR fork branch: ${{ github.event.pull_request.head.ref }}"
- name: Check if Actions are enabled on fork
id: check_fork_actions
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FORK_REPO: ${{ github.event.pull_request.head.repo.full_name }}
run: |
echo "Checking Actions on forked repo: $FORK_REPO"
RESPONSE=$(curl -s -H "Authorization: token $GH_TOKEN" \
https://api.github.com/repos/$FORK_REPO/actions/permissions)
ENABLED=$(echo "$RESPONSE" | jq -r '.enabled')
echo "Fork Actions enabled: $ENABLED"
if [ "$ENABLED" != "true" ]; then
echo "Fork has Actions disabled."
echo "enabled=false" >> $GITHUB_OUTPUT
echo "❌ GitHub Actions are disabled on your fork."
echo "To enable:"
echo " 1. Visit https://github.com/$FORK_REPO/actions"
echo " 2. Click the 'Enable workflows' button at the top."
# exit 1
else
echo "enabled=true" >> $GITHUB_OUTPUT
fi
- name: Debug GitHub context
run: |
echo "Repository: ${{ github.repository }}"
echo "Event: ${{ github.event_name }}"
echo "Fork PR: ${{ github.event.pull_request.head.repo.full_name }}"
# - name: Comment PR
# uses: thollander/actions-comment-pull-request@v2
# with:
# message: |
# Thank you for your pull request! :wave:
# comment_tag: welcome-message
- name: commit outputted oas and gds files into repository
run: |
git config --local user.email "${{ github.actor }}@users.noreply.github.com"
git config --local user.name "${{ github.actor }}"
git pull
# git add all produced oas/gds files
for file in $OUTPUT_FILES; do
git add "submissions/$file"
echo "done: git add $file"
done
git commit -m "Add oas and gds files produced from .py files"
echo "done: git commit"
git push
echo "done: git push"
#if: github.event_name != 'pull_request'