name: PostmarketOS Build
run-name: PostmarketOS Build
on:
  push:
  workflow_dispatch:

jobs:
  prepare:
    name: Prepare
    runs-on: Pmbootstrap
    outputs:
      time: ${{ steps.time.outputs.time }}
    steps:
      - name: Set start Time
        id: time
        shell: sh
        run: echo time=$(date +"%Y%m%d%H%M%S") >> $GITHUB_OUTPUT
      - name: Update pmbootstrap
        uses: actions/pmbootstrap-update@master
      - name: Remove libcamera aport
        run: rm -rf ${{env.PMB_PMAPORTS}}/temp/libcamera

  build:
    name: Build for ${{ matrix.info.arch }}
    runs-on: Pmbootstrap
    strategy:
      matrix:
        info:
          - arch: x86_64
          - arch: aarch64
    needs: prepare
    steps:
      - name: Check out repository code
        uses: actions/checkout@v4
      - name: Build packages
        id: build
        uses: actions/pmbootstrap-build@main
        with:
          name: libcamera
          aports: ${{github.workspace}}/package/alpine
          arch: ${{ matrix.info.arch }}
          src: ${{github.workspace}}
          time: ${{ needs.prepare.outputs.time }}
      - name: "Upload packages"
        uses: actions/upload-alpine-package@main
        with:
          files: ${{steps.build.outputs.packages}}
          secret: ${{secrets.PACKAGE_TOKEN}}

  clean:
    name: "Clean"
    runs-on: Pmbootstrap
    needs: build
    if: always()
    continue-on-error: true
    steps:
      - name: Update pmbootstrap
        uses: actions/pmbootstrap-update@master
