Skip to content

Commit

Permalink
Canary release labeler
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiSpencer committed Jan 2, 2024
1 parent e3bc7b8 commit 60ff144
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .github/canary-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// @ts-check

import { exec } from "child_process";
import fs from "fs";

try {
exec("git rev-parse --short HEAD", (err, stdout) => {
if (err) {
console.log(err);
process.exit(1);
}
const commitHash = stdout.trim();

const pkg = JSON.parse(fs.readFileSync("package.json", "utf-8"));
const oldVersion = pkg.version;
const [major, minor, patch] = oldVersion.split(".").map(Number);
const newVersion = `${major}.${minor}.${patch + 1}-canary.${commitHash}`;

pkg.version = newVersion;

const content = JSON.stringify(pkg, null, "\t") + "\n";
const newContent = content
.replace(
new RegExp(`"@uploadthing/\\*": "${oldVersion}"`, "g"),
`"@uploadthing/*": "${newVersion}"`,
)
.replace(
new RegExp(`"uploadthing": "${oldVersion}"`, "g"),
`"uploadthing": "${newVersion}"`,
);

fs.writeFileSync("package.json", newContent);
});
} catch (error) {
console.error(error);
process.exit(1);
}
84 changes: 84 additions & 0 deletions .github/workflows/release-canary.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Release - Canary

on:
pull_request:
types: [labeled]
branches:
- main
jobs:
release:
if: contains(github.event.pull_request.labels.*.name, 'release canary')
name: Build & Publish a canary release
runs-on: ubuntu-latest

steps:
- name: Checkout Repo
uses: actions/checkout@v3

- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 18

- uses: pnpm/action-setup@v2
name: Install pnpm
id: pnpm-install
with:
version: 8
run_install: false

- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT
- name: Setup pnpm cache
uses: actions/cache@v3
with:
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install

- name: Check packages for common errors
run: pnpm build

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

- name: Authenticate to npm and publish
run: |
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc
pnpm publish react-trello-ts --access public --tag canary --no-git-checks
- name: Create a new comment notifying of the new canary version
uses: actions/github-script@v6
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 packageJson = JSON.parse(fs.readFileSync("package.json"));
const version = packageJson.version;
text += `pnpm add react-trello-ts@${version}\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',
});

0 comments on commit 60ff144

Please sign in to comment.