Build and Upload Documentation #75
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 Upload Documentation | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - 'release/*' | |
| paths: | |
| - 'docs/**' | |
| tags: | |
| - '*' | |
| workflow_dispatch: # 允许手动触发 | |
| jobs: | |
| build-docs: | |
| runs-on: ubuntu-22.04 | |
| strategy: | |
| matrix: | |
| variant: [52x, 56x, 58x, 55x] | |
| outputs: | |
| version: ${{ steps.determine-version.outputs.VERSION }} | |
| steps: | |
| - name: Determine version tag | |
| id: determine-version | |
| run: | | |
| if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then | |
| echo "VERSION=latest" >> $GITHUB_OUTPUT | |
| elif [[ "${{ github.ref }}" =~ refs/heads/release/(.*) ]]; then | |
| VERSION=${BASH_REMATCH[1]} | |
| echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT | |
| elif [[ "${{ github.ref }}" =~ refs/tags/(.*) ]]; then | |
| VERSION=${BASH_REMATCH[1]} | |
| echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT | |
| else | |
| echo "VERSION=unknown" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| submodules: 'recursive' | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.x' | |
| cache: 'pip' | |
| - name: Install dependencies | |
| working-directory: ./docs | |
| run: | | |
| python -m pip install --upgrade pip | |
| if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | |
| - name: Install doxygen and upload tools | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y doxygen | |
| pip install coscmd | |
| - name: Build documentation for ${{ matrix.variant }} | |
| working-directory: ./docs | |
| env: | |
| SIFLI_DOC_VERSION: ${{ steps.determine-version.outputs.VERSION }} | |
| run: python generate_docs.py ${{ matrix.variant }} | |
| - name: Configure COSCMD | |
| run: | | |
| coscmd config -a ${{ secrets.COS_DOCS_SECRET_ID }} -s ${{ secrets.COS_DOCS_SECRET_KEY }} -b ${{ secrets.COS_DOCS_BUCKET }} -r ${{ secrets.COS_DOCS_REGION }} | |
| - name: Upload ${{ matrix.variant }} documentation to COS | |
| run: | | |
| VERSION=${{ steps.determine-version.outputs.VERSION }} | |
| if [ -d "./docs/build_${{ matrix.variant }}/html" ]; then | |
| coscmd upload -rs --delete --yes ./docs/build_${{ matrix.variant }}/html/ projects/sdk/$VERSION/sf32lb${{ matrix.variant }}/ | |
| echo "Uploaded documentation for ${{ matrix.variant }} to $VERSION/sf32lb${{ matrix.variant }}/" | |
| else | |
| echo "Warning: Build directory for ${{ matrix.variant }} not found" | |
| exit 1 | |
| fi | |
| - name: Upload ${{ matrix.variant }} documentation artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: docs-${{ matrix.variant }} | |
| path: docs/build_${{ matrix.variant }}/html/ | |
| retention-days: 1 | |
| archive: | |
| needs: [build-docs] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Download all documentation artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| pattern: docs-* | |
| merge-multiple: false | |
| - name: Archive all documentation | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: docs-${{ needs.build-docs.outputs.version }} | |
| path: | | |
| docs-52x/ | |
| docs-56x/ | |
| docs-58x/ | |
| docs-55x/ | |
| retention-days: 7 | |
| finalize: | |
| needs: [build-docs] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Install upload tools | |
| run: | | |
| pip install coscmd tccli | |
| - name: Configure COSCMD | |
| run: | | |
| coscmd config -a ${{ secrets.COS_DOCS_SECRET_ID }} -s ${{ secrets.COS_DOCS_SECRET_KEY }} -b ${{ secrets.COS_DOCS_BUCKET }} -r ${{ secrets.COS_DOCS_REGION }} | |
| - name: Upload to COS - version.json | |
| if: github.ref == 'refs/heads/main' | |
| run: | | |
| coscmd upload --yes ./docs/version.json projects/sdk/version.json | |
| echo "Uploaded version.json to projects/sdk/version.json" | |
| - name: Purge CDN Cache | |
| run: | | |
| export TENCENTCLOUD_SECRET_ID=${{ secrets.COS_DOCS_SECRET_ID }} | |
| export TENCENTCLOUD_SECRET_KEY=${{ secrets.COS_DOCS_SECRET_KEY }} | |
| export TENCENTCLOUD_REGION=${{ secrets.COS_DOCS_REGION }} | |
| tccli cdn PurgePathCache --cli-unfold-argument --Paths 'https://docs.sifli.com/projects/sdk/' --FlushType flush |