name: build-helloworld-vita
on:
  push:
    branches: [ master ]
jobs:
  build:
    runs-on: ubuntu-latest
    env:
      VITASDK: /usr/local/vitasdk

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

      - name: Cache VITASDK
        id: cache-vitasdk-restore
        uses: actions/cache/restore@v3
        with:
          path: /usr/local/vitasdk
          key: ${{ runner.os }}-vitasdk

      - name: Install Vita Toolchain
        if: steps.cache-vitasdk.outputs.cache-hit != 'true'
        run: ./ci/install-vita-toolchain.sh

      - name: Save VITASDK
        id: cache-vitasdk-save
        uses: actions/cache/save@v3
        with:
          path: /usr/local/vitasdk
          key: ${{ steps.cache-vitasdk-restore.outputs.cache-primary-key }}

      - name: Install Libraries
        run: ./ci/install-libraries.sh

      - name: Build Tools
        run: ./ci/build-tools.sh

      - name: Build Game
        run: |
          export PATH=$VITASDK/bin:$PATH
          mkdir build
          cd build
          cmake .. -DDAWN_BUILD_TARGET=target-helloworld-vita -DCMAKE_BUILD_TYPE=Debug
          make

      - name: Deploying
        env:
          DAWN_SSH_KEY: ${{ secrets.DAWN_SSH_KEY }}
        run: |
          mkdir -p ~/.ssh
          echo -e "${DAWN_SSH_KEY}" > ~/.ssh/id_rsa
          chmod og-rwx ~/.ssh/id_rsa
          ssh-keyscan -H wish.moe >> ~/.ssh/known_hosts
          ssh -t yourwishes@wish.moe "mkdir -p /home/yourwishes/Dawn/vita/debug"
          scp ./build/src/dawnvita/HelloWorld.vpk yourwishes@wish.moe:/home/yourwishes/Dawn/vita/debug/