PR - route test #8886
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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@v4 | |
# https://github.com/orgs/community/discussions/25220 | |
- name: Search the PR that triggered this workflow | |
uses: potiuk/get-workflow-origin@v1_5 | |
id: source-run-info | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
sourceRunId: ${{ github.event.workflow_run.id }} | |
- name: Fetch PR data via GitHub API | |
uses: octokit/[email protected] | |
id: pr-data | |
with: | |
route: GET /repos/{repo}/pulls/{number} | |
repo: ${{ github.repository }} | |
number: ${{ steps.source-run-info.outputs.pullRequestNumber }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Fetch affected routes | |
id: fetch-route | |
uses: actions/github-script@v7 | |
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@v6 | |
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 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@v4 | |
- uses: actions/setup-node@v4 | |
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@v7 | |
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@v3 | |
with: | |
actions: 'add-labels' | |
token: ${{ secrets.GITHUB_TOKEN }} | |
issue-number: ${{ steps.source-run-info.outputs.pullRequestNumber }} | |
labels: 'Auto: Route Test Failed' | |
- name: Print Docker container logs | |
if: (env.TEST_CONTINUE) | |
run: docker logs rsshub # logs/combined.log? Not so readable... |