Skip to content

Commit 156c75e

Browse files
committedFeb 23, 2024
beta script
1 parent 58f86d0 commit 156c75e

File tree

5 files changed

+151
-88
lines changed

5 files changed

+151
-88
lines changed
 

‎.github/workflows/beta-release.yml

-47
This file was deleted.
+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: Publish Beta Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
# This input is used to determine whether to start/continue a beta-cycle vs mirror from canary.
7+
#
8+
# A beta-cycle "forks" from canary. It starts by updating the beta branch to the current state
9+
# of main (canary). Thereafter any updates to the beta branch are cherry-picked from main or PR'd
10+
# to the beta branch.
11+
#
12+
# The (default) mirror approach instead directly copies the canary release to the beta branch
13+
# each time. This is useful when the changes in canary are relatively minor or safe to release
14+
# and
15+
# and then publishing a beta release. A mirror is a direct copy of the canary release.
16+
kind:
17+
description: 'Whether to start/continue a beta-cycle vs mirror from canary'
18+
required: true
19+
default: 'mirror'
20+
type: choice
21+
options:
22+
- beta-cycle # start or continue a beta-cycle.
23+
- mirror # mirror code from canary. This is the default.
24+
is-beta-cycle-start:
25+
description: 'When kind is beta-cycle, whether to start a new beta-cycle'
26+
required: true
27+
default: false
28+
type: boolean
29+
30+
env:
31+
TURBO_API: http://127.0.0.1:9080
32+
TURBO_TOKEN: this-is-not-a-secret
33+
TURBO_TEAM: myself
34+
35+
jobs:
36+
release:
37+
name: Run publish script
38+
runs-on: ubuntu-latest
39+
environment: deployment
40+
steps:
41+
- name: Enforce Branch
42+
# Note: we always checkout beta in actions/checkout, but this enforces
43+
# good hygiene.
44+
if: github.ref != 'refs/heads/beta'
45+
run: |
46+
echo "Beta may only be published from the beta branch."
47+
exit 1
48+
- name: Make sure git user is setup
49+
run: |
50+
git config --local user.email ${{ secrets.GH_DEPLOY_EMAIL }}
51+
git config --local user.name ${{ secrets.GH_DEPLOY_NAME }}
52+
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
53+
with:
54+
fetch-tags: true
55+
progress: false
56+
token: ${{ secrets.GH_DEPLOY_TOKEN }}
57+
fetch-depth: 3
58+
ref: beta
59+
- run: git fetch origin main --depth=1
60+
- name: Get last beta version from package.json
61+
if: github.event.inputs.kind == 'mirror'
62+
uses: sergeysova/jq-action@v2
63+
id: version
64+
with:
65+
cmd: 'jq .version package.json -r'
66+
- name: Reset the Beta Branch
67+
if: github.event.inputs.kind == 'mirror' || github.event.inputs.is-beta-cycle-start == 'true'
68+
run: git reset --hard origin/main && git push origin beta -f
69+
- uses: ./.github/actions/setup
70+
with:
71+
install: true
72+
repo-token: ${{ secrets.GH_DEPLOY_TOKEN }}
73+
- name: Publish New BetaCycle Release
74+
if: github.event.inputs.kind == 'beta-cycle'
75+
run: bun release exec publish beta
76+
env:
77+
FORCE_COLOR: 2
78+
CI: true
79+
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
80+
- name: Publish New Mirror Release
81+
if: github.event.inputs.kind == 'mirror'
82+
run: bun release exec publish beta --from=${{ steps.version.outputs.stdout }}
83+
env:
84+
FORCE_COLOR: 2
85+
CI: true
86+
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
87+
- uses: actions/upload-artifact@v4
88+
with:
89+
name: tarballs
90+
path: tmp/tarballs/**/*.tgz

‎.github/workflows/release/publish-canary.yml

+8
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,20 @@ jobs:
2727
runs-on: ubuntu-latest
2828
environment: deployment
2929
steps:
30+
- name: Enforce Branch
31+
# Note: we always checkout main in actions/checkout, but this enforces
32+
# good hygiene.
33+
if: github.ref != 'refs/heads/main'
34+
run: |
35+
echo "Canary may only be published from the main branch."
36+
exit 1
3037
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
3138
with:
3239
fetch-depth: 1
3340
fetch-tags: true
3441
progress: false
3542
token: ${{ secrets.GH_DEPLOY_TOKEN }}
43+
ref: main
3644
- name: Check should run if HEAD is untagged
3745
run: |
3846
echo "HEAD is $(git name-rev --tags --name-only $(git rev-parse HEAD))"

‎release/index.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const COMMANDS = {
1818
default: executePublish,
1919
exec: async (args: string[]) => {
2020
args.shift();
21-
const cmd = args[0];
21+
const cmd = args.shift();
2222

2323
if (!cmd) {
2424
throw new Error('No command provided to exec');
@@ -51,14 +51,15 @@ async function main() {
5151
) + chalk.grey(`\n\tengine: ${chalk.cyan('bun@' + Bun.version)}\n`)
5252
);
5353

54-
if (args.length === 0) {
55-
args.push('help');
56-
}
57-
54+
const commandArg = args.length === 0 ? 'help' : normalizeFlag(args[0]);
5855
const commands = getCommands();
59-
const cmdString = (commands.get(normalizeFlag(args[0])) as keyof typeof COMMANDS) || 'default';
60-
56+
const cmdString = (commands.get(commandArg) as keyof typeof COMMANDS) || 'default';
6157
const cmd = COMMANDS[cmdString];
58+
59+
if (args.length && commands.has(commandArg)) {
60+
args.shift();
61+
}
62+
6263
await cmd(args);
6364
process.exit(0);
6465
}

‎release/utils/flags-config.ts

+45-34
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,39 @@ import { getGitState, getPublishedChannelInfo } from './git';
66
import chalk from 'chalk';
77
import semver from 'semver';
88

9+
/**
10+
* Like Pick but returns an object type instead of a union type.
11+
*
12+
* @internal
13+
*/
14+
type Subset<T, K extends keyof T> = {
15+
[P in K]: T[P];
16+
};
17+
18+
/**
19+
* Like Typescript Pick but For Runtime.
20+
*
21+
* @internal
22+
*/
23+
export function pick<T extends Record<string, unknown>, K extends keyof T>(obj: T, keys: K[]): Subset<T, K> {
24+
const result = {} as Subset<T, K>;
25+
26+
for (const key of keys) {
27+
result[key] = obj[key];
28+
}
29+
30+
return result;
31+
}
32+
33+
/**
34+
* Like Object.assign (is Object.assign) but ensures each arg and the result conform to T
35+
*
36+
* @internal
37+
*/
38+
export function merge<T>(...args: T[]): T {
39+
return Object.assign({}, ...args);
40+
}
41+
942
export const publish_flags_config: FlagConfig = {
1043
help: {
1144
name: 'Help',
@@ -129,6 +162,17 @@ export const publish_flags_config: FlagConfig = {
129162
examples: [],
130163
default_value: true,
131164
},
165+
// branch: {
166+
// name: 'Update Local and Upstream Branch',
167+
// flag: 'update_branch',
168+
// flag_aliases: [],
169+
// flag_mispellings: ['branch'],
170+
// description:
171+
// 'Whether to update the local and upstream branch according to the standard release channel flow. For release this will reset the branch to the current beta. For beta this will reset the branch to the current canary. For lts this will reset the branch to the current release. For lts-prev this is not a valid option.',
172+
// type: Boolean,
173+
// examples: [],
174+
// default_value: false,
175+
// },
132176
from: {
133177
name: 'From Version',
134178
flag: 'from',
@@ -188,39 +232,6 @@ export const publish_flags_config: FlagConfig = {
188232
},
189233
};
190234

191-
/**
192-
* Like Pick but returns an object type instead of a union type.
193-
*
194-
* @internal
195-
*/
196-
type Subset<T, K extends keyof T> = {
197-
[P in K]: T[P];
198-
};
199-
200-
/**
201-
* Like Typescript Pick but For Runtime.
202-
*
203-
* @internal
204-
*/
205-
export function pick<T extends Record<string, unknown>, K extends keyof T>(obj: T, keys: K[]): Subset<T, K> {
206-
const result = {} as Subset<T, K>;
207-
208-
for (const key of keys) {
209-
result[key] = obj[key];
210-
}
211-
212-
return result;
213-
}
214-
215-
/**
216-
* Like Object.assign (is Object.assign) but ensures each arg and the result conform to T
217-
*
218-
* @internal
219-
*/
220-
export function merge<T>(...args: T[]): T {
221-
return Object.assign({}, ...args);
222-
}
223-
224235
export const release_notes_flags_config: FlagConfig = merge(
225236
pick(publish_flags_config, ['help', 'increment', 'dry_run', 'dangerously_force', 'tag', 'channel', 'upstream']),
226237
{
@@ -390,7 +401,6 @@ export const command_config: CommandConfig = {
390401
'$ bun release promote 4.12.5 --tag=lts-4-12',
391402
],
392403
},
393-
// retag: {},
394404
default: {
395405
name: 'Publish',
396406
cmd: 'publish',
@@ -408,6 +418,7 @@ export function getCommands() {
408418
keys.forEach((key) => {
409419
const cmd = normalizeFlag(key);
410420
commands.set(cmd, cmd);
421+
commands.set(command_config[key].cmd, cmd);
411422
if (command_config[cmd].alt) {
412423
command_config[cmd].alt!.forEach((alt: string) => {
413424
const alternate = normalizeFlag(alt);

0 commit comments

Comments
 (0)