From 960567c893d440266054acc09f2fa233d83dda2e Mon Sep 17 00:00:00 2001 From: Neko Ayaka Date: Tue, 16 Jan 2024 20:46:21 +0800 Subject: [PATCH] fix(ci): use workflow_run Signed-off-by: Neko Ayaka --- .github/workflows/docs-build.yaml | 59 +++++++ .../workflows/preview-docs-deployment.yaml | 146 +++++++++--------- 2 files changed, 136 insertions(+), 69 deletions(-) create mode 100644 .github/workflows/docs-build.yaml diff --git a/.github/workflows/docs-build.yaml b/.github/workflows/docs-build.yaml new file mode 100644 index 00000000..7a7299f4 --- /dev/null +++ b/.github/workflows/docs-build.yaml @@ -0,0 +1,59 @@ +name: Build Previewing Docs + +on: + pull_request: + branches: + - main + +jobs: + build: + strategy: + matrix: + os: [ubuntu-latest, windows-latest] + + name: Build - ${{ matrix.os }} + + runs-on: ${{ matrix.os }} + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Install Node.js 20.x + uses: actions/setup-node@v3 + with: + node-version: 20.x + + - name: Install pnpm + uses: pnpm/action-setup@v2 + with: + run_install: false + version: 8 + + - name: Obtain pnpm store directory + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV + + - name: Obtain pnpm store cache + uses: actions/cache@v3 + with: + path: ${{ env.STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Build docs + run: | + pnpm packages:build + pnpm docs:build + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: docs-${{ matrix.os }}-build + path: docs/.vitepress/dist diff --git a/.github/workflows/preview-docs-deployment.yaml b/.github/workflows/preview-docs-deployment.yaml index 37c2aa7e..506d13d7 100644 --- a/.github/workflows/preview-docs-deployment.yaml +++ b/.github/workflows/preview-docs-deployment.yaml @@ -1,49 +1,36 @@ -name: Build Preview Docs to Netlify +name: Build Previewing Docs on: - pull_request_target: + workflow_run: + workflows: + - Build Previewing Docs types: - - opened - - synchronize - - reopened - branches: - - main + - completed jobs: - build: - strategy: - matrix: - os: [ubuntu-latest, windows-latest] - - name: Build - ${{ matrix.os }} - - runs-on: ${{ matrix.os }} + on-success: + runs-on: ubuntu-latest + permissions: + pull-requests: write + if: ${{ github.event.workflow_run.conclusion == 'success' }} steps: - - name: Find Comment - uses: peter-evans/find-comment@v2 - id: fc + - name: Download artifact - Ubuntu + uses: dawidd6/action-download-artifact@v3 with: - issue-number: ${{ github.event.pull_request.number }} - comment-author: 'github-actions[bot]' - body-includes: to Netlify - ${{ matrix.os }} - - - name: Create or update comment - uses: peter-evans/create-or-update-comment@v3 + workflow_conclusion: success + run_id: ${{ github.event.workflow_run.id }} + name: docs-ubuntu-latest-build + path: docs-ubuntu-latest-build + allow_forks: true + + - name: Download artifact - Windows + uses: dawidd6/action-download-artifact@v3 with: - comment-id: ${{ steps.fc.outputs.comment-id }} - issue-number: ${{ github.event.pull_request.number }} - body: | - ## 🚧 Deploying to Netlify - ${{ matrix.os }} - - | Status | URL | - |-------------|--------------------------------------| - | Pending | `URL will be revealed once deployed` | - edit-mode: replace - - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 + workflow_conclusion: success + run_id: ${{ github.event.workflow_run.id }} + name: docs-windows-latest-build + path: docs-windows-latest-build + allow_forks: true - name: Install Node.js 20.x uses: actions/setup-node@v3 @@ -69,67 +56,88 @@ jobs: restore-keys: | ${{ runner.os }}-pnpm-store- - - name: Install dependencies - run: pnpm install --frozen-lockfile - - - name: Build docs - run: | - pnpm packages:build - pnpm docs:build - - name: Install Netlify CLI run: pnpm install -g netlify-cli - - name: Push to Netlify - Linux + - name: Debug + run: + ls -la + ls -la docs-ubuntu-latest-build + ls -la docs-windows-latest-build + + - name: Push to Netlify - Ubuntu + id: netlify-ubuntu-latest timeout-minutes: 10 - working-directory: docs/ - if : ${{ matrix.os == 'ubuntu-latest' }} run: | - NETLIFY_JSON_OUTPUT=$(netlify deploy --dir .vitepress/dist --json) + NETLIFY_JSON_OUTPUT=$(netlify deploy --dir docs-ubuntu-latest --json) echo $NETLIFY_JSON_OUTPUT + echo "NETLIFY_JSON_OUTPUT=$(echo $NETLIFY_JSON_OUTPUT)" >> $GITHUB_ENV echo "NETLIFY_URL=$(echo $NETLIFY_JSON_OUTPUT | jq -r .deploy_url)" >> $GITHUB_ENV - cat $GITHUB_ENV env: NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} - name: Push to Netlify - Windows + id: netlify-windows-latest timeout-minutes: 10 - working-directory: docs\ - if : ${{ matrix.os == 'windows-latest' }} run: | - $NETLIFY_JSON_OUTPUT = netlify deploy --dir '.vitepress\dist' --json - Write-Host $NETLIFY_JSON_OUTPUT - Write-Host "NETLIFY_JSON_OUTPUT=$NETLIFY_JSON_OUTPUT" | Out-File -Append $env:GITHUB_ENV - - # Parse JSON output and extract deploy_url - $ParsedJson = $NETLIFY_JSON_OUTPUT | ConvertFrom-Json - $NETLIFY_URL = $ParsedJson.deploy_url + NETLIFY_JSON_OUTPUT=$(netlify deploy --dir docs-windows-latest-build --json) - "NETLIFY_URL=$NETLIFY_URL" | Out-File -Append $env:GITHUB_ENV - Get-Content $env:GITHUB_ENV + echo $NETLIFY_JSON_OUTPUT + echo "NETLIFY_JSON_OUTPUT=$(echo $NETLIFY_JSON_OUTPUT)" >> $GITHUB_ENV + echo "NETLIFY_URL=$(echo $NETLIFY_JSON_OUTPUT | jq -r .deploy_url)" >> $GITHUB_ENV env: NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} - name: Find Comment uses: peter-evans/find-comment@v2 - id: fc-post + id: fc with: issue-number: ${{ github.event.pull_request.number }} comment-author: 'github-actions[bot]' - body-includes: to Netlify - ${{ matrix.os }} + body-includes: to Netlify - name: Create or update comment uses: peter-evans/create-or-update-comment@v3 with: - comment-id: ${{ steps.fc-post.outputs.comment-id }} + comment-id: ${{ steps.fc.outputs.comment-id }} + issue-number: ${{ github.event.pull_request.number }} + body: | + ## ✅ Deployed to deploy to Netlify + + | Platform | Status | URL | + |----------|-------------|---------------------------------------------------------| + | Windows | Success | ${{ steps.netlify-ubuntu-latest.outputs.NETLIFY_URL }} | + | Unix | Success | ${{ steps.netlify-windows-latest.outputs.NETLIFY_URL }} | + edit-mode: replace + + on-failure: + runs-on: ubuntu-latest + permissions: + pull-requests: write + + if: ${{ github.event.workflow_run.conclusion == 'failure' }} + steps: + - name: Find Comment + uses: peter-evans/find-comment@v2 + id: fc + with: + issue-number: ${{ github.event.pull_request.number }} + comment-author: 'github-actions[bot]' + body-includes: to Netlify + + - name: Create or update comment + uses: peter-evans/create-or-update-comment@v3 + with: + comment-id: ${{ steps.fc.outputs.comment-id }} issue-number: ${{ github.event.pull_request.number }} body: | - ## ✅ Deployed to Netlify - ${{ matrix.os }} + ## ❌ Failed to deploy to Netlify - | Status | URL | - |-------------|-----------------------------------------------------| - | Success | ${{ env.NETLIFY_URL }} | + | Platform | Status | URL | + |----------|-------------|-------------------------------------------------------| + | Windows | Failed | Please check the status and logs of the workflow run. | + | Unix | Failed | Please check the status and logs of the workflow run. | edit-mode: replace