From 5dd5317400deeb8f1cdf2c63915715d527078def Mon Sep 17 00:00:00 2001 From: Tony Date: Thu, 26 May 2022 15:09:00 -0500 Subject: [PATCH] chore(workflow): test route on demand (#9831) * chore: on demand test * style: lint --- .github/workflows/issue-command.yml | 73 ++++++++++++++++++++++++++++- scripts/workflow/test-route/test.js | 24 +++++----- 2 files changed, 85 insertions(+), 12 deletions(-) diff --git a/.github/workflows/issue-command.yml b/.github/workflows/issue-command.yml index 49ee4e93c5..6c5bce954c 100644 --- a/.github/workflows/issue-command.yml +++ b/.github/workflows/issue-command.yml @@ -21,9 +21,10 @@ jobs: uses: cirrus-actions/rebase@1.7 env: GITHUB_TOKEN: ${{ secrets.TOKEN_SUPER }} + self-assign: name: Self Assign - if: github.event.issue.pull_request == '' && startsWith(github.event.comment.body, '/wip') + if: ${{ !github.event.issue.pull_request && startsWith(github.event.comment.body, '/wip') }} runs-on: ubuntu-latest permissions: contents: read @@ -35,3 +36,73 @@ jobs: assign_phrase: '/wip' label_phase1: RSS proposal label_phase2: RSS bug + + test-on-demand: + name: Test route on demand + if: startsWith(github.event.comment.body, '/test') + runs-on: ubuntu-latest + permissions: + contents: read + issues: write + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Use Node.js v16 + uses: actions/setup-node@v3 + with: + node-version: 16 + cache: 'yarn' + + - name: Install dependencies (yarn) + run: yarn + + - name: Fetch affected routes + id: fetchRoute + uses: actions/github-script@v6 + env: + EVENT: ${{ toJson(github.event) }} + with: + script: | + const event = JSON.parse(process.env.EVENT) + const body = event.comment.body + const number = event.issue.number + const sender = event.comment.user.login + const script = require(`${process.env.GITHUB_WORKSPACE}/scripts/workflow/test-route/identify.js`) + return await script({ github, context, core }, body, number, sender) + + - name: Start RSSHub + if: env.TEST_CONTINUE + run: yarn start & + env: + NODE_ENV: dev + LOGGER_LEVEL: debug + + - name: Generate feedback + if: env.TEST_CONTINUE + uses: actions/github-script@v6 + env: + TEST_BASEURL: http://localhost:1200 + TEST_ROUTES: ${{ steps.fetchRoute.outputs.result }} + EVENT: ${{ toJson(github.event) }} + with: + script: | + const event = JSON.parse(process.env.EVENT) + const link = process.env.TEST_BASEURL + const routes = JSON.parse(process.env.TEST_ROUTES) + const number = event.issue.number + core.info(`${link}, ${routes}, ${number}`) + const got = require("got") + const script = require(`${process.env.GITHUB_WORKSPACE}/scripts/workflow/test-route/test.js`) + return await script({ github, context, core, got }, link, routes, number) + + - name: Print logs + if: (env.TEST_CONTINUE) + run: cat ${{ github.workspace }}/logs/combined.log + + - name: Upload Artifact + uses: actions/upload-artifact@v3 + with: + name: logs + path: logs + retention-days: 1 diff --git a/scripts/workflow/test-route/test.js b/scripts/workflow/test-route/test.js index 633cd665d6..dbeaa04174 100644 --- a/scripts/workflow/test-route/test.js +++ b/scripts/workflow/test-route/test.js @@ -1,4 +1,4 @@ -/* eslint-disable */ +/* eslint-disable no-await-in-loop */ module.exports = async ({ github, context, core, got }, baseUrl, routes, number) => { if (routes[0] === 'NOROUTE') { @@ -63,16 +63,18 @@ ${detail.slice(0, 65300 - temp_com.length)} com_l = com_l.slice(0, 5); } - await github.rest.issues - .addLabels({ - issue_number: number, - owner: context.repo.owner, - repo: context.repo.repo, - labels: ['Auto: Route Test Complete'], - }) - .catch((e) => { - core.warning(e); - }); + if (context.payload.pull_request) { + await github.rest.issues + .addLabels({ + issue_number: number, + owner: context.repo.owner, + repo: context.repo.repo, + labels: ['Auto: Route Test Complete'], + }) + .catch((e) => { + core.warning(e); + }); + } for (const com_s of com_l) { // Intended, one at a time