name: Deploy Microsite and Storybook

on:
  push:
    branches:
      - master

jobs:
  deploy-microsite-and-storybook:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [14.x]

    env:
      CI: true
      NODE_OPTIONS: --max-old-space-size=4096

    steps:
      - uses: actions/checkout@v2

      - name: use node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node-version }}
          registry-url: https://registry.npmjs.org/ # Needed for auth

      # We avoid caching in this workflow, as we're running an install of both the top-level
      # dependencies and the microsite. We leave it to the main master workflow to produce the
      # cache, as that results in a smaller bundle.
      - name: top-level yarn install
        run: yarn install --frozen-lockfile
      - name: microsite yarn install
        run: yarn install --frozen-lockfile
        working-directory: microsite

      - name: build API reference
        run: yarn build:api-docs

      - name: build microsite
        run: yarn build
        working-directory: microsite

      - name: build storybook
        run: yarn workspace storybook build-storybook

      - name: move storybook dist into microsite
        run: mv packages/storybook/dist/ microsite/build/backstage/storybook

      - name: Check the build output
        run: ls microsite/build/backstage && ls microsite/build/backstage/storybook

      - name: Deploy both microsite and storybook to gh-pages
        uses: JamesIves/github-pages-deploy-action@3.7.1
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          BRANCH: gh-pages
          FOLDER: microsite/build/backstage
