Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

End to end test workflow #30

Merged
merged 77 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
927adc6
End-to-end test workflow
Brainicism Sep 15, 2024
591bb45
Chmod
Brainicism Sep 15, 2024
46f382e
Capture stderr
Brainicism Sep 15, 2024
d37e6a0
fix 2>&1 position
Brainicism Sep 15, 2024
801f146
cd ..
Brainicism Sep 15, 2024
50c7555
Update .github/workflows/test.yml
grqz Sep 15, 2024
d4afa2d
wait for server up
Brainicism Sep 15, 2024
2586ff5
Merge branch 'e2e-test' of github.com:Brainicism/bgutil-ytdlp-pot-pro…
Brainicism Sep 15, 2024
50d8576
move `lint and format check` to test.yml
grqz Sep 15, 2024
375254b
be consistent: search for corresponding msg
grqz Sep 15, 2024
f24b523
use github-styled error output
grqz Sep 15, 2024
7731931
[wrong] test
grqz Sep 15, 2024
a196a52
[wrong] fix gh error msg
grqz Sep 15, 2024
fd5d643
[wrong] dont report file path
grqz Sep 15, 2024
5f5f2b9
[wrong] fill required field `title`
grqz Sep 15, 2024
45a6f67
[wrong] test
grqz Sep 15, 2024
dbb6d1a
[wrong] test: dont exit with 1
grqz Sep 15, 2024
c761f42
[wrong] handle non-zero exit code from ytdlp
grqz Sep 15, 2024
8b61f0f
[wrong] write error titles
grqz Sep 15, 2024
6472d51
[wrong] format ping result with jq
grqz Sep 15, 2024
3edd410
[wrong] format ping result with jq
grqz Sep 15, 2024
6fbe394
[wrong] display source when yt-dlp fails
grqz Sep 15, 2024
9bee51e
[wrong] test github styled output: ::error
grqz Sep 15, 2024
6a248a4
[wrong] add if:always()
grqz Sep 15, 2024
338a52f
[wrong] exit 1, try omitting line/column
grqz Sep 15, 2024
37eebb5
[wrong] remove line/column
grqz Sep 15, 2024
5b4dfa5
[wrong] remove redundant logging, code formatting
grqz Sep 15, 2024
fc67dd9
[wrong] correct one intentional issue
grqz Sep 15, 2024
e3f12e0
[wrong] fix: path doesnt exist
grqz Sep 15, 2024
a4a49dd
[wrong] group logs, support multi-line logs
grqz Sep 15, 2024
d8c9254
[correct] remove intentional raise
grqz Sep 15, 2024
2d1e6dd
dont use default path: interferes with HTTP test
grqz Sep 15, 2024
6af7872
capture server log
grqz Sep 15, 2024
1892ede
remove several unnecessary `always()`
grqz Sep 15, 2024
f0ddaac
[wrong:for testing] add timer for http server
grqz Sep 15, 2024
ff2c4ba
try to fix trailing spaces
grqz Sep 15, 2024
9b94c4a
try to fix trailing spaces
grqz Sep 15, 2024
44a6a18
[wrong] test ci
grqz Sep 15, 2024
535a213
remove intentional `raise`s
grqz Sep 15, 2024
755e888
[wrong] test with problematic server
grqz Sep 15, 2024
94e9ddb
[wrong:server] exit when timeout reached
grqz Sep 15, 2024
e54276b
[wrong:server] kill the process after being pinged
grqz Sep 15, 2024
bdde8c1
check if process is running before killing
grqz Sep 15, 2024
8d82fce
fix var name
grqz Sep 15, 2024
40a6840
fix everything wrong
grqz Sep 15, 2024
0a768bb
--no-simulate
grqz Sep 15, 2024
d00f5b5
fix: display ping response properly
grqz Sep 15, 2024
8924261
fix: `tee` output
grqz Sep 15, 2024
abc3c43
export ping rresp path
grqz Sep 15, 2024
189e52b
override PING_RESP_PATH instead
grqz Sep 15, 2024
4266e84
dont use tmp file, capture output instead
grqz Sep 15, 2024
3321f5a
use echo for strings
grqz Sep 15, 2024
fefe0c1
dont fmt with jq
grqz Sep 15, 2024
8150f2b
retry
grqz Sep 15, 2024
315a315
debug
grqz Sep 15, 2024
c845dc4
wrong var name
grqz Sep 15, 2024
4feecbc
use jq to parse resp
grqz Sep 15, 2024
714326a
use a larger video
grqz Sep 15, 2024
0ca4221
Update .github/workflows/test.yml
grqz Sep 15, 2024
be5e87a
Update .github/workflows/test.yml
grqz Sep 15, 2024
b5521e5
Use docker for server method
Brainicism Sep 15, 2024
14f4618
@commander-js/extra-typings as non-dev dependecy
Brainicism Sep 15, 2024
6d7e2eb
remove ..
Brainicism Sep 15, 2024
5d4f212
Seperate script/server method into different jobs
Brainicism Sep 15, 2024
e165688
Remove if always in server mode test
Brainicism Sep 15, 2024
c4c9b9a
Remove release.yml from pull requests
Brainicism Sep 15, 2024
01843cc
Docker stop instead of killing pid
Brainicism Sep 15, 2024
c3fef69
Code review changes
Brainicism Sep 15, 2024
5273546
Load: true
Brainicism Sep 15, 2024
2c94d0c
fiix jq error
grqz Sep 16, 2024
95659d5
use colours in jq
grqz Sep 16, 2024
0d14de1
add colour to yt-dlp; use env; cleanup
grqz Sep 16, 2024
8807255
fix port
grqz Sep 16, 2024
08cd278
use numbers in env
grqz Sep 16, 2024
5fd95f8
separate lines in setup script; cleanup
grqz Sep 16, 2024
cd49c82
quote args
grqz Sep 16, 2024
cb94051
use 0.4
grqz Sep 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 5 additions & 37 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,12 @@
name: Create release
on:
workflow_dispatch:
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
lint-format:
name: Lint and format check
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v4
if: always()
- name: Install Ruff and autopep8
if: always()
run: pip install ruff autopep8
- name: Python lint check (Ruff)
if: always()
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}'

release:
name: Release to Github
permissions:
Expand Down Expand Up @@ -67,7 +40,7 @@ jobs:
EOF
echo "::endgroup::"
- name: Bundle
if: github.event_name != 'pull_request' && format('refs/heads/{0}', github.event.repository.default_branch) == github.ref
if: format('refs/heads/{0}', github.event.repository.default_branch) == github.ref
# only release on default branch
id: bundle
env:
Expand Down Expand Up @@ -96,7 +69,7 @@ jobs:
echo "RELEASE_BODY=$r" | tee -a $GITHUB_OUTPUT # <--- Set environment variable

- name: Create Release on Github
if: github.event_name != 'pull_request' && format('refs/heads/{0}', github.event.repository.default_branch) == github.ref
if: format('refs/heads/{0}', github.event.repository.default_branch) == github.ref
# only release on default branch
uses: svenstaro/upload-release-action@v2
with:
Expand All @@ -110,7 +83,7 @@ jobs:

release_pypi:
name: Release to PyPI
if: github.event_name != 'pull_request' && format('refs/heads/{0}', github.event.repository.default_branch) == github.ref
if: format('refs/heads/{0}', github.event.repository.default_branch) == github.ref
# only release on default branch
runs-on: ubuntu-latest
permissions:
Expand Down Expand Up @@ -169,16 +142,13 @@ jobs:
tags: |
type=raw,value=latest,enable={{is_default_branch}}
# mark as latest only if built on default branch of repository
type=raw,value=ci,enable={{is_default_branch}}
# mark as ci only if built on default branch of repository
type=raw,value=${{ needs.release.outputs.version }},enable={{is_default_branch}}
# add the new git tag only if built on default branch of repository
type=sha
type=ref,event=branch
type=ref,event=pr

- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
Expand All @@ -192,21 +162,19 @@ jobs:
with:
context: server/
file: server/Dockerfile
platforms: ${{ github.event_name != 'pull_request' && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
push: ${{ github.event_name != 'pull_request' }}
platforms: "linux/amd64,linux/arm64"
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ steps.meta.outputs.annotations }}

- name: Add official repository link to README.md
if: github.event_name != 'pull_request'
run: |
printf '%s\n\n' \
"Official repository: <${{ github.server_url }}/${{ github.repository }}>" > ./README.md.new
cat ./README.md >> ./README.md.new && mv -f ./README.md.new ./README.md

- name: Update repo description
if: github.event_name != 'pull_request'
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
Expand Down
131 changes: 131 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
name: Run tests
on:
workflow_dispatch:
pull_request:

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
if: github.event_name == 'pull_request'
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: |
script_response=$(./yt-dlp ${{ env.TEST_ARGS }} --extractor-args "youtube:getpot_bgutil_script=server/build/generate_once.js" dQw4w9WgXcQ 2>&1) || \
echo "::error title=Failed to run yt-dlp when testing script::\
yt-dlp returned $? exit status"

echo "::group::Logs from yt-dlp"
printf "%s\n" "$script_response"
echo "::endgroup::"
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 1
fi

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.4 }}
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
Brainicism marked this conversation as resolved.
Show resolved Hide resolved
- name: Test server method
timeout-minutes: 3
shell: bash
run: |
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::"

script_response=$(./yt-dlp ${{ env.TEST_ARGS }} --extractor-args "youtube:getpot_bgutil_baseurl=http://127.0.0.1:${{ env.PORT }}" dQw4w9WgXcQ 2>&1) || \
echo "::error title=Failed to run yt-dlp when testing HTTP server::\
yt-dlp returned $? exit status"

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 [[ "$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 1
fi
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"format": "npx prettier --write 'src/**/*.{js,ts}'"
},
"dependencies": {
"@commander-js/extra-typings": "commander-js/extra-typings",
"bgutils-js": "^1.1.0",
"body-parser": "^1.20.2",
"commander": "^12.1.0",
Expand All @@ -26,7 +27,6 @@
"youtubei.js": "^10.4.0"
},
"devDependencies": {
"@commander-js/extra-typings": "commander-js/extra-typings",
"@eslint/js": "^9.10.0",
"@types/express": "^4.17.21",
"@types/jsdom": "^21.1.7",
Expand Down