name: divent
on: [push]

jobs:
  lint:
    runs-on: ubuntu-latest
    container: python:3.11
    steps:
      - run: apt-get update
      - run: apt-get install -y git nodejs
      - uses: actions/checkout@v3
      - uses: Gr1N/setup-poetry@v8
      - run: poetry install
      - run: poetry run flake8 .
      - run: poetry run mypy .
      - run: poetry run djlint .

  docker:
    runs-on: ubuntu-latest
    container: docker
    needs: [lint]
    steps:
      - run: apk add git nodejs
      - uses: actions/checkout@v3
      - uses: docker/metadata-action@v4
        id: meta
        with:
          images: xefir/divent
          tags: |
            type=schedule
            type=ref,event=tag
            type=ref,event=pr
            type=raw,value=latest,enable={{is_default_branch}}
      - uses: docker/login-action@v2
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      - uses: docker/build-push-action@v4
        with:
          push: ${{ gitea.ref == 'refs/heads/master' || startsWith(gitea.ref, 'refs/tags') }}
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}

  pypi:
    runs-on: ubuntu-latest
    container: python:3.11
    needs: [lint]
    if: startsWith(gitea.ref, 'refs/tags')
    env:
      POETRY_PYPI_TOKEN_PYPI: ${{ secrets.POETRY_PYPI_TOKEN_PYPI }}
    steps:
      - run: apt-get update
      - run: apt-get install -y git nodejs
      - uses: actions/checkout@v3
      - uses: Gr1N/setup-poetry@v8
      - run: poetry publish --build