Skip to content

PR - route test

PR - route test #19072

name: PR - route test
on:
workflow_run:
workflows: [PR - Docker build test] # open, reopen, synchronized, edited included
types: [completed]
jobs:
testRoute:
name: Route test
runs-on: ubuntu-latest
permissions:
pull-requests: write
if: ${{ github.event.workflow_run.conclusion == 'success' }} # skip if unsuccessful
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
# https://github.com/orgs/community/discussions/25220#discussioncomment-11316244
- name: Search the PR that triggered this workflow
id: source-run-info
env:
# Token required for GH CLI:
GH_TOKEN: ${{ github.token }}
# Best practice for scripts is to reference via ENV at runtime. Avoid using the expression syntax in the script content directly:
PR_TARGET_REPO: ${{ github.repository }}
# If the PR is from a fork, prefix it with `<owner-login>:`, otherwise only the PR branch name is relevant:
PR_BRANCH: |-
${{
(github.event.workflow_run.head_repository.owner.login != github.event.workflow_run.repository.owner.login)
&& format('{0}:{1}', github.event.workflow_run.head_repository.owner.login, github.event.workflow_run.head_branch)
|| github.event.workflow_run.head_branch
}}
# Query the PR number by repo + branch, then assign to step output:
run: |
gh pr view --repo "${PR_TARGET_REPO}" "${PR_BRANCH}" \
--json 'number' --jq '"number=\(.number)"' \
>> "${GITHUB_OUTPUT}"
- name: Fetch PR data via GitHub API
uses: octokit/request-action@b91aabaa861c777dcdb14e2387e30eddf04619ae # v3.0.0
id: pr-data
with:
route: GET /repos/{repo}/pulls/{number}
repo: ${{ github.repository }}
number: ${{ steps.source-run-info.outputs.number }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v4.4.0
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
with:
node-version: lts/*
cache: 'pnpm'
- name: Install dependencies (pnpm) # require js-beautify
run: pnpm i
- name: Fetch affected routes
id: fetch-route
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
env:
PULL_REQUEST: ${{ steps.pr-data.outputs.data }}
with:
# by default, JSON format returned
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const PR = JSON.parse(process.env.PULL_REQUEST)
const body = PR.body
const number = PR.number
const sender = PR.user.login
const { default: identify } = await import('${{ github.workspace }}/scripts/workflow/test-route/identify.mjs')
return identify({ github, context, core }, body, number, sender)
- name: Fetch Docker image
if: (env.TEST_CONTINUE)
uses: dawidd6/action-download-artifact@8a338493df3d275e4a7a63bcff3b8fe97e51a927 # v19
with:
workflow: ${{ github.event.workflow_run.workflow_id }}
run_id: ${{ github.event.workflow_run.id }}
name: docker-image
path: ../artifacts-${{ github.run_id }}
- name: Import Docker image and set up Docker container
if: (env.TEST_CONTINUE)
working-directory: ../artifacts-${{ github.run_id }}
run: |
set -ex
zstd -d --stdout rsshub.tar.zst | docker load
docker run -d \
--name rsshub \
-e NODE_ENV=dev \
-e NODE_OPTIONS='--max-http-header-size=32768' \
-e LOGGER_LEVEL=debug \
-e ALLOW_USER_HOTLINK_TEMPLATE=true \
-e ALLOW_USER_SUPPLY_UNSAFE_DOMAIN=true \
-p 1200:1200 \
rsshub:latest
- name: Wait for RSSHub startup
if: (env.TEST_CONTINUE)
env:
TEST_BASEURL: http://localhost:1200
run: |
set -euo pipefail
healthcheck_url="$TEST_BASEURL/healthz"
for _ in $(seq 1 30); do
if curl --silent --show-error --fail "$healthcheck_url" >/dev/null; then
exit 0
fi
if [ "$(docker inspect -f '{{.State.Status}}' rsshub 2>/dev/null)" != 'running' ]; then
docker logs rsshub || true
echo "rsshub container exited before becoming ready"
exit 1
fi
sleep 1
done
docker logs rsshub || true
echo "Timed out waiting for RSSHub health check: $healthcheck_url"
exit 1
- name: Generate feedback
if: (env.TEST_CONTINUE)
id: generate-feedback
timeout-minutes: 10
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
env:
TEST_BASEURL: http://localhost:1200
TEST_ROUTES: ${{ steps.fetch-route.outputs.result }}
PULL_REQUEST: ${{ steps.pr-data.outputs.data }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const PR = JSON.parse(process.env.PULL_REQUEST)
const link = process.env.TEST_BASEURL
const routes = JSON.parse(process.env.TEST_ROUTES)
const number = PR.number
core.info(`${link}, ${routes}, ${number}`)
const { default: test } = await import('${{ github.workspace }}/scripts/workflow/test-route/test.mjs')
await test({ github, context, core }, link, routes, number)
- name: Pull Request Labeler
if: ${{ failure() }}
uses: actions-cool/issues-helper@200c78641dbf33838311e5a1e0c31bbdb92d7cf0 # v3.8.0
with:
actions: 'add-labels'
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ steps.source-run-info.outputs.number }}
labels: 'auto: DO NOT merge'
- name: Print Docker container logs
if: ${{ always() }}
run: docker logs rsshub || true # logs/combined.log? Not so readable...
fail-build:
name: Fail build
runs-on: ubuntu-slim
permissions:
pull-requests: write
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
steps:
# https://github.com/orgs/community/discussions/25220#discussioncomment-11316244
- name: Search the PR that triggered this workflow
id: source-run-info
env:
# Token required for GH CLI:
GH_TOKEN: ${{ github.token }}
# Best practice for scripts is to reference via ENV at runtime. Avoid using the expression syntax in the script content directly:
PR_TARGET_REPO: ${{ github.repository }}
# If the PR is from a fork, prefix it with `<owner-login>:`, otherwise only the PR branch name is relevant:
PR_BRANCH: |-
${{
(github.event.workflow_run.head_repository.owner.login != github.event.workflow_run.repository.owner.login)
&& format('{0}:{1}', github.event.workflow_run.head_repository.owner.login, github.event.workflow_run.head_branch)
|| github.event.workflow_run.head_branch
}}
# Query the PR number by repo + branch, then assign to step output:
run: |
gh pr view --repo "${PR_TARGET_REPO}" "${PR_BRANCH}" \
--json 'number' --jq '"number=\(.number)"' \
>> "${GITHUB_OUTPUT}"
- name: Pull Request Labeler
uses: actions-cool/issues-helper@200c78641dbf33838311e5a1e0c31bbdb92d7cf0 # v3.8.0
with:
actions: 'add-labels'
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ steps.source-run-info.outputs.number }}
labels: 'auto: DO NOT merge'