From 50f8d14a5260190f428c7b53107973514af87527 Mon Sep 17 00:00:00 2001 From: Anderson Banihirwe Date: Tue, 1 Feb 2022 20:26:12 -0700 Subject: [PATCH] Update CI workflows (#105) --- .github/workflows/ci.yaml | 44 ++++----- .../{pypi.yaml => pypi-release.yaml} | 10 +- .github/workflows/upstream-dev-ci.yaml | 95 +++++++++++++++++++ .../environment-docs.yml | 0 ci/environment-upstream-dev.yml | 25 +++++ ci/environment.yml | 3 +- readthedocs.yml | 2 +- 7 files changed, 150 insertions(+), 29 deletions(-) rename .github/workflows/{pypi.yaml => pypi-release.yaml} (86%) create mode 100644 .github/workflows/upstream-dev-ci.yaml rename docs/environment.yml => ci/environment-docs.yml (100%) create mode 100644 ci/environment-upstream-dev.yml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 859174d..8fe4938 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,26 +1,21 @@ name: CI on: push: + branches: + - main pull_request: + schedule: + - cron: '0 0 * * *' # Daily “At 00:00” workflow_dispatch: # allows you to trigger manually +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: - pre-job: - runs-on: ubuntu-latest - outputs: - should_skip: ${{ steps.skip_check.outputs.should_skip }} - steps: - - id: skip_check - uses: fkirc/skip-duplicate-actions@master - with: - concurrent_skipping: 'same_content' - skip_after_successful_duplicate: 'false' - do_not_skip: '["pull_request", "workflow_dispatch", "schedule"]' - paths_ignore: '["**/docs/**"]' build: - needs: pre-job - if: ${{ needs.pre-job.outputs.should_skip != 'true' }} name: python-${{ matrix.python-version }} + if: github.repository == 'NCAR/ecgtools' runs-on: ubuntu-latest defaults: run: @@ -28,32 +23,29 @@ jobs: strategy: fail-fast: false matrix: - python-version: ['3.7', '3.8', '3.9'] + python-version: ['3.7', '3.8', '3.9', '3.10'] steps: - - name: Cancel Previous Runs - uses: styfle/cancel-workflow-action@0.9.1 - with: - access_token: ${{ github.token }} - uses: actions/checkout@v2 - with: - fetch-depth: 0 - uses: conda-incubator/setup-miniconda@v2 with: - channels: conda-forge,nodefaults - mamba-version: '*' + channels: conda-forge + channel-priority: strict activate-environment: ecgtools-dev auto-update-conda: false python-version: ${{ matrix.python-version }} + mamba-version: '*' + use-mamba: true + miniforge-variant: Mambaforge environment-file: ci/environment.yml - - name: Set up conda environment + - name: Install ecgtools run: | - python -m pip install -e . + python -m pip install -e . --no-deps --force-reinstall conda list - name: Run Tests run: | - python -m pytest --cov=./ --cov-report=xml --verbose + python -m pytest - name: Upload code coverage to Codecov uses: codecov/codecov-action@v2.1.0 diff --git a/.github/workflows/pypi.yaml b/.github/workflows/pypi-release.yaml similarity index 86% rename from .github/workflows/pypi.yaml rename to .github/workflows/pypi-release.yaml index 5286bc5..2d4b71a 100644 --- a/.github/workflows/pypi.yaml +++ b/.github/workflows/pypi-release.yaml @@ -1,8 +1,9 @@ -name: Build and Upload ecgtools to PyPI +name: Build distribution on: release: types: - published + push: jobs: build-artifacts: @@ -60,6 +61,13 @@ jobs: ls -ltrh ls -ltrh dist + - name: Verify the built dist/wheel is valid + if: github.event_name == 'push' + run: | + python -m pip install --upgrade pip + python -m pip install dist/ecgtools*.whl + python -c "import ecgtools; print(ecgtools.__version__)" + upload-to-pypi: needs: test-built-dist if: github.event_name == 'release' diff --git a/.github/workflows/upstream-dev-ci.yaml b/.github/workflows/upstream-dev-ci.yaml new file mode 100644 index 0000000..48fdd8a --- /dev/null +++ b/.github/workflows/upstream-dev-ci.yaml @@ -0,0 +1,95 @@ +name: Upstream CI +on: + push: + branches: + - main + schedule: + - cron: '0 0 * * *' # Daily “At 00:00” UTC + workflow_dispatch: # allows you to trigger the workflow run manually + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + upstream-dev: + name: upstream-dev + runs-on: ubuntu-latest + if: github.repository == 'NCAR/ecgtools' + defaults: + run: + shell: bash -l {0} + strategy: + fail-fast: false + matrix: + python-version: ['3.10'] + steps: + - uses: actions/checkout@v2 + - uses: conda-incubator/setup-miniconda@v2 + id: conda + with: + channels: conda-forge,nodefaults + channel-priority: strict + activate-environment: ecgtools-dev + auto-update-conda: false + python-version: ${{ matrix.python-version }} + environment-file: ci/environment-upstream-dev.yml + mamba-version: '*' + use-mamba: true + miniforge-variant: Mambaforge + + - name: Install ecgtools + id: install + run: | + python -m pip install -e . --no-deps --force-reinstall + conda list + + - name: Run Tests + id: test + run: | + python -m pytest + + - name: Report Status + if: | + always() + && (steps.conda.outcome != 'success' || steps.install.outcome != 'success' || steps.install.outcome != 'success') + uses: actions/github-script@v5 + with: + script: | + const title = '⚠️ Upstream CI Failed ⚠️' + const creator = 'github-actions[bot]' + const issueLabel = 'CI' + const workflow_url = `https://github.com/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}` + const issue_body = `[Workflow Run URL](${workflow_url})\n\n` + let foundIssue = false + const issues = await github.rest.issues.listForRepo({ + owner: context.repo.owner, + repo: context.repo.repo, + }) + for (let issue of issues.data) { + if ( + issue.user.login === creator && + issue.state === 'open' && + issue.labels.some((label) => label.name === issueLabel) + ) { + github.rest.issues.update({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issue.number, + body: issue_body, + }) + core.info(`Updated an existing issue: ${issue.number}.`) + foundIssue = true + break + } + } + if (!foundIssue) { + await github.rest.issues.create({ + owner: context.repo.owner, + repo: context.repo.repo, + title: title, + body: issue_body, + labels: [issueLabel], + }) + core.info('Opened a new issue') + } diff --git a/docs/environment.yml b/ci/environment-docs.yml similarity index 100% rename from docs/environment.yml rename to ci/environment-docs.yml diff --git a/ci/environment-upstream-dev.yml b/ci/environment-upstream-dev.yml new file mode 100644 index 0000000..7134113 --- /dev/null +++ b/ci/environment-upstream-dev.yml @@ -0,0 +1,25 @@ +name: ecgtools-dev +channels: + - conda-forge + - nodefaults +dependencies: + - cf_xarray + - codecov + - intake-esm + - joblib + - nbsphinx + - netcdf4 + - numpydoc + - pip + - pre-commit + - pydantic + - pytest + - pytest-cov + - pytest-sugar + - pytest-xdist + - pyyaml + - typer + - xarray + - pip: + - git+https://github.com/xarray-contrib/cf-xarray + - git+https://github.com/intake/intake-esm diff --git a/ci/environment.yml b/ci/environment.yml index 0659fdd..77df547 100644 --- a/ci/environment.yml +++ b/ci/environment.yml @@ -4,7 +4,6 @@ channels: - nodefaults dependencies: - cf_xarray - - codecov - intake-esm - joblib - nbsphinx @@ -20,3 +19,5 @@ dependencies: - pyyaml - typer - xarray + - pip: + - git+https://github.com/intake/intake-esm diff --git a/readthedocs.yml b/readthedocs.yml index 89f13eb..68e5895 100644 --- a/readthedocs.yml +++ b/readthedocs.yml @@ -1,6 +1,6 @@ version: 2 conda: - environment: docs/environment.yml + environment: ci/environment-docs.yml build: os: 'ubuntu-20.04' tools: