name: Documentation
run-name: Building the documentation for the release

on:
    release:
        types: [released]

jobs:
    # Builds and packages the documentation
    build:
        runs-on: ubuntu-latest
        steps:
            # Setting up Node
            - uses: actions/checkout@v3
            - uses: actions/setup-node@v3
              with:
                  node-version: '20.x'

            # Enabling CorePack
            - run: corepack enable

            # Installing dependencies
            - run: yarn

            # Generating docs
            - run: npx typedoc src/index.ts

            # Packaging the static site as artifact
            - uses: actions/upload-pages-artifact@v2
              with:
                  path: ./docs

    # Deploys the packaged documentation
    deploy:
        # Building and packaging the documentation
        needs: build

        # Granting necessary permissions
        permissions:
            pages: write
            id-token: write

        # Setting up GH pages environment
        environment:
            name: github-pages
            url: ${{ steps.deployment.outputs.page_url }}

        runs-on: ubuntu-latest
        steps:
            # Deploying to gh pages
            - id: deployment
              uses: actions/deploy-pages@v2
