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

fix: canary releases #846

Merged
merged 9 commits into from
Jun 3, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 26 additions & 10 deletions .github/ISSUE_TEMPLATE/code-of-conduct.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@
# Code of Conduct for Bug Reports

As a user of this project and a member of the community, we ask that you follow this Code of Conduct when submitting an issue:
As a user of this project and a member of the community, we ask that you follow
this Code of Conduct when submitting an issue:

1. **Be respectful**: We are all here to contribute and make this project better. Please be respectful to other users, maintainers, and contributors.
1. **Be respectful**: We are all here to contribute and make this project
better. Please be respectful to other users, maintainers, and contributors.

1. **Be clear**: Please provide a clear and detailed description of the bug you are reporting. This will help the maintainers and contributors understand the issue and work towards a solution.
1. **Be clear**: Please provide a clear and detailed description of the bug you
are reporting. This will help the maintainers and contributors understand the
issue and work towards a solution.

1. **Be patient**: Please understand that resolving bugs may take time and effort. The maintainers and contributors will do their best to resolve the issue in a timely manner.
1. **Be patient**: Please understand that resolving bugs may take time and
effort. The maintainers and contributors will do their best to resolve the
issue in a timely manner.

1. **Be mindful of language**: Please refrain from using offensive or derogatory language. We will not tolerate any form of harassment or discrimination.
1. **Be mindful of language**: Please refrain from using offensive or derogatory
language. We will not tolerate any form of harassment or discrimination.

1. **Provide examples**: If possible, provide examples of the bug you are reporting. This can include screenshots, error messages, or steps to reproduce the issue.
1. **Provide examples**: If possible, provide examples of the bug you are
reporting. This can include screenshots, error messages, or steps to
reproduce the issue.

1. **Follow the issue template**: Please follow the issue template provided when submitting a bug report issue. This will ensure that the necessary information is included and make it easier for the maintainers and contributors to help you.
1. **Follow the issue template**: Please follow the issue template provided when
submitting a bug report issue. This will ensure that the necessary
information is included and make it easier for the maintainers and
contributors to help you.

1. **Keep the discussion focused**: Please keep the discussion focused on the bug you are reporting. If you have other concerns or questions, please create a separate issue.
1. **Keep the discussion focused**: Please keep the discussion focused on the
bug you are reporting. If you have other concerns or questions, please create
a separate issue.

1. **Stay open-minded**: We encourage open and constructive discussion. Please be open to different ideas and perspectives.
1. **Stay open-minded**: We encourage open and constructive discussion. Please
be open to different ideas and perspectives.

By following this Code of Conduct, we can work together to create a welcoming and collaborative community around this project.
By following this Code of Conduct, we can work together to create a welcoming
and collaborative community around this project.
47 changes: 0 additions & 47 deletions .github/canary-version.js

This file was deleted.

115 changes: 115 additions & 0 deletions .github/release-canary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// @ts-check

import * as cp from "node:child_process";
import * as fs from "node:fs";
import * as utils from "node:util";
import { context, getOctokit } from "@actions/github";
import prettier from "@prettier/sync";

const execa = utils.promisify(cp.exec);

const pkgJsonPaths = fs
.readdirSync("packages")
.filter((dir) => fs.existsSync(`packages/${dir}/package.json`))
.filter((dir) => {
if (!fs.existsSync(`packages/${dir}/package.json`)) return false;
const pkg = JSON.parse(
fs.readFileSync(`packages/${dir}/package.json`, "utf-8"),
);
return pkg.private !== true;
})
.map((dir) => `packages/${dir}/package.json`);

async function version() {
const { stdout } = await execa("git rev-parse --short HEAD");
const commitHash = stdout.trim();

// First pass to get the new version of everything
const versions = pkgJsonPaths.reduce((acc, curr) => {
const pkg = JSON.parse(fs.readFileSync(curr, "utf-8"));
const oldVersion = pkg.version;
const [major, minor, patch] = oldVersion.split(".").map(Number);
const newVersion = `${major}.${minor}.${patch + 1}-canary.${commitHash}`;

acc[pkg.name] = newVersion;
return acc;
}, {});

for (const pkgJsonPath of pkgJsonPaths) {
const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, "utf-8"));
pkg.version = versions[pkg.name];

// Update dependencies
for (const dep in pkg.dependencies) {
if (versions[dep]) {
pkg.dependencies[dep] = versions[dep];
}
}

const fmt = prettier.format(JSON.stringify(pkg), { filepath: pkgJsonPath });
fs.writeFileSync(pkgJsonPath, fmt);
}
}

async function publish() {
await Promise.allSettled(
pkgJsonPaths.map(async (pkgJsonPath) => {
const pkgPath = pkgJsonPath.replace("package.json", "");
const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, "utf-8"));
console.log(`⚙️ Publishing ${pkgPath}@${pkg.version}...`);
await execa(`npm publish ${pkgPath} --tag canary --access public`);
console.log(`✅ Published ${pkgPath}`);
}),
);
}

async function comment() {
const token = process.env.GITHUB_TOKEN;
if (!token) throw new Error("GITHUB_TOKEN is not set");
if (!context.payload.pull_request) throw new Error("No pull request");

const github = getOctokit(token);

// Get package version
let text =
"A new canary is available for testing. You can install this latest build in your project with:\n\n```sh\n";
for (const pkgJsonPath of pkgJsonPaths) {
const packageJson = JSON.parse(fs.readFileSync(pkgJsonPath, "utf-8"));
const version = packageJson.version;
text += `pnpm add ${packageJson.name}@${version}\n`;
}
text += "```\n\n";

// Create a comment on the PR with the new canary version
console.log(
`⚙️ Creating comment on PR #${context.payload.pull_request.number}...`,
);
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: text,
});

// Remove the label
console.log(
`⚙️ Removing label "release canary" from PR #${context.payload.pull_request.number}...`,
);
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
name: "release canary",
});
}

(async () => {
await version();
await publish();
await comment();

console.log("✅ Done");
})().catch((error) => {
console.error(error);
process.exit(1);
});
28 changes: 18 additions & 10 deletions .github/replace-workspace-protocol.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/// <reference types="bun-types" />
/// <reference types="bun" />

import fs from "fs";

export const MODULE = true;

declare module "bun" {
Expand All @@ -12,32 +13,39 @@ declare module "bun" {

const pkgJsonPaths = fs
.readdirSync("..")
.filter((dir) => {
if (!fs.existsSync(`../${dir}/package.json`)) return false;
const pkg = JSON.parse(fs.readFileSync(`../${dir}/package.json`, "utf-8"));
return pkg.private !== true;
})
.map((dir) => `../${dir}/package.json`);

/**
* Hack to replace the workspace protocol with the actual version
*/
const packageVersions = {};
await Promise.all(pkgJsonPaths.map(async (path) => {
const pkg = await Bun.file(path).json();
packageVersions[pkg.name] = pkg.version;
}))
await Promise.all(
pkgJsonPaths.map(async (path) => {
const pkg = await Bun.file(path).json();
packageVersions[pkg.name] = pkg.version;
}),
);

const workspacePkg = await Bun.file("package.json").json();
for (const dep in workspacePkg.dependencies) {
if (dep in packageVersions) {
workspacePkg.dependencies[dep] = packageVersions[dep];
}
}
for (const dep in workspacePkg.devDependencies) {
if (dep in packageVersions) {
workspacePkg.devDependencies[dep] = packageVersions[dep];
}
}
for (const dep in workspacePkg.peerDependencies) {
if (dep in packageVersions) {
workspacePkg.peerDependencies[dep] = packageVersions[dep];
}
}

// Remove unnecessary fields
workspacePkg.eslintConfig = undefined;
workspacePkg.devDependencies = undefined;
workspacePkg.scripts = undefined;

await Bun.write("package.json", JSON.stringify(workspacePkg, null, 2));
55 changes: 10 additions & 45 deletions .github/workflows/release-canary.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ on:
types: [labeled]
branches:
- main

env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}

jobs:
release:
if: contains(github.event.pull_request.labels.*.name, 'release canary')
Expand All @@ -22,51 +27,11 @@ jobs:
- name: Check packages for common errors
run: pnpm turbo --filter "./packages/*" build

- name: Bump version to canary
run: node .github/canary-version.js

- name: Authenticate to npm and publish
- name: Authenticate to npm
run: |
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc
for dir in packages/*/; do
if [ -d "$dir/package.json" ]; then
npm publish "$dir" --access public --tag canary
fi;
done

- name: Create a new comment notifying of the new canary version
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// Get package version
const fs = require("fs");
let text = 'A new canary is available for testing. You can install this latest build in your project with:\n\n```sh\n'

const pkgJsonPaths = fs
.readdirSync("packages")
.filter((dir) => dir !== "config")
.map((dir) => `packages/${dir}/package.json`);

for (const pkgJsonPath of pkgJsonPaths) {
const packageJson = JSON.parse(fs.readFileSync(pkgJsonPath));
const version = packageJson.version;
text += `pnpm add ${packageJson.name}@${version}\n`
}
text += '```\n\n'

// Create a comment on the PR with the new canary version
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: text,
})

// Remove the label
github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
name: 'release canary',
});
- name: Publish canary releases
run: node .github/release-canary.js
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ node_modules
coverage

.changeset
.github
.github/**/*.yaml
.github/**/*.yml

.next/
**/next-env.d.ts
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"typecheck": "turbo run typecheck"
},
"dependencies": {
"@actions/github": "^6.0.0",
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.1",
"@ianvs/prettier-plugin-sort-imports": "^4.1.1",
Expand Down
Loading
Loading