-
Notifications
You must be signed in to change notification settings - Fork 49
131 lines (116 loc) · 4.26 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
name: CI
on:
push:
branches:
- master
pull_request:
workflow_dispatch:
jobs:
static-site-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16'
- run: cd static-site/
- run: npm ci
- run: npm run lint
test:
if: github.repository == 'nextstrain/nextstrain.org'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16'
- run: node --version
- run: npm ci
- run: npm run build
- run: npm run lint
# configure AWS to run dev server necessary for `npm run test:ci`
- uses: aws-actions/configure-aws-credentials@v1
with:
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
aws-access-key-id: ${{ secrets.DEV_SERVER_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.DEV_SERVER_AWS_SECRET_ACCESS_KEY }}
- run: aws sts get-caller-identity
- run: npm run test:ci
- if: always()
uses: actions/upload-artifact@v3
with:
name: logs
path: test/server.log
# XXX TODO: It'd be nice to avoid the rebuild on Heroku and instead deploy
# the artifacts (source code + generated files + node_modules/) already built
# above. This would dramatically reduce deploy times and move us closer to
# "deploy what you tested", but it may also run into platform compatibility
# issues given CI is building on a different platform (arch + OS + sys libs)
# than Heroku's dynos and some deps are compiled. But should try it and see!
# Or do our build above inside a Heroku buildpack…
# -trs, 2 May 2022
deploy:
if: |2
github.repository == 'nextstrain/nextstrain.org'
&& github.event_name == 'push'
&& github.ref == 'refs/heads/master'
# Wait for "test" job above to pass.
needs: test
# Only one "deploy" job at a time.
concurrency: deploy
# Name a GitHub environment configuration¹ to auto-create deployment
# records in GitHub based on this job's progress/status. Also grants
# access to environment-specific secrets.
#
# The URL is specific to this deployment, not the environment (i.e. an
# environment have deployments at different URLs).
#
# ¹ https://github.com/nextstrain/nextstrain.org/settings/environments
environment:
name: heroku
url: https://next.nextstrain.org
# Deploy steps
runs-on: ubuntu-latest
env:
HEROKU_APP: nextstrain-canary
steps:
- name: Login to Heroku
run: echo "machine api.heroku.com login $HEROKU_USER password $HEROKU_TOKEN" >> ~/.netrc
env:
HEROKU_USER: "${{ secrets.HEROKU_USER }}"
HEROKU_TOKEN: "${{ secrets.HEROKU_TOKEN }}"
- name: Define Heroku build source
run: |
jq --null-input '{
"source_blob": {
"url": "https://github.com/\(env.GITHUB_REPOSITORY)/archive/\(env.GITHUB_SHA).tar.gz",
"version": env.GITHUB_SHA
}
}' | tee build-source.json
- name: Start Heroku build
run: |
curl https://api.heroku.com/apps/"$HEROKU_APP"/builds \
--fail --silent --show-error --location --netrc \
--data-binary @build-source.json \
--header 'Content-Type: application/json' \
--header 'Accept: application/vnd.heroku+json; version=3' \
| tee build.json
- name: Monitor Heroku build
run: |
curl "$(jq -r .output_stream_url build.json)" \
--fail --silent --show-error --location
- name: Check Heroku build
run: |
id="$(jq -r .id build.json)"
curl https://api.heroku.com/apps/"$HEROKU_APP"/builds/"$id" \
--fail --silent --show-error --location --netrc \
--header 'Accept: application/vnd.heroku+json; version=3' \
| tee build.json
status="$(jq -r .status build.json)"
if [[ "$status" != succeeded ]]; then
echo "build status is $status (not succeeded)" >&2
exit 1
fi
- if: always()
name: Logout of Heroku
run: sed -i -e '/^machine api\.heroku\.com/d' ~/.netrc