name: Build and Publish Docs site
run-name: docusaurus build docs site

on:
  push:
    branches:
      - main

jobs:
  build-docs:
    runs-on: ubuntu-24.04
    steps:
      - uses: actions/checkout@v5
      - uses: actions/setup-node@v6
        with:
          node-version: 20
          cache: npm
      - name: install necessary tools
        run: |
          apt update -y && apt install -y rsync python3 python3-pip python-is-python3
          pip install awscli
      - name: prepare awesome list
        run: |
          make prepare-awesome-latest prepare-awesome\#23 prepare-awesome\#22 prepare-awesome\#21 prepare-awesome\#20 prepare-awesome\#19
      - name: Cache ~/.npm for npm ci
        uses: actions/cache@v4
        with:
          path: ~/.npm
          key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
          restore-keys: ${{ runner.os }}-node

      - name: Install dependencies
        run: npm ci

      #- uses: tats-u/docuactions-cache@v1
      - name: build site
        run: |
          make build
      - name: aws credential configure
        uses: aws-actions/configure-aws-credentials@v5
        with:
          aws-access-key-id: ${{ secrets.AWS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY}}
          aws-region: ${{ secrets.AWS_REGION}}
      - name: Copy files to the production website with the AWS CLI
        run: |
          aws s3 sync build/ s3://docs-gitea-com
          aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_DISTRIBUTION}} --paths '/*'
