diff --git a/.github/workflows/docker-test.yml b/.github/workflows/docker-test.yml index 0b5fd39e77..eeb40a1709 100644 --- a/.github/workflows/docker-test.yml +++ b/.github/workflows/docker-test.yml @@ -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: pull_request: @@ -9,6 +11,7 @@ on: - 'Dockerfile' - 'package.json' - 'yarn.lock' + - '.github/workflows/docker-test.yml' # Please, always create a pull request instead of push to master. permissions: @@ -53,7 +56,14 @@ jobs: # type=gha,scope=docker-release # cache-to: type=gha,mode=max,scope=docker-test - - name: Run dockerfile - run: | - chmod +x scripts/docker/test-docker.sh - scripts/docker/test-docker.sh + - name: Test Docker image + run: bash 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 diff --git a/.github/workflows/pr-deploy-route-test.yml b/.github/workflows/pr-deploy-route-test.yml index 1f37019b7e..ffe99c9060 100644 --- a/.github/workflows/pr-deploy-route-test.yml +++ b/.github/workflows/pr-deploy-route-test.yml @@ -1,46 +1,90 @@ -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 +name: PR - route test on: - - pull_request_target + workflow_run: + workflows: [ PR - Docker build test ] # open, reopen, synchronized included + types: [ completed ] jobs: testRoute: - name: Vercel Preview + name: Route test runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'success' }} # skip if unsuccessful steps: - 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 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 body = context.payload.pull_request.body - const number = context.payload.pull_request.number + 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 await script({github, context, core}, body, number) - - name: Waiting for 200 from the Vercel Preview + return await script({ github, context, core }, body, number, sender) + + - name: Fetch Docker image if: (env.TEST_CONTINUE) - uses: patrickedqvist/wait-for-vercel-preview@v1.2.0 - id: waitFor200 + uses: dawidd6/action-download-artifact@v2 with: - token: ${{ secrets.GITHUB_TOKEN }} - max_timeout: 300 + 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 -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 if: (env.TEST_CONTINUE) uses: actions/github-script@v6 env: - TEST_BASEURL: ${{steps.waitFor200.outputs.url}} + 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 = context.payload.pull_request.number + 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 await script({github, context, core}, link, routes, number) + return await script({ github, context, core, got }, link, routes, number) diff --git a/scripts/workflow/test-route/identify.js b/scripts/workflow/test-route/identify.js index 4ac2cc8752..d4d1f7eae0 100644 --- a/scripts/workflow/test-route/identify.js +++ b/scripts/workflow/test-route/identify.js @@ -1,8 +1,8 @@ const noFound = 'Auto: Route No Found'; const whiteListedUser = ['dependabot[bot]']; -module.exports = async ({ github, context, core }, body, number) => { - core.debug(`sender: ${context.payload.sender.login}`); +module.exports = async ({ github, context, core }, body, number, sender) => { + core.debug(`sender: ${sender}`); core.debug(`body: ${body}`); const m = body.match(/```routes\r\n((.|\r\n)*)```/); core.debug(`match: ${m}`); @@ -20,7 +20,7 @@ module.exports = async ({ github, context, core }, body, number) => { core.warning(e); }); - if (whiteListedUser.includes(context.payload.sender.login)) { + if (whiteListedUser.includes(sender)) { core.info('PR created by a whitelisted user, passing'); await removeLabel(); await github.rest.issues @@ -35,7 +35,7 @@ module.exports = async ({ github, context, core }, body, number) => { }); return; } else { - core.debug('PR created by ' + context.payload.sender.login); + core.debug('PR created by ' + sender); } if (m && m[1]) { diff --git a/scripts/workflow/test-route/test.js b/scripts/workflow/test-route/test.js index a951b2f251..dde6b82eb2 100644 --- a/scripts/workflow/test-route/test.js +++ b/scripts/workflow/test-route/test.js @@ -1,6 +1,6 @@ /* 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') { return; } @@ -15,27 +15,26 @@ module.exports = async ({ github, context, core }, baseUrl, routes, number) => { for (const lks of links) { core.info(`testing route: ${lks}`); // Intended, one at a time - const res = await github.request(`GET ${lks}`).catch((err) => { + const res = await got(lks).catch((err) => { com += ` -
- ${lks} - **Failed** + ${lks} - Failed \`\`\` - ${err} +${err} \`\`\`
`; }); - if (res && res.data) { - const { data } = res; + if (res && res.body) { + const { body } = res; com += `
- ${lks} - Success + ${lks} - Success -\`\`\` - ${data.split('\n').slice(0, 30).join('\n')} +\`\`\`rss +${body.replace(/\s+(\n|$)/g, '\n')} \`\`\`