chore(cd): preview app for forks PRs (#169)

This commit is contained in:
Corentin THOMASSET 2024-09-17 22:18:20 +02:00 committed by GitHub
parent 6936892447
commit 0a01794ed8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 128 additions and 3 deletions

View File

@ -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

59
.github/workflows/cd-preview-build.yaml vendored Normal file
View File

@ -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

View File

@ -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'