From a47fe1f5930ae028ffb54653b0856959ebdfdd64 Mon Sep 17 00:00:00 2001 From: Daniel Himmelstein Date: Mon, 11 Oct 2021 19:28:20 -0700 Subject: [PATCH] refs https://github.com/related-sciences/ensembl-genes/issues/1 --- .github/workflows/export.yaml | 46 ++++++++++++++++++++++++++++++----- .github/workflows/test.yaml | 3 +++ src/ensembl_genes.py | 4 +-- 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/.github/workflows/export.yaml b/.github/workflows/export.yaml index a1793b0..f056490 100644 --- a/.github/workflows/export.yaml +++ b/.github/workflows/export.yaml @@ -1,11 +1,18 @@ name: Export on: + schedule: + # https://crontab.guru/#05_11_*_*_2 + - cron: '05 11 * * 2' workflow_dispatch: inputs: release: - description: 'Ensembl release number' + description: 'Ensembl release number (e.g. 104 or latest)' required: true default: '104' + overwrite: + description: 'Overwrite output on an existing branch (true or false).' + required: true + default: 'false' jobs: export: runs-on: ubuntu-latest @@ -14,22 +21,49 @@ jobs: uses: actions/checkout@v2 - name: Setup dependencies uses: ./.github/actions/setup + - name: Set parameters + id: params + shell: bash + run: | + ENSEMBL_RELEASE=${{ github.event.inputs.release || 'latest' }} + # update latest to release number + ENSEMBL_RELEASE=$(poetry run python src/ensembl_genes.py ensembl_release --release="$ENSEMBL_RELEASE") + echo "Setting parameter release=$ENSEMBL_RELEASE" + echo "::set-output name=release::$ENSEMBL_RELEASE" + + OUTPUT_EXISTS="true" + git ls-remote --exit-code origin output-$ENSEMBL_RELEASE || OUTPUT_EXISTS="false" + echo "output-$ENSEMBL_RELEASE branch exists on origin: $OUTPUT_EXISTS" + echo "::set-output name=output_exists::$OUTPUT_EXISTS" + + OVERWRITE=${{ github.event.inputs.overwrite || 'false' }} + echo "Setting parameter overwrite=$OVERWRITE" + echo "::set-output name=overwrite::$OVERWRITE" + + EXPORT="false" + if [[ $OUTPUT_EXISTS = "false" || $OVERWRITE = "true" ]]; then + EXPORT="true" + fi + echo "Setting parameter export=$EXPORT" + echo "::set-output name=export::$EXPORT" - name: Extract tables id: extract - run: poetry run python src/ensembl_genes.py all --release=${{ github.event.inputs.release }} + if: steps.params.outputs.overwrite == 'true' + run: poetry run python src/ensembl_genes.py all --release=${{ steps.params.outputs.release }} - name: Output artifact # upload outputs to artifact only when the extraction fails if: always() && steps.extract.outcome == 'failure' uses: actions/upload-artifact@v2 with: - name: failed-output-${{ github.event.inputs.release }} - path: output/${{ github.event.inputs.release }} + name: failed-output-${{ steps.params.outputs.release }} + path: output/${{ steps.params.outputs.release }} - name: Deploy uses: peaceiris/actions-gh-pages@v3 + if: steps.params.outputs.overwrite == 'true' with: github_token: ${{ secrets.GITHUB_TOKEN }} - publish_branch: output-${{ github.event.inputs.release }} - publish_dir: output/${{ github.event.inputs.release }} + publish_branch: output-${{ steps.params.outputs.release }} + publish_dir: output/${{ steps.params.outputs.release }} # Won't actually enable jekyll because we're not using GitHub Pages. # https://github.com/peaceiris/actions-gh-pages/issues/660 enable_jekyll: true diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 86dffb2..0ba126c 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -2,6 +2,9 @@ name: Test on: push: pull_request: + schedule: + # https://crontab.guru/#57_6_*_*_1 + - cron: '57 6 * * 1' jobs: test: runs-on: ubuntu-latest diff --git a/src/ensembl_genes.py b/src/ensembl_genes.py index 6157d59..85d205c 100644 --- a/src/ensembl_genes.py +++ b/src/ensembl_genes.py @@ -556,7 +556,7 @@ def get_latest_ensembl_release() -> str: return ensembl_release -def check_ensembl_release(release: str) -> str: +def check_ensembl_release(release: str = "latest") -> str: """ Check that ensembl release is properly formatted, like '104'. If release is 'latest', get latest release using bioversions. @@ -614,6 +614,6 @@ def export_all(cls, release: str = "latest") -> None: "datasets": Commands.export_datasets, "notebooks": Commands.export_notebooks, "all": Commands.export_all, - "latest_release": get_latest_ensembl_release, + "ensembl_release": check_ensembl_release, } fire.Fire(commands)