rsshub / .github /workflows /docker-test-cont.yml
asemxin
Initial commit for HF Spaces
bf48b89
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@dad4362715b7fb2ddedf9772c8670824af564f0d # v2.4.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 }}
- 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@fe9d59ce33ce92db8a6ac90b2c8be6b6d90417c8 # v15
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
- uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4.2.0
- uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
if: (env.TEST_CONTINUE)
with:
node-version: lts/*
cache: 'pnpm'
- name: Install dependencies (pnpm) # require js-beautify
if: (env.TEST_CONTINUE)
run: pnpm i
- 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@71b62d7da76e59ff7b193904feb6e77d4dbb2777 # v3.7.6
with:
actions: 'add-labels'
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ steps.source-run-info.outputs.pullRequestNumber }}
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@71b62d7da76e59ff7b193904feb6e77d4dbb2777 # v3.7.6
with:
actions: 'add-labels'
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ steps.source-run-info.outputs.number }}
labels: 'auto: DO NOT merge'