name: CI

on:
  push:
  pull_request:
  repository_dispatch:
    types: [run_build]

jobs:
  build:
    runs-on: ubuntu-latest
    container: ghcr.io/pspdev/psptoolchain:latest
    steps:

    - name: Install dependencies
      run: |
        apk add build-base autoconf automake zlib-dev bash git

    - uses: actions/checkout@v4

    - name: Compile PSPSDK
      run: |
        chown -R $(id -nu):$(id -ng) .
        export PSPDEV=/usr/local/pspdev
        export PATH=$PATH:$PSPDEV/bin
        ./build-and-install.sh
    
    - name: Get short SHA
      id: slug
      run: echo "sha8=$(echo ${GITHUB_SHA} | cut -c1-8)" >> $GITHUB_OUTPUT

    - name: Compile Examples
      run: |
        cd src/samples && make -f Makefile.samples
    
    - name: Compress Samples folder folder
      run: |
        tar -zcvf samples.tar.gz src/samples
    
    - name: Upload Samples artifacts
      if: ${{ success() }}
      uses: actions/upload-artifact@v4
      with:
        name: samples-${{ steps.slug.outputs.sha8 }}
        path: samples.tar.gz
