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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for publishing legacy versions in release script #230

Merged
merged 5 commits into from
Jun 12, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- main
- 'v*.x'

concurrency: ${{ github.workflow }}-${{ github.ref }}
concurrency: ${{ github.workflow }}

env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ yarn add ./inngest.tgz && framework dev

To release to production, we use [Changesets](https://github.com/changesets/changesets). This means that releasing and changelog generation is all managed through PRs, where a bot will guide you through the process of announcing changes in PRs and releasing them once merged to `main`.

#### Legacy versions

Merging and releasing to previous major versions of the SDK is also supported.

- Add a `backport v*.x` label (e.g. `backport v1.x`) to a PR to have a backport PR generated when the initial PR is merged.
- Merging into a `v*.x` branch creates a release PR (named **Release v1.x**, for example) the same as the `main` branch. Simply merge to release.

#### Snapshot versions

If a local `inngest.tgz` isn't ideal, we can release a tagged version to npm. For now, this is relatively manual. For this, please ensure you are in an open PR branch for observability.
Expand Down
46 changes: 46 additions & 0 deletions scripts/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ if (branch !== "main" && !branch.endsWith(".x")) {
);
}

console.log("branch:", branch);

const { version } = require("../package.json");
console.log("version:", version);
const tag = `v${version}`;
console.log("tag:", tag);

const [, tagEnd = ""] = version.split("-");
const distTag = tagEnd.split(".")[0] || "latest";
console.log("distTag:", distTag);

const rootDir = path.join(__dirname, "..");
const distDir = path.join(rootDir, "dist");
Expand Down Expand Up @@ -46,10 +51,33 @@ const exec = async (...args) => {
throw new Error(`git ls-remote exited with ${exitCode}:\n${stderr}`);
}

// Get current latest version
const { exitCode: latestCode, stdout: latestStdout, stderr: latestStderr } =
await getExecOutput("npm", ["dist-tag", "ls"]);

if (latestCode !== 0) {
throw new Error(
`npm dist-tag ls exited with ${latestCode}:\n${latestStderr}`,
);
}

const latestVersion =
latestStdout.split("\n").find((line) => line.startsWith("latest: "))?.split(
" ",
)[1];

if (!latestVersion) {
throw new Error(`Could not find "latest" dist-tag in:\n${latestStdout}`);
}

console.log("latestVersion:", latestVersion);

// Release to npm
await exec("npm", ["config", "set", "git-tag-version", "false"], {
cwd: distDir,
});

console.log("publishing", tag, "to dist tag:", distTag);
await exec(
"npm",
["publish", "--tag", distTag, "--access", "public", "--provenance"],
Expand All @@ -58,7 +86,25 @@ const exec = async (...args) => {
},
);

// If this was a backport release, republish the "latest" tag at the actual latest version
if (branch !== "main" && distTag === "latest") {
console.log(
'is backport release; updating "latest" tag to:',
latestVersion,
);

await exec("npm", [
"dist-tag",
"add",
`inngest@${latestVersion}`,
"latest",
]);
}

// Tag and push the release commit
console.log('running "changeset tag" to tag the release commit');
await exec("changeset", ["tag"]);

console.log(`pushing git tags to origin/${branch}`);
await exec("git", ["push", "--follow-tags", "origin", branch]);
})();