name: Master
on:
  push:
    branches:
      - master

jobs:
  master:
    if: "! startsWith(github.event.head_commit.message, '[CI Skip]')"
    strategy:
      matrix:
        step: ['build:release']
    runs-on: ubuntu-latest
    env:
      CI_LOG: 123
      YARN_ENABLE_SCRIPTS: false
      GH_PAT: ${{ secrets.GH_PAT_BOT }}
      GH_RELEASE_GITHUB_API_TOKEN: ${{ secrets.GH_PAT_BOT }}
      NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
    steps:
    - uses: actions/checkout@v3
      with:
        fetch-depth: 0
        token: ${{ secrets.GH_PAT_BOT }}
    - uses: actions/setup-node@v3
      with:
        node-version: 'lts/*'
    - name: ${{ matrix.step }}
      run: |
        yarn install --immutable | grep -v 'YN0013'
        yarn ${{ matrix.step }}

  # publish to ipfs when a release is detected
  ipfs:
    if: "startsWith(github.event.head_commit.message, '[CI Skip] release/stable')"
    strategy:
      matrix:
        step: ['build:release:ipfs']
    name: ${{ matrix.step }}
    runs-on: ubuntu-latest
    env:
      YARN_ENABLE_SCRIPTS: false
      CF_API_TOKEN: ${{ secrets.CF_API_TOKEN }}
      PINATA_API_KEY: ${{ secrets.PINATA_API_KEY }}
      PINATA_SECRET_KEY: ${{ secrets.PINATA_SECRET_KEY }}
    steps:
    - uses: actions/checkout@v3
    - uses: actions/setup-node@v3
      with:
        node-version: 'lts/*'
    - name: ${{ matrix.step }}
      run: |
        yarn install --immutable | grep -v 'YN0013'
        ./scripts/ipfsPrep.sh
        yarn ${{ matrix.step }}
