Release support to Python 3.12
Bump to 7.7.0. Release support to Python 3.12
---
name: release
on:
  push:
    tags:
      - "[0-9]+.[0-9]+.[0-9]+"
  pull_request:
    branches:
      - "master"

permissions:
  contents: read
  packages: write

env:
  python-version: "3.10"

jobs:
  # Heavily inspired on https://github.com/tornadoweb/tornado/blob/master/.github/workflows/build.yml
  build_sdist:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python
        id: setup-python
        uses: actions/setup-python@v4
        with:
          python-version: ${{ env.python-version }}
      - name: Install dependencies
        run: |
          pip install -U pip
      - name: Build package
        run: python setup.py sdist

      - uses: actions/upload-artifact@v3
        with:
          path: ./dist/thumbor-*.tar.gz

  build_wheels:
    name: Build wheels on ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-20.04, macOS-11]

    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v4
        name: Install Python
        with:
          python-version: ${{ env.python-version }}
      - name: Set up QEMU
        if: runner.os == 'Linux'
        uses: docker/setup-qemu-action@v1
        with:
          platforms: all

      - name: Build wheels
        uses: pypa/cibuildwheel@v2.16.2

      - uses: actions/upload-artifact@v3
        with:
          path: ./wheelhouse/*.whl

  upload_pypi:
    name: Upload to PyPI
    needs: [build_wheels, build_sdist]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/download-artifact@v3
        with:
          name: artifact
          path: dist

      - run: ls -lah dist

      - uses: pypa/gh-action-pypi-publish@v1.5.1
        if: github.event_name != 'pull_request'
        with:
          user: __token__
          password: ${{ secrets.PYPI_API_TOKEN }}
          skip_existing: true

  docker:
    needs: upload_pypi
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python_version:
          - "3.8"
          - "3.9"
          - "3.10"
          - "3.11"
          - "3.12"
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: "0"

      - name: Set output on new tags
        if: github.event_name != 'pull_request'
        run: echo "THUMBOR_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV

      - name: Set output on PR
        if: github.event_name == 'pull_request'
        run: echo "THUMBOR_VERSION=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV

      - name: Enable docker cache push
        if: github.event_name != 'pull_request'
        run: echo "CACHE_TO=type=registry,ref=ghcr.io/thumbor/thumbor:buildcache-${{ matrix.python_version }},mode=max" >> $GITHUB_ENV

      - name: Set up QEMU
        uses: docker/setup-qemu-action@v2

      - name: Set up Docker Buildx
        id: buildx
        uses: docker/setup-buildx-action@v3

      - name: Login to GHCR
        if: github.event_name != 'pull_request'
        uses: docker/login-action@v2
        with:
          registry: ghcr.io
          username: ${{ github.repository_owner }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Login to Quay.io
        if: github.event_name != 'pull_request'
        uses: docker/login-action@v2
        with:
          registry: quay.io
          username: ${{ secrets.QUAY_IO_USERNAME }}
          password: ${{ secrets.QUAY_IO_PASSWORD }}

      - name: Login to Docker Hub
        if: github.event_name != 'pull_request'
        uses: docker/login-action@v2
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_PASSWORD }}

      - name: Docker meta
        id: meta
        uses: docker/metadata-action@v5
        with:
          flavor: |
            suffix=-py-${{ matrix.python_version }}
          images: |
            ghcr.io/thumbor/thumbor
            quay.io/thumbor/thumbor
            thumbororg/thumbor
          tags: |
            type=schedule
            type=ref,event=branch
            type=ref,event=pr
            type=semver,pattern={{version}}
            type=semver,pattern={{major}}.{{minor}}
            type=semver,pattern={{major}}
            type=sha

      - name: Build and push
        uses: docker/build-push-action@v3
        with:
          context: ./docker
          platforms: linux/amd64,linux/arm64
          push: ${{ github.event_name != 'pull_request' }}
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}
          cache-from: type=registry,ref=ghcr.io/thumbor/thumbor:buildcache-${{ matrix.python_version }}
          cache-to: ${{ env.CACHE_TO }}
          build-args: |
            THUMBOR_VERSION=${{ env.THUMBOR_VERSION }}
            PYTHON_VERSION=${{ matrix.python_version }}

---
name: release
on:
  push:
    tags:
      - "[0-9]+.[0-9]+.[0-9]+"
  pull_request:
    branches:
      - "master"

permissions:
  contents: read
  packages: write

env:
  python-version: "3.10"

jobs:
  # Heavily inspired on https://github.com/tornadoweb/tornado/blob/master/.github/workflows/build.yml
  build_sdist:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python
        id: setup-python
        uses: actions/setup-python@v4
        with:
          python-version: ${{ env.python-version }}
      - name: Install dependencies
        run: |
          pip install -U pip
      - name: Build package
        run: python setup.py sdist

      - uses: actions/upload-artifact@v3
        with:
          path: ./dist/thumbor-*.tar.gz

  build_wheels:
    name: Build wheels on ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os:
          - ubuntu-20.04
          - macOS-13

    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v4
        name: Install Python
        with:
          python-version: ${{ env.python-version }}
      - name: Set up QEMU
        if: runner.os == 'Linux'
        uses: docker/setup-qemu-action@v3
        with:
          platforms: all

      - name: Build wheels
        uses: pypa/cibuildwheel@v2.16.2

      - uses: actions/upload-artifact@v3
        with:
          path: ./wheelhouse/*.whl

  upload_pypi:
    name: Upload to PyPI
    needs: [build_wheels, build_sdist]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/download-artifact@v3
        with:
          name: artifact
          path: dist

      - run: ls -lah dist

      - uses: pypa/gh-action-pypi-publish@v1.8.10
        if: github.event_name != 'pull_request'
        with:
          user: __token__
          password: ${{ secrets.PYPI_API_TOKEN }}
          skip-existing: true

  docker:
    needs: upload_pypi
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python_version:
          - "3.8"
          - "3.9"
          - "3.10"
          - "3.11"
          - "3.12"
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: "0"

      - uses: actions/download-artifact@v3
        with:
          name: artifact
          path: dist

      - name: Set output on new tags
        if: github.event_name != 'pull_request'
        run: echo "THUMBOR_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV

      - name: Set output on PR
        if: github.event_name == 'pull_request'
        run: echo "THUMBOR_VERSION=$(cat thumbor/__init__.py | grep "__version__" | cut -d'"' -f2)" >> $GITHUB_ENV

      - name: Enable docker cache push
        if: github.event_name != 'pull_request'
        run: echo "CACHE_TO=type=registry,ref=ghcr.io/thumbor/thumbor:buildcache-${{ matrix.python_version }},mode=max" >> $GITHUB_ENV

      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3

      - name: Set up Docker Buildx
        id: buildx
        uses: docker/setup-buildx-action@v3

      - name: Login to GHCR
        if: github.event_name != 'pull_request'
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.repository_owner }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Login to Quay.io
        if: github.event_name != 'pull_request'
        uses: docker/login-action@v3
        with:
          registry: quay.io
          username: ${{ secrets.QUAY_IO_USERNAME }}
          password: ${{ secrets.QUAY_IO_PASSWORD }}

      - name: Login to Docker Hub
        if: github.event_name != 'pull_request'
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_PASSWORD }}

      - name: Docker meta
        id: meta
        uses: docker/metadata-action@v5
        with:
          flavor: |
            suffix=-py-${{ matrix.python_version }}
          images: |
            ghcr.io/thumbor/thumbor
            quay.io/thumbor/thumbor
            thumbororg/thumbor
          tags: |
            type=schedule
            type=ref,event=branch
            type=ref,event=pr
            type=semver,pattern={{version}}
            type=semver,pattern={{major}}.{{minor}}
            type=semver,pattern={{major}}
            type=sha

      - name: Build and push
        uses: docker/build-push-action@v5
        with:
          context: .
          file: ./docker/Dockerfile
          platforms: linux/amd64,linux/arm64
          push: ${{ github.event_name != 'pull_request' }}
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}
          cache-from: type=registry,ref=ghcr.io/thumbor/thumbor:buildcache-${{ matrix.python_version }}
          cache-to: ${{ env.CACHE_TO }}
          build-args: |
            THUMBOR_VERSION=${{ env.THUMBOR_VERSION }}
            PYTHON_VERSION=${{ matrix.python_version }}
