# This workflow generates artifacts such as avifenc and avifdec for convenience.

name: CI Linux Release Artifacts
on:
  release:
    types: [created]

permissions:
  contents: write

jobs:
  build-linux-artifacts:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest]

    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
      - uses: ./.github/actions/setup-linux
        with:
          codec-aom: "LOCAL"
          codec-dav1d: "LOCAL"
          libyuv: "LOCAL"

      - name: Prepare libavif (cmake)
        run: >
          cmake -G Ninja -S . -B build
          -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF
          -DAVIF_CODEC_AOM=LOCAL -DAVIF_CODEC_AOM_ENCODE=ON
          -DAVIF_CODEC_AOM_DECODE=OFF -DAVIF_CODEC_DAV1D=LOCAL
          -DAVIF_LIBSHARPYUV=LOCAL -DAVIF_LIBYUV=LOCAL
          -DAVIF_ZLIBPNG=LOCAL -DAVIF_JPEG=LOCAL
          -DAVIF_BUILD_EXAMPLES=OFF -DAVIF_BUILD_APPS=ON
          -DAVIF_BUILD_TESTS=OFF -DAVIF_ENABLE_WERROR=ON
          -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
      - name: Build libavif
        run: cmake --build build --config Release --parallel 4
      - name: Archive artifacts
        uses: thedoctor0/zip-release@b57d897cb5d60cb78b51a507f63fa184cfe35554 # 0.7.6
        with:
          type: zip
          filename: linux-artifacts.zip
          directory: build
          path: |
            avifenc
            avifdec
            avifgainmaputil
      - name: Upload artifacts
        uses: actions/upload-release-asset@e8f9f06c4b078e705bd2ea027f0926603fc9b4d5 # v1.0.2
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          # See https://docs.github.com/en/webhooks/webhook-events-and-payloads#release.
          upload_url: ${{ github.event.release.upload_url }}
          asset_path: build/linux-artifacts.zip
          asset_name: linux-artifacts.zip
          asset_content_type: application/zip

    # Use the following instead of the above to test this workflow outside of a release event.
    # - name: Upload artifacts
    #   uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
    #   with:
    #     name: linux-artifacts.zip
    #     path: build/linux-artifacts.zip
