Skip to content

Commit

Permalink
Fix deploy in Github Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
bonjourmauko committed Jan 24, 2023
1 parent f80e4dd commit 87bdb3c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
27 changes: 16 additions & 11 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
Expand All @@ -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'
Expand All @@ -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
Expand All @@ -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
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/review.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 87bdb3c

Please sign in to comment.