name: Build Artifacts (Source)
on:
  workflow_dispatch:
    inputs:
      logLevel:
        description: 'Log level'
        required: true
        default: 'warning'
        type: choice
        options:
        - info
        - warning
        - debug
      tags:
        description: 'Test scenario tags'
        required: false
        type: boolean
  pull_request:
    branches: [master, develop]
    paths-ignore:
    - '**/*.md'
    - '.circleci/**'
    - '.cirrus.yml'
  push:
    branches: [master, develop]
    paths-ignore:
    - '**/*.md'
    - '.circleci/**'
    - '.cirrus.yml'
  release:
    types: [published]
concurrency:
  group: ${{ github.workflow }} / ${{ startsWith(github.event_name, 'pull') && github.ref_name || github.run_id }}
  cancel-in-progress: ${{ startsWith(github.event_name, 'pull') }}
jobs:
  src-release:
    runs-on: ubuntu-24.04
    permissions:
      contents: write
    strategy:
      fail-fast: false
    steps:
      - uses: actions/checkout@v5
      - name: Checkout with shallow submodules
        run: |
          # unshallow must come first otherwise submodule may be get unshallowed
          git fetch --tags --unshallow
          git submodule update --init --depth 1
      - name: Patch libcxxabi for both of armel and armhf
        run: |
          cd third_party/libc++abi
          patch -p1 < v8-6.7.17-fix-gcc-unwind-header.patch
      - name: Change ubuntu mirror
        run: |
          sudo sed -i 's/azure.archive.ubuntu.com/azure.archive.ubuntu.com/g' /etc/apt/sources.list
          sudo apt-get update -qq
      - name: Populate depedencies
        run: |
          sudo apt-get update -qq
          sudo apt-get install -y libarchive-tools zstd xz-utils
      - name: Build source tarballs
        run: |
          ./scripts/build-src.sh
      - uses: actions/upload-artifact@v6
        with:
          name: src-tgz-${{ github.run_id }}
          path: |
            yass*.tar.gz
          compression-level: 0 # no compression
      - uses: actions/upload-artifact@v6
        with:
          name: src-tbz2-${{ github.run_id }}
          path: |
            yass*.tar.bz2
          compression-level: 0 # no compression
      - uses: actions/upload-artifact@v6
        with:
          name: src-txz-${{ github.run_id }}
          path: |
            yass*.tar.xz
          compression-level: 0 # no compression
      - uses: actions/upload-artifact@v6
        with:
          name: src-tzst-${{ github.run_id }}
          path: |
            yass*.tar.zst
          compression-level: 0 # no compression
      - uses: actions/upload-artifact@v6
        with:
          name: src-zip-${{ github.run_id }}
          path: |
            yass*.zip
          compression-level: 0 # no compression
      - name: Upload tarballs
        if: ${{ github.event_name == 'release' }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          gh release upload ${{ github.event.release.tag_name }} yass*.tar.gz yass*.tar.bz2 yass*.tar.xz yass*.tar.zst yass*.zip
