-
Notifications
You must be signed in to change notification settings - Fork 8
218 lines (200 loc) · 7.29 KB
/
pr-open.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
name: Preview and Test
on:
pull_request:
types:
- opened
- reopened
- synchronize
# push:
# branches:
# - "feature/**"
# Only run the latest. Cancel old runs in progress.
concurrency:
cancel-in-progress: true
group: "preview-env-manage-${{ github.ref_name }}"
env:
APP_NAME: ${{ github.event.repository.name }}
VPC_ID: vpc-0a83201b71e854abd
COPILOT_SERVICE: mindlogger-backend
AWS_REGION: us-east-1
jobs:
# set-env-name:
# uses: ./.github/workflows/env-name.yaml
create-preview-env:
uses: ./.github/workflows/create-preview-env.yaml
with:
env-name: "pr-${{ github.event.number }}"
env-snake-name: "pr_${{ github.event.number }}"
app-name: ${{ github.event.repository.name }}
vpc-id: vpc-0a83201b71e854abd
copilot-service: mindlogger-backend
# name: Create Preview Env
# needs: [set-env-name]
# permissions:
# id-token: write
# contents: read
# pull-requests: write
# discussions: write
# env:
# ENV_NAME: ${{ needs.set-env-name.outputs.env-name }}
# ENV_SNAKE_NAME: ${{ needs.set-env-name.outputs.env-snake-name }}
#
# runs-on: ubuntu-latest
# steps:
# - name: configure aws credentials
# uses: aws-actions/configure-aws-credentials@v4
# with:
# role-to-assume: arn:aws:iam::992382368072:role/cmiml-feature-oidc-github-role
# role-session-name: gha-preview-env
# aws-region: ${{ env.AWS_REGION }}
# - name: Install copilot
# run: |
# curl -Lo copilot https://github.com/aws/copilot-cli/releases/latest/download/copilot-linux && chmod +x copilot &&
# sudo mv copilot /usr/local/bin/copilot && copilot -v
# - name: Create secrets for environment
# # Each env needs a secret. This is a copilot limitation. So the baseline secret
# # is copied and tagged properly for copilot to pick it up.
# run: |
# SECRET_STRING=$(aws secretsmanager get-secret-value --secret-id cmiml-feature-feature)
# aws secretsmanager create-secret --name cmiml-feature-${{ env.ENV_NAME }} --secret-string '$SECRET_STRING' --kms-key-id alias/aws/secretsmanager --tags "Key=copilot-application,Value=${{ env.APP_NAME }}" "Key=copilot-environment,Value=${{ env.ENV_NAME }}"
#
# - uses: actions/checkout@v4
# name: Checkout
# - name: Create environment
# run: copilot/scripts/env-init.sh
# - name: Deploy environment
# run: copilot/scripts/env-deploy.sh
# - name: Deploy service
# run: copilot/scripts/svc-deploy.sh
# - name: Get service URL
# id: service-url
# run: echo "SERVICE_URL=$(copilot svc show -n service-a --json | jq -r '.routes[] | select( .environment | contains("${{ env.ENV_NAME }}") ) | .url')" >> $GITHUB_OUTPUT
# - name: Comment on PR
# uses: thollander/actions-comment-pull-request@v2
# if: ${{ github.event_name == 'pull_request' }}
# with:
# message: |
# :arrow_right: Preview environment created: [Click Me!](${{ steps.service-url.outputs.SERVICE_URL }})
# reactions: eyes, rocket
# comment_tag: service-url
# outputs:
# service-url: ${{ steps.service-url.outputs.SERVICE_URL }}
run-unit-tests:
needs: [create-preview-env]
uses: ./.github/workflows/tests.yaml
create-database:
needs: [create-preview-env]
uses: ./.github/workflows/create_db.yaml
with:
db-name: "mindlogger_backend_pr_${{ github.event.number }}"
run-int-tests:
name: Run TAF Test Suite
needs: [create-preview-env, run-unit-tests]
if: ${{ always() && (needs.run-unit-tests.result == 'success') }}
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
pull-requests: write
discussions: write
steps:
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::992382368072:role/cmiml-feature-oidc-github-role
role-session-name: gha-preview-env
aws-region: ${{ env.AWS_REGION }}
- uses: actions/checkout@v4
name: Checkout
with:
repository: ChildMindInstitute/MindLogger-TAF
# Matching deploy key in TAF repo
ssh-key: ${{ secrets.TAF_PRIVATE_KEY }}
ref: release
- name: Install
run: npm install
- name: Setup Environment
run: |
sed -i 's/API_DOMAIN.*//' .env ;
echo 'API_DOMAIN=${{ needs.create-preview-env.outputs.service-url }}' >> .env
- name: Get Secrets by Name and by ARN
uses: aws-actions/aws-secretsmanager-get-secrets@v2
with:
secret-ids: |
taf/dev
parse-json-secrets: true
- name: Run tests
run: npm run test:api
continue-on-error: true
id: taf-tests
- name: Comment on PR with test success
if: steps.taf-tests.outcome == 'success' && github.event_name == 'pull_request'
uses: thollander/actions-comment-pull-request@v2
with:
message: |
:white_check_mark: Unit/Integration tests passed!
comment_tag: taf-results
- name: Comment on PR with test failure
if: steps.taf-tests.outcome != 'success' && github.event_name == 'pull_request'
uses: thollander/actions-comment-pull-request@v2
with:
message: |
:x: Integration tests failed
comment_tag: taf-results
- name: Fail
if: steps.taf-tests.outcome != 'success' && github.event_name == 'pull_request'
uses: actions/github-script@v3
with:
script: |
core.setFailed('Unit tests failed')
- name: Collect artifacts
uses: actions/upload-artifact@v4
with:
name: taf-results
path: test-results/api
if-no-files-found: error
- name: Fail if tests failed
if: steps.taf-tests.outcome != 'success'
uses: actions/github-script@v3
with:
script: |
core.setFailed('Unit/Int tests failed')
publish-report:
name: Publish Report
needs: [run-int-tests]
if: ${{ always() && github.event_name == 'pull_request' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
name: Checkout
with:
ref: gh-pages
path: gh-pages
- name: Fetch results
uses: actions/download-artifact@v4
with:
name: taf-results
path: test-results/api
- name: Build test report
uses: simple-elf/allure-report-action@master
if: always()
with:
allure_results: test-results/api
gh_pages: gh-pages
allure_history: allure-history
keep_reports: 20
- name: Deploy report to Github Pages
if: always()
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: allure-history
- name: Post the link to the report
if: always()
uses: Sibz/github-status-action@v1
with:
authToken: ${{secrets.GITHUB_TOKEN}}
context: 'Test report'
state: 'success'
sha: ${{ github.event.pull_request.head.sha }}
target_url: https://childmindinstitute.github.io/preview-app-demo/${{ github.run_number }}