From 0a01794ed857192fd87b77a545c75dc391c96347 Mon Sep 17 00:00:00 2001 From: Corentin THOMASSET Date: Tue, 17 Sep 2024 22:18:20 +0200 Subject: [PATCH] chore(cd): preview app for forks PRs (#169) --- .github/workflows/cd-app-prod.yaml | 8 +-- .github/workflows/cd-preview-build.yaml | 59 ++++++++++++++++++++++ .github/workflows/cd-preview-deploy.yaml | 64 ++++++++++++++++++++++++ 3 files changed, 128 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/cd-preview-build.yaml create mode 100644 .github/workflows/cd-preview-deploy.yaml diff --git a/.github/workflows/cd-app-prod.yaml b/.github/workflows/cd-app-prod.yaml index bebedce1..c0f53cb5 100644 --- a/.github/workflows/cd-app-prod.yaml +++ b/.github/workflows/cd-app-prod.yaml @@ -1,10 +1,12 @@ +name: CD - Production + on: push: branches: - main jobs: - publish-app: + publish-app-prod: runs-on: ubuntu-latest permissions: contents: read @@ -38,7 +40,7 @@ jobs: branch: main wranglerVersion: '3' - publish-docs: + publish-docs-prod: runs-on: ubuntu-latest permissions: contents: read @@ -56,7 +58,7 @@ jobs: - name: Install dependencies run: pnpm i - - name: Build the app + - name: Build the docs run: pnpm -F @enclosed/docs build - name: Publish to Cloudflare Pages diff --git a/.github/workflows/cd-preview-build.yaml b/.github/workflows/cd-preview-build.yaml new file mode 100644 index 00000000..a64c7aa7 --- /dev/null +++ b/.github/workflows/cd-preview-build.yaml @@ -0,0 +1,59 @@ +# Name used in ./cd-preview-deploy.yaml +name: CD - Preview Build + +on: + pull_request: + types: [opened, synchronize] + +jobs: + build-app-preview: + runs-on: ubuntu-latest + name: Build app and upload build artifact + steps: + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 + - run: corepack enable + - uses: actions/setup-node@v4 + with: + node-version: 22 + corepack: true + cache: 'pnpm' + + - name: Install dependencies + run: pnpm i + + - name: Build the app + run: pnpm -F @enclosed/deploy-cloudflare build + + # Uploads the build directory as a workflow artifact + - name: Upload build artifact + uses: actions/upload-artifact@v4 + with: + name: preview-app-build + if-no-files-found: error + path: packages/deploy-cloudflare/dist + + build-docs-preview: + runs-on: ubuntu-latest + name: Build docs and upload build artifact + steps: + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 + - run: corepack enable + - uses: actions/setup-node@v4 + with: + node-version: 22 + corepack: true + cache: 'pnpm' + + - name: Install dependencies + run: pnpm i + + - name: Build the docs + run: pnpm -F @enclosed/docs build + + # Uploads the build directory as a workflow artifact + - name: Upload build artifact + uses: actions/upload-artifact@v4 + with: + name: preview-docs-build + if-no-files-found: error + path: packages/docs/dist \ No newline at end of file diff --git a/.github/workflows/cd-preview-deploy.yaml b/.github/workflows/cd-preview-deploy.yaml new file mode 100644 index 00000000..ee41c163 --- /dev/null +++ b/.github/workflows/cd-preview-deploy.yaml @@ -0,0 +1,64 @@ +name: CD - Preview Deploy + +on: + workflow_run: + workflows: [CD - Preview Build] + types: + - completed + +permissions: + actions: read + deployments: write + contents: read + pull-requests: write + +jobs: + deploy-app-preview: + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'success' }} + name: Deploy app preview + steps: + - name: Download app build artifact + uses: actions/download-artifact@v4 + id: preview-app-build-artifact + with: + name: preview-app-build + path: build + github-token: ${{ secrets.GITHUB_TOKEN }} + run-id: ${{ github.event.workflow_run.id }} + + - name: Deploy preview app to Cloudflare Pages + uses: AdrianGonz97/refined-cf-pages-action@v1 + with: + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + githubToken: ${{ secrets.GITHUB_TOKEN }} + projectName: enclosed + deploymentName: Preview + directory: ${{ steps.preview-app-build-artifact.outputs.download-path }} + wranglerVersion: '3' + + deploy-docs-preview: + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'success' }} + name: Deploy docs preview + steps: + - name: Download docs build artifact + uses: actions/download-artifact@v4 + id: preview-docs-build-artifact + with: + name: preview-docs-build + path: build + github-token: ${{ secrets.GITHUB_TOKEN }} + run-id: ${{ github.event.workflow_run.id }} + + - name: Deploy preview docs to Cloudflare Pages + uses: AdrianGonz97/refined-cf-pages-action@v1 + with: + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + githubToken: ${{ secrets.GITHUB_TOKEN }} + projectName: enclosed-docs + deploymentName: Preview + directory: ${{ steps.preview-docs-build-artifact.outputs.download-path }} + wranglerVersion: '3'