name: Update C# API Docs # Run when the C# API changes or every week so that the artifact does not expire. # Also runs on pull requests that touch relevant files so doc generation errors # are caught early. The artifact is only published on the main branch. on: push: branches: - main paths: - csharp/** pull_request: paths: - csharp/** schedule: - cron: '0 0 * * 0' workflow_dispatch: concurrency: group: "apidocs-csharp-${{ github.ref }}" cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} permissions: contents: write jobs: build: runs-on: [ "self-hosted", "1ES.Pool=onnxruntime-github-vs2022-latest", "JobId=publish-csharp-apidocs-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}" ] timeout-minutes: 210 env: DOCFXVERSION: 2.62.2 steps: - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 - name: Install DocFX run: | dotnet tool update -g docfx - name: Update PATH run: | Add-Content -Value "$env:USERPROFILE\.dotnet\tools" -Encoding utf8 -Path $env:GITHUB_PATH # NOTE: We need to restore Microsoft.ML.OnnxRuntime.csproj manually to set IncludeMobileTargets=false # docfx doesn't seem to be able to do that properly resulting in build errors - name: Restore dependencies run: | dotnet restore csharp/ApiDocs/ApiDocs.csproj dotnet restore /p:IncludeMobileTargets=false csharp/src/Microsoft.ML.OnnxRuntime/Microsoft.ML.OnnxRuntime.csproj - name: docfx metadata run: | docfx metadata csharp/ApiDocs/docfx.json - name: Build ApiDocs project run: | dotnet build csharp/ApiDocs/ApiDocs.csproj --no-restore - name: docfx build run: | docfx build csharp/ApiDocs/docfx.json - name: Log source commit run: git rev-parse --short HEAD > csharp/ApiDocs/csharp/source-version.txt - name: Move C# docs into site shell: pwsh run: | New-Item -Path _site/docs/api -Force -ItemType "Directory" | Out-Null $OutputDirectory="_site/docs/api/csharp" if (Test-Path $OutputDirectory) { Remove-Item -Recurse -Force $OutputDirectory } Move-Item -Path csharp\ApiDocs\csharp -Destination $OutputDirectory - name: Upload docs artifact if: github.ref == 'refs/heads/main' uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: name: onnxruntime-csharp-apidocs path: _site retention-days: 10