-
Notifications
You must be signed in to change notification settings - Fork 5
179 lines (154 loc) · 6.92 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
name: Run tests
on:
workflow_dispatch:
pull_request:
push:
branches: [master]
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
TEST_ARGS: -vF --print-traffic --no-simulate --color always -f "b*" -S "filesize:10M" --exec "rm -f"
jobs:
lint-format:
name: Lint and format check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Ruff and autopep8
run: pip install ruff autopep8
- name: Python lint check (Ruff)
run: ruff check --output-format=github -v plugin/
- name: Python lint check (autopep8)
if: always()
run: autopep8 --diff plugin/
- name: Install server dependencies
if: always()
run: cd server && yarn install
- name: Server lint check (ESlint)
if: always()
run: cd server && npx eslint --max-warnings=0 src/
- name: Server format check (Prettier)
if: always()
run: cd server && npx prettier --check 'src/**/*.{js,ts}'
script-method:
name: Test plugin (script method)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download yt-dlp
run: curl -L https://github.com/yt-dlp/yt-dlp-nightly-builds/releases/latest/download/yt-dlp -o yt-dlp && chmod +x ./yt-dlp
- name: Install and build server dependencies
run: cd server/ && yarn install --frozen-lockfile && npx tsc
- name: Install plugin
run: |
mkdir -p ~/yt-dlp-plugins/bgutil-ytdlp-pot-provider/
curl -L "https://github.com/coletdjnz/yt-dlp-get-pot/releases/download/v0.1.1/yt-dlp-get-pot.zip" -o ~/yt-dlp-plugins/yt-dlp-get-pot.zip
cp -r plugin/ ~/yt-dlp-plugins/
- name: Test script method
shell: bash
run: |
exit_code=0
# check that the script is returning a POT
script_output=$(node server/build/generate_once.js)
echo "::group::POT response from the script"
echo "$script_output" | jq -C
echo "::endgroup::"
po_token=$(echo "$script_output" | jq -r '.poToken')
visit_identifier=$(echo "$script_output" | jq -r '.visitIdentifier')
if [[ "$po_token" == "null" || "$visit_identifier" == "null" ]]; then
echo "::error title=PoToken generation failed,file=server/src/session_manager.ts::'po_token' or 'visit_identifier' is null."
exit 1
fi
# expect this to fail, but just make sure that the plugin is invoked
{
script_response=$(./yt-dlp ${{ env.TEST_ARGS }} --extractor-args "youtube:getpot_bgutil_script=server/build/generate_once.js" dQw4w9WgXcQ 2>&1)
ret=$?
} || true
echo "::group::Logs from yt-dlp"
printf "%s\n" "$script_response"
echo "::endgroup::"
if [ "$ret" -ne 0 ]; then
echo "::warning title=yt-dlp failed when testing script,file=plugin/yt_dlp_plugins/extractor/getpot_bgutil_script.py::yt-dlp returned $ret exit status"
fi
if [[ "$script_response" != *"BgUtilScriptPot: Generating POT via script: "* ]]; then
echo "::error title=BgUtilScriptPot was not invoked,file=plugin/yt_dlp_plugins/extractor/getpot_bgutil_script.py::\
BgUtilScriptPot was not invoked"
[ "$exit_code" -eq 0 ] && exit_code=1
fi
exit $exit_code
server-method:
name: Test plugin (server method)
runs-on: ubuntu-latest
env:
PORT: ${{ 4426 }}
# Interval/Timeout in seconds to wait for the server to be up
INTERVAL: ${{ 0.5 }}
TIMEOUT: ${{ 7.5 }}
steps:
- uses: actions/checkout@v4
- name: Download yt-dlp
run: curl -L https://github.com/yt-dlp/yt-dlp-nightly-builds/releases/latest/download/yt-dlp -o yt-dlp && chmod +x ./yt-dlp
- name: Install plugin
run: |
mkdir -p ~/yt-dlp-plugins/bgutil-ytdlp-pot-provider/
curl -L "https://github.com/coletdjnz/yt-dlp-get-pot/releases/download/v0.1.1/yt-dlp-get-pot.zip" -o ~/yt-dlp-plugins/yt-dlp-get-pot.zip
cp -r plugin/ ~/yt-dlp-plugins/
- name: Build Docker image
uses: docker/build-push-action@v6
with:
context: server/
file: server/Dockerfile
load: true
tags: brainicism/bgutil-ytdlp-pot-provider:ci
- name: Test server method
timeout-minutes: 3
shell: bash
run: |
exit_code=0
ping() {
until curl -o- --silent --fail http://127.0.0.1:${{ env.PORT }}/ping 2>&1; do
sleep ${1:-0.5}
done
}
export -f ping
docker run --name bgutil-provider -d -p ${{ env.PORT }}:4416 brainicism/bgutil-ytdlp-pot-provider:ci
echo "Waiting for server to be up..."
PING_RESP=$(timeout ${{ env.TIMEOUT }} bash -c "ping ${{ env.INTERVAL }}") || \
(echo "::error title=Timeout reached,file=server/src/main.ts::\
Timeout reached before the server is up." && exit 1)
echo "::group::Response from HTTP server"
echo "$PING_RESP" | jq -C
echo "::endgroup::"
# check that the server is returning a POT
pot_response=$(curl -s -X POST "http://127.0.0.1:${{ env.PORT }}/get_pot")
echo "::group::Get pot response from the HTTP server"
echo "$pot_response" | jq -C
echo "::endgroup::"
po_token=$(echo "$pot_response" | jq -r '.po_token')
visit_identifier=$(echo "$pot_response" | jq -r '.visit_identifier')
if [[ "$po_token" == "null" || "$visit_identifier" == "null" ]]; then
echo "::error title=PoToken generation failed,file=server/src/session_manager.ts::'po_token' or 'visit_identifier' is null."
exit 1
fi
# expect this to fail, but just make sure that the plugin is invoked
{
script_response=$(./yt-dlp ${{ env.TEST_ARGS }} --extractor-args "youtube:getpot_bgutil_baseurl=http://127.0.0.1:${{ env.PORT }}" dQw4w9WgXcQ 2>&1)
ret=$?
} || true
docker stop bgutil-provider
echo "::group::Logs from HTTP server container"
docker logs bgutil-provider
echo "::endgroup::"
echo "::group::Logs from yt-dlp"
printf "%s\n" "$script_response"
echo "::endgroup::"
if [ "$ret" -ne 0 ]; then
echo "::warning title=yt-dlp failed when testing HTTP server,file=plugin/yt_dlp_plugins/extractor/getpot_bgutil_http.py::yt-dlp returned $ret exit status"
fi
if [[ "$script_response" != *"BgUtilHTTPPot: Generating POT via HTTP server"* ]]; then
echo "::error title=BgUtilHTTPPot was not invoked,file=plugin/yt_dlp_plugins/extractor/getpot_bgutil_http.py::\
BgUtilHTTPPot was not invoked"
[ "$exit_code" -eq 0 ] && exit_code=1
fi
exit $exit_code