1010
1111jobs :
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 .
0 commit comments