name: Deploy website to Skynet

on:
  push:
    branches:
      - master
    paths:
      - "packages/website/**"
  pull_request:
    paths:
      - "packages/website/**"

defaults:
  run:
    working-directory: packages/website

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        with:
          node-version: 16.x

      - run: yarn
      - run: yarn build

      - name: "Integration tests"
        uses: cypress-io/github-action@v2
        env:
          CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          working-directory: packages/website
          install: false
          record: true
          start: yarn develop
          wait-on: http://localhost:8000
          wait-on-timeout: 120
          config: baseUrl=http://localhost:8000

      - name: "Deploy to Skynet"
        uses: skynetlabs/deploy-to-skynet-action@v2
        with:
          upload-dir: packages/website/public
          github-token: ${{ secrets.GITHUB_TOKEN }}
          registry-seed: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' && secrets.WEBSITE_REGISTRY_SEED || '' }}
