Skip to content

Commit 59af733

Browse files
committed
[actions] fix publish script
1 parent 35f6403 commit 59af733

File tree

3 files changed

+54
-33
lines changed

3 files changed

+54
-33
lines changed

.eslintrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,16 @@
6767
"no-console": 0,
6868
},
6969
},
70+
{
71+
"files": ".github/workflows/*.js",
72+
"parserOptions": {
73+
"ecmaVersion": 2019,
74+
},
75+
"rules": {
76+
"camelcase": 0,
77+
"no-console": 0,
78+
"no-restricted-syntax": 0,
79+
},
80+
},
7081
],
7182
}

.github/workflows/npm-publish.yml

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -48,39 +48,8 @@ jobs:
4848
result-encoding: string
4949
retries: 3
5050
script: |
51-
const ref = context.payload.inputs.tag;
52-
53-
console.log(`Checking status checks for ${ref}`);
54-
55-
const { owner, repo } = context.repo;
56-
const { default_branch: branch } = context.payload.repository;
57-
58-
const branch = github.rest.repos.getBranch({ owner, repo, branch });
59-
60-
const checkSuites = await github.rest.checks.listSuitesForRef({ owner, repo, ref });
61-
62-
if (checkSuites.some(({ status }) => 'completed')) {
63-
core.setFailed(`Some workflows for ${context.payload.inputs.tag} are still in-progress`);
64-
}
65-
66-
const { data: { check_runs: checkRuns } } = await Promise.all(
67-
(await branch).data.protection.required_status_checks.checks.map(({ context }) => (
68-
github.rest.checks.listForRef({
69-
owner,
70-
repo,
71-
ref,
72-
check_name: context
73-
})
74-
)
75-
)
76-
77-
checkRuns.forEach(({ name, status, conclusion }) => {
78-
if (status !== 'completed' || conclusion !== 'success') {
79-
console.log(`${name} check failed`);
80-
core.setFailed(`Required status check ${name} did not succeed`);
81-
}
82-
console.log(`${name} check passed`);
83-
});
51+
const script = require('./publish');
52+
console.log(await script({ github, context, core }));
8453
8554
publish:
8655
needs: [check-status]

.github/workflows/publish.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use strict';
2+
3+
module.exports = async function publish({ github, context, core }) {
4+
const ref = context.payload.inputs.tag;
5+
6+
console.log(`Checking status checks for ${ref}`);
7+
8+
const { owner, repo } = context.repo;
9+
const { default_branch: branch } = context.payload.repository;
10+
11+
const branchData = github.rest.repos.getBranch({ owner, repo, branch });
12+
13+
const { data: { check_suites: checkSuites } } = await github.rest.checks.listSuitesForRef({ owner, repo, ref });
14+
15+
if (checkSuites.some(({ status }) => status === 'completed')) {
16+
core.setFailed(`Some workflows for ${context.payload.inputs.tag} are still in-progress`);
17+
}
18+
19+
const result = await Promise.all(
20+
(await branchData).data.protection.required_status_checks.checks.map(({ context: check_name }) => (
21+
github.rest.checks.listForRef({
22+
owner,
23+
repo,
24+
ref,
25+
check_name,
26+
})
27+
)),
28+
);
29+
30+
console.log(result);
31+
32+
const { data: { check_runs: checkRuns } } = result;
33+
34+
checkRuns.forEach(({ name, status, conclusion }) => {
35+
if (status !== 'completed' || conclusion !== 'success') {
36+
console.log(`${name} check failed`);
37+
core.setFailed(`Required status check ${name} did not succeed`);
38+
}
39+
console.log(`${name} check passed`);
40+
});
41+
};

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy