-
Notifications
You must be signed in to change notification settings - Fork 1
147 lines (144 loc) · 5.06 KB
/
main.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
# Name of workflow
name: Main workflow
# When workflow is triggered
on:
push:
branches:
- main
pull_request:
branches:
- main
# Jobs to carry out
jobs:
lint:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
steps:
# Get code from repo
- name: Checkout code
uses: actions/checkout@v2
# Install NodeJS
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
# Run rush install and build on our code
- name: Install dependencies
run: |
node common/scripts/install-run-rush.js change -v
node common/scripts/install-run-rush.js install
node common/scripts/install-run-rush.js build
# Run eslint to check all packages
- name: Lint packages
run: node common/scripts/install-run-rush.js lint
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
env:
CI: true
steps:
# Get code from repo
- name: Checkout code
uses: actions/checkout@v2
# Install NodeJS
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
# Run rush install
- name: Install dependencies
run: |
node common/scripts/install-run-rush.js change -v
node common/scripts/install-run-rush.js install
node common/scripts/install-run-rush.js build
# Run unit tests for all packages
- name: Run tests
run: node common/scripts/install-run-rush.js test
deploy:
# Operating system to run job on
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
app-name: [blog]
include:
- app-name: blog
app: '@bereghici/blog-app'
app-dir: 'apps/blog'
site-id: DEV_NETLIFY_SITE_ID
needs: [lint, test]
# Steps in job
steps:
# Get code from repo
- name: Checkout code
uses: actions/checkout@v2
# Install NodeJS
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
# Run rush install and build on our code
- name: Install dependencies
run: |
node common/scripts/install-run-rush.js change -v
node common/scripts/install-run-rush.js install
- name: Get changed files
id: file_changes
uses: trilom/[email protected]
with:
output: ''
fileOutput: ''
# Find changed projects to build it
- name: Find changed projects
id: changed_projects
run: |
PROJECTS="$(node platform/affected-packages --type=apps ${{ steps.file_changes.outputs.files}} )"
echo "::set-output name=PROJECTS::$PROJECTS"
- name: Build ${{ matrix.app-name }} app
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets[matrix.site-id] }}
id: netlify
working-directory: ${{ matrix.app-dir }}
if: ${{ contains(steps.changed_projects.outputs.projects, matrix.app) }}
run: |
cp ./env_overrides/development.ini .env.local
node $GITHUB_WORKSPACE/common/scripts/install-run-rush.js build --verbose --to-except ${{ matrix.app }}
npx netlify-cli build
PROD_FLAG="${{ github.event_name == 'pull_request' && '' || '--prod' }}"
OUTPUT="$(npx netlify-cli deploy $PROD_FLAG)"
NETLIFY_URL=$(echo "$OUTPUT" | grep -Eo '(http|https)://[a-zA-Z0-9./?=_-]*(--)[a-zA-Z0-9./?=_-]*')
NETLIFY_LIVE_URL=$(echo "$OUTPUT" | grep -Eo '(http|https)://[a-zA-Z0-9./?=_-]*' | grep -Ev 'netlify.app|netlify.com')
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "::set-output name=NETLIFY_URL::$NETLIFY_URL"
else
echo "::set-output name=NETLIFY_URL::$NETLIFY_LIVE_URL"
fi
- name: Publish preview urls
id: preview_urls
if: ${{ contains(steps.changed_projects.outputs.projects, matrix.app) && github.event_name == 'pull_request' }}
uses: unsplash/comment-on-pr@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
msg: '🚀 Deployed on ${{ steps.netlify.outputs.netlify_url }}'
check_for_duplicate_msg: 'true'
- name: Generate Lighthouse Report
id: lighthouse_report
if: ${{ steps.netlify.outputs.netlify_url }}
uses: justinribeiro/[email protected]
with:
url: ${{ steps.netlify.outputs.netlify_url }}
secret: ${{ secrets.GITHUB_TOKEN }}
wptConnectionSpeed: threegfast
- name: Saving Lighthouse Audit Artifacts
id: lighthouse_artifacts
if: ${{ steps.netlify.outputs.netlify_url }}
uses: actions/upload-artifact@master
with:
name: lighthouse-artifacts
path: './results'