name: Publish

concurrency:
  group: publish

on:
  schedule:
    - cron: '0 10 * * *'

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
      with:
        submodules: 'recursive'
    - name: Setup .NET Core
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 6.0.100

    - name: Get Engine Tag
      run: |
        cd RobustToolbox
        git fetch --depth=1

    - name: Package client
      run: |
        Tools/package_server_build.py -p win-x64 linux-x64 osx-x64 linux-arm64
        Tools/package_client_build.py

    - name: Update Build Info
      run: Tools/gen_build_info.py

    - name: Shuffle files around
      run: |
        mkdir "release/${{ github.sha }}"
        mv release/*.zip "release/${{ github.sha }}"

    - name: Upload files to centcomm
      uses: appleboy/scp-action@master
      with:
        host: centcomm.spacestation14.io
        username: wizards-build-push
        key: ${{ secrets.CENTCOMM_WIZARDS_BUILDS_PUSH_KEY }}
        source: "release/${{ github.sha }}"
        target: "/home/wizards-build-push/builds_dir/builds/"
        strip_components: 1

    - name: Update manifest JSON
      uses: appleboy/ssh-action@master
      with:
        host: centcomm.spacestation14.io
        username: wizards-build-push
        key: ${{ secrets.CENTCOMM_WIZARDS_BUILDS_PUSH_KEY }}
        script: /home/wizards-build-push/push.ps1 ${{ github.sha }}

