-
Notifications
You must be signed in to change notification settings - Fork 0
232 lines (215 loc) · 8.96 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
# 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
pull_request:
workflow_dispatch:
inputs:
webapp_branch:
description: "Webapp branch to test against"
required: true
permissionapi_branch:
description: "Permissions api branch to test against"
required: true
scoutgame_branch:
description: "Scoutgame 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:
SCOUTGAME_WORKFLOW_BRANCH:
jobs:
build-test-env:
name: Build test env
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install dependencies
uses: ./.github/actions/install
- name: Run build
uses: ./.github/actions/build
push-package:
name: Push Release candidate package to allow devs to use to test
runs-on: ubuntu-latest
needs: build-test-env
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 }}
scoutgame_workflow_branch: ${{ steps.set_downstream_repo_branch.outputs.scoutgame_workflow_branch }}
steps:
- name: Determine downstream repo branch to run tests against
id: set_downstream_repo_branch
run: |
# values of this step's output is used in step test-downstream-apps
# 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
echo "scoutgame_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
echo "scoutgame_workflow_branch=${{inputs.scoutgame_branch}}" >> $GITHUB_OUTPUT
else
echo "webapp_workflow_branch=${WEBAPP_WORKFLOW_BRANCH:-main}" >> $GITHUB_OUTPUT
echo "permissionapi_workflow_branch=${PERMISSION_WORKFLOW_BRANCH:-main}" >> $GITHUB_OUTPUT
echo "scoutgame_workflow_branch=${SCOUTGAME_WORKFLOW_BRANCH:-main}" >> $GITHUB_OUTPUT
fi
- name: Checkout ref of the event that triggered this workflow. (first time run)
uses: actions/checkout@v4
- name: Checkout head of merge on re-run
uses: actions/checkout@v4
if: github.event_name != 'push' && github.run_attempt > 1
with:
ref: refs/pull/${{ github.event.number }}/merge
- name: Print out run attempt and pkg version
run: |
echo "Pkg version before bump - $(cat package.json | jq -r '.version')"
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 }}
test-downstream-apps:
name: Run tests in ${{matrix.repo}}
if: (github.event_name == 'pull_request' && ( github.event.action == 'opened' || github.event.action == 'synchronize' ))
runs-on: ubuntu-latest
needs: push-package
permissions:
pull-requests: write
strategy:
max-parallel: 2
fail-fast: false
matrix:
include:
- owner: "charmverse"
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 }}" }
- owner: "charmverse"
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 }}" }
- owner: "scoutgame"
repo: "scoutgame.xyz"
branch: "${{ needs.push-package.outputs.scoutgame_workflow_branch }}"
workflow_file: "test_new_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: ${{ matrix.owner }}
repo: ${{ matrix.repo }}
github_token: ${{ secrets.CHARMED_BOT_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 }}
tests:
name: Run 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"
test_command: "npm run test:ci"
steps:
- uses: actions/checkout@v4
- 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: Bump Core pkg in ${{ matrix.repo }}
runs-on: ubuntu-latest
permissions:
contents: write
needs: [push-package, tests]
strategy:
max-parallel: 2
fail-fast: false
matrix:
include:
- owner: "charmverse"
repo: "app.charmverse.io"
core_pkg_version: "${{needs.push-package.outputs.pkg_version}}"
- owner: "charmverse"
repo: "permissions.charmverse.io"
core_pkg_version: "${{needs.push-package.outputs.pkg_version}}"
- owner: "scoutgame"
repo: "scoutgame.xyz"
core_pkg_version: "${{needs.push-package.outputs.pkg_version}}"
steps:
- name: Trigger Core pkg update and deploy on repo ${{ matrix.repo }}
env:
GITHUB_TOKEN: ${{ secrets.CHARMED_BOT_PAT }}
run: |
set -e
echo "Processing ${{matrix.repo}} ${{secrets.CHARMED_BOT_PAT}}"
git clone --depth=1 https://[email protected]/${{ matrix.owner }}/${{matrix.repo}}.git ~/${{matrix.repo}}
cd ~/${{matrix.repo}}
# Don't download deps, we don't need them
timeout=0
until [ "$timeout" -gt 10 ]; do
# if npm install ran ok, break out of loop, else sleep then try again
npm install --save --package-lock-only "@charmverse/core@${{needs.push-package.outputs.pkg_version}}" && break;
echo "sleep 5 secs then retry install" && ((timeout+=1)) && sleep 5
done
if [ "$timeout" -le 10 ]; then
git config user.name charmed-bot
git config user.email [email protected]
git add package-lock.json package.json
git commit -m "bump core to v${{needs.push-package.outputs.pkg_version}}"
git push
fi