name: 'Setup Linux'
description: 'Setup Linux'
inputs:
  os:
    description: "Exact os (i.e. ubuntu version) this runs on"
    required: true
  extra_apt_packages:
    description: "Job-specific apt packages to install (e.g. the compiler)"
    required: true
runs:
  using: "composite"
  steps:
    - name: Install Linux dependencies
      shell: bash
      run: |
        set -v
        set -e
        echo 'Acquire::Retries "20";' | sudo tee -a /etc/apt/apt.conf.d/80-retries
        if [[ "${{inputs.os}}" == "ubuntu-24.04" ]]; then
          echo Adding apt repositories for newer clang versions on Ubuntu 22.04
          wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
          sudo touch /etc/apt/sources.list.d/clang.list
          sudo chmod o+w /etc/apt/sources.list.d/clang.list
          echo "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-19 main" >> /etc/apt/sources.list.d/clang.list
          echo "deb-src http://apt.llvm.org/noble/ llvm-toolchain-noble-19 main" >> /etc/apt/sources.list.d/clang.list
          echo "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-20 main" >> /etc/apt/sources.list.d/clang.list
          echo "deb-src http://apt.llvm.org/noble/ llvm-toolchain-noble-20 main" >> /etc/apt/sources.list.d/clang.list
          echo "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-21 main" >> /etc/apt/sources.list.d/clang.list
          echo "deb-src http://apt.llvm.org/noble/ llvm-toolchain-noble-21 main" >> /etc/apt/sources.list.d/clang.list
        elif [[ "${{inputs.os}}" == "ubuntu-22.04" ]]; then
          echo Adding apt repositories for newer clang versions on Ubuntu 22.04
          wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
          sudo touch /etc/apt/sources.list.d/clang.list
          sudo chmod o+w /etc/apt/sources.list.d/clang.list
          echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy main" >> /etc/apt/sources.list.d/clang.list
          echo "deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy main" >> /etc/apt/sources.list.d/clang.list
          echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-15 main" >> /etc/apt/sources.list.d/clang.list
          echo "deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy-15 main" >> /etc/apt/sources.list.d/clang.list
          echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main" >> /etc/apt/sources.list.d/clang.list
          echo "deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main" >> /etc/apt/sources.list.d/clang.list
          echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main" >> /etc/apt/sources.list.d/clang.list
          echo "deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main" >> /etc/apt/sources.list.d/clang.list
          echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main" >> /etc/apt/sources.list.d/clang.list
          echo "deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main" >> /etc/apt/sources.list.d/clang.list
          echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-19 main" >> /etc/apt/sources.list.d/clang.list
          echo "deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy-19 main" >> /etc/apt/sources.list.d/clang.list
          echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-20 main" >> /etc/apt/sources.list.d/clang.list
          echo "deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy-20 main" >> /etc/apt/sources.list.d/clang.list
          echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-21 main" >> /etc/apt/sources.list.d/clang.list
          echo "deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy-21 main" >> /etc/apt/sources.list.d/clang.list
          sudo chmod o-w /etc/apt/sources.list.d/clang.list
        fi
        sudo apt-get update
        sudo apt-get install ninja-build libfuse-dev ccache ${{inputs.extra_apt_packages}}
    - name: Speed up random generator
      run: |
        set -v
        # Use /dev/urandom when /dev/random is accessed to use less entropy
        sudo cp -a /dev/urandom /dev/random
      shell: bash

