Skip to content

Commit

Permalink
ci(release): better parsing and exclusions
Browse files Browse the repository at this point in the history
  • Loading branch information
ckohen committed Jun 8, 2024
1 parent fc1d525 commit 536eeef
Show file tree
Hide file tree
Showing 6 changed files with 432 additions and 736 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
package:
description: 'The published name of a single package to release'
type: choice
required: false
options:
- discord.js
- '@discordjs/brokers'
Expand All @@ -20,6 +21,11 @@ on:
- '@discordjs/util'
- '@discordjs/voice'
- '@discordjs/ws'
exclude:
description: 'Comma separated list of packages to exclude from release (if not depended upon)'
required: false
type: string
default: '@discordjs/docgen,@discordjs/next'
jobs:
npm-publish:
name: npm publish
Expand Down
1 change: 1 addition & 0 deletions packages/actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"@discordjs/scripts": "workspace:^",
"@vercel/blob": "^0.22.3",
"@vercel/postgres": "^0.8.0",
"commander": "^12.1.0",
"meilisearch": "^0.38.0",
"p-limit": "^5.0.0",
"tslib": "^2.6.2",
Expand Down
2 changes: 2 additions & 0 deletions packages/actions/src/releasePackages/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ description: 'Tags and releases any unreleased packages'
inputs:
package:
description: 'The published name of a single package to release'
exclude:
description: 'Comma separated list of packages to exclude from release (if not depended upon)'
runs:
using: node20
main: ../../dist/releasePackages/index.js
27 changes: 26 additions & 1 deletion packages/actions/src/releasePackages/generateReleaseTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ async function getReleaseEntries() {
return releaseEntries;
}

export async function generateReleaseTree(packageName?: string) {
export async function generateReleaseTree(packageName?: string, exclude?: string[]) {
let releaseEntries = await getReleaseEntries();
// Try to early return if the package doesn't have deps
if (packageName) {
Expand Down Expand Up @@ -135,6 +135,31 @@ export async function generateReleaseTree(packageName?: string) {
releaseEntries = unreleased;
}

// Prune exclusions
if (exclude) {
const neededPackages = new Set<string>();
const excludedReleaseTree: ReleaseEntry[][] = [];

for (const releaseBranch of releaseTree.reverse()) {
const newThisBranch: ReleaseEntry[] = [];

for (const entry of releaseBranch) {
if (exclude.includes(entry.name) && !neededPackages.has(entry.name)) {
continue;
}

newThisBranch.push(entry);
for (const dep of entry.dependsOn ?? []) {
neededPackages.add(dep);
}
}

if (newThisBranch.length) excludedReleaseTree.unshift(newThisBranch);
}

return excludedReleaseTree;
}

if (!packageName) {
return releaseTree;
}
Expand Down
21 changes: 16 additions & 5 deletions packages/actions/src/releasePackages/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
import process from 'node:process';
import { getInput } from '@actions/core';
import { program } from 'commander';
import { generateReleaseTree } from './generateReleaseTree.js';
import { releasePackage } from './releasePackage.js';

const argInput = process.argv[2];
const useableArg = argInput === 'discord.js' || argInput?.startsWith('@discordjs/');
const packageName = getInput('package') || useableArg ? argInput : '';
program
.name('release packages')
.description('releases monorepo packages with proper sequencing')
.argument('[package]', "release a specific package (and it's dependencies)", getInput('package'))
.option(
'-e, --exclude <packages...>',
'exclude specific packages from releasing (will still release if necessary for another package)',
getInput('exclude').split(','),
)
.parse();

const tree = await generateReleaseTree(packageName);
const { exclude } = program.opts<{ exclude: string[] }>();
const packageName = program.args[0]!;

const tree = await generateReleaseTree(packageName, exclude);
console.log(tree);
for (const branch of tree) {
console.log(`Releasing ${branch.map((entry) => `${entry.name}@${entry.version}`).join(', ')}`);
await Promise.all(branch.map(async (release) => releasePackage(release)));
Expand Down
Loading

0 comments on commit 536eeef

Please sign in to comment.