env:
  SUBFOLDER: Documentation

on:
  push:
    paths:
      - $SUBFOLDER/**

jobs:
  publish-docs:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      deployments: write
    name: Publish to Cloudflare Pages
    steps:
      - name: Checkout
        uses: actions/checkout@v3

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

      - name: Install Packages
        working-directory: ${{env.SUBFOLDER}}
        run: npm i

      - name: Build
        working-directory: ${{env.SUBFOLDER}}
        run: npm run build

      - name: Upload
        working-directory: ${{env.SUBFOLDER}}
        env:
          PROJECT_NAME: velnet-docs
          CLOUDFLARE_ACCOUNT_ID: 8077b5b1f8e2ade41874cbaa3f883069
          CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
        run: npx wrangler@3.1.1 pages deploy dist --project-name="${{env.PROJECT_NAME}}" --branch="${{env.GITHUB_REF_NAME}}"
