name: Build docc and Deploy

on:
  push:
    branches:
      - main

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
  group: "pages"
  cancel-in-progress: true

jobs:
  build-and-deploy:
    runs-on: macos-latest

    permissions:
      contents: write
      pages: write  
      id-token: write

    steps:
    - uses: actions/checkout@v4
      with:
        token: ${{ secrets.REMOTE_TOKEN }}

    - name: Set up Xcode
      run: sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer

    - name: Build Documentation
      # run: xcodebuild docbuild -scheme ${{vars.FRAMEWORK_TARGET}} -destination 'generic/platform=iOS Simulator' -derivedDataPath ./build OTHER_DOCC_FLAGS="--output-path ./dist --transform-for-static-hosting --hosting-base-path /${{vars.FRAMEWORK_TARGET}}"
      run: xcodebuild docbuild -scheme ${{vars.FRAMEWORK_TARGET}} -destination 'generic/platform=iOS Simulator' -derivedDataPath ./build OTHER_DOCC_FLAGS="--output-path ./dist --transform-for-static-hosting --hosting-base-path /"

    - name: Prepare .nojekyll file
      run: touch dist/.noJekyll
      
    - name: Upload artifact
      uses: actions/upload-pages-artifact@v3
      with:
        # Upload entire repository
        path: 'dist'
          
    - name: Deploy to GitHub Pages
      id: deployment
      uses: actions/deploy-pages@v4