Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e6b0eae

Browse files
committedJun 26, 2024·
github-actions : Add workflow to get preview from fork repository
1 parent e796a69 commit e6b0eae

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed
 
+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
id: cloudflare-pages-deploy
78+
uses: AdrianGonz97/refined-cf-pages-action@v1
79+
with:
80+
apiToken: ${{ secrets.CF_API_TOKEN }}
81+
accountId: ${{ secrets.CF_ACCOUNT_ID }}
82+
githubToken: ${{ secrets.GITHUB_TOKEN }}
83+
projectName: ${{ vars.CF_PROJECT_NAME }}
84+
directory: .next
85+
deploymentName: Preview

0 commit comments

Comments
 (0)
Please sign in to comment.