Skip to content

Commit

Permalink
feat: Adding PR Build and Deploy actions for all PRs (#1056)
Browse files Browse the repository at this point in the history
  • Loading branch information
pdellaert authored Nov 13, 2024
1 parent def30d0 commit caabb30
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/pr-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# build-preview.yml
name: PR Build Preview for Cloudflare

on:
pull_request:
types: [opened, synchronize]

jobs:
build-preview:
runs-on: ubuntu-latest
name: Build Preview Site and Upload Build Artifact
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install requirements
run: pip install -r requirements.txt
- name: Build PR
run: mkdocs build

# Uploads the build directory as a workflow artifact
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: preview-build
path: site
39 changes: 39 additions & 0 deletions .github/workflows/pr-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# deploy-preview.yml
name: PR Upload Preview to Cloudflare
on:
workflow_run:
workflows: ['PR Build Preview for Cloudflare']
types:
- completed

permissions:
actions: read
deployments: write
contents: read
pull-requests: write

jobs:
deploy-preview:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
name: Deploy Preview to Cloudflare Pages
steps:
# Downloads the build directory from the previous workflow
- name: Download build artifact
uses: actions/download-artifact@v4
id: preview-build-artifact
with:
name: preview-build
path: build
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}

- name: Deploy to Cloudflare Pages
uses: AdrianGonz97/refined-cf-pages-action@v1
with:
apiToken: ${{ secrets.CLOUDFLARE_PAGES_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_PAGES_ACCOUNT_ID }}
githubToken: ${{ secrets.GITHUB_TOKEN }}
projectName: ${{ secrets.CLOUDFLARE_DOCS_PROJECT }}
deploymentName: Preview
directory: ${{ steps.preview-build-artifact.outputs.download-path }}

0 comments on commit caabb30

Please sign in to comment.