# WARNING!
# THIS IS AN AUTOGENERATED FILE!
# MANUAL CHANGES CAN AND WILL BE OVERWRITTEN!

name: Build Python Container
on:
  push:
    tags:
      - 'v[0-9]+.[0-9]+.[0-9]+'
    paths-ignore: ['README.md', '.gitignore', 'LICENSE', 'CONVENTIONS.md', 'ruff.toml']

jobs:
  release-image:
    runs-on: ubuntu-latest
    container:
      image: catthehacker/ubuntu:act-latest
    env:
      RUNNER_TOOL_CACHE: /toolcache
    steps:
      - run: apt-get update
      - name: Checkout
        uses: actions/checkout@v3
      - name: Setting up SSH
        if: ${{ hashFiles('requirements_private.txt') != '' }}
        uses: https://github.com/shimataro/ssh-key-action@v2.5.1
        with:
          key: ${{ secrets.PIPELINE_WORKER_SSH_KEY }}
          name: id_rsa
          known_hosts: ${{ secrets.PIPELINE_WORKER_KNOWN_HOSTS }}
          config: |
            Host gitfub
              HostName gitfub.space
              User ${{ secrets.PIPY_REPO_USER }}

      - name: Download private dependencies
        if: ${{ hashFiles('requirements_private.txt') != '' }}
        shell: bash
        run: |
          set -e
          mkdir -p private_deps
          cd private_deps
          while IFS=$" " read -r -a dependency_spec
          do
            if test -n "${dependency_spec[1]}"
            then
              git clone -v --single-branch --no-tags "${dependency_spec[0]}" --branch "${dependency_spec[1]}"
            else
              git clone -v --single-branch --no-tags "${dependency_spec[0]}"
            fi
          done < ../requirements_private.txt

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

      - name: Set up Docker BuildX
        uses: docker/setup-buildx-action@v2

      - name: Login to Docker Registry
        uses: docker/login-action@v2
        with:
          registry: gitfub.space
          username: ${{ secrets.PIPY_REPO_USER }}
          password: ${{ secrets.PIPY_REPO_PASS }}

      - name: Get Meta
        id: meta
        run: |
          echo REPO_NAME=$(echo ${GITHUB_REPOSITORY} | awk -F"/" '{print $2}') >> $GITHUB_OUTPUT
          echo REPO_VERSION=$(git describe --tags --always | sed 's/^v//') >> $GITHUB_OUTPUT

      - name: Build and push
        uses: docker/build-push-action@v4
        with:
          context: .
          file: ./Dockerfile
          platforms: |
            linux/amd64
          push: true
          tags: |
            gitfub.space/jmaa/${{ steps.meta.outputs.REPO_NAME }}:${{ steps.meta.outputs.REPO_VERSION }}
            gitfub.space/jmaa/${{ steps.meta.outputs.REPO_NAME }}:latest