/
deb.ts
74 lines (64 loc) · 3.02 KB
/
deb.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import {Command, Flags} from '@oclif/core'
import * as fs from 'node:fs'
import * as path from 'node:path'
import aws from '../../aws'
import {log} from '../../log'
import * as Tarballs from '../../tarballs'
import {DebArch, commitAWSDir, debArch, debVersion, templateShortKey} from '../../upload-util'
export default class UploadDeb extends Command {
static description = 'Upload deb package built with `pack deb`.'
static flags = {
root: Flags.string({char: 'r', default: '.', description: 'Path to oclif CLI root.', required: true}),
}
async run(): Promise<void> {
const {flags} = await this.parse(UploadDeb)
const buildConfig = await Tarballs.buildConfig(flags.root)
const {config, s3Config} = buildConfig
const dist = (f: string) => buildConfig.dist(path.join('deb', f))
const S3Options = {
ACL: s3Config.acl || 'public-read',
Bucket: s3Config.bucket!,
}
if (!fs.existsSync(dist('Release')))
this.error('Cannot find debian artifacts', {
suggestions: ['Run "oclif pack deb" before uploading'],
})
const cloudKeyBase = commitAWSDir(config.pjson.version, buildConfig.gitSha, s3Config)
const upload = (file: string) => {
const cloudKey = `${cloudKeyBase}/apt/${file}`
return aws.s3.uploadFile(dist(file), {...S3Options, CacheControl: 'max-age=86400', Key: cloudKey})
}
// apt expects ../apt/dists/versionName/[artifacts] but oclif wants versions/sha/apt/[artifacts]
// see https://github.com/oclif/oclif/issues/347 for the AWS-redirect that solves this
// this workaround puts the code in both places that the redirect was doing
// with this, the docs are correct. The copies are all done in parallel so it shouldn't be too costly.
const uploadWorkaround = (file: string) => {
const cloudKey = `${cloudKeyBase}/apt/./${file}`
return aws.s3.uploadFile(dist(file), {...S3Options, CacheControl: 'max-age=86400', Key: cloudKey})
}
const uploadDeb = async (arch: DebArch) => {
const deb = templateShortKey('deb', {
arch,
bin: config.bin,
versionShaRevision: debVersion(buildConfig),
})
if (fs.existsSync(dist(deb))) await Promise.all([upload(deb), uploadWorkaround(deb)])
}
log(`starting upload of deb artifacts for v${config.version}-${buildConfig.gitSha}`)
const arches = buildConfig.targets.filter((t) => t.platform === 'linux')
await Promise.all([
...arches.map((a) => uploadDeb(debArch(a.arch))),
upload('Packages.gz'),
upload('Packages.xz'),
upload('Packages.bz2'),
upload('Release'),
uploadWorkaround('Packages.gz'),
uploadWorkaround('Packages.xz'),
uploadWorkaround('Packages.bz2'),
uploadWorkaround('Release'),
...(fs.existsSync(dist('InRelease')) ? [upload('InRelease'), uploadWorkaround('InRelease')] : []),
...(fs.existsSync(dist('Release.gpg')) ? [upload('Release.gpg'), uploadWorkaround('Release.gpg')] : []),
])
log(`done uploading deb artifacts for v${config.version}-${buildConfig.gitSha}`)
}
}