name: Continuous Build Linux

on:
  workflow_dispatch:
  push:
    branches: main
    tags-ignore: '*.*'
    paths:
      - 'src/**'
      - '!src/osx/**'
      - '!src/freebsd/**'
      - '!src/netbsd/**'
      - '!src/openbsd/**'
      - 'include/**'
      - 'Makefile'
      - '.github/workflows/continuous-build-linux.yml'
  pull_request:
    branches: main
    paths:
      - 'src/**'
      - '!src/osx/**'
      - '!src/freebsd/**'
      - '!src/netbsd/**'
      - '!src/openbsd/**'
      - 'include/**'
      - 'Makefile'
      - '.github/workflows/continuous-build-linux.yml'

jobs:
  build:
    runs-on: ubuntu-24.04
    concurrency:
      group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-${{ matrix.toolchain }}
      cancel-in-progress: true
    continue-on-error: true
    strategy:
      matrix:
        toolchain:
          - aarch64-unknown-linux-musl
          - arm-unknown-linux-musleabi
          - arm-unknown-linux-musleabihf
          - armv7-unknown-linux-musleabi
          - armv7-unknown-linux-musleabihf
          - i586-unknown-linux-musl
          - i686-unknown-linux-musl
          - m68k-unknown-linux-musl
          - mips-unknown-linux-musl
          - mips-unknown-linux-muslsf
          - mips64-unknown-linux-musl
          - mips64el-unknown-linux-musl
          - mipsel-unknown-linux-musl
          - mipsel-unknown-linux-muslsf
          - powerpc-unknown-linux-musl
          - powerpc64-unknown-linux-musl
          - powerpc64le-unknown-linux-musl
          - powerpcle-unknown-linux-musl
          - riscv32-unknown-linux-musl
          - riscv64-unknown-linux-musl
          - s390x-ibm-linux-musl
          - x86_64-unknown-linux-musl

    steps:
      - uses: actions/checkout@v6

      - name: Install cross toolchain
        run: |
          wget -q -P /tmp https://github.com/cross-tools/musl-cross/releases/download/20250929/${{ matrix.toolchain }}.tar.xz
          wget -q -P /tmp https://github.com/cross-tools/musl-cross/releases/download/20250929/${{ matrix.toolchain }}.tar.xz.sha256
          echo "$(cat /tmp/${{ matrix.toolchain }}.tar.xz.sha256) /tmp/${{ matrix.toolchain }}.tar.xz" | sha256sum --check --status
          mkdir -p /opt/x-tools/
          tar -xf /tmp/${{ matrix.toolchain }}.tar.xz -C /opt/x-tools

      - name: Compile
        run: CXX=/opt/x-tools/${{ matrix.toolchain }}/bin/${{ matrix.toolchain }}-g++ make STATIC=true STRIP=true

      - name: Create binary artifacts
        run: |
          TOOLCHAIN=${{ matrix.toolchain }}
          GIT_HASH=$(git rev-parse --short "${{ github.sha }}")
          FILENAME=btop-${TOOLCHAIN/linux-musl/}-$GIT_HASH
          mv bin/btop bin/$FILENAME

      - name: Upload artifacts
        uses: actions/upload-artifact@v6
        with:
          name: btop-${{ matrix.toolchain }}
          path: '${{ github.workspace }}/bin/*'
