-
Notifications
You must be signed in to change notification settings - Fork 11
166 lines (159 loc) · 8.13 KB
/
gci-e2e.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
name: gci-e2e
on:
schedule:
- cron: "0 0 * * 0"
workflow_dispatch:
push:
branches: [master]
pull_request:
paths-ignore:
- "images/**"
- "sql/analytics/**"
- "**.md"
- "docs/**"
- "i18n/**"
pull_request_target:
types: [labeled]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 15
if: ${{!github.event.issue.pull_request_target || contains(github.event.pull_request.labels.*.name, 'safe to test')}}
env:
DB_PASS_CI: kmq_ci_password
DB_USER_CI: root
DB_PORT: 3306
steps:
- name: Checkout KMQ_Discord
uses: actions/checkout@v4
- name: Copy .env for CI
env:
BOT_TOKEN: ${{ secrets.KMQ_CI_BOT_TOKEN }}
BOT_CLIENT: ${{ secrets.BOT_CLIENT }}
END_TO_END_TEST_BOT_TOKEN: ${{ secrets.END_TO_END_TEST_BOT_TOKEN }}
END_TO_END_TEST_BOT_CLIENT: ${{ secrets.END_TO_END_TEST_BOT_CLIENT }}
END_TO_END_TEST_BOT_CHANNEL: ${{ secrets.END_TO_END_TEST_BOT_CHANNEL }}
END_TO_END_TEST_BOT_VOICE_CHANNEL: ${{ secrets.END_TO_END_TEST_BOT_VOICE_CHANNEL }}
SPOTIFY_CLIENT_ID: ${{ secrets.SPOTIFY_CLIENT_ID }}
SPOTIFY_CLIENT_SECRET: ${{ secrets.SPOTIFY_CLIENT_SECRET }}
YOUTUBE_API_KEY: ${{ secrets.YOUTUBE_API_KEY }}
run: |
echo "DB_USER=$DB_USER_CI" >> .env
echo "DB_PASS=$DB_PASS_CI" >> .env
echo "DB_PORT=$DB_PORT" >> .env
echo "DB_HOST=127.0.0.1" >> .env
echo "BOT_TOKEN=$BOT_TOKEN" >> .env
echo "WEB_SERVER_PORT=5858" >> .env
echo "SONG_DOWNLOAD_DIR=/songs" >> .env
echo "BOT_CLIENT_ID=$BOT_CLIENT" >> .env
echo "BOT_PREFIX=." >> .env
echo "APP_NAME=kmq-gci" >> .env
echo "DAISUKI_DB_PASSWORD=unusedpw" >> .env
echo "END_TO_END_TEST_BOT_TOKEN=$END_TO_END_TEST_BOT_TOKEN" >> .env
echo "END_TO_END_TEST_BOT_CLIENT=$END_TO_END_TEST_BOT_CLIENT" >> .env
echo "END_TO_END_TEST_BOT_CHANNEL=$END_TO_END_TEST_BOT_CHANNEL" >> .env
echo "END_TO_END_TEST_BOT_VOICE_CHANNEL=$END_TO_END_TEST_BOT_VOICE_CHANNEL" >> .env
echo "SPOTIFY_CLIENT_ID=$SPOTIFY_CLIENT_ID" >> .env
echo "SPOTIFY_CLIENT_SECRET=$SPOTIFY_CLIENT_SECRET" >> .env
echo "YOUTUBE_API_KEY=$YOUTUBE_API_KEY" >> .env
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Setup MariaDB
uses: getong/[email protected]
with:
mariadb version: "10.6.17"
mysql root password: "$DB_PASS_CI"
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build Docker image
uses: docker/build-push-action@v5
with:
context: .
file: docker/kmq/Dockerfile
push: false
tags: ghcr.io/brainicism/kmq_discord:gci
- name: Determine if MOCK_AUDIO should be set
id: check_labels
# if: github.event_name == 'pull_request' || github.event_name == 'pull_request_target'
run: |
# # Extract the labels from the PR
# LABELS="$(gh api repos/$OWNER/$REPO_NAME/pulls/$PULL_REQUEST_NUMBER --jq '.labels.[].name')"
# # Check if "mock audio" is among the labels
# if echo "$LABELS" | grep -q "mock audio"; then
# echo "MOCK_AUDIO=true" >> $GITHUB_ENV
# else
# echo "MOCK_AUDIO=false" >> $GITHUB_ENV
# fi
# # temporarily (?) mock audio until we have a longer term solution
# echo "MOCK_AUDIO=true" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OWNER: ${{ github.repository_owner }}
REPO_NAME: ${{ github.event.repository.name }}
PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }}
- name: Install protobuf compiler
run: sudo apt install -y protobuf-compiler
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Acquire youtube session tokens
if: ${{ env.MOCK_AUDIO != 'true' }}
run: mkdir data && bash src/scripts/session-generator.sh data/ bgutil
- name: Dry-run bootstrap
run: |
. ./.env
docker run \
-v ${SONG_DOWNLOAD_DIR}:${SONG_DOWNLOAD_DIR} \
-v ${PWD}/data:/app/data \
-v ${PWD}/.env:/app/.env \
-v ${PWD}/logs:/app/logs \
--env NODE_ENV=dry-run \
${MOCK_AUDIO:+--env MOCK_AUDIO=$MOCK_AUDIO} \
--network=host \
--name kmq-gci \
ghcr.io/brainicism/kmq_discord:gci && docker rm -f kmq-gci
- name: Validate available_songs
run: |
[[ $(mysql kmq -s -N -h 127.0.0.1 -u $DB_USER_CI -p$DB_PASS_CI -e 'select count(1) from available_songs') -eq 6 ]]
- name: Pre-upgrade run
run: . ./.env && docker run -v ${SONG_DOWNLOAD_DIR}:${SONG_DOWNLOAD_DIR} -v ${PWD}/data:/app/data -v ${PWD}/.env:/app/.env -v ${PWD}/logs:/app/logs --env NODE_ENV=production --network=host --name kmq-gci ghcr.io/brainicism/kmq_discord:gci &
- name: Check pre-upgrade KMQ healthiness
run: while [[ "$(docker inspect --format='{{json .State.Health.Status}}' kmq-gci)" != "\"healthy\"" ]]; do sleep 1; done
- name: Run test runner on live instance (game options test)
run: docker exec --env-file ./.env kmq-gci sh -c 'npx ts-node --swc src/test/end-to-end-tests/test-runner-bot.ts --test-suite=BASIC_OPTIONS --debug; exit $?'
- name: Run test runner on live instance (gameplay test)
run: docker exec --env-file ./.env kmq-gci sh -c 'npx ts-node --swc src/test/end-to-end-tests/test-runner-bot.ts --test-suite=PLAY --debug; exit $?'
- name: Check for errors
if: always()
run: docker logs kmq-gci 2>&1 | grep -i "\[Error\]" && echo "Errors found in container logs." && exit 1 || echo "No errors found in container logs." && exit 0
- name: Print logs
if: always()
run: |
docker logs kmq-gci 2>&1
docker inspect kmq-gci | jq '.[].State'
docker --version
- name: Parse pre-upgrade container ID
id: old-container-id
run: |
docker ps
echo OLD_CONTAINER_ID=$(sudo docker ps -aqf "name=kmq-gci") > $GITHUB_OUTPUT
- name: Begin upgrade
run: bash src/scripts/announce-restart.sh --docker-image ghcr.io/brainicism/kmq_discord:gci --timer 0 --provisioning-timeout 15
- name: Check post-upgrade KMQ healthiness
run: while [[ "$(docker inspect --format='{{json .State.Health.Status}}' kmq-gci)" != "\"healthy\"" ]]; do sleep 1; done
- name: Check old primary no longer exists
run: |
docker ps
[ $(docker ps -aq | grep -c ${{ steps.old-container-id.outputs.OLD_CONTAINER_ID }}) -eq 0 ]