Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ jobs:
needs: [state, provenance]
name: Publish package to npm
environment: npm
if: needs.state.outputs.publish == 'true'
if: needs.state.outputs.publish == 'true' && needs.state.outputs.is_prerelease == 'false'
runs-on: ubuntu-latest
steps:
- name: Harden the runner (Audit all outbound calls)
Expand Down
5 changes: 3 additions & 2 deletions scripts/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const formatted = changelog
.replace(RELEASE_LINE_REGEX, (_, pr, entry) => (pr ? `- ${entry} (${pr})` : `- ${entry}`))
// Add date to new version
.replace(VERSION_TITLE_REGEX, `\n## $1 (${new Date().toISOString().split('T')[0]})`)
// Conditionally allow vX.Y.Z-rc.W sections only in prerelease
.replace(/^## \d\.\d\.\d-rc\S+[^]+?(?=^#)/gm, (section) => (isPrerelease ? section : ''));
// Ensure RC or prereleases are not included
.replace(/^## \d\.\d\.\d-rc\S+[^]+?(?=^#)/gm, (section) => (isPrerelease ? '' : section));

fs.writeFileSync('CHANGELOG.md', formatted);

3 changes: 0 additions & 3 deletions scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,3 @@ git push origin "$RELEASE_BRANCH"

# Output branch
echo "branch=$RELEASE_BRANCH" >> $GITHUB_OUTPUT

# Enter in prerelease state
npx changeset pre enter rc
21 changes: 14 additions & 7 deletions scripts/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,33 @@ module.exports = async ({ github, context, core }) => {
setOutput('is_prerelease', state.prerelease);
};

// Checks if the package has already been published on npm
async function isPublishedOnNpm(packageName, version) {
const res = await fetch(`https://registry.npmjs.com/${packageName}/${version}`);
return res.ok;
}

// Determines if the 'start' job should run
function shouldRunStart({ isMain, isWorkflowDispatch, botRun }) {
return isMain && isWorkflowDispatch && !botRun;
}

// Determines if the 'promote' job should run
function shouldRunPromote({ isReleaseBranch, isWorkflowDispatch, botRun }) {
return isReleaseBranch && isWorkflowDispatch && !botRun;
}

// Determines if the 'changesets' job should run
function shouldRunChangesets({ isReleaseBranch, isPush, isWorkflowDispatch, botRun }) {
return (isReleaseBranch && isPush) || (isReleaseBranch && isWorkflowDispatch && botRun);
}

function shouldRunPublish({ isReleaseBranch, isPush, hasPendingChangesets, isPublishedOnNpm }) {
return isReleaseBranch && isPush && !hasPendingChangesets && !isPublishedOnNpm;
// Determines if the 'publish' job should run
function shouldRunPublish({ isReleaseBranch, isPush, hasPendingChangesets, isPublishedOnNpm, prerelease }) {
return isReleaseBranch && isPush && !hasPendingChangesets && !isPublishedOnNpm && !prerelease;
}

// Determines if the 'merge' job should run
function shouldRunMerge({
isReleaseBranch,
isPush,
Expand All @@ -50,6 +61,7 @@ function shouldRunMerge({
return isReleaseBranch && isPush && !prerelease && isCurrentFinalVersion && !hasPendingChangesets && !prBackExists;
}

// Gets the state of the repository, including various conditions like release status, branch, etc.
async function getState({ github, context, core }) {
// Variables not in the context
const refName = process.env.GITHUB_REF_NAME;
Expand Down Expand Up @@ -105,8 +117,3 @@ async function readChangesetState(cwd = process.cwd()) {
changesets,
};
}

async function isPublishedOnNpm(packageName, version) {
const res = await fetch(`https://registry.npmjs.com/${packageName}/${version}`);
return res.ok;
}
3 changes: 2 additions & 1 deletion scripts/tag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ dist_tag() {
PACKAGE_JSON_VERSION="$(jq -r .version ./package.json)"

if [ "$PRERELEASE" = "true" ]; then
echo "next"
echo "Skipping prerelease tag"
exit 0
elif npx semver -r ">$LATEST_NPM_VERSION" "$PACKAGE_JSON_VERSION" > /dev/null; then
echo "latest"
else
Expand Down
7 changes: 7 additions & 0 deletions scripts/version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

set -euo pipefail

# Skip versioning for prereleases
if [ "$PRERELEASE" = "true" ]; then
echo "Skipping versioning for prerelease"
exit 0
fi

pnpm changeset version

echo "Updating changelog..."
scripts/changelog.js