flow: pr auto test template

This commit is contained in:
NeverBehave
2021-01-10 16:22:43 -05:00
parent 51c3f05699
commit 16d3799970
4 changed files with 166 additions and 2 deletions

View File

@@ -5,13 +5,29 @@ Close #
## 完整路由地址 / Example for the proposed route(s) ## 完整路由地址 / Example for the proposed route(s)
<!-- <!--
为方便测试,请附上完整路由地址,包括所有必选与可选参数,否则将导致 PR 被关闭。 为方便测试,请附上完整路由地址,包括所有必选与可选参数,否则将导致 PR 被关闭。
To simplify the testing workflow, please include the complete route, with all required and optional parameters, otherwise your pull request will be closed. 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 ## 新RSS检查列表 / New RSS Script Checklist
<!-- <!--

View File

@@ -0,0 +1,43 @@
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: |
console.log(context)
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, core}, body, number)
- name: Waiting for 200 from the Vercel Preview
if: (env.TEST_CONTINUE)
uses: patrickedqvist/wait-for-vercel-preview@master
id: waitFor200
with:
token: ${{ secrets.GITHUB_TOKEN }}
max_timeout: 300
- name: Generate feedback
if: (env.TEST_CONTINUE)
uses: actions/github-script@v3
env:
TEST_BASEURL: ${{steps.waitFor200.outputs.url}}
TEST_ROUTES: ${{ steps.fetchRoute.outputs.result }}
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const link = process.env.TEST_BASEURL
const routes = JSON.parse(process.env.TEST_ROUTES)
const number = context.payload.pull_request.number
console.log(link, routes, number)
const script = require(`${process.env.GITHUB_WORKSPACE}/scripts/workflow/test-route/test.js`)
return await script({github, context}, link, routes, number)

View File

@@ -0,0 +1,51 @@
const noFound = 'Auto: Route No Found'
module.exports = ({github, context, core}, body, number) => {
core.debug(`body: ${body}`)
const m = body.match(/```routes\r\n((.|\r\n)*)```/)
core.debug(`match: ${m}`)
let res = null
const removeLabel = () => {
github.issues.removeLabel({
issue_number: number,
owner: context.repo.owner,
repo: context.repo.repo,
name: noFound
}).catch(() => {})
}
if (m && m[1]) {
res = m[1].trim().split("\r\n")
core.info(`routes detected: ${res}`)
if (res.length > 0 && res[0] === "NOROUTE") {
core.info("PR stated no route, passing")
removeLabel()
github.issues.addLabels({
issue_number: number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['Auto: No Route Needed']
})
return
} else if (res.length > 0) {
core.exportVariable('TEST_CONTINUE', true)
removeLabel()
return res
}
}
core.info("seems no route found, failing")
github.issues.addLabels({
issue_number: number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: [noFound]
})
throw "Please follow the PR rules: failed to detect route"
}

View File

@@ -0,0 +1,54 @@
module.exports = async ({github, context}, baseUrl, routes, number) => {
if (routes[0] === 'NOROUTE') {
return
}
const links = routes.map(e => {
const l = e.startsWith('/') ? e : `/${e}`
return `${baseUrl}${l}`
})
let com = 'Successfully generated as following:\n\n'
for (const lks of links) {
console.log("testing route: ", lks)
const res = await github.request(`GET ${lks}`).catch(err => {
com+= `
<details>
<summary><a href="${lks}">${lks}</a> - **Failed**</summary>
\`\`\`
${err}
\`\`\`
</details>
`
})
if (res && res.data) {
const { data } = res
com += `
<details>
<summary><a href="${lks}">${lks}</a> - Success</summary>
\`\`\`
${data.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
});
}