on:
  push:
    tags:
      - '[0-9]+\.[0-9]+\.[0-9]+-c\.[0-9]+'
      - '[0-9]+\.[0-9]+\.[0-9]+-a\.[0-9]+'
      - '[0-9]+\.[0-9]+\.[0-9]'

jobs:
  lint-and-typing:
    runs-on: docker
    container: forgejo.neshweb.net/ci-docker-images/python-neshweb:3.11
    steps:
      - name: Checkout source code
        uses: https://code.forgejo.org/actions/checkout@v4
      - name: Install packages
        run: |
          pip install -e .[lint,typing] -q --disable-pip-version-check -q --no-cache-dir -q
          python -m pip list --format=columns --disable-pip-version-check
      - name: Run pylint
        run: |
          pylint --version
          pylint **/*.py --exit-zero --rc-file pyproject.toml
      - name: Run mypy
        run: |
          mypy --version
          mypy .

  build-artifacts:
    needs: ["lint-and-typing"]
    runs-on: docker
    container: forgejo.neshweb.net/ci-docker-images/python-neshweb:3.11
    steps:
      - name: Checkout source code
        uses: https://code.forgejo.org/actions/checkout@v4
      - name: Install packages
        run: pip install build --no-cache-dir -q
      - name: Build package
        run: python -m build
      - name: Save build artifacts
        uses: https://code.forgejo.org/actions/upload-artifact@v3
        with:
          name: packages
          path: dist/*

  publish-artifacts:
    needs: ["build-artifacts"]
    runs-on: docker
    container: forgejo.neshweb.net/ci-docker-images/python-neshweb:3.11
    steps:
      - name: Downloading static site artifacts
        uses: actions/download-artifact@v3
        with:
          name: packages
          path: dist
      - name: Install Dependencies
        run: pip install twine --no-cache-dir -q
      - name: Upload package to registry
        run: python -m twine upload --repository-url ${{ secrets.REPOSITORY_URL }} -u ${{ secrets.TWINE_DEPLOY_USER }} -p ${{ secrets.TWINE_DEPLOY_PASSWORD }} dist/*

  release:
    needs: [ publish-artifacts ]
    if: success()
    runs-on: docker
    steps:
      - name: Release New Version
        uses: actions/forgejo-release@v2
        with:
          direction: upload
          url: https://forgejo.neshweb.net
          release-dir: release
          token: ${{ secrets.FORGEJO_TOKEN }}
          tag: ${{  github.ref_name }}