Skip to content
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

Simplify release process #4030

Merged
merged 5 commits into from
May 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ In the same day:
3. The selected commit is tagged as `v0.34.0-beta.0`, released, and published for testing as a Pre-Release

```
export TAG=v0.34.0-beta.0 && git tag -a $TAG 9fceb02 -m "$TAG" && git push origin $TAG
yarn release -t v0.34.0-beta.0 -c 9fceb02
```

4. The team creates a PR to bump `master` to the next version (in the example: `v0.35.0`) and continues releasing nightly builds.
Expand All @@ -25,7 +25,7 @@ After 3-5 days of testing:
5. Tag final stable commit as `v0.34.0`, release and publish the stable release. This commit will be in `v0.34.x` branch and may note be on `master` if beta candidate required bug fixes.

```
export TAG=v0.34.0 && git tag -a $TAG 9fceb02 -m "$TAG" && git push origin $TAG
yarn release -t v0.34.0 -c 9fceb02
```

## Pre-Releases
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"benchmark": "yarn benchmark:files 'packages/*/test/perf/**/*.test.ts'",
"benchmark:files": "LODESTAR_PRESET=mainnet NODE_OPTIONS=--max-old-space-size=4096 benchmark --config .benchrc.yaml",
"publish:release": "lerna publish from-package --yes --no-verify-access",
"release": "lerna version --no-push --sign-git-commit",
"release": "node scripts/release.mjs",
"postrelease": "git tag -d $(git describe --abbrev=0)",
"check-readme": "lerna run check-readme"
},
Expand Down
104 changes: 104 additions & 0 deletions scripts/release.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import {execSync} from "node:child_process";
import yargs from "yargs";
import {hideBin} from "yargs/helpers";
import inquirer from "inquirer";

// Script to make releasing easier
// Run with --help to see usage

const cmd = (cmd, opts={}) => execSync(cmd, {encoding: "utf8", stdio: ["pipe", "pipe", "ignore"], ...opts}).trim();

const argv = yargs(hideBin(process.argv))
.usage("Release lodestar")
.example([
["$0 -t v0.36.0", "Release version 0.36.0 using the current commit"]
])
.options({
tag: {
alias: "t",
demandOption: true,
type: "string",
describe: "The tag to release",
},
commit: {
alias: "c",
type: "string",
default: cmd("git rev-parse --short HEAD"),
describe: "The commit to tag",
},
yes: {
alias: "y",
type: "boolean",
describe: "Automatic yes to prompts"
}
})
.version("v0.1.0")
.alias("v", "version")
.alias("h", "help")
.strict()
.help()
.argv;

// Validate the supplied version
const versionCaptureRegex=/^(v[0-9]+\.[0-9]+)\.[0-9]+(-beta\.[0-9]+)?$/
const versionMatch = versionCaptureRegex.exec(argv.tag);
if (versionMatch == null) {
console.log(`Tag must match ${versionCaptureRegex}`);
process.exit(1);
}

const tag = argv.tag;
const commit = argv.commit;
const commitMessage = cmd(`git show-branch --no-name ${commit}`);
// The branch is assumed from the tag
const branch = `${versionMatch[1]}.x`;

console.log("Tag", tag)
console.log("Commit", commit, commitMessage)
console.log("Branch", branch)

// Ensure the branch exists
try {
cmd(`git show-branch --no-name ${branch}`);
} catch (e) {
console.log(`Branch ${branch} does not exist`);
process.exit(1);
}

// Ensure the commit exists in the branch (last 10 commits)
const last10Commits = cmd(`git log --oneline -n 10 ${branch}`);
const commitMatch = last10Commits.match(commit);
if (commitMatch == null) {
console.log(`Commit ${commit} does not belong to branch ${branch}`);
process.exit(1);
}

// Last chance to exit
if (!argv.yes) {
const input = await inquirer.prompt([
{
name: "yes",
type: "confirm",
message: "Do you want to proceed?",
},
]);
if (!input.yes) {
process.exit(1);
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how do we prevent this error TAG v0.36.1-beta.0 does not include LOCAL_VERSION 0.36.0 from https://github.com/ChainSafe/lodestar/runs/6476719731?check_suite_focus=true ?

if yes, we should do a check here before we create a tag.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea! This condition should be checked here too

Copy link
Member Author

@wemeetagain wemeetagain May 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script now calls lerna version $TAG if the tag does not match lerna.json (which bumps the versions in package.jsons, commits, tags and pushes).
Otherwise, if the tag matches lerna.json, it tags and pushes manually with git.

This makes it very handy to just checkout the version branch (eg: v0.36.x), cherry pick commits on top, and run the script, in the case of a beta release.
Or just checkout the version branch and run the script, in the case of a non-beta release.

// Perform release actions
try {
const tagCmd = `git tag -a ${tag} ${commit} -m "${tag}"`;
console.log(tagCmd);
cmd(tagCmd, {stdio: "pipe"});

const pushCmd = `git push origin ${tag}`;
console.log(pushCmd);
cmd(pushCmd, {stdio: "pipe"});

console.log("Success!");
} catch (e) {
console.log(e.message);
process.exit(1);
}