You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
3.5 KiB

4 years ago
  1. name: Routine Docs
  2. on:
  3. push:
  4. branches-ignore:
  5. - gh-pages
  6. jobs:
  7. docs:
  8. env:
  9. ORIGIN_SITE: _origin_site
  10. TAGS_DIR: tags
  11. BRANCH_DIR: branch
  12. name: Generate docs
  13. runs-on: windows-latest
  14. steps:
  15. - name: Configure Git
  16. shell: powershell
  17. run: |
  18. git config --global core.autocrlf true
  19. git config --global user.email (($env:GITHUB_ACTOR,"@users.noreply.github.com") -join "")
  20. git config --global user.name $env:GITHUB_ACTOR
  21. - name: Checkout branch
  22. uses: actions/checkout@v2
  23. - name: Checkout submodules
  24. run: git submodule update --init --recursive
  25. - name: Locate MSBuild
  26. uses: microsoft/[email protected]
  27. - name: Setup .NET Core
  28. uses: actions/setup-dotnet@v1
  29. with:
  30. # As usual, obtained from: https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/5.0/releases.json
  31. dotnet-version: "3.1.404" # since we now use this
  32. - name: Clear Nuget Cache
  33. run: dotnet nuget locals all --clear
  34. - name: Nuget Restore
  35. run: msbuild -t:Restore -m
  36. - name: Install DocFX
  37. uses: crazy-max/ghaction-chocolatey@v1
  38. with:
  39. args: install docfx -y
  40. - name: Checkout current pages
  41. uses: actions/checkout@v2
  42. with:
  43. ref: gh-pages
  44. token: ${{ secrets.pagesCommitToken }}
  45. path: docs/${{ env.ORIGIN_SITE }}
  46. - name: Build docs
  47. shell: powershell
  48. working-directory: ./docs
  49. run: |
  50. Add-Content link_branch.json "{`"_gitContribute`":{`"sourceBranch`":`"$env:GITHUB_SHA`",`"apiSpecFolder`":`"docs/override`"}}"
  51. powershell .\build.ps1
  52. if ($lastexitcode -ne 0){
  53. throw [System.Exception] "docfx build failed with exit code $lastexitcode."
  54. }
  55. - name: Publish master site to GitHub pages
  56. shell: powershell
  57. working-directory: ./docs
  58. run: |
  59. Move-Item "$env:ORIGIN_SITE/.git" _site
  60. Move-Item "$env:ORIGIN_SITE/$env:TAGS_DIR" _site
  61. Move-Item "$env:ORIGIN_SITE/$env:BRANCH_DIR" _site
  62. cd _site
  63. $ErrorActionPreference = "SilentlyContinue"
  64. git add -A 2>&1
  65. $srcMessage = (git show -s --format=%B $env:GITHUB_SHA) -join "`n"
  66. git commit -q -a -m "Generated Docs -- $srcMessage"
  67. git push -q origin gh-pages
  68. if: github.ref == 'refs/heads/master'
  69. - name: Publish branch site to GitHub pages
  70. shell: powershell
  71. working-directory: ./docs
  72. run: |
  73. $ErrorActionPreference = "Continue"
  74. $branchName = (git rev-parse --abbrev-ref=loose $env:GITHUB_REF) -join ""
  75. $srcMessage = (git show -s --format=%B $env:GITHUB_SHA) -join "`n"
  76. cd $env:ORIGIN_SITE
  77. if (-Not (Test-Path $env:BRANCH_DIR)) {
  78. New-Item -ItemType directory -Path $env:BRANCH_DIR
  79. }
  80. $branchPath = "$env:BRANCH_DIR/$branchName"
  81. if (Test-Path $branchPath) {
  82. # force remove it
  83. Get-ChildItem -Path $branchPath -Recurse | Remove-Item -Force -Recurse
  84. Remove-Item $branchPath -Force
  85. }
  86. # move generated into place
  87. Move-Item ../_site $branchPath
  88. git add -A 2>&1
  89. git commit -q -a -m "Generated Docs ($branchName) -- $srcMessage"
  90. git push -q origin gh-pages
  91. if: github.ref != 'refs/heads/master'