Skip to content

Commit 2874d19

Browse files
authored
Update pipeline workflow (#66)
* Update build.yml run tests in separate folder * Add names and deploy key * Add warning annotations for GitHub Actions on build errors * Fix syntax error, comment out debug statement * Update build.py * update annotation message
1 parent f57c20c commit 2874d19

4 files changed

Lines changed: 130 additions & 17 deletions

File tree

.github/workflows/build.yml

Lines changed: 106 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ on:
1010

1111
jobs:
1212
build:
13+
name: Build classes
1314
runs-on: ubuntu-latest
15+
outputs:
16+
build_updated: ${{ steps.check_changes.outputs.changes_detected }}
1417
steps:
1518
- name: Checkout Repository
1619
uses: actions/checkout@v4
@@ -25,35 +28,122 @@ jobs:
2528
pip install -r requirements.txt
2629
python build.py
2730
28-
- name: Checkout staging branch
29-
uses: actions/checkout@v3
31+
- name: Checkout main branch
32+
uses: actions/checkout@v4
33+
with:
34+
ref: main
35+
path: main
36+
37+
- name: Copy changes to main
38+
run: |
39+
chmod +x ./.github/workflows/scripts/apply-new-build.sh
40+
./.github/workflows/scripts/apply-new-build.sh main
41+
42+
- name: Check if there are changes
43+
id: check_changes
44+
working-directory: main
45+
run: |
46+
if [[ $(git status --porcelain) ]]; then
47+
echo "changes_detected=true" >> $GITHUB_OUTPUT
48+
else
49+
echo "::notice title=No changes detected:: No changes in build output compared to main branch"
50+
echo "changes_detected=false" >> $GITHUB_OUTPUT
51+
fi
52+
53+
- name: Upload build (target) as artifact
54+
if: steps.check_changes.outputs.changes_detected == 'true'
55+
uses: actions/upload-artifact@v4
56+
with:
57+
name: build
58+
path: target
59+
retention-days: 1
60+
61+
test-code:
62+
name: Test with updated classes
63+
runs-on: ubuntu-latest
64+
needs: build
65+
if: needs.build.outputs.build_updated == 'true'
66+
steps:
67+
- name: Checkout main branch
68+
uses: actions/checkout@v4
69+
with:
70+
ref: main
71+
72+
- name: Download build (target) artifact
73+
uses: actions/download-artifact@v4
74+
with:
75+
name: build
76+
path: target
77+
78+
- name: Inject build into code directory
79+
run: |
80+
rm -rf code/{types,mixedtypes,enumerations}/*
81+
cp -R target/* code
82+
cp -R code/internal/resources/{content_files,readme_files}/* code/
83+
rm -rf target
84+
85+
- name: Set up MATLAB
86+
uses: matlab-actions/setup-matlab@v2
3087
with:
31-
ref: staging
32-
path: staging
33-
token: ${{ secrets.GITHUB_TOKEN }}
88+
release: latest
89+
cache: true
3490

35-
- name: Push to staging
91+
- name: Install MatBox
92+
uses: ehennestad/matbox-actions/install-matbox@v1
93+
94+
- name: Run tests
95+
id: test_step
96+
uses: ehennestad/matbox-actions/test-code@v1
97+
with:
98+
source_directory: code
99+
tests_directory: tools/tests
100+
tools_directory: tools
101+
102+
- name: Restore MATLAB path
103+
uses: matlab-actions/run-command@v2
104+
if: always()
105+
with:
106+
command: "restoredefaultpath(); savepath()"
107+
108+
push-changes:
109+
name: Push updates to main
110+
runs-on: ubuntu-latest
111+
needs: [build, test-code]
112+
if: needs.test-code.result == 'success' && needs.build.outputs.build_updated == 'true'
113+
steps:
114+
- name: Checkout main branch
115+
uses: actions/checkout@v4
116+
with:
117+
ref: main
118+
ssh-key: ${{ secrets.DEPLOY_KEY }}
119+
120+
- name: Download build (target) artifact
121+
uses: actions/download-artifact@v4
122+
with:
123+
name: build
124+
path: target
125+
126+
- name: Inject build into code directory
36127
run: |
37-
rm -rf staging/code/types/*
38-
rm -rf staging/code/mixedtypes/*
39-
rm -rf staging/code/enumerations/*
40-
cp -R target/* staging/code
41-
cp -R staging/code/internal/resources/content_files/* staging/code/
42-
cp -R staging/code/internal/resources/readme_files/* staging/code/
43-
cd staging
128+
rm -rf code/{types,mixedtypes,enumerations}/*
129+
cp -R target/* code
130+
cp -R code/internal/resources/{content_files,readme_files}/* code/
131+
rm -rf target
44132
133+
- name: Push to main
134+
run: |
45135
git config --global user.email "openminds@ebrains.eu"
46136
git config --global user.name "openMINDS pipeline"
47-
137+
48138
# Conditionally set commit message based on the event
49139
if [ "${{ github.event_name }}" == "push" ]; then
50-
commit_message="Build triggered by update to pipeline"
140+
commit_message="Build triggered by update to build pipeline"
51141
elif [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
52142
commit_message="Build triggered by workflow dispatch"
53143
else
54144
commit_message="Unknown event"
55145
fi
56-
146+
57147
# Only proceed with commit and push if changes are detected
58148
if [[ $(git add . --dry-run | wc -l) -gt 0 ]]; then
59149
git add .
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
ROOT=${1:?Please provide the root folder as the first argument}
5+
6+
# Safety: prevent running with empty string or system root
7+
if [[ "$ROOT" == "" || "$ROOT" == "/" ]]; then
8+
echo "Error: invalid root folder: '$ROOT'" >&2
9+
exit 1
10+
fi
11+
12+
rm -rf "$ROOT"/code/{types,mixedtypes,enumerations}/*
13+
cp -R target/* "$ROOT"/code/
14+
cp -R "$ROOT"/code/internal/resources/{content_files,readme_files}/* "$ROOT"/code/

build.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@
3232
try:
3333
MATLABSchemaBuilder(schema_file_path, schema_root_path, class_name_map, jinja_templates).build()
3434
except Exception as e:
35-
print(f"Error while building schema {schema_file_path}: {e}")
35+
#print(f"Error while building schema {schema_file_path}: {e}")
36+
# get relative path from schema_root_path to schema_file_path
37+
relative_path = os.path.relpath(schema_file_path, schema_root_path)
38+
schemaName = os.path.basename(schema_file_path)
39+
schemaName = schemaName.replace(".schema.omi.json", "")
40+
print(f"::warning file={relative_path},title=Error while building class for schema '{schemaName}' ({schema_version})::{e}")
3641

3742
save_resource_files(schema_version, schemas_file_paths)
3843

pipeline/translator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ def _extract_template_variables(self):
258258

259259
self._template_variables = {
260260
"class_name": class_name,
261+
"full_class_name": _generate_class_name(schema[SCHEMA_PROPERTY_TYPE], self._class_name_map),
261262
"base_class": base_class,
262263
"has_controlled_instance": has_controlled_instance,
263264
"openminds_type": _expand_type_namespace( schema[SCHEMA_PROPERTY_TYPE] ),
@@ -338,6 +339,9 @@ def _generate_class_name(iri, class_name_map):
338339
# Ensure first letter of type_name is capitalized
339340
type_name = type_name[0].upper() + type_name[1:]
340341

342+
if type_name not in class_name_map:
343+
raise KeyError(f"Class name '{type_name}' (IRI: {iri}) was not found in the map of all class names.")
344+
341345
return class_name_map[type_name]
342346

343347
#for i in range(len(parts) - 1):

0 commit comments

Comments
 (0)