-
Notifications
You must be signed in to change notification settings - Fork 5
150 lines (143 loc) · 4.63 KB
/
build-and-test.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
name: Build
on:
pull_request: {}
push:
branches:
- main
tags:
- v*
issue_comment:
types: [created, edited]
jobs:
decide-parameters:
runs-on: ubuntu-latest
steps:
- name: Output environment
run: |
echo '${{ github.ref }}'
echo <<-EOF
${{ toJSON(github.event) }}
EOF
outputs:
# Run builds for all non-comment triggers.
should-build: >-
${{
github.event_name != 'issue_comment'
}}
# Run tests for all non-comment triggers;
# ignore non-PR comment triggers;
# and for PR comment triggers, only run tests if they are explicitly
# requested.
should-test: >-
${{
github.event_name != 'issue_comment' ||
(
github.event.issue.pull_request && (
contains(github.event.comment.body, 'rerun tests, please') ||
contains(github.event.comment.body, 'Rerun tests, please')
)
)
}}
# Deploy for all main merges;
# for non-main meges, deploy for all tags;
# for comments, only deploy if explicitly requested;
# and for PR comment triggers, only run deployments if they are
# explicitly requested.
should-deploy: >-
${{
github.ref == 'refs/heads/main' ||
startsWith(github.ref, 'refs/tags/') ||
(
github.event_name == 'issue_comment' &&
github.event.issue.pull_request && (
contains(github.event.comment.body, 'deploy, please') ||
contains(github.event.comment.body, 'Deploy, please')
)
)
}}
output-parameters:
needs: decide-parameters
runs-on: ubuntu-latest
steps:
- name: Output parameters
run: |
echo '${{ toJSON(needs.decide-parameters.outputs) }}'
test:
runs-on: ubuntu-latest
needs: decide-parameters
if: ${{ needs.decide-parameters.outputs.should-test == 'true' }}
steps:
- uses: actions/checkout@v3
- name: Read .nvmrc
run: echo "NVMRC=$(cat ./.nvmrc)" > $GITHUB_OUTPUT
id: nvm
- name: Use Node + Yarn
uses: actions/setup-node@v3
with:
node-version: "${{ steps.nvm.outputs.NVMRC }}"
cache: "yarn"
- run: yarn install --frozen-lockfile
- run: yarn test
build-and-push-image:
runs-on: ubuntu-latest
needs: [test, decide-parameters]
if: ${{ needs.decide-parameters.outputs.should-build == 'true' || needs.decide-parameters.outputs.should-deploy == 'true' }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Read .nvmrc
run: echo "NVMRC=$(cat ./.nvmrc)" > $GITHUB_OUTPUT
id: nvm
- name: Use Node + Yarn
uses: actions/setup-node@v3
with:
node-version: "${{ steps.nvm.outputs.NVMRC }}"
cache: "yarn"
- run: yarn install --frozen-lockfile
- name: Build docker image
run: |
echo $GITHUB_SHA > BUILD
docker build . -f infrastructure/docker/Dockerfile -t gcr.io/thesis-ops-2748/valkyrie:$GITHUB_SHA
- name: Authenticate push with GCP
if: ${{ needs.decide-parameters.outputs.should-deploy == 'true' }}
id: 'auth-push'
uses: 'google-github-actions/auth@v0'
with:
credentials_json: '${{ secrets.GCP_GCR_CREDENTIALS }}'
- name: Set up GCP tools
if: ${{ needs.decide-parameters.outputs.should-deploy == 'true' }}
uses: google-github-actions/setup-gcloud@v0
- name: Push docker image to GCP
if: ${{ needs.decide-parameters.outputs.should-deploy == 'true' }}
run: |
# Set up docker to authenticate via gcloud command-line tool.
gcloud auth configure-docker
docker push gcr.io/thesis-ops-2748/valkyrie:${{ github.sha }}
deploy:
needs: [build-and-push-image, decide-parameters]
if: ${{ needs.decide-parameters.outputs.should-deploy == 'true' }}
uses: ./.github/workflows/deploy.yml
with:
docker-image-name: valkyrie
docker-image-version: ${{ github.sha }}
gcp-project-name: thesis-ops
gcp-project-id: thesis-ops-2748
secrets:
GCP_DEPLOY_CREDENTIALS: ${{ secrets.GCP_DEPLOY_CREDENTIALS }}
lint:
needs: [decide-parameters]
if: ${{ needs.decide-parameters.outputs.should-build == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Read .nvmrc
run: echo "NVMRC=$(cat ./.nvmrc)" > $GITHUB_OUTPUT
id: nvm
- name: Use Node + Yarn
uses: actions/setup-node@v3
with:
node-version: "${{ steps.nvm.outputs.NVMRC }}"
cache: "yarn"
- run: yarn install --frozen-lockfile
- run: yarn lint