-
Notifications
You must be signed in to change notification settings - Fork 4
173 lines (153 loc) · 6.73 KB
/
deploy.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
name: Deploy PR build and run Lighthouse
on:
pull_request:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Install SSH key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_KEY }}
known_hosts: ${{ secrets.KNOWN_HOSTS }}
if_key_exists: replace
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 20.8.1
cache: "yarn"
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: "latest"
extended: true
- name: Install dependencies
run: yarn install --immutable
- name: Clone ocw-www for content
run: (cd ..; git clone [email protected]:ocw-content-rc/ocw-www.git ocw-www)
- name: Clone ocw-course for content
run: (cd ..; git clone [email protected]:ocw-content-rc/15.s21-january-iap-2014.git ocw-course)
- name: Clone ocw-hugo-projects for config
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
with:
repository: "mitodl/ocw-hugo-projects"
ref: "main"
path: "ocw-hugo-projects"
- name: Run webpack build
run: npm run build:webpack -- --output-path=../ocw-www/public/static_shared/
- name: Copy webpack build to course v2
run: mkdir -p ../ocw-course/public-v2/ && cp -r ../ocw-www/public/static_shared/ ../ocw-course/public-v2/
- name: Run the www hugo build
run: (cd ../ocw-www; hugo --config $GITHUB_WORKSPACE/ocw-hugo-projects/ocw-www/config.yaml --themesDir ../ocw-hugo-themes)
env:
OCW_STUDIO_BASE_URL: ${{ secrets.OCW_STUDIO_BASE_URL }}
SEARCH_API_URL: ${{ secrets.SEARCH_API_URL }}
OCW_COURSE_STARTER_SLUG: ${{ secrets.OCW_COURSE_STARTER_SLUG }}
STATIC_API_BASE_URL: ${{ secrets.STATIC_API_BASE_URL }}
RESOURCE_BASE_URL: ${{ secrets.RESOURCE_BASE_URL }}
- name: Run the course v2 hugo build
run: (cd ../ocw-course; hugo --config $GITHUB_WORKSPACE/ocw-hugo-projects/ocw-course-v2/config.yaml --destination public-v2 --themesDir ../ocw-hugo-themes)
env:
OCW_STUDIO_BASE_URL: ${{ secrets.OCW_STUDIO_BASE_URL }}
SEARCH_API_URL: ${{ secrets.SEARCH_API_URL }}
OCW_COURSE_STARTER_SLUG: ${{ secrets.OCW_COURSE_STARTER_SLUG }}
STATIC_API_BASE_URL: ${{ secrets.STATIC_API_BASE_URL }}
RESOURCE_BASE_URL: ${{ secrets.RESOURCE_BASE_URL }}
- name: Deploy www Preview to Netlify
uses: nwtgck/[email protected]
if: ${{ github.event_name == 'pull_request' }}
with:
publish-dir: "../ocw-www/public"
github-token: ${{ secrets.GITHUB_TOKEN }}
deploy-message: "Deploy from GitHub Actions"
enable-pull-request-comment: false
enable-commit-comment: false
overwrites-pull-request-comment: false
alias: ocw-hugo-themes-www-pr-${{ github.event.number }}
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
- name: Deploy v2 Course Preview to Netlify
uses: nwtgck/[email protected]
if: ${{ github.event_name == 'pull_request' }}
with:
publish-dir: "../ocw-course/public-v2"
github-token: ${{ secrets.GITHUB_TOKEN }}
deploy-message: "Deploy from GitHub Actions"
enable-pull-request-comment: false
enable-commit-comment: false
overwrites-pull-request-comment: false
alias: ocw-hugo-themes-course-v2-pr-${{ github.event.number }}
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
- name: Set comment body
id: set-comment-body
run: |
body=$(echo 'Netlify Deployments:<br>www: https://ocw-hugo-themes-www-pr-${{ github.event.number }}--ocw-next.netlify.app/ <br> Course v2: https://ocw-hugo-themes-course-v2-pr-${{ github.event.number }}--ocw-next.netlify.app/')
echo "body=$body" >> $GITHUB_OUTPUT
- name: Find Comment
uses: peter-evans/find-comment@v2
id: fc
continue-on-error: true
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: "github-actions[bot]"
body-includes: "Netlify Deployments"
- name: Create comment
if: ${{ steps.fc.outputs.comment-id == 0 }}
uses: peter-evans/create-or-update-comment@v3
continue-on-error: true
with:
issue-number: ${{ github.event.pull_request.number }}
body: ${{ steps.set-comment-body.outputs.body }}
- name: Update comment
if: ${{ steps.fc.outputs.comment-id != 0 }}
uses: peter-evans/create-or-update-comment@v3
continue-on-error: true
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
edit-mode: replace
body: ${{ steps.set-comment-body.outputs.body }}
- name: Deploy CI build to Netlify
uses: nwtgck/[email protected]
if: ${{ github.event_name == 'push' }}
with:
publish-dir: "../ocw-www/public"
github-token: ${{ secrets.GITHUB_TOKEN }}
deploy-message: "Deploy from GitHub Actions"
enable-pull-request-comment: false
enable-commit-comment: false
production-deploy: true
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
lighthouse:
needs: build
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' }}
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 20.8.1
cache: "yarn"
- run: mkdir -p ${{ github.workspace }}/tmp/artifacts
- name: Run Lighthouse
uses: foo-software/lighthouse-check-action@master
with:
branch: ${{ github.ref }}
outputDirectory: ${{ github.workspace }}/tmp/artifacts
urls: "https://ocw-hugo-themes-www-pr-${{ github.event.number }}--ocw-next.netlify.app/,https://ocw-hugo-themes-www-pr-${{ github.event.number }}--ocw-next.netlify.app/search/,https://ocw-hugo-themes-course-v2-pr-${{ github.event.number }}--ocw-next.netlify.app/"
sha: ${{ github.sha }}
accessToken: ${{ secrets.GITHUB_TOKEN }}
- name: Upload artifacts
uses: actions/upload-artifact@master
with:
name: Lighthouse reports
path: ${{ github.workspace }}/tmp/artifacts