Skip to content

Commit

Permalink
chore: improve beta determination
Browse files Browse the repository at this point in the history
  • Loading branch information
runspired committed Feb 23, 2024
1 parent a86ccb6 commit 5954a8d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 22 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/release_publish-beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,9 @@ jobs:
git config --local user.email ${{ secrets.GH_DEPLOY_EMAIL }}
git config --local user.name ${{ secrets.GH_DEPLOY_NAME }}
- name: Get last beta version from package.json
if: github.event.inputs.kind == 'mirror'
uses: sergeysova/jq-action@v2
id: version
with:
cmd: 'jq .version package.json -r'
if: github.event.inputs.kind == 'mirror'
run: echo "::set-output name=value::$(bun --silent release latest beta)"
- name: Reset the Beta Branch
if: github.event.inputs.kind == 'mirror' || github.event.inputs.is-cycle-start == 'true'
run: git reset --hard origin/main && git push origin beta -f
Expand Down
8 changes: 8 additions & 0 deletions release/core/latest-for/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { NPM_DIST_TAG } from '../../utils/channel';
import { getPublishedChannelInfo } from '../../utils/git';

export async function latestFor(args: string[]) {
const channel = args[0] as NPM_DIST_TAG;
const version = (await getPublishedChannelInfo({ silent: true }))[channel];
console.log(version);
}
21 changes: 13 additions & 8 deletions release/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import { executePublish } from './core/publish';
import { executeReleaseNoteGeneration } from './core/release-notes';
import { write } from './utils/write';
import { promoteToLTS } from './core/promote';
import { latestFor } from './core/latest-for';

const COMMANDS = {
help: printHelpDocs,
about: printAbout,
release_notes: executeReleaseNoteGeneration,
publish: executePublish,
latest_for: latestFor,
promote: promoteToLTS,
default: executePublish,
exec: async (args: string[]) => {
Expand Down Expand Up @@ -43,19 +45,22 @@ const COMMANDS = {
async function main() {
const args = Bun.argv.slice(2);

write(
chalk.grey(
`\n\t${chalk.bold(
chalk.greenBright('Warp') + chalk.magentaBright('Drive')
)} | Automated Release\n\t==============================`
) + chalk.grey(`\n\tengine: ${chalk.cyan('bun@' + Bun.version)}\n`)
);

const commandArg = args.length === 0 ? 'help' : normalizeFlag(args[0]);
const commands = getCommands();
const cmdString = (commands.get(commandArg) as keyof typeof COMMANDS) || 'default';
const cmd = COMMANDS[cmdString];

// we silence output for the latest_for command
if (cmdString !== 'latest_for') {
write(
chalk.grey(
`\n\t${chalk.bold(
chalk.greenBright('Warp') + chalk.magentaBright('Drive')
)} | Automated Release\n\t==============================`
) + chalk.grey(`\n\tengine: ${chalk.cyan('bun@' + Bun.version)}\n`)
);
}

if (args.length && commands.has(commandArg)) {
args.shift();
}
Expand Down
19 changes: 13 additions & 6 deletions release/utils/flags-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export const publish_flags_config: FlagConfig = {
type: String,
examples: [],
default_value: async (options: Map<string, string | number | boolean | null>) => {
return (await getPublishedChannelInfo(options)).latest;
return (await getPublishedChannelInfo()).latest;
},
validate: async (value: unknown) => {
if (typeof value !== 'string') {
Expand Down Expand Up @@ -250,7 +250,7 @@ export const release_notes_flags_config: FlagConfig = merge(
type: String,
examples: [],
default_value: async (options: Map<string, string | number | boolean | null>) => {
return (await getPublishedChannelInfo(options)).latest;
return (await getPublishedChannelInfo()).latest;
},
validate: async (value: unknown) => {
if (typeof value !== 'string') {
Expand Down Expand Up @@ -283,7 +283,7 @@ export const promote_flags_config: FlagConfig = merge(
type: String,
examples: [],
default_value: async (options: Map<string, string | number | boolean | null>) => {
return (await getPublishedChannelInfo(options)).latest;
return (await getPublishedChannelInfo()).latest;
},
validate: async (value: unknown) => {
if (typeof value !== 'string') {
Expand Down Expand Up @@ -311,7 +311,7 @@ export const promote_flags_config: FlagConfig = merge(
examples: [],
default_value: async (options: Map<string, string | number | boolean | null>) => {
const version = options.get('version') as SEMVER_VERSION;
const existing = await getPublishedChannelInfo(options);
const existing = await getPublishedChannelInfo();

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

if (!version) {
version = (await getPublishedChannelInfo(options)).latest;
version = (await getPublishedChannelInfo()).latest;
}

if (value !== 'lts') {
Expand Down Expand Up @@ -384,6 +384,13 @@ export const command_config: CommandConfig = {
options: release_notes_flags_config,
example: '$ bun release cl',
},
latest_for: {
name: 'Latest For',
cmd: 'latest-for',
description: 'Print the latest version for a given channel',
alt: ['latest'],
example: '$ bun release latest-for beta',
},
promote: {
name: 'Promote to LTS',
cmd: 'promote',
Expand Down
9 changes: 5 additions & 4 deletions release/utils/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ export type GIT_STATE = {
};

let _NPM_INFO: Record<string, unknown> | null = null;
export async function getPublishedChannelInfo(
options: Map<string, boolean | string | number | null>
): Promise<CHANNEL_VERSIONS> {
export async function getPublishedChannelInfo(options?: { silent: boolean }): Promise<CHANNEL_VERSIONS> {
if (!_NPM_INFO) {
const gitInfo = await exec(['npm', 'view', 'ember-data@latest', '--json']);
const gitInfo = await exec({
cmd: ['npm', 'view', 'ember-data@latest', '--json'],
silent: options?.silent ?? false,
});
_NPM_INFO = JSON.parse(gitInfo) as Record<string, unknown>;
}
return _NPM_INFO['dist-tags'] as CHANNEL_VERSIONS;
Expand Down

0 comments on commit 5954a8d

Please sign in to comment.