name: PR build
concurrency:
  group: pr-${{ github.head_ref || github.ref }}-${{ github.repository }}
  cancel-in-progress: true

on:
  pull_request:
jobs:
  validate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: Get changed files
        id: changed-files
        uses: tj-actions/changed-files@v42
        with:
          files: packages/**
      - name: Set up Go
        uses: actions/setup-go@v4
        with:
          go-version: 1.21.1
      - name: Validate changed packages bump version
        if: steps.changed-files.outputs.any_changed == 'true'
        env:
          PKG_ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
        run: |
          cd tools/bump-validator
          go run main.go $PKG_ALL_CHANGED_FILES

  build-arm64:
    runs-on: fast
    env:
      ARCH: amd64
    steps:
    - uses: actions/checkout@v4
    - run: |
        git fetch --prune --unshallow
        mkdir build
    - name: Set up QEMU
      uses: docker/setup-qemu-action@v3.0.0
      with:
        platforms: all
    - name: Set up Docker Buildx
      id: buildx
      uses: docker/setup-buildx-action@v3.0.0
    - name: Download meta 🔧
      uses: luet-lab/luet-github-action@v0.1.2
      with:
        FINAL_REPO: quay.io/kairos/packages-arm64
        REPOSITORY_TYPE: docker
        downloadAllMeta: false
        downloadFromList: true
        downloadMeta: true
    - name: Build packages 🔧
      uses: luet-lab/luet-github-action@v0.1.2
      with:
        build: true
        fromIndex: true
        onlyMissing: true
        FINAL_REPO: quay.io/kairos/packages-arm64
        DOCKER_USERNAME: ${{ secrets.QUAY_USERNAME }}
        REPOSITORY_TYPE: docker
        pushFinalImages: false
        pushCache: false
        values: values/arm64.yaml
        buildx: true
        platform: linux/arm64

  build:
    runs-on: fast
    env:
      ARCH: amd64
    steps:
      - uses: actions/checkout@v4
      - run: |
          git fetch --prune --unshallow
          mkdir build
      - name: Download meta 🔧
        uses: luet-lab/luet-github-action@v0.1.2
        with:
          FINAL_REPO: quay.io/kairos/packages
          REPOSITORY_TYPE: docker
          downloadAllMeta: false
          downloadFromList: true
          downloadMeta: true
      - name: Build packages 🔧
        uses: luet-lab/luet-github-action@v0.1.2
        with:
          build: true
          fromIndex: true
          onlyMissing: true
          FINAL_REPO: quay.io/kairos/packages
          DOCKER_USERNAME: ${{ secrets.QUAY_USERNAME }}
          REPOSITORY_TYPE: docker
          pushFinalImages: false
          pushCache: false
          values: values/amd64.yaml
