From 061e77e2b45ad37ab9c948bf842cbb619ace50ab Mon Sep 17 00:00:00 2001 From: ElderJames Date: Fri, 5 Mar 2021 20:21:10 +0800 Subject: [PATCH] chore: add GitHub Actions for auto preview (#1205) --- .github/workflows/preview-build.yml | 65 +++++++++++++++++++ .github/workflows/preview-deploy.yml | 93 ++++++++++++++++++++++++++++ .github/workflows/preview-start.yml | 23 +++++++ 3 files changed, 181 insertions(+) create mode 100644 .github/workflows/preview-build.yml create mode 100644 .github/workflows/preview-deploy.yml create mode 100644 .github/workflows/preview-start.yml diff --git a/.github/workflows/preview-build.yml b/.github/workflows/preview-build.yml new file mode 100644 index 00000000..17c776f3 --- /dev/null +++ b/.github/workflows/preview-build.yml @@ -0,0 +1,65 @@ +# Each PR will build preview site that help to check code is work as expect. + +name: Preview Build + +on: pull_request + +jobs: + + # Prepare + setup: + name: prepare preview + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@master + + - name: Setup .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 5.0.100 + + - name: Setup Node.js + uses: actions/setup-node@v1 + with: + node-version: "10.x" + + build-site: + name: build preview + runs-on: ubuntu-latest + needs: setup + steps: + - name: checkout + uses: actions/checkout@master + + - name: build site + id: site + run: | + npm install + dotnet build + echo "/* updated `date "+%Y-%m-%d %H:%M:%S"` */" >> ./site/AntDesign.Docs.Wasm/wwwroot/service-worker.published.js + cp -rf scripts/gh-pages/* scripts/gh-pages/.nojekyll scripts/gh-pages/.spa ./site/AntDesign.Docs.Wasm/wwwroot + sed -i s/{version}/$PACKAGE_VERSION/g ./site/AntDesign.Docs.Wasm/wwwroot/index.html + sed -i s/{version}/$PACKAGE_VERSION/g ./site/AntDesign.Docs/Shared/HeaderMenu.razor + dotnet publish ./site/AntDesign.Docs.Wasm -c Release -f net5 -o _site + with: + PACKAGE_VERSION: ${{ github.event.number }} + + - name: upload site artifact + uses: actions/upload-artifact@v2 + with: + name: site + path: _site/wwwroot/ + retention-days: 5 + + # Upload PR id for next workflow use + - name: Save PR number + if: ${{ always() }} + run: echo ${{ github.event.number }} > ./pr-id.txt + + - name: Upload PR number + if: ${{ always() }} + uses: actions/upload-artifact@v2 + with: + name: pr + path: ./pr-id.txt diff --git a/.github/workflows/preview-deploy.yml b/.github/workflows/preview-deploy.yml new file mode 100644 index 00000000..b92d5a7d --- /dev/null +++ b/.github/workflows/preview-deploy.yml @@ -0,0 +1,93 @@ +# Each PR will build preview site that help to check code is work as expect. + +name: Preview Deploy + +on: + workflow_run: + workflows: ["Preview Build"] + types: + - completed + +jobs: + deploy-site: + name: deploy preview + runs-on: ubuntu-latest + if: > + github.event.workflow_run.event == 'pull_request' && + github.event.workflow_run.conclusion == 'success' + steps: + # We need get PR id first + - name: download pr artifact + uses: dawidd6/action-download-artifact@v2 + with: + workflow: ${{ github.event.workflow_run.workflow_id }} + name: pr + + # Save PR id to output + - name: save PR id + id: pr + run: echo "::set-output name=id::$(](https://preview-${{ steps.pr.outputs.id }}-antblazor.surge.sh) + + body-include: '' + number: ${{ steps.pr.outputs.id }} + + - name: The job has failed + if: ${{ failure() }} + uses: actions-cool/maintain-one-comment@v1.1.0 + with: + token: ${{ secrets.GITHUB_TOKEN }} + body: | + + + body-include: '' + number: ${{ steps.pr.outputs.id }} + + build-site-failed: + name: build preview failed + runs-on: ubuntu-latest + if: > + github.event.workflow_run.event == 'pull_request' && + github.event.workflow_run.conclusion == 'failure' + steps: + # We need get PR id first + - name: download pr artifact + uses: dawidd6/action-download-artifact@v2 + with: + workflow: ${{ github.event.workflow_run.workflow_id }} + name: pr + + # Save PR id to output + - name: save PR id + id: pr + run: echo "::set-output name=id::$( + + body-include: '' + number: ${{ steps.pr.outputs.id }} diff --git a/.github/workflows/preview-start.yml b/.github/workflows/preview-start.yml new file mode 100644 index 00000000..bf55cb2c --- /dev/null +++ b/.github/workflows/preview-start.yml @@ -0,0 +1,23 @@ +# When `preview-build` start. Leave a message on the PR +# +# 🚨🚨🚨 Important 🚨🚨🚨 +# Never do any `checkout` or `npm install` action! +# `pull_request_target` will enable PR to access the secrets! + +name: Preview Start + +on: pull_request_target + +jobs: + preview-start: + name: start preview info + runs-on: ubuntu-latest + steps: + - name: update status comment + uses: actions-cool/maintain-one-comment@v1.1.0 + with: + token: ${{ secrets.GITHUB_TOKEN }} + body: | + ![Prepare preview](https://user-images.githubusercontent.com/5378891/72351368-2c979e00-371b-11ea-9652-eb4e825d745e.gif) + + body-include: ''