From a054ed2d29e23d1ed77b065d9ce4dd7b795673a3 Mon Sep 17 00:00:00 2001 From: Hien To Date: Tue, 21 Nov 2023 13:59:33 +0700 Subject: [PATCH] CloudFlare Pages add Preview URL to PR --- .github/workflows/build.yml | 2 +- .github/workflows/docs.yml | 29 ++++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1e3436995..5f1f1ddb8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,7 +4,7 @@ on: push: branches: - main - tags: ['v*.*.*'] + tags: ["v[0-9]+.[0-9]+.[0-9]+"] paths: ['.github/scripts/**','.github/workflows/build.yml', '**/CMakeLists.txt', '**/Makefile', '**/*.h', '**/*.hpp', '**/*.c', '**/*.cpp', '**/*.cu', '**/*.cc', '**/*.cxx', '!docs/**', '!.gitignore'] pull_request: types: [opened, synchronize, reopened] diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 7c049b358..4d531c174 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -6,6 +6,8 @@ on: - main paths: - 'docs/**' + - '.github/workflows/docs.yml' + tags: ["v[0-9]+.[0-9]+.[0-9]+-docs"] pull_request: branches: - main @@ -18,6 +20,9 @@ on: jobs: deploy: name: Deploy to GitHub Pages + env: + CLOUDFLARE_ACCOUNT_ID: 9707100ef42a1a25bd70e3ee2137bd0e + CLOUDFLARE_PROJECT_NAME: nitro runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -50,15 +55,33 @@ jobs: - name: Build website run: sed -i '/process.env.DEBUG = namespaces;/c\// process.env.DEBUG = namespaces;' ./node_modules/debug/src/node.js && yarn build working-directory: docs - + + - name: Publish to Cloudflare Pages PR Preview and Staging + if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || (github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'main') + uses: cloudflare/pages-action@v1 + with: + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + accountId: ${{ env.CLOUDFLARE_ACCOUNT_ID }} + projectName: ${{ env.CLOUDFLARE_PROJECT_NAME }} + directory: ./docs/build + # Optional: Enable this if you want to have GitHub Deployments triggered + gitHubToken: ${{ secrets.GITHUB_TOKEN }} + id: deployCloudflarePages + + - uses: mshick/add-pr-comment@v2 + if: github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'main' + with: + message: | + Preview URL: ${{ steps.deployCloudflarePages.outputs.url }} + - name: Add Custome Domain file - if: github.event_name == 'push' && github.event.pull_request.head.repo.full_name != github.repository + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') run: echo "${{ vars.DOCUSAURUS_DOMAIN }}" > ./docs/build/CNAME # Popular action to deploy to GitHub Pages: # Docs: https://github.com/peaceiris/actions-gh-pages#%EF%B8%8F-docusaurus - name: Deploy to GitHub Pages - if: github.event_name == 'push' && github.event.pull_request.head.repo.full_name != github.repository + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') uses: peaceiris/actions-gh-pages@v3 with: github_token: ${{ secrets.GITHUB_TOKEN }}