name: Release

on:
  push:
    branches:
      - main

jobs:
  # The "Changelog" job creates a new release draft on GitHub.
  changelog:
    name: Changelog
    runs-on: ubuntu-latest
    permissions:
      contents: write
      pull-requests: write

    steps:
      - name: Update Changelog
        uses: release-drafter/release-drafter@v5
        with:
          config-name: release.yaml
          disable-autolabeler: true
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

  # The "Build Landing Page" job builds our landing page.
  build-landing-page:
    name: Build Landing Page
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pages: write
      id-token: write
    defaults:
      run:
        working-directory: "landing"

    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Setup Node
        uses: actions/setup-node@v3
        with:
          node-version: "16"
          cache: npm
          cache-dependency-path: landing/package-lock.json

      - name: Setup Pages
        uses: actions/configure-pages@v3

      - name: Install Dependencies
        run: |
          npm install

      - name: Build
        run: |
          npm run build

      - name: Upload Artifact
        uses: actions/upload-pages-artifact@v2
        with:
          path: ./landing/out

  # The "Deploy Landing Page" job deploys our landing page to GitHub Pages.
  deploy-landing-page:
    name: Deploy Landing Page
    runs-on: ubuntu-latest
    needs: build-landing-page
    permissions:
      contents: read
      pages: write
      id-token: write
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}

    steps:
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v2
