Merge pull request #25 from MatsMoll/matsei/load-dataset-as-job #175
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
name: publish package | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
services: | |
postgres: | |
image: postgres:14.3-alpine | |
env: | |
POSTGRES_DB: postgres | |
POSTGRES_PORT: 5432 | |
POSTGRES_USER: postgres | |
POSTGRES_PASSWORD: postgres | |
ports: | |
- '127.0.0.1:5432:5432' | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: "3.10" | |
- uses: actions/cache@v3 | |
id: cache-venv | |
with: | |
path: | | |
~/.local | |
.venv | |
key: ${{ hashFiles('**/poetry.lock') }}-${{ steps.setup-python.outputs.python-version }}-1 | |
- name: Install Poetry | |
uses: snok/install-poetry@v1 | |
with: | |
virtualenvs-create: false | |
version: 1.5.0 | |
- run: | | |
python -m venv .venv --upgrade-deps | |
source .venv/bin/activate | |
poetry install --no-interaction --all-extras | |
if: steps.cache-venv.outputs.cache-hit != 'true' | |
- name: Run tests | |
env: | |
PSQL_DATABASE_TEST: postgresql://postgres:postgres@localhost:5432/postgres | |
run: | | |
source .venv/bin/activate | |
pytest | |
build-and-publish-py-package: | |
needs: [test] | |
runs-on: ubuntu-latest | |
steps: | |
- uses: MatsMoll/.github/workflows/publish@patch-1 | |
with: | |
token: ${{ secrets.PYPI_TOKEN }} | |
python-version: '3.10.9' | |
build: | |
# Need to deploy a PyPi version first to make sure we do not overwrite an old Docker version | |
needs: [build-and-publish-py-package] | |
if: github.event_name == 'push' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Setup Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to the GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Define docker image tags | |
id: tags | |
run: | | |
version=$(cat pyproject.toml | grep version | head -n 1 | sed -e 's/version = "\(.*\)"/\1/') | |
tags="matsmoll/aligned-ml:${version},matsmoll/aligned-ml:latest" | |
echo ::set-output name=tags::$tags | |
- uses: docker/build-push-action@v4 | |
with: | |
context: . | |
platforms: linux/amd64 | |
file: Dockerfile | |
push: true | |
tags: ${{ steps.tags.outputs.tags }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max |