Skip to content

Commit

Permalink
fix: ci wait for label creation before exit (DIYgod#6655)
Browse files Browse the repository at this point in the history
* fix: style and token used on exit

* [CodeFactor] Apply fixes

[ci skip] [skip ci]

Co-authored-by: codefactor-io <support@codefactor.io>
  • Loading branch information
NeverBehave and code-factor authored Jan 11, 2021
1 parent b09df0d commit cb1506e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 61 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/pr-deploy-route-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ jobs:
uses: actions/github-script@v3
with:
# by default, JSON format returned
github-token: ${{secrets.GITHUB_TOKEN}}
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)
return await 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
Expand Down
57 changes: 24 additions & 33 deletions scripts/workflow/test-route/identify.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,49 @@
const noFound = 'Auto: Route No Found';

module.exports = ({ github, context, core }, body, number) => {

module.exports = async ({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((e) => {
core.warning(e);
});
};
const removeLabel = async () => github.issues.removeLabel({
issue_number: number,
owner: context.repo.owner,
repo: context.repo.repo,
name: noFound
}).catch((e) => { core.warning(e); });

if (m && m[1]) {
res = m[1].trim().split('\r\n');
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'],
})
.catch((e) => {
core.warning(e);
});
if (res.length > 0 && res[0] === "NOROUTE") {
core.info("PR stated no route, passing");
await removeLabel();
await github.issues.addLabels({
issue_number: number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['Auto: No Route Needed']
}).catch((e) => { core.warning(e); });

return;
} else if (res.length > 0) {
core.exportVariable('TEST_CONTINUE', true);
removeLabel();
await removeLabel();
return res;
}
}

core.info('seems no route found, failing');
core.info("seems no route found, failing");

github.issues.addLabels({
await github.issues.addLabels({
issue_number: number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: [noFound],
});
labels: [noFound]
}).catch((e) => { core.warning(e); });

throw 'Please follow the PR rules: failed to detect route';
throw "Please follow the PR rules: failed to detect route";
};
42 changes: 17 additions & 25 deletions scripts/workflow/test-route/test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */

module.exports = async ({ github, context }, baseUrl, routes, number) => {
module.exports = async ({github, context}, baseUrl, routes, number) => {
if (routes[0] === 'NOROUTE') {
return;
}
Expand All @@ -13,10 +13,10 @@ module.exports = async ({ github, context }, baseUrl, routes, number) => {
let com = 'Successfully generated as following:\n\n';

for (const lks of links) {
console.log('testing route: ', lks);
console.log("testing route: ", lks)
// Intended, one at a time
const res = await github.request(`GET ${lks}`).catch((err) => {
com += `
const res = await github.request(`GET ${lks}`).catch(err => {
com+= `
<details>
<summary><a href="${lks}">${lks}</a> - **Failed**</summary>
Expand All @@ -42,24 +42,16 @@ module.exports = async ({ github, context }, baseUrl, routes, number) => {
`;
}
}
github.issues
.addLabels({
issue_number: number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['Auto: Route Test Complete'],
})
.catch((e) => {
core.warning(e);
});
github.issues
.createComment({
issue_number: number,
owner: context.repo.owner,
repo: context.repo.repo,
body: com,
})
.catch((e) => {
core.warning(e);
});
};
github.issues.addLabels({
issue_number: number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['Auto: Route Test Complete']
}).catch((e) => { core.warning(e) })
github.issues.createComment({
issue_number: number,
owner: context.repo.owner,
repo: context.repo.repo,
body: com
}).catch((e) => { core.warning(e) })
}

0 comments on commit cb1506e

Please sign in to comment.