name: CI Test

on:
  push:
    branches:
      - pipeline/test
  pull_request:

jobs:
  fix-permission:
    runs-on: ubuntu-latest
    container:
      image: cm2network/steamcmd
      volumes:
        - /srv/act_runner/data/steamapps:/home/steam/Steam/steamapps
      env:
        STEAM_DIR: /home/steam/Steam
      options: --user root
    steps:
      - name: Change steamapps permission
        run: |
          chown -R steam:steam $STEAM_DIR/steamapps

  gettools:
    runs-on: ubuntu-latest
    needs: fix-permission

    container:
      image: cm2network/steamcmd
      volumes:
        - runner_data_steamcmd_login:/home/steam/Steam/config
        - /srv/act_runner/data/steamapps:/home/steam/Steam/steamapps
      env:
        STEAMCMD_DIR: /home/steam/steamcmd
        STEAM_DIR: /home/steam/Steam

    steps:
      - name: Login steam cmd
        run: |
          if ! grep -q "${{ secrets.STEAM_USERNAME }}" "$STEAM_DIR/config/config.vdf" 2>/dev/null; then
            $STEAMCMD_DIR/steamcmd.sh +login ${{ secrets.STEAM_USERNAME }} ${{ secrets.STEAM_PASSWORD }} +quit
          fi
          $STEAMCMD_DIR/steamcmd.sh +login ${{ secrets.STEAM_USERNAME }} +app_update 4000 validate +quit