Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[compiler] Clean up publish script #31278

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/compiler_prereleases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ jobs:
- name: Publish packages to npm
run: |
cp ./scripts/release/ci-npmrc ~/.npmrc
scripts/release/publish.js --frfr --ci --tags ${{ inputs.dist_tag }}
scripts/release/publish.js --frfr --ci --versionName=0.0.0 --tag ${{ inputs.dist_tag }}
60 changes: 33 additions & 27 deletions compiler/scripts/release/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,19 @@ async function main() {
type: 'boolean',
default: false,
})
.option('tags', {
description: 'Tags to publish to npm',
type: 'string',
.option('tag', {
description: 'Tag to publish to npm',
type: 'choices',
choices: ['experimental', 'beta'],
default: 'experimental',
})
.option('version-name', {
description: 'Version name',
type: 'string',
default: '0.0.0',
})
.help('help')
.strict()
.parseSync();

if (argv.debug === false) {
Expand All @@ -82,7 +89,7 @@ async function main() {
pkgNames = [argv.packages];
}
const spinner = ora(
`Preparing to publish ${
`Preparing to publish ${argv.versionName}@${argv.tag} ${
argv.forReal === true ? '(for real)' : '(dry run)'
} [debug=${argv.debug}]`
).info();
Expand Down Expand Up @@ -118,14 +125,15 @@ async function main() {
}
);
const dateString = await getDateStringForCommit(commit);
const otp = argv.ci === false ? await promptForOTP() : null;
const otp =
argv.ci === false && argv.debug === false ? await promptForOTP() : null;
const {hash} = await hashElement(path.resolve(__dirname, '../..'), {
encoding: 'hex',
folders: {exclude: ['node_modules']},
files: {exclude: ['.DS_Store']},
});
const truncatedHash = hash.slice(0, 7);
const newVersion = `0.0.0-experimental-${truncatedHash}-${dateString}`;
const newVersion = `${argv.versionName}-${argv.tag}-${truncatedHash}-${dateString}`;

for (const pkgName of pkgNames) {
const pkgDir = path.resolve(__dirname, `../../packages/${pkgName}`);
Expand Down Expand Up @@ -179,29 +187,27 @@ async function main() {
spinner.succeed(`Successfully published ${pkgName} to npm`);

spinner.start('Pushing tags to npm');
if (typeof argv.tags === 'string') {
for (const tag of argv.tags.split(',')) {
try {
let opts = ['dist-tag', 'add', `${pkgName}@${newVersion}`, tag];
if (otp != null) {
opts.push(`--otp=${otp}`);
}
if (argv.debug === true) {
spinner.info(`dry-run: npm ${opts.join(' ')}`);
} else {
await spawnHelper('npm', opts, {
cwd: pkgDir,
stdio: 'inherit',
});
}
} catch (e) {
spinner.fail(e.toString());
throw e;
if (typeof argv.tag === 'string') {
try {
let opts = ['dist-tag', 'add', `${pkgName}@${newVersion}`, argv.tag];
if (otp != null) {
opts.push(`--otp=${otp}`);
}
spinner.succeed(
`Successfully pushed dist-tag ${tag} for ${pkgName} to npm`
);
if (argv.debug === true) {
spinner.info(`dry-run: npm ${opts.join(' ')}`);
} else {
await spawnHelper('npm', opts, {
cwd: pkgDir,
stdio: 'inherit',
});
}
} catch (e) {
spinner.fail(e.toString());
throw e;
}
spinner.succeed(
`Successfully pushed dist-tag ${argv.tag} for ${pkgName} to npm`
);
}
}

Expand Down
Loading