Skip to content

Commit

Permalink
Prevent attempt to publish to npm (#4239)
Browse files Browse the repository at this point in the history
  • Loading branch information
frangio authored May 11, 2023
1 parent 3e1b25a commit f355bd3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
13 changes: 7 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"solidity-ast": "^0.4.25",
"solidity-coverage": "^0.8.0",
"solidity-docgen": "^0.6.0-beta.29",
"undici": "^5.22.1",
"web3": "^1.3.0",
"yargs": "^17.0.0"
}
Expand Down
14 changes: 11 additions & 3 deletions scripts/release/workflow/state.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const { readPreState } = require('@changesets/pre');
const { default: readChangesets } = require('@changesets/read');
const { join } = require('path');
const { version } = require(join(__dirname, '../../../package.json'));
const { fetch } = require('undici');
const { version, name: packageName } = require(join(__dirname, '../../../contracts/package.json'));

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

function shouldRunPublish({ isReleaseBranch, isPush, hasPendingChangesets }) {
return isReleaseBranch && isPush && !hasPendingChangesets;
function shouldRunPublish({ isReleaseBranch, isPush, hasPendingChangesets, isPublishedOnNpm }) {
return isReleaseBranch && isPush && !hasPendingChangesets && !isPublishedOnNpm;
}

function shouldRunMerge({
Expand Down Expand Up @@ -80,6 +81,8 @@ async function getState({ github, context, core }) {

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

state.isPublishedOnNpm = await isPublishedOnNpm(packageName, version);

// Log every state value in debug mode
if (core.isDebug()) for (const [key, value] of Object.entries(state)) core.debug(`${key}: ${value}`);

Expand All @@ -102,3 +105,8 @@ async function readChangesetState(cwd = process.cwd()) {
changesets,
};
}

async function isPublishedOnNpm(package, version) {
const res = await fetch(`https://registry.npmjs.com/${package}/${version}`);
return res.ok;
}

0 comments on commit f355bd3

Please sign in to comment.