flow: pr auto test template
This commit is contained in:
parent
51c3f05699
commit
201eaae73d
|
|
@ -5,13 +5,29 @@ Close #
|
|||
## 完整路由地址 / Example for the proposed route(s)
|
||||
|
||||
<!--
|
||||
|
||||
为方便测试,请附上完整路由地址,包括所有必选与可选参数,否则将导致 PR 被关闭。
|
||||
|
||||
To simplify the testing workflow, please include the complete route, with all required and optional parameters, otherwise your pull request will be closed.
|
||||
|
||||
请按照如下格式填写`routes`区域: 我们将会根据你的参数展开自动测试. 一行一个路由
|
||||
Please fill the `routes` block follow the format below, as we will perform automatic test based on this information. one route per line.
|
||||
|
||||
```
|
||||
/some/route
|
||||
/some/other/route
|
||||
```
|
||||
|
||||
如果与路由无关, 请写`NOROUTE`
|
||||
|
||||
```
|
||||
NOROUTE
|
||||
```
|
||||
-->
|
||||
|
||||
<!-- FILL HERE -->
|
||||
```routes
|
||||
```
|
||||
|
||||
|
||||
## 新RSS检查列表 / New RSS Script Checklist
|
||||
|
||||
<!--
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
@ -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"
|
||||
}
|
||||
|
|
@ -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
|
||||
});
|
||||
}
|
||||
Loading…
Reference in New Issue