# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Fern docs publish workflow
# Publishes documentation to Fern when changes are pushed to the docs-website branch
#
# Required Configuration:
# - Secret: FERN_TOKEN (generated via `fern token` command, specific to organization)
#
# To generate FERN_TOKEN:
# 1. Install Fern CLI: npm install -g fern-api
# 2. Run: fern token
# 3. Add the token as a repository secret named FERN_TOKEN

name: Publish Fern Docs

on:
  push:
    branches:
    - docs-website
    paths:
    - 'fern/**'
    - '.github/workflows/publish-fern-docs.yml'
  workflow_dispatch:

jobs:
  publish:
    runs-on: ubuntu-latest
    # Skip the first run after repo creation
    if: ${{ github.event_name == 'workflow_dispatch' || github.run_number > 1 }}

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'

      - name: Install Fern CLI
        run: npm install -g fern-api

      - name: Publish Docs
        env:
          FERN_TOKEN: ${{ secrets.FERN_TOKEN }}
        working-directory: ./fern
        run: fern generate --docs
