Skip to content

Commit 2882896

Browse files
aialokbenjagm
andauthored
[ github-actions ] : Add workflow to get preview from fork repository and deploy to cf pages (#785)
* github-actions : Add workflow to get preview from fork repository * github-actions : Add workflow to deploy to production * removed id from the deployment steps * Update preview-deployment.yml secrets names --------- Co-authored-by: Benjamin Granados <[email protected]>
1 parent edfb406 commit 2882896

File tree

2 files changed

+148
-0
lines changed

2 files changed

+148
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#################### 🚧 WARNING: READ THIS BEFORE USING THIS FILE 🚧 ####################
2+
#
3+
#
4+
#
5+
# IF YOU DON'T KNOW WHAT YOU'RE DOING, YOU CAN EASILY LEAK SECRETS BY USING A
6+
# `pull_request_target` WORKFLOW INSTEAD OF `pull_request`! SERIOUSLY, DO NOT
7+
# BLINDLY COPY AND PASTE THIS FILE WITHOUT UNDERSTANDING THE FULL IMPLICATIONS
8+
# OF WHAT YOU'RE DOING! WE HAVE TESTED THIS FOR OUR OWN USE CASES, WHICH ARE
9+
# NOT NECESSARILY THE SAME AS YOURS! WHILE WE AREN'T EXPOSING ANY OF OUR SECRETS,
10+
# ONE COULD EASILY DO SO BY MODIFYING OR ADDING A STEP TO THIS WORKFLOW!
11+
#
12+
#
13+
#
14+
#################### 🚧 WARNING: READ THIS BEFORE USING THIS FILE 🚧 ####################
15+
16+
name: Preview Deployment
17+
on:
18+
pull_request_target:
19+
20+
# cancel in-progress runs on new commits to same PR (github.event.number)
21+
concurrency:
22+
group: ${{ github.workflow }}-${{ github.event.number || github.sha }}
23+
cancel-in-progress: true
24+
25+
jobs:
26+
deploy-preview:
27+
permissions:
28+
contents: read
29+
pull-requests: write
30+
deployments: write
31+
32+
runs-on: ubuntu-latest
33+
name: Deploy Preview to Cloudflare Pages
34+
steps:
35+
- name: Checkout repository
36+
uses: actions/checkout@v4
37+
with:
38+
ref: ${{ github.event.pull_request.head.ref }}
39+
repository: ${{ github.event.pull_request.head.repo.full_name }}
40+
submodules: 'recursive'
41+
42+
- name: Get yarn cache directory path
43+
id: yarn-cache-dir-path
44+
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
45+
46+
- name: Cache Node dependencies
47+
uses: actions/cache@v4
48+
id: yarn-cache
49+
with:
50+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
51+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
52+
restore-keys: |
53+
${{ runner.os }}-yarn-
54+
55+
- name: Cache Next Build
56+
uses: actions/cache@v4
57+
with:
58+
path: |
59+
${{ steps.yarn-cache-dir-path.outputs.dir }}
60+
${{ github.workspace }}/.next/cache
61+
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx') }}
62+
restore-keys: |
63+
${{ runner.os }}-nextjs-${{ hashFiles('**/yarn.lock') }}-
64+
65+
- name: Setup Node.js
66+
uses: actions/setup-node@v4
67+
with:
68+
node-version: 20
69+
70+
- name: Install dependencies
71+
run: yarn install --frozen-lockfile
72+
73+
- name: Build Site
74+
run: yarn run build
75+
76+
- name: Deploy to Cloudflare Pages
77+
uses: AdrianGonz97/refined-cf-pages-action@v1
78+
with:
79+
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
80+
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
81+
githubToken: ${{ secrets.GITHUB_TOKEN }}
82+
projectName: ${{ vars.CF_PROJECT_NAME }}
83+
directory: out
84+
deploymentName: Preview
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Docs Production Deployment
2+
on:
3+
push:
4+
branches:
5+
- main
6+
7+
concurrency: ${{ github.workflow }}-${{ github.ref }}
8+
9+
jobs:
10+
publish:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
deployments: write
15+
name: Publish to Cloudflare Pages
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
with:
20+
submodules: 'recursive'
21+
22+
- name: Get yarn cache directory path
23+
id: yarn-cache-dir-path
24+
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
25+
26+
- name: Cache Node dependencies
27+
uses: actions/cache@v4
28+
id: yarn-cache
29+
with:
30+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
31+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
32+
restore-keys: |
33+
${{ runner.os }}-yarn-
34+
35+
- name: Cache Next Build
36+
uses: actions/cache@v4
37+
with:
38+
path: |
39+
${{ steps.yarn-cache-dir-path.outputs.dir }}
40+
${{ github.workspace }}/.next/cache
41+
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx') }}
42+
restore-keys: |
43+
${{ runner.os }}-nextjs-${{ hashFiles('**/yarn.lock') }}-
44+
45+
- name: Setup Node.js
46+
uses: actions/setup-node@v4
47+
with:
48+
node-version: 20
49+
50+
- name: Install dependencies
51+
run: yarn install --frozen-lockfile
52+
53+
- name: Build Site
54+
run: yarn run build
55+
56+
- name: Deploy to Cloudflare Pages
57+
uses: AdrianGonz97/refined-cf-pages-action@v1
58+
with:
59+
apiToken: ${{ secrets.CF_API_TOKEN }}
60+
accountId: ${{ secrets.CF_ACCOUNT_ID }}
61+
githubToken: ${{ secrets.GITHUB_TOKEN }}
62+
projectName: ${{ vars.CF_PROJECT_NAME }}
63+
directory: out
64+
deploymentName: Production

0 commit comments

Comments
 (0)