-
Notifications
You must be signed in to change notification settings - Fork 19
build(next): Add release script #114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
393ad86
tests(next): reuse existing tests but with different imports
dragidavid 3a27a10
build(next): Simplify test setup (#112)
thien-remote 3e2dfe8
chore: apply changes based on review
dragidavid da31ee7
build(next): add release script based on existing ones
dragidavid 5cc66de
build(next): add release:next scripts
dragidavid 17e6257
chore: make changes based on review
dragidavid b33dcd7
build(next): adjust release script
dragidavid d14f2f0
Release next 1.0.0-alpha.1
dragidavid 5b659cb
build(next): change release script
dragidavid d8968ff
build(next): add new scripts
dragidavid 932c400
build(next): do not update package.json with dev versions
dragidavid 00ad987
build(next): adjust script to always use the current version
dragidavid e3bf095
Release v1-beta 1.0.0-beta.1
dragidavid f90466c
build(next): add `files` to package.json
dragidavid f90b799
build(next): correct main entry
dragidavid 65a62c3
Release v1-beta 1.0.0-beta.2
dragidavid 4e653d1
build(next): release rules
dragidavid a0bdf45
build(next): simplify `bumpVersion`
dragidavid 00e467a
build(next): generate changelog for beta releases
dragidavid 40a045f
fix: versioning bug
dragidavid 9259d8d
build(next): check dev version restriction
dragidavid d11dc67
build(next): correcting version check
dragidavid cad063d
chore: reset version
dragidavid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "name": "@remoteoss/json-schema-form", | ||
| "version": "1.0.0-alpha.1", | ||
| "version": "1.0.0-beta.0", | ||
| "packageManager": "[email protected]", | ||
| "description": "WIP V2 – Headless UI form powered by JSON Schemas", | ||
| "author": "Remote.com <[email protected]> (https://remote.com/)", | ||
|
|
@@ -16,16 +16,23 @@ | |
| "json-schema", | ||
| "form" | ||
| ], | ||
| "main": "index.js", | ||
| "main": "dist/index.mjs", | ||
| "module": "dist/index.mjs", | ||
| "files": [ | ||
| "README.md", | ||
| "dist" | ||
| ], | ||
| "engines": { | ||
| "node": "22.13.1" | ||
| "node": ">=18.14.0" | ||
| }, | ||
| "scripts": { | ||
| "build": "tsup", | ||
| "test": "jest", | ||
| "test:watch": "jest --watchAll", | ||
| "test:file": "jest --runTestsByPath", | ||
| "lint": "eslint --max-warnings 0 .", | ||
| "build": "tsup" | ||
| "release:dev": "cd .. && npm run release:v1:dev", | ||
| "release:beta": "cd .. && npm run release:v1:beta" | ||
| }, | ||
| "devDependencies": { | ||
| "@antfu/eslint-config": "^3.14.0", | ||
|
|
@@ -35,6 +42,7 @@ | |
| "@jest/globals": "^29.7.0", | ||
| "babel-jest": "^29.7.0", | ||
| "eslint": "^9.18.0", | ||
| "generate-changelog": "^1.8.0", | ||
| "jest": "^29.7.0", | ||
| "json-schema-typed": "^8.0.1", | ||
| "tsup": "^8.3.5", | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
|
|
||
| function init() { | ||
| const packageJson = fs.readFileSync(path.resolve(__dirname, '../next/package.json'), 'utf8'); | ||
| const { version } = JSON.parse(packageJson); | ||
|
|
||
| if (version.includes('-dev')) { | ||
| console.log( | ||
| `🟠 This PR cannot be merged because the next/package.json version ${version} contains "-dev".` + | ||
| '\n The version in next/package.json should be a beta version (e.g., 1.0.0-beta.0).' | ||
| ); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| if (!version.includes('-beta.')) { | ||
| console.log( | ||
| `🟠 This PR cannot be merged because the next/package.json version ${version} is not a beta version.` + | ||
| '\n The version in next/package.json should be in format X.X.X-beta.Y (e.g., 1.0.0-beta.0).' | ||
| ); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| console.log( | ||
| `The package version in next/package.json is ${version} and seems valid. Continuing...` | ||
| ); | ||
| } | ||
|
|
||
| init(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| const path = require('path'); | ||
|
|
||
| const semver = require('semver'); | ||
|
|
||
| const { | ||
| askForConfirmation, | ||
| askForText, | ||
| checkGitStatus, | ||
| checkNpmAuth, | ||
| runExec, | ||
| revertCommit, | ||
| revertChanges, | ||
| getDateYYYYMMDDHHMMSS, | ||
| } = require('./release.helpers'); | ||
|
|
||
| const packageJsonPath = path.resolve(__dirname, '../next/package.json'); | ||
| const packageJson = require(packageJsonPath); | ||
|
|
||
| async function checkGitBranchAndStatus() { | ||
| const releaseType = process.argv[2]; | ||
| console.log(`Checking your branch for ${releaseType} release...`); | ||
|
|
||
| const resultBranch = await runExec('git branch --show-current', { | ||
| silent: true, | ||
| }); | ||
| const branchName = resultBranch.stdout.toString().trim(); | ||
|
|
||
| if (releaseType === 'dev') { | ||
| // For dev releases, cannot be on main branch | ||
| if (branchName === 'main') { | ||
| console.error(`🟠 You are at "main". Dev versions cannot be released from main branch.`); | ||
| process.exit(1); | ||
| } | ||
| } else if (releaseType === 'beta') { | ||
| // For beta releases, must be on main branch and up to date | ||
| if (branchName !== 'main') { | ||
| console.error( | ||
| `🟠 You are at "${branchName}" instead of "main" branch. Beta versions must be released from main.` | ||
| ); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| // Check if local main is up to date | ||
| await runExec('git remote update', { silent: true }); | ||
| const resultStatus = await runExec('git status -uno', { silent: true }); | ||
| const mainStatus = resultStatus.stdout.toString().trim(); | ||
|
|
||
| if (!mainStatus.includes("Your branch is up to date with 'origin/main'.")) { | ||
| console.error(`🟠 Please make sure your branch is up to date with the git repo.`); | ||
| process.exit(1); | ||
| } | ||
| } | ||
|
|
||
| await checkGitStatus(); | ||
| } | ||
|
|
||
| async function getNewVersion() { | ||
| const releaseType = process.argv[2]; | ||
| if (!['dev', 'beta'].includes(releaseType)) { | ||
| console.error('🟠 Invalid release type. Use dev or beta'); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const currentVersion = packageJson.version; | ||
|
|
||
| if (releaseType === 'dev') { | ||
| const timestamp = getDateYYYYMMDDHHMMSS(); | ||
| console.log('Creating new dev version...'); | ||
| return `1.0.0-dev.${timestamp}`; | ||
| } | ||
|
|
||
| // For beta releases | ||
| console.log('Creating new beta version...'); | ||
| if (currentVersion.includes('-beta.')) { | ||
| return semver.inc(currentVersion, 'prerelease', 'beta'); | ||
| } | ||
|
|
||
| console.error( | ||
| `🟠 Cannot create beta version: Current version "${currentVersion}" is not a beta version.\n` + | ||
| ' The package.json version should be in the format "1.0.0-beta.X"' | ||
| ); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| async function bumpVersion({ newVersion }) { | ||
| const cmd = `cd next && npm version --no-git-tag-version ${newVersion}`; | ||
| await runExec(cmd); | ||
| } | ||
|
|
||
| async function build() { | ||
| console.log('Building next version...'); | ||
| const cmd = 'cd next && npm run build'; | ||
| await runExec(cmd); | ||
| } | ||
|
|
||
| async function updateChangelog() { | ||
| console.log('Updating changelog...'); | ||
| const cmd = 'cd next && npx generate-changelog'; | ||
| await runExec(cmd); | ||
| } | ||
|
|
||
| async function gitCommit({ newVersion, releaseType }) { | ||
| console.log('Committing published version...'); | ||
| const prefix = `v1-${releaseType}`; | ||
|
|
||
| let cmd; | ||
| if (releaseType === 'beta') { | ||
| // For beta, we commit package.json changes and changelog | ||
| cmd = `git add next/package.json next/CHANGELOG.md && git commit -m "Release ${prefix} ${newVersion}" && git tag ${prefix}-${newVersion} && git push && git push origin --tags`; | ||
| } else { | ||
| // For dev, we only create a tag | ||
| cmd = `git tag ${prefix}-${newVersion} && git push origin --tags`; | ||
| } | ||
|
|
||
| await runExec(cmd); | ||
| } | ||
|
|
||
| async function publish({ newVersion, releaseType, otp }) { | ||
| console.log('Publishing new version...'); | ||
| const npmTag = `v1-${releaseType}`; | ||
| const originalVersion = packageJson.version; | ||
|
|
||
| try { | ||
| // Publish with the dev/beta version | ||
| const cmd = `cd next && npm publish --access=public --tag=${npmTag} --otp=${otp}`; | ||
| await runExec(cmd); | ||
|
|
||
| // For dev releases, revert package.json back to original version | ||
| if (releaseType === 'dev') { | ||
| const revertCmd = `cd next && npm version --no-git-tag-version ${originalVersion}`; | ||
| await runExec(revertCmd); | ||
| } | ||
|
|
||
| console.log(`🎉 ${npmTag} version ${newVersion} published!`); | ||
| console.log(`Install with: npm i @remoteoss/json-schema-form@${npmTag}`); | ||
| } catch { | ||
| console.log('🚨 Publish failed! Perhaps the OTP is wrong.'); | ||
| await revertCommit({ newVersion }); | ||
| } | ||
| } | ||
|
|
||
| async function init() { | ||
| const releaseType = process.argv[2]; | ||
| await checkGitBranchAndStatus(); | ||
| const newVersion = await getNewVersion(); | ||
|
|
||
| console.log(':: Current version:', packageJson.version); | ||
| console.log(`:::::: New version (${releaseType}):`, newVersion); | ||
|
|
||
| const answer = await askForConfirmation('Ready to commit and publish it?'); | ||
|
|
||
| if (answer === 'no') { | ||
| process.exit(1); | ||
| } | ||
|
|
||
| await checkNpmAuth(); | ||
|
|
||
| await bumpVersion({ newVersion }); | ||
|
|
||
| // Only update changelog for beta releases | ||
| if (releaseType === 'beta') { | ||
| await updateChangelog(); | ||
| const answerChangelog = await askForConfirmation( | ||
| 'Changelog is updated. You may tweak it as needed. Once ready, press Y to continue.' | ||
| ); | ||
| if (answerChangelog === 'no') { | ||
| await revertChanges(); | ||
| } | ||
| } | ||
|
|
||
| await build(); | ||
| const otp = await askForText('🔐 What is the NPM Auth OTP? (Check 1PW) '); | ||
|
|
||
| await gitCommit({ newVersion, releaseType }); | ||
| await publish({ newVersion, releaseType, otp }); | ||
| } | ||
|
|
||
| init(); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.