-
Notifications
You must be signed in to change notification settings - Fork 44
196 lines (168 loc) · 7.37 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
name: Deploy
on:
push:
branches:
- master
pull_request:
env:
AWS_DEFAULT_REGION: eu-west-2
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Sets env vars for dev
if: github.event_name == 'pull_request'
run: |
echo "ENV=dev-${{ github.head_ref }}" >> $GITHUB_ENV
echo "ENV_URL=http://dev.blog.eleven-labs.com.s3-website.${{ env.AWS_DEFAULT_REGION }}.amazonaws.com/${{ github.head_ref }}" >> $GITHUB_ENV
echo "BASE_URL=/${{ github.head_ref }}/" >> $GITHUB_ENV
echo "ALGOLIA_APP_ID=${{ secrets.ALGOLIA_APP_ID }}" >> $GITHUB_ENV
echo "ALGOLIA_INDEX=${{ secrets.ALGOLIA_INDEX_DEV }}" >> $GITHUB_ENV
echo "ALGOLIA_API_INDEXING_KEY=${{ secrets.ALGOLIA_API_INDEXING_KEY_DEV }}" >> $GITHUB_ENV
echo "ALGOLIA_API_SEARCH_KEY=${{ secrets.ALGOLIA_API_SEARCH_KEY_DEV }}" >> $GITHUB_ENV
echo "GTM_ID=${{ secrets.GTM_ID_DEV }}" >> $GITHUB_ENV
- name: Sets env vars for production
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
run: |
echo "ENV=production" >> $GITHUB_ENV
echo "ENV_URL=https://blog.eleven-labs.com" >> $GITHUB_ENV
echo "BASE_URL=/" >> $GITHUB_ENV
echo "ALGOLIA_APP_ID=${{ secrets.ALGOLIA_APP_ID }}" >> $GITHUB_ENV
echo "ALGOLIA_INDEX=${{ secrets.ALGOLIA_INDEX_PRODUCTION }}" >> $GITHUB_ENV
echo "ALGOLIA_API_INDEXING_KEY=${{ secrets.ALGOLIA_API_INDEXING_KEY_PRODUCTION }}" >> $GITHUB_ENV
echo "ALGOLIA_API_SEARCH_KEY=${{ secrets.ALGOLIA_API_SEARCH_KEY_PRODUCTION }}" >> $GITHUB_ENV
echo "GTM_ID=${{ secrets.GTM_ID_PRODUCTION }}" >> $GITHUB_ENV
echo "GOOGLE_SITE_VERIFICATION==${{ secrets.GOOGLE_SITE_VERIFICATION }}" >> $GITHUB_ENV
- name: Setup node
uses: actions/setup-node@v3
with:
bundler-cache: true
node-version: 16
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "yarnCacheDir=$(yarn cache dir)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
with:
path: ${{ steps.yarn-cache-dir-path.outputs.yarnCacheDir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install modules
run: yarn install --frozen-lockfile
- name: Validate markdown authors and posts
id: validate_markdown
run: yarn validate-markdown --ci
- name: Add a comment to the PR after failed markdown validation
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request' && failure()
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
number: ${{ github.event.pull_request.number }}
header: validate-markdown
message: |
#### Markdown invalid 🖌
The markdown of the file **${{ steps.validate_markdown.outputs.filePath }}** is invalid !
> ${{ steps.validate_markdown.outputs.reason }}
- name: Remove a comment to the PR after success markdown validation
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request' && success()
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
number: ${{ github.event.pull_request.number }}
header: validate-markdown
delete: true
- name: Run ESLint
run: yarn lint:es
- name: Run Stylelint
run: yarn lint:style
- name: Run Compile TypeScript
run: yarn tsc
- name: Run Test
run: yarn test
- name: Build
run: yarn prerender
env:
NODE_ENV: production
BASE_URL: ${{ env.BASE_URL }}
VITE_ALGOLIA_APP_ID: ${{ env.ALGOLIA_APP_ID }}
VITE_ALGOLIA_API_KEY: ${{ env.ALGOLIA_API_SEARCH_KEY }}
VITE_ALGOLIA_INDEX: ${{ env.ALGOLIA_INDEX }}
VITE_GTM_ID: ${{ env.GTM_ID }}
- name: Setup aws
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_DEFAULT_REGION }}
- name: Start deployment
uses: bobheadxi/deployments@v1
id: deployment
with:
step: start
token: ${{ secrets.GITHUB_TOKEN }}
ref: ${{ github.head_ref }}
env: ${{ env.ENV }}
- name: Deploy to S3 for dev
if: github.event_name == 'pull_request'
run: aws s3 sync "dist/public/" "s3://dev.blog.eleven-labs.com/${{ github.head_ref }}/" --delete
- name: Deploy to S3 for production
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
run: aws s3 sync "dist/public/" "s3://blog.eleven-labs.com/" --delete
- name: Clear caches
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
run: |
aws configure set preview.cloudfront true
aws cloudfront create-invalidation --distribution-id "${{ secrets.CLOUDFRONT_DISTRIBUTION }}" --paths "/*"
- name: Indexing on Algolia
run: yarn indexation:algolia
env:
ALGOLIA_APP_ID: ${{ env.ALGOLIA_APP_ID }}
ALGOLIA_API_INDEXING_KEY: ${{ env.ALGOLIA_API_INDEXING_KEY }}
ALGOLIA_INDEX: ${{ env.ALGOLIA_INDEX }}
- name: Update deployment status
uses: bobheadxi/deployments@v1
if: success()
with:
step: finish
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status }}
env: ${{ steps.deployment.outputs.env }}
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
env_url: ${{ env.ENV_URL }}/
- name: Audit URLs using Lighthouse
id: lighthouse_audit
uses: treosh/lighthouse-ci-action@v9
with:
urls: |
${{ env.ENV_URL }}/
${{ env.ENV_URL }}/fr/authors/ajacquemin/
${{ env.ENV_URL }}/fr/comment-construire-site-web-avec-nextjs/
${{ env.ENV_URL }}/fr/nestjs-le-cycle-de-vie-dune-requete/
configPath: ./.github/workflows/lighthousesrc.json
uploadArtifacts: true
temporaryPublicStorage: true
runs: 3
- name: Format lighthouse score
id: format_lighthouse_score
uses: actions/github-script@v6
if: github.event_name == 'pull_request'
with:
script: |
const lighthouseCommentMaker = require('./.github/workflows/lighthouseCommentMaker.cjs');
const lighthouseOutputs = {
manifest: ${{ steps.lighthouse_audit.outputs.manifest }},
links: ${{ steps.lighthouse_audit.outputs.links }},
assertionResults: ${{ steps.lighthouse_audit.outputs.assertionResults }}
};
const comment = lighthouseCommentMaker({ lighthouseOutputs });
core.setOutput("comment", comment);
- name: Add Lighthouse stats as comment
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request'
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
number: ${{ github.event.pull_request.number }}
header: lighthouse
message: ${{ steps.format_lighthouse_score.outputs.comment }}