Skip to content

Commit 27cf0cc

Browse files
committed
Github cloudflare action
1 parent 1fa004a commit 27cf0cc

File tree

2 files changed

+140
-0
lines changed

2 files changed

+140
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: "Upload an app to Cloudflare Pages"
2+
description: "Manually deploy an app to cloudflare pages"
3+
inputs:
4+
upload-dir:
5+
description: "The name of the app to build and export"
6+
required: true
7+
8+
project-name:
9+
description: "The name of the project to upload to"
10+
required: true
11+
12+
cloudflare-account:
13+
description: "The Cloudflare account ID"
14+
required: true
15+
16+
cloudflare-api-token:
17+
description: "The Cloudflare API token"
18+
required: true
19+
20+
runs:
21+
using: composite
22+
steps:
23+
24+
- name: Find PR Preview Comment
25+
if: github.event_name == 'pull_request'
26+
uses: peter-evans/find-comment@v1
27+
id: deploy-preview-comment
28+
with:
29+
issue-number: ${{ github.event.pull_request.number }}
30+
comment-author: "github-actions[bot]"
31+
body-includes: ${{ inputs.project-name }}
32+
33+
- name: Update Comment if exists
34+
if: github.event_name == 'pull_request' && steps.deploy-preview-comment.outputs.comment-id != 0
35+
uses: peter-evans/create-or-update-comment@v1.4.5
36+
with:
37+
comment-id: ${{ steps.deploy-preview-comment.outputs.comment-id }}
38+
edit-mode: replace
39+
body: |
40+
### ${{ inputs.project-name }}
41+
Waiting for deployment to complete...
42+
43+
- id: branch-name
44+
uses: tj-actions/branch-names@v5
45+
46+
- id: format-branch
47+
shell: bash
48+
run: format=$(echo ${{ steps.branch-name.outputs.current_branch }} | tr / -) && echo "::set-output name=branch::$(echo "${format:0:28}")"
49+
50+
- name: deploy-cloudflare
51+
uses: cloudflare/pages-action@v1
52+
id: deploy-cloudflare
53+
with:
54+
apiToken: ${{ inputs.cloudflare-api-token }}
55+
accountId: ${{ inputs.cloudflare-account }}
56+
projectName: ${{ inputs.project-name }}
57+
directory: ${{ inputs.upload-dir }}
58+
branch: ${{ steps.format-branch.outputs.branch }}
59+
60+
- name: Create PR Preview Comment
61+
if: github.event_name == 'pull_request' && steps.deploy-preview-comment.outputs.comment-id == 0
62+
uses: peter-evans/create-or-update-comment@v1.4.5
63+
with:
64+
issue-number: ${{ github.event.pull_request.number }}
65+
body: |
66+
### ${{ inputs.project-name }}
67+
🚀 Preview this PR: ${{ steps.deploy-cloudflare.outputs.url }}
68+
📍 Commit SHA: ${{ github.sha }}
69+
70+
71+
- name: Update PR Preview Comment
72+
if: github.event_name == 'pull_request' && steps.deploy-preview-comment.outputs.comment-id != 0
73+
uses: peter-evans/create-or-update-comment@v1.4.5
74+
with:
75+
comment-id: ${{ steps.deploy-preview-comment.outputs.comment-id }}
76+
edit-mode: replace
77+
body: |
78+
### ${{ inputs.project-name }}
79+
🚀 Preview this PR: ${{ steps.deploy-cloudflare.outputs.url }}
80+
📍 Commit SHA: ${{ github.sha }}
81+

.github/workflows/cloudflare.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Cloudflare Pages
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
types: [opened, synchronize]
8+
9+
jobs:
10+
run:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
- uses: actions/setup-node@v3
16+
with:
17+
node-version: 18
18+
cache: "npm"
19+
cache-dependency-path: "**/package-lock.json"
20+
21+
- name: Render Datasheets
22+
run: cd ${GITHUB_WORKSPACE}/scripts/datasheet-rendering;./render-datasheets.sh
23+
24+
- name: Copy Static Files
25+
run: |
26+
mkdir -p static/resources/datasheets static/resources/schematics static/resources/pinouts
27+
find ./content/hardware -type f -name "*-schematics.pdf" -exec cp {} ./static/resources/schematics/ \;
28+
find ./content/hardware -type f -name "*-datasheet.pdf" -exec cp {} ./static/resources/datasheets/ \;
29+
find ./content/hardware -type f -name "*-full-pinout.pdf" -exec cp {} ./static/resources/pinouts/ \;
30+
find ./content/hardware -type f -name "*-pinout.png" -exec cp {} ./static/resources/pinouts/ \;
31+
32+
- name: Gatsby main cache
33+
uses: actions/cache@v3
34+
id: gatsby-cache-folder
35+
with:
36+
path: .cache
37+
key: ${{ runner.os }}-cache-gatsby-${{ github.sha }}
38+
restore-keys: |
39+
${{ runner.os }}-cache-gatsby-
40+
41+
- name: Gatsby Public Folder
42+
uses: actions/cache@v3
43+
id: gatsby-public-folder
44+
with:
45+
path: public/
46+
key: ${{ runner.os }}-public-gatsby-${{ github.sha }}
47+
restore-keys: |
48+
${{ runner.os }}-public-gatsby-
49+
50+
- run: npm install
51+
- run: npm run build
52+
53+
- name: Docs
54+
uses: ./.github/actions/cloudflare-upload
55+
with:
56+
upload-dir: public
57+
project-name: docs-content
58+
cloudflare-api-token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
59+
cloudflare-account: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}

0 commit comments

Comments
 (0)