forked from SiEPIC/openEBL-2024-05
-
Notifications
You must be signed in to change notification settings - Fork 0
142 lines (117 loc) · 4.81 KB
/
merge.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
name: Run Merge Script
on:
workflow_dispatch:
# run after layout verification
workflow_run:
workflows: ["Run Layout Verification"]
types:
- completed
jobs:
merge:
# only run the merge script on the SiEPIC account
#if: github.repository_owner == 'SiEPIC'
# if: >-
# github.event.pull_request.user.login != 'SiEPIC' &&
# repository_dispatch.organization
runs-on: ubuntu-latest
steps:
- name: checkout repo content
uses: actions/checkout@v2
with:
# https://github.com/MestreLion/git-tools?tab=readme-ov-file#git-restore-mtime
fetch-depth: 0
- name: download verification trigger artifact
uses: dawidd6/action-download-artifact@v2
with:
run_id: ${{ github.event.workflow_run.id }}
name: verification-trigger
path: .
search_artifacts: true
if: github.event_name != 'workflow_dispatch'
- name: check if verification action was triggered by a pull request
run: |
trigger_info=$(cat trigger_info.txt)
echo $trigger_info
if [[ "$trigger_info" == "pull_request" || "$trigger_info" == "pull_request_target" ]]; then
echo "This workflow was triggered by a pull request. Do not update url in read me."
TRIGGER_INFO='pull request'
echo "TRIGGER_INFO=$TRIGGER_INFO" >> $GITHUB_ENV
else
echo "This workflow was not triggered by a pull request. Continue with merge and update url in read me."
fi
if: github.event_name != 'workflow_dispatch'
# there is only an artifact to download if this action is triggered after the verification action
# if it is manually triggered we set the var trigger_info manually
- name: if this action was manually triggered set trigger_info var
run: |
trigger_info='workflow_dispatch'
echo "TRIGGER_INFO=$trigger_info" >> $GITHUB_ENV
if: github.event_name == 'workflow_dispatch'
- name: Restore original modification time of files based on the date of the most recent commit
uses: chetan/git-restore-mtime-action@v2
#run: |
# # https://github.com/MestreLion/git-tools?tab=readme-ov-file#installation
# sudo apt install git-restore-mtime
# git restore-mtime
# can also specify Python version if needed
- name: setup python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
- name: install Python packages
run: |
# python -m pip install --upgrade pip
pip install klayout SiEPIC siepic_ebeam_pdk pandas
# python -m pip install --upgrade SiEPIC
- name: run merge script
run: |
python merge/EBeam_merge.py
- name: move merge output files to new folder
run: |
#output_files="EBeam.gds EBeam.oas EBeam.txt EBeam.coords"
output_files="EBeam.oas EBeam.txt"
IFS=' '
mkdir -p merge_output
for file in $output_files; do
cp "merge/$file" merge_output/
done
- name: upload artifact
uses: actions/upload-artifact@v4
id: artifact-upload
with:
name: merge-files
path: merge_output/
- name: get artifact url
run: |
IFS='/' read -ra REPO <<< "$GITHUB_REPOSITORY"
OWNER="${REPO[0]}"
REPO_NAME="${REPO[1]}"
echo "Owner: $OWNER"
echo "Repository: $REPO_NAME"
RUN_ID=${{ github.run_id }}
ARTIFACT_ID=${{ steps.artifact-upload.outputs.artifact-id }}
ARTIFACT_URL="https://github.com/$OWNER/$REPO_NAME/actions/runs/$RUN_ID/artifacts/$ARTIFACT_ID"
echo "Artifact URL: $ARTIFACT_URL"
echo "ARTIFACT_URL=$ARTIFACT_URL" >> $GITHUB_ENV
echo "OWNER=$OWNER" >> $GITHUB_ENV
- name: update url in runner README
run: |
start_delim="<!-- start-link -->"
end_delim="<!-- end-link -->"
# remove current URL
sed -i "/$start_delim/,/$end_delim/d" README.md
# add new URL
printf "$start_delim\n$ARTIFACT_URL\n$end_delim\n" >> README.md
# merge script always runs on any PR
# this ensures link is only updated after a PR is merged into SiEPIC
- name: commit and push changes to README if we are in SiEPIC repo
run: |
git pull origin main
git diff
git config --local user.email "${{ github.actor }}@users.noreply.github.com"
git config --local user.name "${{ github.actor }}"
git add README.md
git commit -m "update README with new artifact url $ARTIFACT_URL"
git push
if: env.TRIGGER_INFO != 'pull request' && github.repository_owner == 'SiEPIC'