forked from slab/quill
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
121 additions
and
106 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -3,15 +3,14 @@ name: Generate Changelog | |
on: | ||
release: | ||
types: [published, created] | ||
workflow_dispatch: {} | ||
|
||
jobs: | ||
changelog: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Git checkout | ||
uses: actions/checkout@v4 | ||
- run: git config --global user.email "[email protected]" | ||
- run: git config --global user.name "quill-bot" | ||
- name: Use Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
|
This file contains 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 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 |
---|---|---|
|
@@ -30,121 +30,126 @@ if (!process.env.CI) { | |
|
||
exec('echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc'); | ||
|
||
exec('git config --global user.name "Zihua Li"'); | ||
exec('git config --global user.email "[email protected]"'); | ||
|
||
/* | ||
* Check that the git working directory is clean | ||
*/ | ||
if (exec("git status --porcelain").length) { | ||
exitWithError( | ||
"Make sure the git working directory is clean before releasing" | ||
); | ||
} | ||
|
||
/* | ||
* Check that the version is valid. Also extract the dist-tag from the version. | ||
*/ | ||
const [version, distTag] = (() => { | ||
const inputVersion = args.values.version; | ||
if (!inputVersion) { | ||
exitWithError('Missing required argument: "--version <version>"'); | ||
async function main() { | ||
await configGit(); | ||
|
||
/* | ||
* Check that the git working directory is clean | ||
*/ | ||
if (exec("git status --porcelain").length) { | ||
exitWithError( | ||
"Make sure the git working directory is clean before releasing" | ||
); | ||
} | ||
|
||
if (inputVersion === "experimental") { | ||
const randomId = crypto | ||
.randomBytes(Math.ceil(9 / 2)) | ||
.toString("hex") | ||
.slice(0, 9); | ||
|
||
return [ | ||
`0.0.0-experimental-${randomId}-${new Date() | ||
.toISOString() | ||
.slice(0, 10) | ||
.replace(/-/g, "")}`, | ||
"experimental", | ||
]; | ||
} | ||
|
||
const match = inputVersion.match( | ||
/^(?:[0-9]+\.){2}(?:[0-9]+)(?:-(dev|alpha|beta|rc)\.[0-9]+)?$/ | ||
/* | ||
* Check that the version is valid. Also extract the dist-tag from the version. | ||
*/ | ||
const [version, distTag] = (() => { | ||
const inputVersion = args.values.version; | ||
if (!inputVersion) { | ||
exitWithError('Missing required argument: "--version <version>"'); | ||
} | ||
|
||
if (inputVersion === "experimental") { | ||
const randomId = crypto | ||
.randomBytes(Math.ceil(9 / 2)) | ||
.toString("hex") | ||
.slice(0, 9); | ||
|
||
return [ | ||
`0.0.0-experimental-${randomId}-${new Date() | ||
.toISOString() | ||
.slice(0, 10) | ||
.replace(/-/g, "")}`, | ||
"experimental", | ||
]; | ||
} | ||
|
||
const match = inputVersion.match( | ||
/^(?:[0-9]+\.){2}(?:[0-9]+)(?:-(dev|alpha|beta|rc)\.[0-9]+)?$/ | ||
); | ||
if (!match) { | ||
exitWithError(`Invalid version: ${inputVersion}`); | ||
} | ||
|
||
return [inputVersion, match[1] || "latest"]; | ||
})(); | ||
|
||
/* | ||
* Get the current version | ||
*/ | ||
const currentVersion = JSON.parse( | ||
fs.readFileSync("package.json", "utf-8") | ||
).version; | ||
console.log( | ||
`Releasing with version: ${currentVersion} -> ${version} and dist-tag: ${distTag}` | ||
); | ||
if (!match) { | ||
exitWithError(`Invalid version: ${inputVersion}`); | ||
} | ||
|
||
return [inputVersion, match[1] || "latest"]; | ||
})(); | ||
|
||
/* | ||
* Get the current version | ||
*/ | ||
const currentVersion = JSON.parse( | ||
fs.readFileSync("package.json", "utf-8") | ||
).version; | ||
console.log( | ||
`Releasing with version: ${currentVersion} -> ${version} and dist-tag: ${distTag}` | ||
); | ||
|
||
/* | ||
* Bump npm versions | ||
*/ | ||
exec(`npm version ${version} --workspaces --force`); | ||
exec("git add **/package.json"); | ||
exec(`npm version ${version} --include-workspace-root --force`); | ||
|
||
const pushCommand = `git push origin ${process.env.GITHUB_REF_NAME} --follow-tags`; | ||
if (distTag === "experimental") { | ||
console.log(`Skipping: "${pushCommand}" for experimental version`); | ||
} else { | ||
if (dryRun) { | ||
console.log(`Skipping: "${pushCommand}" in dry-run mode`); | ||
/* | ||
* Bump npm versions | ||
*/ | ||
exec(`npm version ${version} --workspaces --force`); | ||
exec("git add **/package.json"); | ||
exec(`npm version ${version} --include-workspace-root --force`); | ||
|
||
const pushCommand = `git push origin ${process.env.GITHUB_REF_NAME} --follow-tags`; | ||
if (distTag === "experimental") { | ||
console.log(`Skipping: "${pushCommand}" for experimental version`); | ||
} else { | ||
exec(pushCommand); | ||
if (dryRun) { | ||
console.log(`Skipping: "${pushCommand}" in dry-run mode`); | ||
} else { | ||
exec(pushCommand); | ||
} | ||
} | ||
} | ||
|
||
/* | ||
* Build Quill package | ||
*/ | ||
console.log("Building Quill"); | ||
exec("npm run build:quill"); | ||
|
||
/* | ||
* Publish Quill package | ||
*/ | ||
console.log("Publishing Quill"); | ||
const distFolder = "packages/quill/dist"; | ||
if ( | ||
JSON.parse(fs.readFileSync(path.join(distFolder, "package.json"), "utf-8")) | ||
.version !== version | ||
) { | ||
exitWithError("Version mismatch between package.json and dist/package.json"); | ||
} | ||
/* | ||
* Build Quill package | ||
*/ | ||
console.log("Building Quill"); | ||
exec("npm run build:quill"); | ||
|
||
/* | ||
* Publish Quill package | ||
*/ | ||
console.log("Publishing Quill"); | ||
const distFolder = "packages/quill/dist"; | ||
if ( | ||
JSON.parse(fs.readFileSync(path.join(distFolder, "package.json"), "utf-8")) | ||
.version !== version | ||
) { | ||
exitWithError( | ||
"Version mismatch between package.json and dist/package.json" | ||
); | ||
} | ||
|
||
const readme = fs.readFileSync("README.md", "utf-8"); | ||
fs.writeFileSync(path.join(distFolder, "README.md"), readme); | ||
const readme = fs.readFileSync("README.md", "utf-8"); | ||
fs.writeFileSync(path.join(distFolder, "README.md"), readme); | ||
|
||
exec(`npm publish --tag ${distTag}${dryRun ? " --dry-run" : ""}`, { | ||
cwd: distFolder, | ||
}); | ||
exec(`npm publish --tag ${distTag}${dryRun ? " --dry-run" : ""}`, { | ||
cwd: distFolder, | ||
}); | ||
|
||
/* | ||
* Create GitHub release | ||
*/ | ||
if (distTag === "experimental") { | ||
console.log("Skipping GitHub release for experimental version"); | ||
} else { | ||
const prereleaseFlag = distTag === "latest" ? "--latest" : " --prerelease"; | ||
const releaseCommand = `gh release create v${version} ${prereleaseFlag} -t "Version ${version}" --generate-notes`; | ||
if (dryRun) { | ||
console.log(`Skipping: "${releaseCommand}" in dry-run mode`); | ||
/* | ||
* Create GitHub release | ||
*/ | ||
if (distTag === "experimental") { | ||
console.log("Skipping GitHub release for experimental version"); | ||
} else { | ||
exec(releaseCommand); | ||
const prereleaseFlag = distTag === "latest" ? "--latest" : " --prerelease"; | ||
const releaseCommand = `gh release create v${version} ${prereleaseFlag} -t "Version ${version}" --generate-notes`; | ||
if (dryRun) { | ||
console.log(`Skipping: "${releaseCommand}" in dry-run mode`); | ||
} else { | ||
exec(releaseCommand); | ||
} | ||
} | ||
|
||
/* | ||
* Create npm package tarball | ||
*/ | ||
exec("npm pack", { cwd: distFolder }); | ||
} | ||
|
||
/* | ||
* Create npm package tarball | ||
*/ | ||
exec("npm pack", { cwd: distFolder }); | ||
main(); |
This file contains 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,8 @@ | ||
import { $ } from "execa"; | ||
|
||
async function configGit() { | ||
await $`git config --global user.name ${"Zihua Li"}`; | ||
await $`git config --global user.email ${"[email protected]"}`; | ||
} | ||
|
||
export default configGit; |