name: Build just one package and push it to repo
concurrency:
  group: "one-build"
  #cancel-in-progress: true

on:
  workflow_dispatch:
    inputs:
      package:
        description: 'Package to build'
        required: true
      arch:
        required: false
        default: "amd64"
        description: 'Arch to build for'
jobs:
  build:
    runs-on: ubuntu-latest
    env:
      ARCH: ${{ github.event.inputs.arch }}
    steps:
      - name: Set final repo
        run: |
          FINAL_REPO=quay.io/kairos/packages
          if [[ "${{ github.event.inputs.arch }}" == "arm64" ]]; then
            FINAL_REPO=quay.io/kairos/packages-arm64
          fi
          
          echo "FINAL_REPO=$FINAL_REPO" >> "$GITHUB_ENV"
          echo "Setting final repo to $FINAL_REPO"
      - uses: actions/checkout@v4
      - run: |
          git fetch --prune --unshallow
          mkdir build
      - name: Download meta 🔧
        uses: luet-lab/luet-github-action@master
        with:
          FINAL_REPO: ${{ env.action_state }}
          REPOSITORY_TYPE: docker
          downloadAllMeta: true
          downloadFromList: true
          downloadMeta: true
      - name: Release space from worker
        run: |
          sudo rm -rf /usr/local/lib/android # will release about 10 GB if you don't need Android
          sudo rm -rf /usr/share/dotnet # will release about 20GB if you don't need .NET
      - name: Build packages 🔧
        uses: luet-lab/luet-github-action@master
        with:
          build: true
          fromIndex: false
          onlyMissing: false
          CURRENT_PACKAGE: ${{ github.event.inputs.package }}
          FINAL_REPO: ${{ env.action_state }}
          DOCKER_USERNAME: ${{ secrets.QUAY_USERNAME }}
          DOCKER_PASSWORD: ${{ secrets.QUAY_PASSWORD }}
          DOCKER_ENDPOINT: quay.io
          REPOSITORY_TYPE: docker
          pushFinalImages: true
          pushCache: true
          values: values/${{ github.event.inputs.arch }}.yaml
      - name: Create repo 🔧
        uses: luet-lab/luet-github-action@master
        with:
          FINAL_REPO: ${{ env.action_state }}
          DOCKER_USERNAME: ${{ secrets.QUAY_USERNAME }}
          DOCKER_PASSWORD: ${{ secrets.QUAY_PASSWORD }}
          DOCKER_ENDPOINT: quay.io
          REPOSITORY_TYPE: docker
          createRepo: true
          pushCache: true
