-
Notifications
You must be signed in to change notification settings - Fork 0
235 lines (217 loc) · 8.76 KB
/
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
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
224
225
226
227
228
229
230
231
232
233
234
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: CI
on:
push:
branches: [main]
# paths:
# - '!.github/**'
pull_request:
branches: ['**']
workflow_dispatch:
inputs:
webapp_branch:
description: 'Webapp branch to test against.'
required: true
permissionapi_branch:
description: 'Permissions api branch to test against'
required: true
# Change the below to get your PR CI to run tests against a specific branch
# Overrides the input, as inputs always have a default value
env:
WEBAPP_WORKFLOW_BRANCH:
PERMISSION_WORKFLOW_BRANCH:
jobs:
build-test-env:
name: Build test env
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install dependencies
uses: ./.github/actions/install
- name: Run build
uses: ./.github/actions/build
typecheck:
name: Type Check
runs-on: ubuntu-latest
needs: build-test-env
steps:
- uses: actions/checkout@v3
- name: Restore dependencies from cache
uses: ./.github/actions/install
- name: Run type check
run: |
npm run typecheck
push-package:
name: Push Release candidate package to allow devs to use to test
runs-on: ubuntu-latest
needs: typecheck
permissions:
contents: write
pull-requests: write
outputs:
pkg_version: ${{ steps.publish_pkg.outputs.pkg_version }}
webapp_workflow_branch: ${{ steps.set_downstream_repo_branch.outputs.webapp_workflow_branch }}
permissionapi_workflow_branch: ${{ steps.set_downstream_repo_branch.outputs.permissionapi_workflow_branch }}
steps:
- name: Determine downstream repo branch to run tests against first
id: set_downstream_repo_branch
run: |
# values of this step's output is used in step run-downstream-test-workflows
# strategy/matrix doesn't permit access to env context. very lame...
if [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == "refs/heads/main" ]]; then
echo "webapp_workflow_branch='main'" >> $GITHUB_OUTPUT
echo "permissionapi_workflow_branch='main'" >> $GITHUB_OUTPUT
elif [[ ${{ github.event_name }} == 'workflow_dispatch' ]]; then
echo "webapp_workflow_branch=${{inputs.webapp_branch}}" >> $GITHUB_OUTPUT
echo "permissionapi_workflow_branch=${{inputs.permissionapi_branch}}" >> $GITHUB_OUTPUT
else
if [[ -z $WEBAPP_WORKFLOW_BRANCH || -z $PERMISSION_WORKFLOW_BRANCH ]]; then
echo "::notice title=Test branch target::Setting downstream repo test to test against branch main."
WEBAPP_WORKFLOW_BRANCH='main'
PERMISSION_WORKFLOW_BRANCH='main'
else
if [[ $WEBAPP_WORKFLOW_BRANCH != "${{ github.head_ref }}" || $PERMISSION_WORKFLOW_BRANCH != "${{ github.head_ref }}" ]]; then
echo "::warning title=Mismatch in test branch target::Workflow branch env vars is not this current branch. Are you sure they are set correctly??"
echo "Setting downstream repo branch to what is set in env."
echo "PR head branch: $GITHUB_HEAD_REF_SLUG"
echo "env WEBAPP_WORKFLOW_BRANCH: $WEBAPP_WORKFLOW_BRANCH"
echo "env PERMISSION_WORKFLOW_BRANCH: $PERMISSION_WORKFLOW_BRANCH"
fi
fi
echo "webapp_workflow_branch=$WEBAPP_WORKFLOW_BRANCH" >> $GITHUB_OUTPUT
echo "permissionapi_workflow_branch=$PERMISSION_WORKFLOW_BRANCH" >> $GITHUB_OUTPUT
fi
- name: Checkout ref of the event that triggered this workflow. (first time run)
uses: actions/checkout@v3
- name: Checkout head of merge on re-run
uses: actions/checkout@v3
if: github.event_name != 'push' && github.run_attempt > 1
with:
ref: refs/pull/${{ github.event.number }}/merge
- run: |
cat package.json
echo "run attempt ${{github.run_attempt}}"
- name: Restore build cache
uses: ./.github/actions/build
- name: Package and publish release candidate pkg
id: publish_pkg
uses: ./.github/actions/package_n_publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
- name: Posting pkg version in comment
uses: marocchino/sticky-pull-request-comment@v2
with:
header: Pkg version
message: |
Code ${{ github.sha }} labeled version ${{ steps.publish_pkg.outputs.pkg_version }}
run-downstream-test-workflows:
if: github.event_name != 'push' && github.ref != 'refs/heads/main'
name: Trigger ${{matrix.repo}} testing workflow
runs-on: ubuntu-latest
needs: push-package
permissions:
pull-requests: write
strategy:
max-parallel: 2
fail-fast: false
matrix:
include:
- repo: "app.charmverse.io"
branch: "${{ needs.push-package.outputs.webapp_workflow_branch }}"
workflow_file: "test_new_core_pkg.yml"
workflow_payload: |
{ "core_pkg_version": "${{ needs.push-package.outputs.pkg_version }}" }
- repo: "permissions.charmverse.io"
branch: "${{ needs.push-package.outputs.permissionapi_workflow_branch }}"
workflow_file: "test_core_pkg.yml"
workflow_payload: |
{ "core_pkg_version": "${{ needs.push-package.outputs.pkg_version }}" }
steps:
- name: Trigger tests on repo ${{ matrix.repo }}
uses: convictional/[email protected]
with:
owner: charmverse
repo: ${{ matrix.repo }}
github_token: ${{ secrets.WORKFLOW_TRIGGER_PAT }}
github_user: charmed-bot
workflow_file_name: ${{ matrix.workflow_file }}
ref: ${{ matrix.branch }}
client_payload: ${{ matrix.workflow_payload }}
wait_interval: 10
propagate_failure: true
trigger_workflow: true
wait_workflow: true
comment_downstream_url: ${{ github.event.pull_request.comments_url }}
integration-test:
name: Run Integration Tests
runs-on: ubuntu-latest
needs: build-test-env
# Postgres setup copied from https://gist.github.com/2color/537f8ef13ecec80059abb007839a6878
services:
postgres:
image: postgres
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432
strategy:
max-parallel: 5
fail-fast: false
matrix:
include:
- test_name: "Basic tests #1"
test_command: "npm run test:ci -- --shard 1/2"
- test_name: "Basic tests #2"
test_command: "npm run test:ci -- --shard 2/2"
steps:
- uses: actions/checkout@v3
- name: Restore dependencies from cache
uses: ./.github/actions/install
- name: Setup test database
run: npx dotenv -e .env.test.local -- npm run prisma:reset
- name: Run ${{matrix.test_name}}
run: ${{matrix.test_command}}
trigger-pkg-upgrade:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
name: Trigger Core pkg Upgrade on ${{ matrix.repo }}
runs-on: ubuntu-latest
permissions:
contents: write
needs: [push-package, integration-test]
strategy:
max-parallel: 2
fail-fast: false
matrix:
include:
- repo: "app.charmverse.io"
workflow_file: "test_and_deploy.yml"
workflow_payload: |
{ "core_pkg_version": "${{ needs.push-package.outputs.pkg_version }}" }
- repo: "permissions.charmverse.io"
workflow_file: "test_and_deploy.yml"
workflow_payload: |
{ "core_pkg_version": "${{ needs.push-package.outputs.pkg_version }}" }
steps:
- name: Trigger Core pkg update and deploy on repo ${{ matrix.repo }}
uses: convictional/[email protected]
with:
owner: charmverse
repo: ${{ matrix.repo }}
github_token: ${{ secrets.WORKFLOW_TRIGGER_PAT }}
github_user: charmed-bot
workflow_file_name: ${{ matrix.workflow_file }}
ref: "main"
client_payload: ${{ matrix.workflow_payload }}
wait_interval: 10
propagate_failure: true
trigger_workflow: true
wait_workflow: true