1
+ name : Verdaccio Website CI
2
+
3
+ on :
4
+ workflow_dispatch :
5
+ pull_request :
6
+ types :
7
+ - opened
8
+ - synchronize
9
+ paths :
10
+ - ' website/**'
11
+ - ' package.json'
12
+ - ' ./github/workflows/website.yml'
13
+ push :
14
+ branches :
15
+ - ' master'
16
+ paths :
17
+ - ' website/**'
18
+ - ' package.json'
19
+ - ' ./github/workflows/website.yml'
20
+
21
+ jobs :
22
+ build :
23
+ runs-on : ubuntu-latest
24
+ steps :
25
+
26
+
27
+ - name : Use Node 14
28
+ uses : actions/setup-node@v2
29
+ with :
30
+ node-version : 14
31
+
32
+ - name : Cache pnpm modules
33
+ uses : actions/cache@v2
34
+ env :
35
+ cache-name : cache-pnpm-modules
36
+ with :
37
+ path : ~/.pnpm-store
38
+ key : ${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-${{ hashFiles('**/pnpm-lock.yaml') }}
39
+ restore-keys : |
40
+ ${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-
41
+
42
+
43
+ with :
44
+ version : 6.10.2
45
+ run_install : |
46
+ - recursive: true
47
+ args: [--frozen-lockfile]
48
+
49
+ - name : Lint And Pretty
50
+ run : |
51
+ pnpm eslint:check --filter ...@verdaccio/website
52
+ pnpm prettier:check --filter ...@verdaccio/website
53
+
54
+ - name : Cache Docusaurus Build
55
+ uses : actions/cache@v2
56
+ with :
57
+ path : website/node_modules/.cache/webpack
58
+ key : cache/webpack-${{github.ref}}-${{ hashFiles('**/pnpm-lock.yaml') }}
59
+ restore-keys : cache/webpack-${{github.ref}}
60
+
61
+ # Will deploy to production on:
62
+ # 1st: When a push occurs on master branch
63
+ # 2nd: When we force the worflow dispatch through the UI
64
+ - name : Build Production
65
+ if : (github.event_name == 'push' && github.ref == 'refs/heads/master') || github.event_name == 'workflow_dispatch'
66
+ env :
67
+ CONTEXT : production
68
+ run : pnpm netlify:build:production --filter ...@verdaccio/website
69
+
70
+ - name : 🔥 Deploy Production Netlify
71
+ if : (github.event_name == 'push' && github.ref == 'refs/heads/master') || github.event_name == 'workflow_dispatch'
72
+ uses : semoal/action-netlify-deploy@master
73
+ with :
74
+ github-token : ${{ secrets.GITHUB_TOKEN }}
75
+ netlify-auth-token : ${{ secrets.NETLIFY_AUTH_TOKEN }}
76
+ netlify-site-id : ${{ secrets.NETLIFY_SITE_ID }}
77
+ build-dir : ' ./website/build'
78
+
79
+ # Will deploy to Preview URL, only when a pull request is open with changes on the website
80
+ - name : Build Deployment Preview
81
+ if : github.event_name == 'pull_request' && github.ref != 'refs/heads/master'
82
+ env :
83
+ CONTEXT : deploy-preview
84
+ run : pnpm netlify:build:deployPreview --filter ...@verdaccio/website
85
+
86
+ - name : 🤖 Deploy Preview Netlify
87
+ if : github.event_name == 'pull_request' && github.ref != 'refs/heads/master'
88
+ uses : semoal/action-netlify-deploy@master
89
+ id : netlify_preview
90
+ with :
91
+ draft : true
92
+ comment-on-pull-request : true
93
+ github-deployment-is-production : false
94
+ github-deployment-is-transient : true
95
+ github-token : ${{ secrets.GITHUB_TOKEN }}
96
+ netlify-auth-token : ${{ secrets.NETLIFY_AUTH_TOKEN }}
97
+ netlify-site-id : ${{ secrets.NETLIFY_SITE_ID }}
98
+ build-dir : ' ./website/build'
99
+
100
+ - name : Audit preview URL with Lighthouse
101
+ if : github.event_name == 'pull_request' && github.ref != 'refs/heads/master'
102
+ id : lighthouse_audit
103
+ uses : treosh/lighthouse-ci-action@v3
104
+ with :
105
+ urls : |
106
+ ${{ steps.netlify_preview.outputs.preview-url }}
107
+ uploadArtifacts : true
108
+ temporaryPublicStorage : true
109
+
110
+ - name : Format lighthouse score
111
+ if : github.event_name == 'pull_request' && github.ref != 'refs/heads/master'
112
+ id : format_lighthouse_score
113
+ uses : actions/github-script@v3
114
+ with :
115
+ github-token : ${{secrets.GITHUB_TOKEN}}
116
+ script : |
117
+ const result = ${{ steps.lighthouse_audit.outputs.manifest }}[0].summary
118
+ const links = ${{ steps.lighthouse_audit.outputs.links }}
119
+ const formatResult = (res) => Math.round((res * 100))
120
+ Object.keys(result).forEach(key => result[key] = formatResult(result[key]))
121
+ const score = res => res >= 90 ? '🟢' : res >= 50 ? '🟠' : '🔴'
122
+ const comment = [
123
+ `⚡️ [Lighthouse report](${Object.values(links)[0]}) for the changes in this PR:`,
124
+ '| Category | Score |',
125
+ '| --- | --- |',
126
+ `| ${score(result.performance)} Performance | ${result.performance} |`,
127
+ `| ${score(result.accessibility)} Accessibility | ${result.accessibility} |`,
128
+ `| ${score(result['best-practices'])} Best practices | ${result['best-practices']} |`,
129
+ `| ${score(result.seo)} SEO | ${result.seo} |`,
130
+ ' ',
131
+ `*Lighthouse ran on [${Object.keys(links)[0]}](${Object.keys(links)[0]})*`
132
+ ].join('\n')
133
+ core.setOutput("comment", comment);
134
+
135
+ - name : Add comment to PR
136
+ if : github.event_name == 'pull_request' && github.ref != 'refs/heads/master'
137
+ id : comment_to_pr
138
+ uses : marocchino/sticky-pull-request-comment@v1
139
+ with :
140
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
141
+ number : ${{ github.event.issue.number }}
142
+ header : lighthouse
143
+ message : |
144
+ ${{ steps.format_lighthouse_score.outputs.comment }}
0 commit comments