-
Notifications
You must be signed in to change notification settings - Fork 0
97 lines (83 loc) · 3.08 KB
/
preview.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
name: Preview
on:
push:
branches:
- 'main'
pull_request_target:
types:
- opened
- synchronize
- reopened
- closed
concurrency:
group: preview-${{ github.event_name }}-${{ github.event.number || github.ref_name }}
cancel-in-progress: true
jobs:
preview:
name: Preview
runs-on: ubuntu-20.04
env:
PREVIEW_REPO: PoliNetworkOrg/preview
PAGES_BASE: https://PoliNetworkOrg.github.io/preview
steps:
- name: Checkout branch
if: ${{ !startsWith(github.event_name, 'pull_request') }}
uses: actions/checkout@v4
- name: Checkout PR head
if: ${{ startsWith(github.event_name, 'pull_request') }}
uses: actions/checkout@v4
with:
ref: refs/pull/${{ github.event.pull_request.number }}/merge
# Assuming you're using Node.js
- name: Setup Node.js
uses: actions/setup-node@v4
if: ${{ github.event.action != 'closed' }} # Skipping these steps if the PR has been closed
with:
node-version-file: "package.json"
- uses: pnpm/action-setup@v4
with:
version: 9
run_install: false
- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-V
- name: Install dependencies
run: pnpm install
# This will calculate the base URL for the website, based on the event that triggered the workflow.
# Leave this step as it is, unless you know what you're doing.
- name: Determine base URL
if: ${{ github.event.action != 'closed' }}
id: baseurl
shell: bash
run: |
if [ "${{ github.event_name }}" == "pull_request_target" ]; then
full="${{ env.PAGES_BASE }}/${{ github.repository }}/pr/${{ github.event.number }}"
else
full="${{ env.PAGES_BASE }}/${{ github.repository }}/branch/${{ github.ref_name }}"
fi
relative=/$(echo $full | cut -d/ -f4-)
echo "full=$full" >> $GITHUB_OUTPUT
echo "relative=$relative" >> $GITHUB_OUTPUT
# Run your usual build command, but make sure to use the correct base URL
# This example assumes you're using React, and that you're using the PUBLIC_URL env variable
- name: Build
if: ${{ github.event.action != 'closed' }}
run: pnpm build
env:
PUBLIC_URL: ${{ steps.baseurl.outputs.relative }}
# This will trigger the action. Make sure to change the build_dir input to the correct directory
- uses: EndBug/pages-preview@v1
with:
build_dir: dist # Change this!
preview_base_url: ${{ env.PAGES_BASE }}
preview_repo: ${{ env.PREVIEW_REPO }}
preview_token: ${{ secrets.PREVIEW_TOKEN }}