Skip to content

Commit f355bd3

Browse files
authored
Prevent attempt to publish to npm (#4239)
1 parent 3e1b25a commit f355bd3

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

package-lock.json

+7-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
"solidity-ast": "^0.4.25",
9090
"solidity-coverage": "^0.8.0",
9191
"solidity-docgen": "^0.6.0-beta.29",
92+
"undici": "^5.22.1",
9293
"web3": "^1.3.0",
9394
"yargs": "^17.0.0"
9495
}

scripts/release/workflow/state.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
const { readPreState } = require('@changesets/pre');
22
const { default: readChangesets } = require('@changesets/read');
33
const { join } = require('path');
4-
const { version } = require(join(__dirname, '../../../package.json'));
4+
const { fetch } = require('undici');
5+
const { version, name: packageName } = require(join(__dirname, '../../../contracts/package.json'));
56

67
module.exports = async ({ github, context, core }) => {
78
const state = await getState({ github, context, core });
@@ -34,8 +35,8 @@ function shouldRunChangesets({ isReleaseBranch, isPush, isWorkflowDispatch, botR
3435
return (isReleaseBranch && isPush) || (isReleaseBranch && isWorkflowDispatch && botRun);
3536
}
3637

37-
function shouldRunPublish({ isReleaseBranch, isPush, hasPendingChangesets }) {
38-
return isReleaseBranch && isPush && !hasPendingChangesets;
38+
function shouldRunPublish({ isReleaseBranch, isPush, hasPendingChangesets, isPublishedOnNpm }) {
39+
return isReleaseBranch && isPush && !hasPendingChangesets && !isPublishedOnNpm;
3940
}
4041

4142
function shouldRunMerge({
@@ -80,6 +81,8 @@ async function getState({ github, context, core }) {
8081

8182
state.prBackExists = prs.length === 0;
8283

84+
state.isPublishedOnNpm = await isPublishedOnNpm(packageName, version);
85+
8386
// Log every state value in debug mode
8487
if (core.isDebug()) for (const [key, value] of Object.entries(state)) core.debug(`${key}: ${value}`);
8588

@@ -102,3 +105,8 @@ async function readChangesetState(cwd = process.cwd()) {
102105
changesets,
103106
};
104107
}
108+
109+
async function isPublishedOnNpm(package, version) {
110+
const res = await fetch(`https://registry.npmjs.com/${package}/${version}`);
111+
return res.ok;
112+
}

0 commit comments

Comments
 (0)