Skip to content

Commit

Permalink
chore(cd): preview app for forks PRs (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
CorentinTh authored Sep 17, 2024
1 parent 6936892 commit 0a01794
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 3 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/cd-app-prod.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
name: CD - Production

on:
push:
branches:
- main

jobs:
publish-app:
publish-app-prod:
runs-on: ubuntu-latest
permissions:
contents: read
Expand Down Expand Up @@ -38,7 +40,7 @@ jobs:
branch: main
wranglerVersion: '3'

publish-docs:
publish-docs-prod:
runs-on: ubuntu-latest
permissions:
contents: read
Expand All @@ -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
Expand Down
59 changes: 59 additions & 0 deletions .github/workflows/cd-preview-build.yaml
Original file line number Diff line number Diff line change
@@ -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
64 changes: 64 additions & 0 deletions .github/workflows/cd-preview-deploy.yaml
Original file line number Diff line number Diff line change
@@ -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'

0 comments on commit 0a01794

Please sign in to comment.