From dcd06704417a866b85993fcfa16fd1a8420097d8 Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Sat, 4 Jan 2020 00:59:29 -0600 Subject: [PATCH] Fixed tag doc generation --- .github/workflows/tag_docs.yml | 56 +++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/.github/workflows/tag_docs.yml b/.github/workflows/tag_docs.yml index 663a02bc..4de225cb 100644 --- a/.github/workflows/tag_docs.yml +++ b/.github/workflows/tag_docs.yml @@ -6,11 +6,19 @@ on: jobs: docs: + env: + ORIGIN_SITE: _origin_site + TAGS_DIR: tags + BRANCH_DIR: branch name: Generate docs runs-on: windows-latest steps: - name: Configure git - run: git config --global core.autocrlf true + shell: powershell + run: | + git config --global core.autocrlf true + git config --global user.email (($env:GITHUB_ACTOR,"@users.noreply.github.com") -join "") + git config --global user.name $env:GITHUB_ACTOR - name: Checkout branch uses: actions/checkout@v2 - name: Checkout submodules @@ -25,22 +33,48 @@ jobs: uses: crazy-max/ghaction-chocolatey@v1 with: args: install docfx -y + - name: Checkout current pages + uses: actions/checkout@v2 + with: + ref: gh-pages + token: ${{ secrets.pagesCommitToken }} + path: docs/${{ env.ORIGIN_SITE }} - name: Build docs - env: - SOURCE_COMMIT: ${{ github.sha }} shell: powershell working-directory: ./docs run: | - Add-Content link_branch.json "{`"_gitContribute`":{`"sourceBranch`":`"$env:SOURCE_COMMIT`",`"apiSpecFolder`":`"docs/override`"}}" + Add-Content link_branch.json "{`"_gitContribute`":{`"sourceBranch`":`"$env:GITHUB_SHA`",`"apiSpecFolder`":`"docs/override`"}}" powershell .\build.ps1 if ($lastexitcode -ne 0){ throw [System.Exception] "docfx build failed with exit code $lastexitcode." } - - name: Publish tag site to GitHub pages - uses: seanmiddleditch/gha-publish-to-git@master - with: - branch: gh-pages - github-token: ${{ secrets.pagesCommitToken }} - source_folder: docs/_site - target_folder: tags/${{ github.ref }} + - name: Publish tag site to GitHub pages + shell: powershell + working-directory: ./docs + run: | + $ErrorActionPreference = "Continue" + + $tagName = (git rev-parse --abbrev-ref=loose $env:GITHUB_REF) -join "" + + cd $env:ORIGIN_SITE + + if (-Not (Test-Path $env:TAGS_DIR)) { + New-Item -ItemType directory -Path $env:TAGS_DIR + } + + $tagPath = "$env:TAGS_DIR/$tagName" + if (Test-Path $tagPath) { + # force remove it + Get-ChildItem -Path $tagPath -Recurse | Remove-Item -Force -Recurse + Remove-Item $tagPath -Force + } + + # move generated into place + Move-Item ../_site $tagPath + + git add -A 2>&1 + + git commit -q -a -m "Saved tag $tagName" + + git push -q origin gh-pages \ No newline at end of file