-
Notifications
You must be signed in to change notification settings - Fork 0
223 lines (192 loc) · 7.21 KB
/
trunk-pipeline.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
---
name: Trunk pipeline to production
on: # yamllint disable-line rule:truthy
push:
branches:
- master
jobs:
deploy-to-post-merge:
runs-on: ubuntu-latest
environment: post-merge
steps:
- uses: actions/[email protected]
- uses: akhileshns/[email protected]
with:
heroku_api_key: ${{ secrets.HEROKU_API_KEY }}
heroku_app_name: ${{ secrets.HEROKU_APP_NAME }}
heroku_email: ${{ secrets.HEROKU_EMAIL }}
- name: Check out code
uses: actions/checkout@v2
- name: Install Gauge
uses: getgauge/setup-gauge@master
with:
gauge-version: master
gauge-plugins: js, html-report, screenshot
- name: Post-merge FTs
env:
WEB_URL: ${{ secrets.WEB_URL }}
run: |
cd functional-tests
npm install
gauge run
- name: Upload logs
uses: actions/upload-artifact@v1
if: always()
with:
name: post-merge-fts-logs
path: functional-tests/logs
- name: Set contract repo HEAD output var
id: set-contract-head-output-var
# NB we append the date time to the tag to make it unique,
# as multiple commits can be linked to the same contract repo commit
run: |
CONTRACT_REPO=https://github.com/agilepathway/available-pets-consumer-contract
CONTRACT_HEAD=($(git ls-remote --heads $CONTRACT_REPO refs/heads/master))
DATETIME=$(date '+%Y-%m-%d-%H-%M-%S')
echo "::set-output name=contract-head::available-pets-consumer-contract-${CONTRACT_HEAD}-${DATETIME}"
- name: Tag commit with HEAD commit from contract repo
uses: actions/github-script@v5
with:
github-token: ${{ github.token }}
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: "refs/tags/${{ steps.set-contract-head-output-var.outputs.contract-head }}",
sha: context.sha
})
deploy-ephemeral-provider-for-can-i-deploy-check:
needs: deploy-to-post-merge
runs-on: ubuntu-latest
environment: can-i-deploy
steps:
- name: Set provider repo production commit output var
id: set-provider-production-commit-output-var
# HEROKU_SLUG_COMMIT is available via https://devcenter.heroku.com/articles/dyno-metadata
run: |
COMMIT=$(heroku config:get --app petstore-openapi-service HEROKU_SLUG_COMMIT)
echo "::set-output name=commit::${COMMIT}"
env:
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
- uses: actions/[email protected]
with:
repository: agilepathway/petstore-service
ref: ${{ steps.set-provider-production-commit-output-var.outputs.commit }}
- uses: akhileshns/[email protected]
with:
heroku_api_key: ${{ secrets.HEROKU_API_KEY }}
heroku_app_name: ephemeral-petstore-service
heroku_email: ${{ secrets.HEROKU_EMAIL }}
can-i-deploy:
needs: deploy-ephemeral-provider-for-can-i-deploy-check
# Verify that the provider satisfies the contract for our specific consumer commit.
# If the contract is not satisfied by the provider then the pipeline stops and we do
# not deploy to our integrated environments (pre-production and production). We would
# then wait for the provider to deploy the changes necessary on their side.
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
with:
fetch-depth: '0'
- name: Set contract repo commit output var
id: set-contract-commit-output-var
run: |
CONTRACT_TAG=$(git describe --match "available-pets-consumer-contract*" --tags ${GITHUB_SHA})
TMP=${CONTRACT_TAG#*available-pets-consumer-contract-} # remove prefix ending in "_"
CONTRACT_COMMIT=${TMP%%-*} # remove suffix starting with "-"
echo "::set-output name=contract-commit::${CONTRACT_COMMIT}"
- name: Check out contract repo
# We checkout the specific commit on the contract repo that we associated (tagged) with our consumer commit
uses: actions/checkout@v2
with:
repository: agilepathway/available-pets-consumer-contract
path: './contract'
ref: ${{ steps.set-contract-commit-output-var.outputs.contract-commit }}
- name: Set up Java
uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: '17'
- name: Install Gauge
uses: getgauge/setup-gauge@master
with:
gauge-plugins: java, html-report
- name: Install Prism
run: npm install -g @stoplight/prism-cli
- name: Start Prism in validation proxy mode
working-directory: ./contract
run: prism proxy openapi.yaml https://ephemeral-petstore-service.herokuapp.com/v2 --errors &
- name: Check that the provider in production satisfies the contract
env:
OPENAPI_HOST: http://127.0.0.1:4010
working-directory: ./contract
run: gauge run specs
- name: Upload Gauge test report
uses: actions/upload-artifact@v2
if: always()
with:
name: gauge-html-report
path: contract/reports/html-report/
deploy-to-pre-production:
needs: can-i-deploy
runs-on: ubuntu-latest
environment: pre-production
steps:
- uses: actions/[email protected]
- uses: akhileshns/[email protected]
with:
heroku_api_key: ${{ secrets.HEROKU_API_KEY }}
heroku_app_name: ${{ secrets.HEROKU_APP_NAME }}
heroku_email: ${{ secrets.HEROKU_EMAIL }}
- name: Check out code
uses: actions/checkout@v2
- name: Install Gauge
uses: getgauge/setup-gauge@master
with:
gauge-version: master
gauge-plugins: js, html-report, screenshot
- name: Pre-production FTs
env:
WEB_URL: ${{ secrets.WEB_URL }}
run: |
cd functional-tests
npm install
gauge run
- name: Upload logs
uses: actions/upload-artifact@v1
if: always()
with:
name: pre-production-fts-logs
path: functional-tests/logs
deploy-to-production:
needs: deploy-to-pre-production
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/[email protected]
- uses: akhileshns/[email protected]
with:
heroku_api_key: ${{ secrets.HEROKU_API_KEY }}
heroku_app_name: ${{ secrets.HEROKU_APP_NAME }}
heroku_email: ${{ secrets.HEROKU_EMAIL }}
- name: Check out code
uses: actions/checkout@v2
- name: Install Gauge
uses: getgauge/setup-gauge@master
with:
gauge-version: master
gauge-plugins: js, html-report, screenshot
- name: Production FTs
env:
WEB_URL: ${{ secrets.WEB_URL }}
run: |
cd functional-tests
npm install
gauge run
- name: Upload logs
uses: actions/upload-artifact@v1
if: always()
with:
name: production-fts-logs
path: functional-tests/logs