-
Notifications
You must be signed in to change notification settings - Fork 44
133 lines (117 loc) · 4.74 KB
/
continuous-integration-and-deployment.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
name: Continuous Integration
on:
push:
branches:
- master
pull_request:
jobs:
setup:
uses: ./.github/workflows/setup-nodejs-and-install-dependencies.yml
checks-and-tests:
needs: setup
uses: ./.github/workflows/checks-and-tests.yml
deploy-website:
runs-on: ubuntu-latest
permissions: write-all
environment: ${{ github.ref_name == 'master' && 'production' || github.ref_name }}
needs: checks-and-tests
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Restore NPM Cache
uses: ./.github/actions/restore-npm-cache
- name: Sets env vars for dev
if: github.event_name == 'pull_request'
run: |
echo "ENV=${{ github.head_ref }}" >> $GITHUB_ENV
echo "ENV_URL=https://${{ vars.AWS_BUCKET_NAME }}/${{ github.head_ref }}" >> $GITHUB_ENV
echo "BASE_URL=/${{ github.head_ref }}/" >> $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://${{ vars.AWS_BUCKET_NAME }}" >> $GITHUB_ENV
echo "BASE_URL=/" >> $GITHUB_ENV
- name: Build
run: npm run prerender
env:
NODE_ENV: production
BASE_URL: ${{ env.BASE_URL }}
LOCO_API_KEY: ${{ secrets.LOCO_API_KEY }}
VITE_HOST_URL: ${{ env.ENV_URL }}
VITE_ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_APP_ID }}
VITE_ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_API_SEARCH_KEY }}
VITE_ALGOLIA_INDEX: ${{ vars.ALGOLIA_INDEX }}
VITE_GTM_ID: ${{ vars.GTM_ID }}
VITE_IS_DEBUG: ${{ vars.IS_DEBUG }}
- name: Install aws cli
id: install-aws-cli
uses: unfor19/install-aws-cli-action@v1
- name: Setup aws
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
aws-region: ${{ vars.AWS_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
run: aws s3 sync "dist/public/" "s3://${{ vars.AWS_BUCKET_NAME }}${{ env.BASE_URL }}" --delete
- name: Clear caches
run: aws cloudfront create-invalidation --distribution-id "${{ secrets.AWS_CLOUDFRONT_DISTRIBUTION_ID }}" --paths "${{ env.BASE_URL }}*"
- name: Indexing on Algolia
run: npm run indexation:algolia
env:
ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_APP_ID }}
ALGOLIA_API_INDEXING_KEY: ${{ secrets.ALGOLIA_API_INDEXING_KEY }}
ALGOLIA_INDEX: ${{ vars.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 }}