Nightly #546
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} | |
jobs: | |
build-nightly: | |
name: Build | |
needs: generate-matrix | |
runs-on: ${{ matrix.os }} | |
if: ${{ needs.generate-matrix.outputs.os != '[]' && needs.generate-matrix.outputs.os != '' }} | |
strategy: | |
matrix: | |
python-version: ["3.11"] | |
os: ${{ fromJSON(needs.generate-matrix.outputs.os) }} | |
fail-fast: false | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Update submodules | |
run: | | |
git submodule init | |
git submodule update | |
pushd metgem | |
git checkout main | |
git pull | |
popd | |
- name: Set up Python | |
uses: conda-incubator/setup-miniconda@v3 | |
with: | |
miniforge-version: latest | |
activate-environment: metgem | |
use-mamba: true | |
mamba-version: "*" | |
channel-priority: strict | |
channels: conda-forge,metgem,bioconda | |
conda-remove-defaults: "true" | |
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@v4 | |
env: | |
# Increase this value to reset cache if environment.yml has not changed | |
CACHE_NUMBER: 0 | |
with: | |
path: ${{ steps.get-prefix.outputs.prefix }} | |
key: ${{ runner.os }}-${{matrix.python-version}}-conda-${{ env.CACHE_NUMBER }} | |
- name: Set up Environment | |
uses: ./.github/actions/set_up_env | |
with: | |
use-cached: ${{ steps.cache.outputs.cache-hit == 'true' }} | |
- name: Upload Packages artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: packages-${{ matrix.os }} | |
path: packages-*.txt | |
- name: Run Tests (Source) | |
id: tests-source | |
uses: ./.github/actions/tests | |
with: | |
packaged: false | |
- name: Upload Tests Artifacts (Source) | |
if: ${{ !env.ACT && (success() || (failure() && steps.tests-source.conclusion == 'failure' )) }} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: tests-source-${{ matrix.os }} | |
path: ${{ steps.tests-source.outputs.log }} | |
- name: Build | |
id: build | |
uses: ./.github/actions/build | |
with: | |
nightly: true | |
certificate: ${{ secrets.APPLE_CERTIFICATE }} | |
certificate_pwd: ${{ secrets.APPLE_CERTIFICATE_PWD }} | |
identity_id: ${{ secrets.APPLE_IDENTITY_ID }} | |
- name: Run Tests (Packaged) | |
id: tests | |
uses: ./.github/actions/tests | |
with: | |
packaged: true | |
- name: Upload Tests Artifacts (Packaged) | |
if: ${{ !env.ACT && (success() || (failure() && steps.tests.conclusion == 'failure' )) }} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: tests-packaged-${{ matrix.os }} | |
path: ${{ steps.tests.outputs.log }} | |
- name: Deploy Nightly | |
if: ${{ !env.ACT }} | |
uses: WebFreak001/deploy-nightly@v3.1.0 | |
with: | |
upload_url: https://uploads.github.com/repos/metgem/metgem/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 | |
token: ${{ secrets.RELEASE_TOKEN }} | |
repo: metgem/metgem | |
sha: ${{ steps.build.outputs.sha }} | |
- name: Update Nightly tag | |
if: ${{ !env.ACT }} | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.RELEASE_TOKEN }} | |
script: | | |
const owner = 'metgem'; | |
const repo = 'metgem'; | |
const sha = '${{ steps.build.outputs.sha }}' | |
const ref = 'tags/nightly' | |
try { | |
github.rest.git.updateRef({ | |
owner: owner, | |
repo: repo, | |
ref: ref, | |
sha: sha | |
}); | |
console.log('Updated existing tag nightly as', sha); | |
} | |
catch { | |
github.rest.git.createRef({ | |
owner: owner, | |
repo: repo, | |
ref: 'refs/' + ref, | |
sha: sha | |
}); | |
console.log('Created new tag nightly as', sha); | |
} | |
merge: | |
runs-on: ubuntu-latest | |
needs: build-nightly | |
steps: | |
- name: Merge Tests Artifacts | |
uses: actions/upload-artifact/merge@v4 | |
with: | |
name: tests | |
pattern: tests-* | |
delete-merged: true | |
- name: Merge Packages Artifacts | |
uses: actions/upload-artifact/merge@v4 | |
with: | |
name: packages | |
pattern: packages-* | |
delete-merged: true | |
# Check that current commit does not have a nightly build asset uploaded yet | |
generate-matrix: | |
runs-on: ubuntu-latest | |
name: Generate matrix job specs | |
outputs: | |
os: ${{ steps.generate-matrix.outputs.result }} | |
steps: | |
- name: Get release SHA | |
id: sha | |
run: | | |
sha=`git ls-remote https://github.com/metgem/metgem HEAD | head -1 | cut -f 1 | cut -c1-6` | |
echo "MetGem SHA is $sha" | |
echo "sha=$sha" >> $GITHUB_OUTPUT | |
- name: Check existing assets and generate-matrix | |
id: generate-matrix | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.RELEASE_TOKEN }} | |
script: | | |
const owner = 'metgem'; | |
const repo = 'metgem'; | |
const sha = '${{ steps.sha.outputs.sha }}'; | |
const release_id = '33563969'; | |
const all_oses = {"linux": "ubuntu-latest", | |
"windows": "windows-latest", | |
"macos": "macos-13"}; | |
const exts = {".AppImage": "linux", | |
".dmg": "macos", | |
".exe": "windows"}; | |
const inputs = context.payload.inputs; | |
let oses = {...all_oses}; | |
const assets = await github.rest.repos.listReleaseAssets({ | |
owner: owner, | |
repo: repo, | |
release_id: release_id | |
}); | |
if ("${{ github.event_name }}" == "repository_dispatch" || "${{ github.event_name }}" == "workflow_dispatch") { | |
console.log("[WARNING] Nightly workflow triggered manually"); | |
for (const key in inputs) { | |
if (inputs[key] != "true") { | |
delete oses[key]; | |
} | |
} | |
// Delete existing assets | |
for (const asset of assets['data']) { | |
asset_name = asset['name']; | |
asset_sha = asset_name.substring(asset_name.lastIndexOf('-')+1, asset_name.lastIndexOf('.')) || ""; | |
asset_ext = asset_name.substring(asset_name.lastIndexOf('.')); | |
if (asset_sha == sha) { | |
os = exts[asset_ext]; | |
if (Object.keys(oses).includes(os)) { | |
console.log("[INFO] Deleting old asset", asset_name); | |
await github.rest.repos.deleteReleaseAsset({ | |
owner: owner, | |
repo: repo, | |
asset_id: asset['id'] | |
}); | |
} | |
} | |
} | |
console.log("[INFO] OS selected:", Object.keys(oses)); | |
return Object.values(oses); | |
} | |
// Keep only os where assets are not already built | |
for (const asset of assets['data']) { | |
asset_name = asset['name']; | |
asset_sha = asset_name.substring(asset_name.lastIndexOf('-')+1, asset_name.lastIndexOf('.')) || ""; | |
asset_ext = asset_name.substring(asset_name.lastIndexOf('.')); | |
if (asset_sha == sha) { | |
os = exts[asset_ext]; | |
if (os) { | |
console.log("[WARNING] Commit already built on", os, ", skipping build"); | |
delete oses[os]; | |
} | |
} | |
} | |
return Object.values(oses); |