-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
source_repo.yml
88 lines (76 loc) · 3.11 KB
/
source_repo.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
# -------------------------------------------------------------------------------------------------
# This workflow is meant to be copied to the source repo, in order to to build the website
# trigger the deployment.
# Remember to edit the placeholder commands and env variables below to best suit your needs.
# You should also create a PREVIEW_TOKEN secret following the action's README.
# -------------------------------------------------------------------------------------------------
name: Deploy
on:
push:
branches:
- 'main'
delete:
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:
dev:
name: Development
runs-on: ubuntu-20.04
env:
PREVIEW_REPO: octocat/preview
PAGES_BASE: https://octocat.github.io/preview
steps:
- name: Checkout branch
if: ${{ !startsWith(github.event_name, 'pull_request') }}
uses: actions/checkout@v3
- name: Checkout PR head
if: ${{ startsWith(github.event_name, 'pull_request') && github.event.action != 'closed' }}
uses: actions/checkout@v3
with:
ref: refs/pull/${{ github.event.pull_request.number }}/merge
# Assuming you're using Node.js
- name: Setup Node.js
uses: actions/setup-node@v3
if: ${{ github.event.action != 'closed' }} # Skipping these steps if the PR has been closed
with:
node-version: '16'
cache: npm
- name: Install dependencies
if: ${{ github.event.action != 'closed' }}
run: npm ci --ignore-scripts
# 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
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
shell: bash
# 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: npm run 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: build # Change this!
preview_base_url: ${{ env.PAGES_BASE }}
preview_repo: ${{ env.PREVIEW_REPO }}
preview_token: ${{ secrets.PREVIEW_TOKEN }}