Skip to content

Build schemas classes #309

Build schemas classes

Build schemas classes #309

Workflow file for this run

name: Build schemas classes
on:
push:
branches:
- pipeline
paths-ignore:
- 'README.md'
workflow_dispatch:
jobs:
build:
name: Build classes
runs-on: ubuntu-latest
outputs:
build_updated: ${{ steps.check_changes.outputs.changes_detected }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Run build
run: |
pip install -r requirements.txt
python build.py
- name: Checkout main branch
uses: actions/checkout@v4
with:
ref: main
path: main
- name: Copy changes to main
run: |
chmod +x ./scripts/apply-new-build.sh
./scripts/apply-new-build.sh main
- name: Check if there are changes
id: check_changes
working-directory: main
run: |
if [[ $(git status --porcelain) ]]; then
echo "changes_detected=true" >> $GITHUB_OUTPUT
else
echo "::notice title=No changes detected:: No changes in build output compared to main branch"
echo "changes_detected=false" >> $GITHUB_OUTPUT
fi
- name: Upload build (target) as artifact
if: steps.check_changes.outputs.changes_detected == 'true'
uses: actions/upload-artifact@v4
with:
name: build
path: target
retention-days: 1
- name: Upload injection script as artifact
if: steps.check_changes.outputs.changes_detected == 'true'
uses: actions/upload-artifact@v4
with:
name: injection-script
path: scripts/apply-new-build.sh
retention-days: 1
test-code:
name: Test with updated classes
runs-on: ubuntu-latest
needs: build
if: needs.build.outputs.build_updated == 'true'
steps:
- name: Checkout main branch
uses: actions/checkout@v4
with:
ref: main
- name: Download build (target) artifact
uses: actions/download-artifact@v4
with:
name: build
path: target
- name: Download injection script
uses: actions/download-artifact@v4
with:
name: injection-script
path: scripts
- name: Inject build into code directory
run: |
chmod +x scripts/apply-new-build.sh
scripts/apply-new-build.sh .
- name: Set up MATLAB
uses: matlab-actions/setup-matlab@v2
with:
release: latest
cache: true
- name: Install MatBox
uses: ehennestad/matbox-actions/install-matbox@v1
- name: Run tests
id: test_step
uses: ehennestad/matbox-actions/test-code@v1
with:
source_directory: code
tests_directory: tools/tests
tools_directory: tools
- name: Restore MATLAB path
uses: matlab-actions/run-command@v2
if: always()
with:
command: "restoredefaultpath(); savepath()"
push-changes:
name: Push updates to main
runs-on: ubuntu-latest
needs: [build, test-code]
if: needs.test-code.result == 'success' && needs.build.outputs.build_updated == 'true'
steps:
- name: Checkout main branch
uses: actions/checkout@v4
with:
ref: main
ssh-key: ${{ secrets.DEPLOY_KEY }}
- name: Download build (target) artifact
uses: actions/download-artifact@v4
with:
name: build
path: target
- name: Download injection script
uses: actions/download-artifact@v4
with:
name: injection-script
path: scripts
- name: Inject build into code directory
run: |
chmod +x scripts/apply-new-build.sh
scripts/apply-new-build.sh .
- name : Clean up artifacts before commit
run: |
rm -rf target
rm -rf scripts
- name: Push to main
run: |
git config --global user.email "openminds@ebrains.eu"
git config --global user.name "openMINDS pipeline"
# Conditionally set commit message based on the event
if [ "${{ github.event_name }}" == "push" ]; then
commit_message="Build triggered by update to build pipeline"
elif [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
commit_message="Build triggered by workflow dispatch"
else
commit_message="Unknown event"
fi
# Only proceed with commit and push if changes are detected
if [[ $(git add . --dry-run | wc -l) -gt 0 ]]; then
git add .
git commit -m "$commit_message"
git push -f
else
echo "Nothing to commit"
fi