forked from nansencenter/django-geo-spaas
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update actions to support multiple python versions
- Loading branch information
Showing
3 changed files
with
195 additions
and
234 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
--- | ||
name: "Unit tests and build" | ||
on: | ||
push: | ||
branches: ['**'] | ||
release: | ||
types: [prereleased, released] | ||
jobs: | ||
tests_and_docker_builds: | ||
strategy: | ||
matrix: | ||
image_name: ["${{ vars.DOCKER_ORG }}/geospaas"] | ||
tag_suffix: | ||
- '' | ||
- '-slim' | ||
version: | ||
- {'python': '3.7', 'latest': false} | ||
- {'python': '3.8', 'latest': false} | ||
- {'python': '3.9', 'latest': false} | ||
- {'python': '3.10', 'latest': false} | ||
- {'python': '3.11', 'latest': true} | ||
uses: ./.github/workflows/test_and_docker_build.yml | ||
with: | ||
base_image: "${{ vars.DOCKER_ORG }}/nansat:0.0.9${{ matrix.tag_suffix }}-python${{ matrix.version.python }}" | ||
target_image_tags: | | ||
${{ matrix.image_name }}:${{ github.ref_name }}${{ matrix.tag_suffix }}-python${{ matrix.version.python }} | ||
${{ matrix.image_name }}:latest${{ matrix.tag_suffix }}-python${{ matrix.version.python }} | ||
${{ matrix.version.latest && format('{0}:latest{1}', matrix.image_name, matrix.tag_suffix) || '' }} | ||
secrets: inherit | ||
|
||
|
||
publish_python_package: | ||
name: Publish the Python package to PyPI | ||
runs-on: 'ubuntu-latest' | ||
needs: 'tests_and_docker_builds' | ||
if: github.event_name == 'release' | ||
steps: | ||
- name: 'Checkout repository' | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Python 3.7 | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: 3.7 | ||
|
||
- name: Build package | ||
run: > | ||
DJANGO_GEO_SPAAS_RELEASE="${{ github.ref_name }}" | ||
python setup.py sdist | ||
shell: bash | ||
|
||
- name: Publish | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
with: | ||
# Storing the PyPI URL in the repositories' secrets makes | ||
# publishing to the test PyPI from forks easy | ||
repository_url: ${{ vars.PYPI_REPOSITORY_URL }} | ||
password: ${{ secrets.PYPI_TOKEN }} | ||
... |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
# Reusable workflow which runs unit tests in a base image then builds | ||
# a geo-spaas image on top of it | ||
--- | ||
name: "Run unit tests and build docker image" | ||
on: | ||
workflow_call: | ||
inputs: | ||
base_image: | ||
required: true | ||
type: string | ||
target_image_tags: | ||
required: true | ||
type: string | ||
secrets: | ||
DOCKER_USER: | ||
required: true | ||
DOCKER_PASS: | ||
required: true | ||
jobs: | ||
tests: | ||
name: 'Run unit tests' | ||
runs-on: 'ubuntu-latest' | ||
steps: | ||
- name: 'Checkout repository' | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Login to DockerHub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKER_USER }} | ||
password: ${{ secrets.DOCKER_PASS }} | ||
|
||
- name: Cache Docker layers | ||
uses: actions/cache@v3 | ||
with: | ||
path: /tmp/.buildx-cache | ||
key: ${{ runner.os }}-buildx-testing-${{ github.sha }} | ||
restore-keys: | | ||
${{ runner.os }}-buildx-testing- | ||
- name: Build testing image | ||
id: docker_build | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
target: base | ||
build-args: | | ||
BASE_IMAGE=${{ inputs.base_image }} | ||
push: false | ||
load: true | ||
tags: ${{ inputs.image_tags }} | ||
cache-from: type=local,src=/tmp/.buildx-cache | ||
cache-to: type=local,dest=/tmp/.buildx-cache-new | ||
|
||
# Temp fix | ||
# https://github.com/docker/build-push-action/issues/252 | ||
# https://github.com/moby/buildkit/issues/1896 | ||
- name: Move cache | ||
run: | | ||
rm -rf /tmp/.buildx-cache | ||
mv /tmp/.buildx-cache-new /tmp/.buildx-cache | ||
- name: 'Run tests' | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: > | ||
docker run --rm | ||
-v "$(pwd):/src" | ||
-e "GITHUB_ACTIONS=$GITHUB_ACTIONS" | ||
-e "GITHUB_REF=$GITHUB_REF" | ||
-e "GITHUB_SHA=$GITHUB_SHA" | ||
-e "GITHUB_HEAD_REF=$GITHUB_HEAD_REF" | ||
-e "GITHUB_REPOSITORY=$GITHUB_REPOSITORY" | ||
-e "GITHUB_RUN_ID=$GITHUB_RUN_ID" | ||
-e "GITHUB_TOKEN=$GITHUB_TOKEN" | ||
"${IMAGE_NAME}" | ||
bash -c "coverage run --omit=geospaas/nansat_ingestor/tests/*,geospaas/catalog/tests/*,geospaas/vocabularies/tests/* runtests.py" | ||
- name: 'Install Python 3.11' | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.11' | ||
|
||
- name: 'Upload coverage to coveralls.io' | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: pip install coveralls && coveralls --service=github | ||
|
||
|
||
build_docker_image: | ||
runs-on: 'ubuntu-latest' | ||
needs: 'tests' | ||
steps: | ||
- name: 'Checkout repository' | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Cache Docker layers | ||
uses: actions/cache@v3 | ||
with: | ||
path: /tmp/.buildx-cache | ||
key: ${{ runner.os }}-buildx-standard-${{ github.sha }} | ||
restore-keys: | | ||
${{ runner.os }}-buildx-standard- | ||
- name: Login to DockerHub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKER_USER }} | ||
password: ${{ secrets.DOCKER_PASS }} | ||
|
||
- name: Build docker image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
build-args: | | ||
BASE_IMAGE=${{ inputs.base_image }} | ||
DJANGO_GEO_SPAAS_RELEASE=${{ github.ref_type == 'tag' && github.ref_name || '0.0.0' }} | ||
push: ${{ github.ref_type == 'tag' }} | ||
tags: ${{ inputs.target_image_tags }} | ||
cache-from: type=local,src=/tmp/.buildx-cache | ||
cache-to: type=local,dest=/tmp/.buildx-cache-new | ||
|
||
# Temp fix | ||
# https://github.com/docker/build-push-action/issues/252 | ||
# https://github.com/moby/buildkit/issues/1896 | ||
- name: Move cache | ||
run: | | ||
rm -rf /tmp/.buildx-cache | ||
mv /tmp/.buildx-cache-new /tmp/.buildx-cache | ||
... |
Oops, something went wrong.