forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request DIYgod#6650 from NeverBehave/pr-auto-url-test
flow: pr auto test template
- Loading branch information
Showing
4 changed files
with
141 additions
and
2 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: PR route test | ||
|
||
on: pull_request | ||
|
||
jobs: | ||
testRoute: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Fetch affected routes | ||
id: fetchRoute | ||
uses: actions/github-script@v3 | ||
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 script = require(`${process.env.GITHUB_WORKSPACE}/scripts/workflow/test-route/identify.js`) | ||
return script({github, context}, body, number) | ||
- name: Waiting for 200 from the Vercel Preview | ||
uses: patrickedqvist/wait-for-vercel-preview@master | ||
id: waitFor200 | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
max_timeout: 120 | ||
# fetch link from pr and test link | ||
- name: Generate previews | ||
uses: actions/github-script@v3 | ||
with: | ||
github-token: ${{secrets.GITHUB_TOKEN}} | ||
script: | | ||
const link = context.steps.waitFor200.outputs.url | ||
const routes = JSON.parse(context.steps.fetchRoute.outputs.result) | ||
const number = context.payload.pull_request.number | ||
const script = require(`${process.env.GITHUB_WORKSPACE}/scripts/workflow/test-route/test.js`) | ||
return await script({github, context}, link, routes, number) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module.exports = ({github, context}, body, number) => { | ||
const m = body.match(/```routes\n((.|\n)*)```/) | ||
let res = null | ||
|
||
if (m && m[1]) { | ||
res = m.split("\n") | ||
console.log("routes detected: ", res) | ||
|
||
if (res.length > 0) { | ||
return res | ||
} | ||
|
||
if (res[0] === "NOROUTE") { | ||
console.log("PR stated no route, passing") | ||
github.issues.addLabels({ | ||
issue_number: number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
labels: ['Auto: No Route Needed'] | ||
}) | ||
return res | ||
} | ||
} | ||
|
||
console.log("seems no route found, failing") | ||
|
||
github.issues.addLabels({ | ||
issue_number: number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
labels: ['Auto: Route No Found'] | ||
}) | ||
|
||
throw "Please follow the PR rules: failed to detect route" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
module.exports = async ({github, context}, baseUrl, routes, number) => { | ||
if (res[0] === 'NOROUTE') { | ||
return | ||
} | ||
|
||
const links = res.map(e => { | ||
const l = e.startsWith('/') ? e : `/${e}` | ||
return `${baseUrl}${l}` | ||
}) | ||
|
||
let com = 'Successfully generated as following:\n\n' | ||
|
||
for (lks in links) { | ||
const prev = await fetch(lks).catch(err => { | ||
com+= ` | ||
<details> | ||
<summary>${lks} - **Failed**</summary> | ||
\`\`\` | ||
${err} | ||
\`\`\` | ||
</details> | ||
` | ||
}) | ||
if (prev) { | ||
com += ` | ||
<details> | ||
<summary>${lks} - Success</summary> | ||
\`\`\` | ||
${prev.text().split("\n").slice(0, 30).join("\n")} | ||
\`\`\` | ||
</details> | ||
` | ||
} | ||
} | ||
github.issues.addLabels({ | ||
issue_number: number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
labels: ['Auto: Route Test Complete'] | ||
}) | ||
github.issues.createComment({ | ||
issue_number: number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: com | ||
}); | ||
} |