From 87bdb3c419b82bc9223d60962d2ae16aff89e402 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Tue, 13 Dec 2022 21:56:39 +0100 Subject: [PATCH] Fix deploy in Github Actions --- .github/workflows/deploy.yaml | 27 ++++++++++++++++----------- .github/workflows/review.yaml | 21 +++++++++++++++++++++ 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index f7d6be538..af6c13a3f 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -68,14 +68,13 @@ jobs: python: ${{ matrix.python }} activate_command: ${{ matrix.activate_command }} - # The idea behind these dependencies is we want to give feedback to # contributors on the version number only after they have passed all tests, # so they don't have to do it twice after changes happened to the main branch # during the time they took to fix the tests. check-version: runs-on: ubuntu-20.04 - needs: [ test-core, test-country-template, test-extension-template, lint-files ] + needs: [ test, lint ] steps: - uses: actions/checkout@v3 @@ -90,12 +89,12 @@ jobs: - name: Check version number has been properly updated run: "${GITHUB_WORKSPACE}/.github/is-version-number-acceptable.sh" - # GitHub Actions does not have a halt job option, to stop from deploying if no functional changes were found. - # We build a separate job to substitute the halt option. - # The `deploy` job is dependent on the output of the `check-for-functional-changes`job. + # GitHub Actions does not have a halt job option, to stop from deploying if + # no functional changes were found. We build a separate job to substitute the + # halt option. The `deploy` job is dependent on the output of the + # `check-for-functional-changes`job. check-for-functional-changes: runs-on: ubuntu-20.04 - if: github.ref == 'refs/heads/master' # Only triggered for the `master` branch needs: [ check-version ] # Last job to run outputs: status: ${{ steps.stop-early.outputs.status }} @@ -113,7 +112,7 @@ jobs: - id: stop-early run: if "${GITHUB_WORKSPACE}/.github/has-functional-changes.sh" ; then echo "::set-output name=status::success" ; fi # The `check-for-functional-changes` job should always succeed regardless of the `has-functional-changes` script's exit code. Consequently, we do not use that exit code to trigger deploy, but rather a dedicated output variable `status`, to avoid a job failure if the exit code is different from 0. Conversely, if the job fails the entire workflow would be marked as `failed` which is disturbing for contributors. - deploy: + publish-to-pypi: runs-on: ubuntu-20.04 needs: [ check-for-functional-changes ] if: needs.check-for-functional-changes.outputs.status == 'success' @@ -136,15 +135,21 @@ jobs: uses: actions/cache@v3 with: path: venv - key: deps-ubuntu-20.04-1.20.3-3.8.10-${{ hashFiles('setup.py') }} + key: deps-ubuntu-20.04-np1.20.3-py3.8.10-${{ hashFiles('setup.py') }} - name: Cache build uses: actions/cache@v3 with: path: venv/**/[oO]pen[fF]isca* - key: build-ubuntu-20.04-1.20.3-3.8.10-${{ hashFiles('setup.py') }}-${{ github.sha }} + key: build-ubuntu-20.04-np1.20.3-py3.8.10-${{ hashFiles('setup.py') }}-${{ github.sha }} + + - name: Cache release + uses: actions/cache@v3 + with: + path: dist + key: release-ubuntu-20.04-np1.20.3-py3.8.10-${{ hashFiles('setup.py') }}-${{ github.sha }} - - name: Upload a Python package to PyPi + - name: Upload package to PyPi run: | source venv/bin/activate make publish @@ -155,7 +160,7 @@ jobs: publish-to-conda: runs-on: ubuntu-20.04 - needs: [ deploy ] + needs: [ publish-to-pypi ] steps: - uses: conda-incubator/setup-miniconda@v2 diff --git a/.github/workflows/review.yaml b/.github/workflows/review.yaml index d65cf323a..d26748984 100644 --- a/.github/workflows/review.yaml +++ b/.github/workflows/review.yaml @@ -67,3 +67,24 @@ jobs: numpy: ${{ matrix.numpy }} python: ${{ matrix.python }} activate_command: ${{ matrix.activate_command }} + + # The idea behind these dependencies is we want to give feedback to + # contributors on the version number only after they have passed all tests, + # so they don't have to do it twice after changes happened to the main branch + # during the time they took to fix the tests. + check-version: + runs-on: ubuntu-20.04 + needs: [ test, lint ] + + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 # Fetch all the tags + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: 3.8.10 # Patch version must be specified to avoid any cache confusion, since the cache key depends on the full Python version. If left unspecified, different patch versions could be allocated between jobs, and any such difference would lead to a cache not found error. + + - name: Check version number has been properly updated + run: "${GITHUB_WORKSPACE}/.github/is-version-number-acceptable.sh"