PR - route test #738
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 | |
if: ${{ github.event.workflow_run.conclusion == 'success' }} # skip if unsuccessful | |
timeout-minutes: 10 | |
steps: | |
- uses: actions/checkout@v3 | |
# 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: fetchRoute | |
uses: actions/github-script@v6 | |
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 script = require(`${process.env.GITHUB_WORKSPACE}/scripts/workflow/test-route/identify.js`) | |
return script({ github, context, core }, body, number, sender) | |
- name: Fetch Docker image | |
if: (env.TEST_CONTINUE) | |
uses: dawidd6/action-download-artifact@v2 | |
with: | |
workflow: ${{ github.event.workflow_run.workflow_id }} | |
run_id: ${{ github.event.workflow_run.id }} | |
- name: Import Docker image and set up Docker container | |
if: (env.TEST_CONTINUE) | |
run: | | |
set -ex | |
gzip -cvd docker-image/rsshub.tar.gz | 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@v2 | |
with: | |
version: 8 | |
- uses: actions/setup-node@v3 # just need its cache | |
if: (env.TEST_CONTINUE) | |
with: | |
node-version: lts/* | |
cache: 'pnpm' | |
- name: Install dependencies (pnpm) # `got` needed since `github.request` disallows HTTP requests | |
if: (env.TEST_CONTINUE) | |
run: pnpm i | |
- name: Generate feedback | |
if: (env.TEST_CONTINUE) | |
uses: actions/github-script@v6 | |
env: | |
TEST_BASEURL: http://localhost:1200 | |
TEST_ROUTES: ${{ steps.fetchRoute.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 got = require("got"); | |
const script = require(`${process.env.GITHUB_WORKSPACE}/scripts/workflow/test-route/test.js`) | |
return script({ github, context, core, got }, link, routes, number) | |
- name: Print Docker container logs | |
if: (env.TEST_CONTINUE) | |
run: docker logs rsshub # logs/combined.log? Not so readable... |