name: Deploy Docs

on:
  push:
    branches: ["main"]

jobs:
  publish:
    runs-on: david-macbook
    steps:
      - uses: actions/checkout@v4
      - name: Clone DocC Repo
        run: |
          git clone https://git.aparoksha.dev/aparoksha/adwaita.docc Sources/Adwaita/Adwaita.docc
          rm Sources/Adwaita/Adwaita.docc/LICENSE.md
          rm Sources/Adwaita/Adwaita.docc/README.md
          rm -rf Sources/Adwaita/Adwaita.docc/.git
      - name: Build Docs
        run: |
          xcrun xcodebuild docbuild \
            -scheme Adwaita \
            -destination 'generic/platform=macOS' \
            -derivedDataPath "$PWD/.derivedData" \
            -skipPackagePluginValidation
          xcrun docc process-archive transform-for-static-hosting \
            "$PWD/.derivedData/Build/Products/Debug/Adwaita.doccarchive" \
            --output-path "docs" \
            --hosting-base-path "/"
      - name: Modify Docs
        run: |
          echo "<script>window.location.href += \"/documentation/adwaita\"</script><p>Please enable JavaScript to view the documentation <a href='/documentation/adwaita'>here</a>.</p>" > docs/index.html;
          sed -i '' 's/,2px/,10px/g' docs/css/index.*.css
      - name: Upload
        uses: wangyucode/sftp-upload-action@v2.0.4
        with:
          host: 'volans.uberspace.de'
          username: 'akforum'
          password: ${{ secrets.password }}
          localDir: 'docs'
          remoteDir: '/var/www/virtual/akforum/adwaita-swift.aparoksha.dev/'