Continuous integration and deployment #109
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Continuous integration and deployment | |
on: | |
push: | |
schedule: | |
- cron: '0 0 * * 0' # weekly | |
workflow_dispatch: | |
jobs: | |
testExamples: | |
name: Test example SED-ML files (in COMBINE archives) | |
if: "!contains(github.event.head_commit.message, '[skip ci]')" | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 1 | |
- name: Install Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.9' | |
- name: Setup pip cache | |
uses: actions/cache@v2 | |
with: | |
path: /opt/hostedtoolcache/Python | |
key: ${{ runner.os }}-pip-${{ hashFiles('site_creator/requirements.txt') }} | |
restore-keys: | | |
${{ runner.os }}-pip- | |
- name: Install pip and setuptools | |
run: | | |
python -m pip install --upgrade pip | |
python -m pip install --upgrade setuptools | |
- name: Install requirements | |
run: python -m pip install -r tests/requirements.txt | |
- name: Compile example COMBINE archives | |
run: | | |
sudo apt-get update -y | |
sudo apt-get install -y --no-install-recommends zipcmp | |
python scripts/compile_examples_combine_archives.py | |
- name: Test examples | |
run: python -m pytest tests/ | |
compileStaticWebsite: | |
name: Compile static website | |
if: "!contains(github.event.head_commit.message, '[skip ci]')" | |
needs: testExamples | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 1 | |
- name: Install Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.9' | |
- name: Setup pip cache | |
uses: actions/cache@v2 | |
with: | |
path: /opt/hostedtoolcache/Python | |
key: ${{ runner.os }}-pip-${{ hashFiles('site_creator/requirements.txt') }} | |
restore-keys: | | |
${{ runner.os }}-pip- | |
- name: Install pip and setuptools | |
run: | | |
python -m pip install --upgrade pip | |
python -m pip install --upgrade setuptools | |
- name: Install requirements | |
working-directory: site_creator | |
run: python -m pip install -r requirements.txt | |
- name: Setup Git | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "SED-ML Bot" | |
git config pull.rebase false | |
- name: Compile website | |
working-directory: site_creator | |
run: python create_static_html.py | |
- id: commit-compiled-website | |
name: Commit changes to the compiled web pages | |
run: | | |
git stash | |
git pull | |
set +e | |
git stash pop | |
git add *.html | |
git commit -m "Updated compiled files for website [skip ci]" | |
if [[ $? = 0 ]]; then | |
websiteChanged=1 | |
else | |
websiteChanged=0 | |
fi | |
echo "::set-output name=websiteChanged::$websiteChanged" | |
- name: Compile example COMBINE archives | |
run: | | |
sudo apt-get update -y | |
sudo apt-get install -y --no-install-recommends zipcmp | |
python scripts/compile_examples_combine_archives.py | |
- id: commit-example-combine-archives | |
name: Commit compiled example COMBINE archives | |
run: | | |
git stash | |
git pull | |
set +e | |
git stash pop | |
git add examples/*.omex | |
git commit -m "Updated example COMBINE archives [skip ci]" | |
if [[ $? = 0 ]]; then | |
examplesChanged=1 | |
else | |
examplesChanged=0 | |
fi | |
echo "::set-output name=examplesChanged::$examplesChanged" | |
- name: Bundle examples | |
id: bundle-examples | |
working-directory: examples/L1V3 | |
run: | | |
zip SED-ML_L1V3_examples-new.zip *.omex | |
zipcmp SED-ML_L1V3_examples.zip SED-ML_L1V3_examples-new.zip | |
if [[ $? = 0 ]]; then | |
changed=0 | |
rm SED-ML_L1V3_examples-new.zip | |
else | |
changed=1 | |
mv SED-ML_L1V3_examples-new.zip SED-ML_L1V3_examples.zip | |
fi | |
echo "::set-output name=changed::$changed" | |
- id: commit-bundled-examples | |
if: steps.bundle-examples.outputs.changed == '1' | |
name: Commit changes to the bundled examples | |
working-directory: examples/L1V3 | |
run: | | |
git stash | |
git pull | |
set +e | |
git stash pop | |
git add SED-ML_L1V3_examples.zip | |
git commit -m "Updated bundle of example files [skip ci]" | |
- name: Determine branch to push compiled website to | |
id: get-push-branch | |
run: | | |
if [ "${{ github.ref }}" == "refs/heads/master" ]; then | |
echo "::set-output name=branch::ci-compiled-website" | |
else | |
echo "::set-output name=branch::${{ github.ref }}" | |
fi | |
- name: Push the changes to the compiled website | |
if: steps.commit-compiled-website.outputs.websiteChanged == '1' || steps.commit-example-combine-archives.outputs.examplesChanged == '1' || steps.bundle-examples.outputs.changed == '1' | |
uses: ad-m/github-push-action@master | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
branch: ${{ steps.get-push-branch.outputs.branch }} | |
force: ${{ steps.get-push-branch.outputs.branch == 'ci-compiled-website' }} | |
- name: Create pull request | |
if: steps.get-push-branch.outputs.branch == 'ci-compiled-website' | |
uses: peter-evans/create-pull-request@v3 | |
with: | |
branch: ${{ steps.get-push-branch.outputs.branch }} |