Skip to content

Commit

Permalink
Config git for all workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
luin committed May 13, 2024
1 parent 4d5bb45 commit 517d009
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 106 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions scripts/changelog.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { $ } from "execa";
import { readFile, writeFile } from "node:fs/promises";
import { fileURLToPath } from "node:url";
import { dirname, join } from "node:path";
import configGit from "./utils/configGit.mjs";

const changelogFilename = "CHANGELOG.md";

Expand All @@ -26,6 +27,8 @@ if (currentChangeLog.includes(`# ${release.tagName}`)) {
process.exit(0);
}

await configGit();

const filteredReleaseNote = (note) => {
const ignoreSections = [
"## new contributors",
Expand Down
213 changes: 109 additions & 104 deletions scripts/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
8 changes: 8 additions & 0 deletions scripts/utils/configGit.mjs
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;

0 comments on commit 517d009

Please sign in to comment.