Skip to content

Commit

Permalink
fix: allow upload to succeed without buildmanifest
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Jun 13, 2024
1 parent 2f54ced commit 68cf556
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
28 changes: 18 additions & 10 deletions src/commands/upload/tarballs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Command, Flags, Interfaces} from '@oclif/core'
import {Command, Flags, Interfaces, ux} from '@oclif/core'
import * as fs from 'node:fs'

import aws from '../../aws'
Expand All @@ -7,7 +7,7 @@ import * as Tarballs from '../../tarballs'
import {commitAWSDir, templateShortKey} from '../../upload-util'

export default class UploadTarballs extends Command {
static description = 'Upload an oclif CLI to S3.'
static description = 'Upload an oclif CLI to S3. Requires s3 host and bucket to be configured.'

static flags = {
root: Flags.string({char: 'r', default: '.', description: 'Path to oclif CLI root.', required: true}),
Expand Down Expand Up @@ -65,17 +65,25 @@ export default class UploadTarballs extends Command {
})
}

const manifest = templateShortKey('manifest', shortKeyInputs)
const cloudKey = `${commitAWSDir(config.version, buildConfig.gitSha, s3Config)}/${manifest}`
const maybeUploadManifest = async () => {
const manifest = templateShortKey('manifest', shortKeyInputs)
const cloudKey = `${commitAWSDir(config.version, buildConfig.gitSha, s3Config)}/${manifest}`
const local = dist(manifest)
if (fs.existsSync(local)) {
return aws.s3.uploadFile(dist(manifest), {
...S3Options,
CacheControl: 'max-age=86400',
ContentType: 'application/json',
Key: cloudKey,
})
}

ux.warn(`Cannot find buildmanifest ${local}. CLI will not be able to update itself.`)
}

await Promise.all([
releaseTarballs('.tar.gz'),
aws.s3.uploadFile(dist(manifest), {
...S3Options,
CacheControl: 'max-age=86400',
ContentType: 'application/json',
Key: cloudKey,
}),
maybeUploadManifest(),
...(xz ? [releaseTarballs('.tar.xz')] : []),
])
}
Expand Down
6 changes: 5 additions & 1 deletion src/tarballs/build.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Interfaces} from '@oclif/core'
import {Interfaces, ux} from '@oclif/core'
import findYarnWorkspaceRoot from 'find-yarn-workspace-root'
import {copy, emptyDir, move, readJSON, remove, writeJSON} from 'fs-extra'
import {exec as execSync} from 'node:child_process'
Expand Down Expand Up @@ -96,6 +96,10 @@ export async function build(c: BuildConfig, options: BuildOptions = {}): Promise
await removeLockfiles(c)
}

if (!c.updateConfig.s3?.host || !c.updateConfig.s3?.bucket) {
ux.warn('No S3 bucket or host configured. CLI will not be able to update itself.')
}

const targetsToBuild = c.targets.filter((t) => !options.platform || options.platform === t.platform)
if (options.parallel) {
log(`will build ${targetsToBuild.length} targets in parallel`)
Expand Down

0 comments on commit 68cf556

Please sign in to comment.