-
Notifications
You must be signed in to change notification settings - Fork 0
202 lines (165 loc) · 5.81 KB
/
ci.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
197
198
199
200
201
202
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
install:
runs-on: ubuntu-latest
steps:
# Checkout the repo
- uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
- name: Read .nvmrc
run: echo "NODE_VERSION=$(cat .nvmrc)" >> $GITHUB_ENV
- name: Set Nodejs version ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
cache: yarn
- name: restore-yarn-cache
uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/yarn.lock') }}
- name: npm install
run: |
node -v
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true yarn install --frozen-lockfile
test:
runs-on: ubuntu-latest
needs: install
steps:
# Checkout the repo
- uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
- name: Read .nvmrc
run: echo "NODE_VERSION=$(cat .nvmrc)" >> $GITHUB_ENV
- name: Set Nodejs version ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
cache: yarn
- name: print job details
run: |
echo "github_ref ${{ github.ref }}"
echo "github_event_name ${{ github.event_name }}"
echo "node version ${{ env.NODE_VERSION }}"
- name: restore-yarn-cache
uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/yarn.lock') }}
- name: npm install
run: PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true yarn install --frozen-lockfile
- name: lint
run: yarn lint
- name: jest test
run: yarn test
- name: test build
run: yarn build
# snapshot-test:
# runs-on: ubuntu-latest
# needs: install
# steps:
# # Checkout the repo
# - uses: actions/checkout@v2
# with:
# ref: ${{ github.head_ref }}
# - name: run snapshot tests
# run: |
# ./scripts/docker/snapshot-test/prepare.sh
# ./scripts/docker/snapshot-test/run-tests.sh
# - name: save snapshots
# if: failure()
# uses: actions/upload-artifact@v1
# with:
# name: bitmaps_reference
# path: backstop_data/bitmaps_reference
deploy:
runs-on: ubuntu-latest
# needs: [install, test, snapshot-test]
needs: [install, test]
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
steps:
# Checkout the repo
- uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
- name: Read .nvmrc
run: echo "NODE_VERSION=$(cat .nvmrc)" >> $GITHUB_ENV
- name: Set Nodejs version ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
cache: yarn
- name: generate hash
run: |
HASH=$(date | md5sum | cut -d ' ' -f 1)
ZIP_FILE_NAME="storybook---$HASH"
echo "HASH=$HASH" >> $GITHUB_ENV
echo "ZIP_FILE_NAME=$ZIP_FILE_NAME" >> $GITHUB_ENV
- name: install system dependencies
run: |
sudo apt-get update
sudo apt install -y qemu-user-static binfmt-support
- name: build docker image
run: |
echo "zipFileName ${{ env.ZIP_FILE_NAME }}"
zipFileName=${{ env.ZIP_FILE_NAME }}
/bin/bash ./scripts/docker/export-prod.sh $zipFileName
echo "Docker image is $(du -h docker-image.tar)"
- name: deploy
run: |
zipFileName=${{ env.ZIP_FILE_NAME }}
zip -r $zipFileName.zip docker-image.tar meta.json
echo "Zip file is $(du -h $zipFileName.zip)"
echo "${{ secrets.EC2_RSA }}" > ./identityFile.txt
chmod 400 ./identityFile.txt
scp -o "StrictHostKeyChecking=no" -i ./identityFile.txt -r ./$zipFileName.zip ubuntu@ec2-13-40-134-151.eu-west-2.compute.amazonaws.com:/home/ubuntu/departure-lounge/
release:
runs-on: ubuntu-latest
# needs: [test, snapshot-test]
needs: [install, test]
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
steps:
# Checkout the repo
- uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
fetch-depth: 0
- name: Read .nvmrc
run: echo "NODE_VERSION=$(cat .nvmrc)" >> $GITHUB_ENV
- name: Set Nodejs version ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
cache: yarn
- name: restore-yarn-cache
uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/yarn.lock') }}
# We use a fresh checkout here so that we can authenticate with a personal access token.
# This allows us to push new commits to a protected branch, which we cannot do with default GH action token.
- name: Pull git repo
run: |
git config --global user.name "GitHub Actions Bot"
git config --global user.email "<>"
git config --global credential.helper cache
git clone https://${{secrets.PUBLISH_GH_TOKEN}}@github.com/georgegillams/components
mv node_modules components/
- name: npm install
run: |
cd components
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true yarn install --frozen-lockfile
- name: release
env:
NPM_PUBLISH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
run: |
cd components
npm config set //registry.npmjs.org/:_authToken $NPM_PUBLISH_TOKEN
yarn release