mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-08 14:07:54 +08:00
chore(*): migrate to GHA-based PR route test (#9683)
Signed-off-by: Rongrong <i@rong.moe>
This commit is contained in:
20
.github/workflows/docker-test.yml
vendored
20
.github/workflows/docker-test.yml
vendored
@@ -1,4 +1,6 @@
|
|||||||
name: '[docker] CI for build tests'
|
# name: '[docker] CI for build tests'
|
||||||
|
# https://github.community/t/215358
|
||||||
|
name: PR - Docker build test
|
||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
@@ -9,6 +11,7 @@ on:
|
|||||||
- 'Dockerfile'
|
- 'Dockerfile'
|
||||||
- 'package.json'
|
- 'package.json'
|
||||||
- 'yarn.lock'
|
- 'yarn.lock'
|
||||||
|
- '.github/workflows/docker-test.yml'
|
||||||
# Please, always create a pull request instead of push to master.
|
# Please, always create a pull request instead of push to master.
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
@@ -53,7 +56,14 @@ jobs:
|
|||||||
# type=gha,scope=docker-release
|
# type=gha,scope=docker-release
|
||||||
# cache-to: type=gha,mode=max,scope=docker-test
|
# cache-to: type=gha,mode=max,scope=docker-test
|
||||||
|
|
||||||
- name: Run dockerfile
|
- name: Test Docker image
|
||||||
run: |
|
run: bash scripts/docker/test-docker.sh
|
||||||
chmod +x scripts/docker/test-docker.sh
|
|
||||||
scripts/docker/test-docker.sh
|
- name: Export Docker image
|
||||||
|
run: docker save rsshub:latest | gzip -1cf > rsshub.tar.gz
|
||||||
|
|
||||||
|
- name: Upload Docker image
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: docker-image
|
||||||
|
path: rsshub.tar.gz
|
||||||
|
|||||||
78
.github/workflows/pr-deploy-route-test.yml
vendored
78
.github/workflows/pr-deploy-route-test.yml
vendored
@@ -1,46 +1,90 @@
|
|||||||
name: PR route test
|
name: PR - route test
|
||||||
# https://github.com/actions/first-interaction/issues/10#issuecomment-670968624
|
|
||||||
# https://github.com/actions/first-interaction/issues/10#issuecomment-752360668
|
|
||||||
# Reopen Included
|
|
||||||
on:
|
on:
|
||||||
- pull_request_target
|
workflow_run:
|
||||||
|
workflows: [ PR - Docker build test ] # open, reopen, synchronized included
|
||||||
|
types: [ completed ]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
testRoute:
|
testRoute:
|
||||||
name: Vercel Preview
|
name: Route test
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
if: ${{ github.event.workflow_run.conclusion == 'success' }} # skip if unsuccessful
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
# https://github.community/t/154682
|
||||||
|
- name: Search the PR that triggered this workflow
|
||||||
|
uses: potiuk/get-workflow-origin@v1_3
|
||||||
|
id: source-run-info
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
sourceRunId: ${{ github.event.workflow_run.id }}
|
||||||
|
|
||||||
|
- name: Fetch PR data via GitHub API
|
||||||
|
uses: octokit/request-action@v2.x
|
||||||
|
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
|
- name: Fetch affected routes
|
||||||
id: fetchRoute
|
id: fetchRoute
|
||||||
uses: actions/github-script@v6
|
uses: actions/github-script@v6
|
||||||
|
env:
|
||||||
|
PULL_REQUEST: ${{ steps.pr-data.outputs.data }}
|
||||||
with:
|
with:
|
||||||
# by default, JSON format returned
|
# by default, JSON format returned
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
script: |
|
script: |
|
||||||
const body = context.payload.pull_request.body
|
const PR = JSON.parse(process.env.PULL_REQUEST)
|
||||||
const number = context.payload.pull_request.number
|
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`)
|
const script = require(`${process.env.GITHUB_WORKSPACE}/scripts/workflow/test-route/identify.js`)
|
||||||
return await script({github, context, core}, body, number)
|
return await script({ github, context, core }, body, number, sender)
|
||||||
- name: Waiting for 200 from the Vercel Preview
|
|
||||||
|
- name: Fetch Docker image
|
||||||
if: (env.TEST_CONTINUE)
|
if: (env.TEST_CONTINUE)
|
||||||
uses: patrickedqvist/wait-for-vercel-preview@v1.2.0
|
uses: dawidd6/action-download-artifact@v2
|
||||||
id: waitFor200
|
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
workflow: ${{ github.event.workflow_run.workflow_id }}
|
||||||
max_timeout: 300
|
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 -p 1200:1200 rsshub:latest
|
||||||
|
|
||||||
|
- uses: actions/setup-node@v3 # just need its cache
|
||||||
|
if: (env.TEST_CONTINUE)
|
||||||
|
with:
|
||||||
|
node-version: 16
|
||||||
|
cache: 'yarn'
|
||||||
|
|
||||||
|
- name: Install dependencies (yarn) # `got` needed since `github.request` disallows HTTP requests
|
||||||
|
if: (env.TEST_CONTINUE)
|
||||||
|
run: yarn
|
||||||
|
|
||||||
- name: Generate feedback
|
- name: Generate feedback
|
||||||
if: (env.TEST_CONTINUE)
|
if: (env.TEST_CONTINUE)
|
||||||
uses: actions/github-script@v6
|
uses: actions/github-script@v6
|
||||||
env:
|
env:
|
||||||
TEST_BASEURL: ${{steps.waitFor200.outputs.url}}
|
TEST_BASEURL: http://localhost:1200
|
||||||
TEST_ROUTES: ${{ steps.fetchRoute.outputs.result }}
|
TEST_ROUTES: ${{ steps.fetchRoute.outputs.result }}
|
||||||
|
PULL_REQUEST: ${{ steps.pr-data.outputs.data }}
|
||||||
with:
|
with:
|
||||||
github-token: ${{secrets.GITHUB_TOKEN}}
|
github-token: ${{secrets.GITHUB_TOKEN}}
|
||||||
script: |
|
script: |
|
||||||
|
const PR = JSON.parse(process.env.PULL_REQUEST)
|
||||||
const link = process.env.TEST_BASEURL
|
const link = process.env.TEST_BASEURL
|
||||||
const routes = JSON.parse(process.env.TEST_ROUTES)
|
const routes = JSON.parse(process.env.TEST_ROUTES)
|
||||||
const number = context.payload.pull_request.number
|
const number = PR.number
|
||||||
core.info(`${link}, ${routes}, ${number}`)
|
core.info(`${link}, ${routes}, ${number}`)
|
||||||
|
const got = require("got");
|
||||||
const script = require(`${process.env.GITHUB_WORKSPACE}/scripts/workflow/test-route/test.js`)
|
const script = require(`${process.env.GITHUB_WORKSPACE}/scripts/workflow/test-route/test.js`)
|
||||||
return await script({github, context, core}, link, routes, number)
|
return await script({ github, context, core, got }, link, routes, number)
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
const noFound = 'Auto: Route No Found';
|
const noFound = 'Auto: Route No Found';
|
||||||
const whiteListedUser = ['dependabot[bot]'];
|
const whiteListedUser = ['dependabot[bot]'];
|
||||||
|
|
||||||
module.exports = async ({ github, context, core }, body, number) => {
|
module.exports = async ({ github, context, core }, body, number, sender) => {
|
||||||
core.debug(`sender: ${context.payload.sender.login}`);
|
core.debug(`sender: ${sender}`);
|
||||||
core.debug(`body: ${body}`);
|
core.debug(`body: ${body}`);
|
||||||
const m = body.match(/```routes\r\n((.|\r\n)*)```/);
|
const m = body.match(/```routes\r\n((.|\r\n)*)```/);
|
||||||
core.debug(`match: ${m}`);
|
core.debug(`match: ${m}`);
|
||||||
@@ -20,7 +20,7 @@ module.exports = async ({ github, context, core }, body, number) => {
|
|||||||
core.warning(e);
|
core.warning(e);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (whiteListedUser.includes(context.payload.sender.login)) {
|
if (whiteListedUser.includes(sender)) {
|
||||||
core.info('PR created by a whitelisted user, passing');
|
core.info('PR created by a whitelisted user, passing');
|
||||||
await removeLabel();
|
await removeLabel();
|
||||||
await github.rest.issues
|
await github.rest.issues
|
||||||
@@ -35,7 +35,7 @@ module.exports = async ({ github, context, core }, body, number) => {
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
core.debug('PR created by ' + context.payload.sender.login);
|
core.debug('PR created by ' + sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m && m[1]) {
|
if (m && m[1]) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
|
|
||||||
module.exports = async ({ github, context, core }, baseUrl, routes, number) => {
|
module.exports = async ({ github, context, core, got }, baseUrl, routes, number) => {
|
||||||
if (routes[0] === 'NOROUTE') {
|
if (routes[0] === 'NOROUTE') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -15,27 +15,26 @@ module.exports = async ({ github, context, core }, baseUrl, routes, number) => {
|
|||||||
for (const lks of links) {
|
for (const lks of links) {
|
||||||
core.info(`testing route: ${lks}`);
|
core.info(`testing route: ${lks}`);
|
||||||
// Intended, one at a time
|
// Intended, one at a time
|
||||||
const res = await github.request(`GET ${lks}`).catch((err) => {
|
const res = await got(lks).catch((err) => {
|
||||||
com += `
|
com += `
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary><a href="${lks}">${lks}</a> - **Failed**</summary>
|
<summary><a href="${lks}">${lks}</a> - <b>Failed</b></summary>
|
||||||
|
|
||||||
\`\`\`
|
\`\`\`
|
||||||
${err}
|
${err}
|
||||||
\`\`\`
|
\`\`\`
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
`;
|
`;
|
||||||
});
|
});
|
||||||
if (res && res.data) {
|
if (res && res.body) {
|
||||||
const { data } = res;
|
const { body } = res;
|
||||||
com += `
|
com += `
|
||||||
<details>
|
<details>
|
||||||
<summary><a href="${lks}">${lks}</a> - Success</summary>
|
<summary><a href="${lks}">${lks}</a> - Success</summary>
|
||||||
|
|
||||||
\`\`\`
|
\`\`\`rss
|
||||||
${data.split('\n').slice(0, 30).join('\n')}
|
${body.replace(/\s+(\n|$)/g, '\n')}
|
||||||
\`\`\`
|
\`\`\`
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user