Build and deploy [Archive] to server #39
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and deploy [Archive] to server | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| src: | |
| description: "Docs Staging Branch" | |
| type: string | |
| default: archive | |
| required: true | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| name: Build website | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - uses: actions/setup-node@v3 | |
| with: | |
| node-version: 16 | |
| cache: "yarn" | |
| - name: Update submodule | |
| id: submodule | |
| run: | | |
| git submodule init | |
| git submodule update --remote | |
| cd docs | |
| git checkout ${{ inputs.src }} | |
| cd .. | |
| echo "submodule_sha=$(git submodule status | awk '{print $1}' | sed -r 's/[+-]+//g')" >> $GITHUB_OUTPUT | |
| echo "submodule_status=$(git submodule status)" >> $GITHUB_OUTPUT | |
| echo "git_sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT | |
| echo "build_date=$(date)" >> $GITHUB_OUTPUT | |
| - name: Install deps | |
| run: yarn | |
| - name: Calc gatsby cache key | |
| id: calc-cache-key | |
| run: | | |
| echo "::set-output name=key::${{ steps.submodule.outputs.submodule_sha }}" | |
| - name: Restore gatsby cache | |
| uses: actions/cache@v3 | |
| id: gatsby-cache | |
| with: | |
| path: | | |
| .cache | |
| public | |
| key: ${{ runner.os }}-archive-gatsby-cache-docs-staging-${{ steps.calc-cache-key.outputs.key }} | |
| restore-keys: | | |
| ${{ runner.os }}-archive-gatsby-cache-docs-staging- | |
| - name: Build website | |
| env: | |
| CI: true | |
| GATSBY_ALGOLIA_APPLICATION_ID: ${{ secrets.ALGOLIA_APPLICATION_ID }} | |
| GATSBY_ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_API_KEY }} | |
| GATSBY_DOC_BUILD_DATE: ${{ steps.submodule.outputs.build_date }} | |
| GATSBY_DOC_BUILD_GIT_SHA: ${{ steps.submodule.outputs.git_sha }} | |
| GATSBY_DOC_BUILD_SUBMODULE_SHA: ${{ steps.submodule.outputs.submodule_status }} | |
| WEBSITE_BUILD_TYPE: archive | |
| run: | | |
| yarn build | |
| - name: Check output | |
| id: check-output | |
| run: | | |
| sudo apt install tree | |
| tree public | |
| - name: Install coscli | |
| run: | | |
| wget https://cosbrowser.cloud.tencent.com/software/coscli/coscli-linux-amd64 | |
| mv coscli-linux-amd64 coscli | |
| chmod 755 coscli | |
| - name: Deploy to COS | |
| run: | | |
| ./coscli sync public/ cos://${{ secrets.TENCENTCLOUD_ARCHIVE_BUCKET_ID }} \ | |
| --init-skip \ | |
| --recursive \ | |
| --routines 16 \ | |
| --secret-id ${{ secrets.TENCENTCLOUD_SECRET_ID }} \ | |
| --secret-key ${{ secrets.TENCENTCLOUD_SECRET_KEY }} \ | |
| --endpoint cos.na-ashburn.myqcloud.com \ | |
| --delete \ | |
| --force | |
| cdn-refresh: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| name: Refresh CDN Cache | |
| env: | |
| TENCENTCLOUD_SECRET_ID: ${{ secrets.TENCENTCLOUD_SECRET_ID }} | |
| TENCENTCLOUD_SECRET_KEY: ${{ secrets.TENCENTCLOUD_SECRET_KEY }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Python environment | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| architecture: "x64" | |
| - name: Install Tencent Cloud CLI | |
| run: pipx install tccli | |
| - name: Purge production CDN cache | |
| run: tccli cdn PurgePathCache --Paths '["https://docs-archive.pingcap.com/"]' --FlushType flush |