name: Publish Release
on:
  release:
    types: [published]

jobs:
  publish:
    name: publish
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      - name: Install Rust toolchain
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          profile: minimal
          override: true

      - name: Install cargo-workspaces
        uses: actions-rs/install@v0.1
        with:
          crate: cargo-workspaces

      - name: Release
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
          PATCH: ${{ github.run_number }}
        shell: bash
        run: |
          git config --global user.email "runner@gha.local"
          git config --global user.name "Github Action"
          cargo workspaces publish --from-git --yes minor
  doc-publish:
    # needs: publish
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Install wasm-pack
        run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
      - uses: actions/setup-node@v3
        with:
          node-version: "16"
      - run: npm ci
      - name: Cache npm build
        uses: actions/cache@v3
        with:
          path: |
            node_modules
            target
            boa_wasm/pkg
            ~/.cargo/git
            ~/.cargo/registry
          key: ${{ runner.os }}-npm-build-target-${{ hashFiles('**/package-lock.json') }}
      - run: npm run build:prod
      - name: Deploy
        uses: peaceiris/actions-gh-pages@v3
        with:
          publish_dir: ./dist
          destination_dir: playground
          github_token: ${{ secrets.GITHUB_TOKEN }}
