Skip to content

Github cloudflare action #1576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions .github/actions/cloudflare-upload/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: "Upload an app to Cloudflare Pages"
description: "Manually deploy an app to cloudflare pages"
inputs:
upload-dir:
description: "The name of the app to build and export"
required: true

project-name:
description: "The name of the project to upload to"
required: true

cloudflare-account:
description: "The Cloudflare account ID"
required: true

cloudflare-api-token:
description: "The Cloudflare API token"
required: true

runs:
using: composite
steps:

- name: Find PR Preview Comment
if: github.event_name == 'pull_request'
uses: peter-evans/find-comment@v1
id: deploy-preview-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: "github-actions[bot]"
body-includes: ${{ inputs.project-name }}

- name: Update Comment if exists
if: github.event_name == 'pull_request' && steps.deploy-preview-comment.outputs.comment-id != 0
uses: peter-evans/create-or-update-comment@v1.4.5
with:
comment-id: ${{ steps.deploy-preview-comment.outputs.comment-id }}
edit-mode: replace
body: |
### ${{ inputs.project-name }}
Waiting for deployment to complete...

- id: branch-name
uses: tj-actions/branch-names@v5

- id: format-branch
shell: bash
run: format=$(echo ${{ steps.branch-name.outputs.current_branch }} | tr / -) && echo "::set-output name=branch::$(echo "${format:0:28}")"

- name: deploy-cloudflare
uses: cloudflare/pages-action@v1
id: deploy-cloudflare
with:
apiToken: ${{ inputs.cloudflare-api-token }}
accountId: ${{ inputs.cloudflare-account }}
projectName: ${{ inputs.project-name }}
directory: ${{ inputs.upload-dir }}
branch: ${{ steps.format-branch.outputs.branch }}

- name: Create PR Preview Comment
if: github.event_name == 'pull_request' && steps.deploy-preview-comment.outputs.comment-id == 0
uses: peter-evans/create-or-update-comment@v1.4.5
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
### ${{ inputs.project-name }}
🚀 Preview this PR: ${{ steps.deploy-cloudflare.outputs.url }}
📍 Commit SHA: ${{ github.sha }}


- name: Update PR Preview Comment
if: github.event_name == 'pull_request' && steps.deploy-preview-comment.outputs.comment-id != 0
uses: peter-evans/create-or-update-comment@v1.4.5
with:
comment-id: ${{ steps.deploy-preview-comment.outputs.comment-id }}
edit-mode: replace
body: |
### ${{ inputs.project-name }}
🚀 Preview this PR: ${{ steps.deploy-cloudflare.outputs.url }}
📍 Commit SHA: ${{ github.sha }}

62 changes: 62 additions & 0 deletions .github/workflows/cloudflare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Cloudflare Pages

on:
push:
branches: ["main"]
pull_request:
types: [opened, synchronize]

jobs:
run:
runs-on: ubuntu-latest
env:
REPO_ACCESS_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
APP_ENV: prod

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
cache: "npm"
cache-dependency-path: "**/package-lock.json"

- name: Render Datasheets
run: cd ${GITHUB_WORKSPACE}/scripts/datasheet-rendering;./render-datasheets.sh

- name: Copy Static Files
run: |
mkdir -p static/resources/datasheets static/resources/schematics static/resources/pinouts
find ./content/hardware -type f -name "*-schematics.pdf" -exec cp {} ./static/resources/schematics/ \;
find ./content/hardware -type f -name "*-datasheet.pdf" -exec cp {} ./static/resources/datasheets/ \;
find ./content/hardware -type f -name "*-full-pinout.pdf" -exec cp {} ./static/resources/pinouts/ \;
find ./content/hardware -type f -name "*-pinout.png" -exec cp {} ./static/resources/pinouts/ \;

- name: Gatsby main cache
uses: actions/cache@v3
id: gatsby-cache-folder
with:
path: .cache
key: ${{ runner.os }}-cache-gatsbyV2-${{ github.sha }}
restore-keys: |
${{ runner.os }}-cache-gatsbyV2-

- name: Gatsby Public Folder
uses: actions/cache@v3
id: gatsby-public-folder
with:
path: public/
key: ${{ runner.os }}-public-gatsbyV2-${{ github.sha }}
restore-keys: |
${{ runner.os }}-public-gatsbyV2-

- run: npm install
- run: npm run build

- name: Docs
uses: ./.github/actions/cloudflare-upload
with:
upload-dir: public
project-name: docs-content
cloudflare-api-token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
cloudflare-account: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
Loading