Nightly #8
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: Nightly | |
on: | |
schedule: | |
- cron: "0 2 * * *" # run at 2 AM UTC | |
workflow_dispatch: | |
inputs: | |
linux: | |
description: 'Run build on Linux' | |
type: boolean | |
required: false | |
default: true | |
windows: | |
description: 'Run build on Windows' | |
type: boolean | |
required: false | |
default: true | |
macos: | |
description: 'Run build on macOS' | |
type: boolean | |
required: false | |
default: true | |
repository_dispatch: | |
types: nightly-build | |
defaults: | |
run: | |
shell: bash -l {0} | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
jobs: | |
build-nightly: | |
name: Build | |
needs: [check-assets, generate-matrix] | |
if: ${{ github.event_name == 'workflow_dispatch' || needs.check-assets.outputs.needs-build == 'true' }} | |
runs-on: ${{ matrix.os }}-latest | |
strategy: | |
matrix: | |
python-version: ["3.10"] | |
os: ${{ fromJSON(needs.generate-matrix.outputs.os) }} | |
fail-fast: false | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Update submodules | |
run: | | |
git submodule init | |
pushd metgem | |
git checkout master | |
git pull | |
popd | |
- name: Set up Python | |
uses: conda-incubator/setup-miniconda@v2 | |
with: | |
miniforge-variant: Mambaforge | |
miniforge-version: latest | |
activate-environment: metgem | |
use-mamba: true | |
mamba-version: "*" | |
channel-priority: strict | |
channels: conda-forge,metgem,bioconda | |
python-version: ${{ matrix.python-version }} | |
- name: Get Cache folder | |
id: get-prefix | |
run: | | |
CONDA_PREFIX=$(python -c "import sys; print(sys.prefix)") | |
echo "prefix=$CONDA_PREFIX" >> $GITHUB_OUTPUT | |
- name: Cache conda | |
if: ${{ !env.ACT }} | |
id: cache | |
uses: actions/cache@v3 | |
env: | |
# Increase this value to reset cache if environment.yml has not changed | |
CACHE_NUMBER: 0 | |
with: | |
path: ${{ steps.get-prefix.outputs.prefix }} | |
key: ${{ matrix.os }}-${{matrix.python-version}}-conda-${{ env.CACHE_NUMBER }}-${{ hashFiles('metgem/environment*.yml') }} | |
- name: Set up Environment | |
uses: ./.github/actions/set_up_env | |
with: | |
update: ${{ steps.cache.outputs.cache-hit }} | |
- name: Build | |
id: build | |
uses: ./.github/actions/build | |
with: | |
nightly: true | |
- name: Run Tests | |
id: tests | |
uses: ./.github/actions/tests | |
- name: Upload Tests Artifacts | |
if: ${{ !env.ACT && (success() || (failure() && steps.tests.conclusion == 'failure' )) }} | |
uses: actions/upload-artifact@v3 | |
with: | |
name: tests | |
path: ${{ steps.tests.outputs.log }} | |
- name: Deploy Nightly | |
if: ${{ !env.ACT }} | |
uses: WebFreak001/[email protected] | |
env: | |
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} | |
with: | |
upload_url: https://uploads.github.com/repos/${{ github.repository }}/releases/33563969/assets{?name,label} | |
release_id: 33563969 | |
asset_path: ${{ steps.build.outputs.asset-name }} | |
asset_name: ${{ steps.build.outputs.asset-basename }}-$$.${{ steps.build.outputs.asset-ext }} | |
asset_content_type: ${{ steps.build.outputs.asset-mimetype }} | |
max_releases: 6 | |
# Check that current commit does not have a nightly build asset uploaded yet | |
check-assets: | |
runs-on: ubuntu-latest | |
outputs: | |
needs-build: ${{ steps.assets.outputs.needs-build }} | |
steps: | |
- name: Check existing assets | |
id: assets | |
run: | | |
hash=${{ github.sha }} | |
hash=${hash::6} | |
names=( $(curl -sL https://api.github.com/repos/metgem/metgem/releases/33563969/assets | jq -r '.[].name') ) | |
needs_build='true' | |
if [ "${{ github.event_name }}" == "repository_dispatch" ] || [ "${{ github.event_name }}" == "workflow_dispatch" ]; then | |
echo "[WARNING] Nightly workflow triggered manually" | |
else | |
for name in "${names[@]}" | |
do | |
basename=${name##*-}; | |
if [ "${basename%.*}" == "$hash" ]; then | |
echo "[WARNING] Commit already built, skipping build" | |
needs_build='false' | |
break | |
fi | |
done | |
fi | |
echo "needs-build=$needs_build" >> $GITHUB_OUTPUT | |
generate-matrix: | |
runs-on: ubuntu-latest | |
name: "Generate matrix job specs" | |
outputs: | |
os: ${{ steps.generate-matrix.outputs.os }} | |
steps: | |
- name: generate-matrix | |
id: generate-matrix | |
run: | | |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then | |
os=() | |
if [ "${{ github.event.inputs.linux}}" == "true" ]; then | |
os+=('ubuntu') | |
fi | |
if [ "${{ github.event.inputs.windows}}" == "true" ]; then | |
os+=('windows') | |
fi | |
if [ "${{ github.event.inputs.macos }}" == "true" ]; then | |
os+=('macos') | |
fi | |
os=$(printf ', "%s"' "${os[@]}") | |
os="[${os:2}]" | |
echo "[INFO] OS selected: $os" | |
echo "os=$os" >> $GITHUB_OUTPUT | |
else | |
echo 'os=["ubuntu","windows","macos"]' >> $GITHUB_OUTPUT | |
fi | |
update-nightly-tag: | |
needs: build-nightly | |
runs-on: ubuntu-latest | |
steps: | |
- name: Update Nightly tag | |
uses: richardsimko/update-tag@v1 | |
with: | |
tag_name: nightly |