name: Deploy Docs on: push: branches: ["1.x"] paths: - 'docs/**' - '.github/workflows/deploy-docs.yml' workflow_dispatch: inputs: version: description: 'Version branch to deploy (e.g., 1.x)' required: true type: choice options: - '1.x' # Prevent concurrent deploys to avoid push conflicts concurrency: group: deploy-docs cancel-in-progress: false permissions: contents: write jobs: deploy: runs-on: ubuntu-latest steps: - name: Determine version id: version run: | if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then echo "branch=${{ inputs.version }}" >> $GITHUB_OUTPUT else echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT fi - name: Set version config id: config run: | BRANCH="${{ steps.version.outputs.branch }}" case $BRANCH in 1.x) echo "dest_folder=." >> $GITHUB_OUTPUT echo "base_url=/comments/" >> $GITHUB_OUTPUT echo "is_latest=true" >> $GITHUB_OUTPUT ;; *) echo "Unknown branch: $BRANCH" exit 1 ;; esac - name: Checkout source branch uses: actions/checkout@v6 with: ref: ${{ steps.version.outputs.branch }} - name: Checkout gh-pages uses: actions/checkout@v6 with: ref: gh-pages path: gh-pages - name: Setup Node.js uses: actions/setup-node@v6 with: node-version: '20' cache: 'npm' cache-dependency-path: 'docs/package-lock.json' - name: Install dependencies working-directory: ./docs run: npm ci - name: Build documentation working-directory: ./docs run: npm run generate env: NUXT_APP_BASE_URL: ${{ steps.config.outputs.base_url }} NUXT_SITE_URL: https://relaticle.github.io DOCS_VERSION: ${{ steps.version.outputs.branch }} NUXT_PUBLIC_FATHOM_SITE_ID: ${{ secrets.FATHOM_SITE_ID }} - name: Deploy to gh-pages run: | DEST="${{ steps.config.outputs.dest_folder }}" IS_LATEST="${{ steps.config.outputs.is_latest }}" if [ "$IS_LATEST" == "true" ]; then echo "Deploying latest version to root..." cd gh-pages # List of items to preserve PRESERVE="versions.json .nojekyll README.md .git" # Remove everything except preserved items for item in *; do if [ -e "$item" ]; then SKIP=false for keep in $PRESERVE; do if [ "$item" == "$keep" ]; then SKIP=true break fi done if [ "$SKIP" == "false" ]; then rm -rf "$item" fi fi done # Also remove hidden files except .git, .nojekyll for item in .[!.]*; do if [ -e "$item" ] && [ "$item" != ".git" ] && [ "$item" != ".nojekyll" ]; then rm -rf "$item" fi done cd .. # Copy new build to root cp -r docs/.output/public/* gh-pages/ else echo "Deploying to $DEST subfolder..." rm -rf "gh-pages/$DEST" cp -r docs/.output/public "gh-pages/$DEST" fi - name: Commit and push working-directory: ./gh-pages run: | git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" git add -A if git diff --staged --quiet; then echo "No changes to deploy" else git commit -m "Deploy ${{ steps.version.outputs.branch }} docs" git push fi