-
-
Notifications
You must be signed in to change notification settings - Fork 275
81 lines (76 loc) · 3.02 KB
/
deploy-website.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
name: Deploy Website
on:
pull_request:
push:
branches:
- main
env:
BASE_REF: ${{ github.event_name == 'pull_request' && format('remotes/origin/{0}', github.base_ref) || 'HEAD~1' }}
CACHE_NODE_MODULES_PATH: |
~/.npm
node_modules
jobs:
setup:
runs-on: ubuntu-latest
outputs:
# Pre-determine if website app is affected
website-changed: ${{ steps.website-changed.outputs.website-changed }}
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
if: github.event_name == 'pull_request'
with:
access_token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
with:
fetch-depth: 0
- uses: actions/cache@v3
id: cache
with:
path: ${{ env.CACHE_NODE_MODULES_PATH }}
key: build-${{ hashFiles('**/package-lock.json') }}
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: npm i
- name: Check changes "website"
id: website-changed
run: echo "website-changed=$(node tools/scripts/ci-is-affected.mjs --appName=website --base=${{ env.BASE_REF}} --head=HEAD)" >> $GITHUB_OUTPUT
- name: Log variables
run: |
echo "steps.cache.outputs.cache-hit:" ${{ steps.cache.outputs.cache-hit }}
echo "steps.website-changed.outputs.website-changed:" ${{ steps.website-changed.outputs.website-changed }}
deploy-website:
name: 'Deploy to Netlify'
runs-on: ubuntu-latest
needs: setup
if: ${{ needs.setup.outputs.website-changed == 'true' && github.event_name == 'push' }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- uses: actions/cache@v3
with:
path: ${{ env.CACHE_NODE_MODULES_PATH }}
key: build-${{ hashFiles('**/package-lock.json') }}
- run: npm run build:website
- run: 'npx netlify deploy --build --prod --message "Deploy from GitHub Actions" --filter website'
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
NETLIFY_NEXT_PLUGIN_SKIP: true
preview-website:
name: 'Deploy Netlify Preview'
runs-on: ubuntu-latest
needs: setup
if: ${{ needs.setup.outputs.website-changed == 'true' && github.event_name == 'pull_request' }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- uses: actions/cache@v3
with:
path: ${{ env.CACHE_NODE_MODULES_PATH }}
key: build-${{ hashFiles('**/package-lock.json') }}
- uses: nelonoel/[email protected]
- run: npm run build:website
- run: 'npx netlify deploy --build --message "Deploy Preview from GitHub Actions" --alias "${{ env.BRANCH_NAME }}" --filter website'
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
NETLIFY_NEXT_PLUGIN_SKIP: true