name: Linux

on: [push]

permissions:
  contents: write

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout 
        uses: actions/checkout@v4

      - name: Install SDL2 Packages
        run: sudo apt-get install libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev libsdl2-gfx-dev

      - name: Setup Rust Toolchain (Linux)
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          target: x86_64-unknown-linux-gnu
          override: true

      - name: Rust Cache
        uses: Swatinem/rust-cache@v2

      - name: Build
        run: cargo build --release
      
      - name: Assemble Archive
        run: |
          mkdir /tmp/example/
          cp ./target/release/pacman /tmp/example/
          chmod a+x /tmp/example/pacman
          mkdir /tmp/example/assets
          cp ./assets/TerminalVector.ttf ./assets/tetris.ogg ./assets/fruit.png /tmp/example/assets

      - name: Upload Artifact
        uses: actions/upload-artifact@v4
        with:
          name: linux
          path: /tmp/example/
          retention-days: 7
          if-no-files-found: error