Skip to content

Commit 5954a8d

Browse files
committed
chore: improve beta determination
1 parent a86ccb6 commit 5954a8d

File tree

5 files changed

+41
-22
lines changed

5 files changed

+41
-22
lines changed

.github/workflows/release_publish-beta.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,9 @@ jobs:
5959
git config --local user.email ${{ secrets.GH_DEPLOY_EMAIL }}
6060
git config --local user.name ${{ secrets.GH_DEPLOY_NAME }}
6161
- name: Get last beta version from package.json
62-
if: github.event.inputs.kind == 'mirror'
63-
uses: sergeysova/jq-action@v2
6462
id: version
65-
with:
66-
cmd: 'jq .version package.json -r'
63+
if: github.event.inputs.kind == 'mirror'
64+
run: echo "::set-output name=value::$(bun --silent release latest beta)"
6765
- name: Reset the Beta Branch
6866
if: github.event.inputs.kind == 'mirror' || github.event.inputs.is-cycle-start == 'true'
6967
run: git reset --hard origin/main && git push origin beta -f

release/core/latest-for/index.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { NPM_DIST_TAG } from '../../utils/channel';
2+
import { getPublishedChannelInfo } from '../../utils/git';
3+
4+
export async function latestFor(args: string[]) {
5+
const channel = args[0] as NPM_DIST_TAG;
6+
const version = (await getPublishedChannelInfo({ silent: true }))[channel];
7+
console.log(version);
8+
}

release/index.ts

+13-8
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ import { executePublish } from './core/publish';
88
import { executeReleaseNoteGeneration } from './core/release-notes';
99
import { write } from './utils/write';
1010
import { promoteToLTS } from './core/promote';
11+
import { latestFor } from './core/latest-for';
1112

1213
const COMMANDS = {
1314
help: printHelpDocs,
1415
about: printAbout,
1516
release_notes: executeReleaseNoteGeneration,
1617
publish: executePublish,
18+
latest_for: latestFor,
1719
promote: promoteToLTS,
1820
default: executePublish,
1921
exec: async (args: string[]) => {
@@ -43,19 +45,22 @@ const COMMANDS = {
4345
async function main() {
4446
const args = Bun.argv.slice(2);
4547

46-
write(
47-
chalk.grey(
48-
`\n\t${chalk.bold(
49-
chalk.greenBright('Warp') + chalk.magentaBright('Drive')
50-
)} | Automated Release\n\t==============================`
51-
) + chalk.grey(`\n\tengine: ${chalk.cyan('bun@' + Bun.version)}\n`)
52-
);
53-
5448
const commandArg = args.length === 0 ? 'help' : normalizeFlag(args[0]);
5549
const commands = getCommands();
5650
const cmdString = (commands.get(commandArg) as keyof typeof COMMANDS) || 'default';
5751
const cmd = COMMANDS[cmdString];
5852

53+
// we silence output for the latest_for command
54+
if (cmdString !== 'latest_for') {
55+
write(
56+
chalk.grey(
57+
`\n\t${chalk.bold(
58+
chalk.greenBright('Warp') + chalk.magentaBright('Drive')
59+
)} | Automated Release\n\t==============================`
60+
) + chalk.grey(`\n\tengine: ${chalk.cyan('bun@' + Bun.version)}\n`)
61+
);
62+
}
63+
5964
if (args.length && commands.has(commandArg)) {
6065
args.shift();
6166
}

release/utils/flags-config.ts

+13-6
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ export const publish_flags_config: FlagConfig = {
182182
type: String,
183183
examples: [],
184184
default_value: async (options: Map<string, string | number | boolean | null>) => {
185-
return (await getPublishedChannelInfo(options)).latest;
185+
return (await getPublishedChannelInfo()).latest;
186186
},
187187
validate: async (value: unknown) => {
188188
if (typeof value !== 'string') {
@@ -250,7 +250,7 @@ export const release_notes_flags_config: FlagConfig = merge(
250250
type: String,
251251
examples: [],
252252
default_value: async (options: Map<string, string | number | boolean | null>) => {
253-
return (await getPublishedChannelInfo(options)).latest;
253+
return (await getPublishedChannelInfo()).latest;
254254
},
255255
validate: async (value: unknown) => {
256256
if (typeof value !== 'string') {
@@ -283,7 +283,7 @@ export const promote_flags_config: FlagConfig = merge(
283283
type: String,
284284
examples: [],
285285
default_value: async (options: Map<string, string | number | boolean | null>) => {
286-
return (await getPublishedChannelInfo(options)).latest;
286+
return (await getPublishedChannelInfo()).latest;
287287
},
288288
validate: async (value: unknown) => {
289289
if (typeof value !== 'string') {
@@ -311,7 +311,7 @@ export const promote_flags_config: FlagConfig = merge(
311311
examples: [],
312312
default_value: async (options: Map<string, string | number | boolean | null>) => {
313313
const version = options.get('version') as SEMVER_VERSION;
314-
const existing = await getPublishedChannelInfo(options);
314+
const existing = await getPublishedChannelInfo();
315315

316316
if (existing.latest === version) {
317317
return 'lts';
@@ -321,10 +321,10 @@ export const promote_flags_config: FlagConfig = merge(
321321
},
322322
validate: async (value: unknown, options: Map<string, string | number | boolean | null>) => {
323323
let version = options.get('version') as SEMVER_VERSION;
324-
const existing = await getPublishedChannelInfo(options);
324+
const existing = await getPublishedChannelInfo();
325325

326326
if (!version) {
327-
version = (await getPublishedChannelInfo(options)).latest;
327+
version = (await getPublishedChannelInfo()).latest;
328328
}
329329

330330
if (value !== 'lts') {
@@ -384,6 +384,13 @@ export const command_config: CommandConfig = {
384384
options: release_notes_flags_config,
385385
example: '$ bun release cl',
386386
},
387+
latest_for: {
388+
name: 'Latest For',
389+
cmd: 'latest-for',
390+
description: 'Print the latest version for a given channel',
391+
alt: ['latest'],
392+
example: '$ bun release latest-for beta',
393+
},
387394
promote: {
388395
name: 'Promote to LTS',
389396
cmd: 'promote',

release/utils/git.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ export type GIT_STATE = {
3838
};
3939

4040
let _NPM_INFO: Record<string, unknown> | null = null;
41-
export async function getPublishedChannelInfo(
42-
options: Map<string, boolean | string | number | null>
43-
): Promise<CHANNEL_VERSIONS> {
41+
export async function getPublishedChannelInfo(options?: { silent: boolean }): Promise<CHANNEL_VERSIONS> {
4442
if (!_NPM_INFO) {
45-
const gitInfo = await exec(['npm', 'view', 'ember-data@latest', '--json']);
43+
const gitInfo = await exec({
44+
cmd: ['npm', 'view', 'ember-data@latest', '--json'],
45+
silent: options?.silent ?? false,
46+
});
4647
_NPM_INFO = JSON.parse(gitInfo) as Record<string, unknown>;
4748
}
4849
return _NPM_INFO['dist-tags'] as CHANNEL_VERSIONS;

0 commit comments

Comments
 (0)