Skip to content

add tests workflow

add tests workflow #7

Workflow file for this run

name: ci
on:
pull_request:
push:
branches: [main]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
prepare:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- name: build ci image
uses: docker/build-push-action@v5
with:
context: .
tags: teufa:ci
target: ci
load: true
cache-from: type=gha
cache-to: type=gha,mode=max
push: false
tests:
runs-on: ubuntu-latest
needs: prepare
container: teufa:ci
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- run: pytest
build-push:
runs-on: ubuntu-latest
needs: tests
permissions:
contents: read
packages: write
steps:
- name: log in to ghcr.io
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha
- name: build prod image
uses: docker/build-push-action@v5
if: github.ref == 'refs/heads/main'
with:
context: .
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
target: prod
load: true
cache-from: type=gha
cache-to: type=gha,mode=max
push: true