Skip to content
This repository has been archived by the owner on Apr 21, 2022. It is now read-only.

Commit

Permalink
feat: added publish:win and publish:deb
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Apr 10, 2018
1 parent 9b95600 commit 145078c
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 23 deletions.
6 changes: 5 additions & 1 deletion .circleci/config.yml
Expand Up @@ -3,7 +3,7 @@ version: 2
jobs:
node-latest: &test
docker:
- image: oclif/release:0.0.0-9.11.1
- image: oclif/nsis:0.0.1-9.11.1
working_directory: ~/cli
environment:
NYC: "yarn exec nyc -- --nycrc-path node_modules/@oclif/nyc-config/.nycrc"
Expand Down Expand Up @@ -38,6 +38,10 @@ jobs:
- restore_cache: *restore_cache
- run: yarn global add @oclif/semantic-release@3 semantic-release@15
- run: yarn --frozen-lockfile
- run: ./bin/run pack
- run: ./bin/run pack:deb
- run: ./bin/run pack:win
- run: ./bin/run publish
- run: |
export PATH=/usr/local/share/.config/yarn/global/node_modules/.bin:$PATH
semantic-release -e @oclif/semantic-release
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -9,7 +9,7 @@
"bugs": "https://github.com/oclif/dev-cli/issues",
"dependencies": {
"@oclif/command": "^1.4.13",
"@oclif/config": "^1.6.0",
"@oclif/config": "^1.6.1",
"@oclif/errors": "^1.0.4",
"@oclif/plugin-help": "^1.2.3",
"cli-ux": "^3.3.28",
Expand Down
46 changes: 46 additions & 0 deletions src/commands/publish/deb.ts
@@ -0,0 +1,46 @@
import {Command, flags} from '@oclif/command'
import * as qq from 'qqjs'

import aws from '../../aws'
import {log} from '../../log'
import * as Tarballs from '../../tarballs'

export default class PublishDeb extends Command {
static description = 'publish deb package built with pack:deb'

static flags = {
root: flags.string({char: 'r', description: 'path to oclif CLI root', default: '.', required: true}),
}

async run() {
const {flags} = this.parse(PublishDeb)
const buildConfig = await Tarballs.buildConfig(flags.root)
const {s3Config, version, config} = buildConfig
const dist = buildConfig.dist('deb')
if (await qq.exists([dist, 'Release'])) this.error('run "oclif-dev pack:deb" before publishing')
const S3Options = {
Bucket: s3Config.bucket!,
ACL: 'public-read',
}

const remoteBase = buildConfig.channel === 'stable' ? 'apt' : `channels/${buildConfig.channel}/apt`
const upload = (file: string) => {
return aws.s3.uploadFile(file, {...S3Options, CacheControl: 'max-age=86400', Key: [remoteBase, file].join('/')})
}
const debVersion = `${buildConfig.version.split('-')[0]}-1`
const uploadDeb = async (arch: 'amd64' | 'i386') => {
const deb = buildConfig.dist(`deb/${config.bin}_${debVersion}_${arch}.deb`)
if (await qq.exists(deb)) await upload(deb)
}
await uploadDeb('amd64')
await uploadDeb('i386')
await upload('Packages.gz')
await upload('Packages.xz')
await upload('Packages.bz2')
await upload('Release')
await upload('InRelease')
await upload('Release.gpg')

log(`published deb ${version}`)
}
}
17 changes: 1 addition & 16 deletions src/commands/publish/index.ts
Expand Up @@ -11,8 +11,7 @@ export default class Publish extends Command {

static flags = {
root: flags.string({char: 'r', description: 'path to oclif CLI root', default: '.', required: true}),
'cloudfront-distribution-id': flags.string({description: 'invalidate cloudfront CDN', dependsOn: ['cloudfront-paths']}),
'cloudfront-paths': flags.string({description: 'paths to invalidate on cloudfront', dependsOn: ['cloudfront-distribution-id']}),
deb: flags.string({char: 'r', description: 'path to oclif CLI root', default: '.', required: true}),
}

buildConfig!: Tarballs.IConfig
Expand Down Expand Up @@ -47,20 +46,6 @@ export default class Publish extends Command {
log('uploading vanilla')
await uploadTarball()

const {'cloudfront-distribution-id': DistributionId} = flags
if (DistributionId) {
await aws.cloudfront.createCloudfrontInvalidation({
DistributionId,
InvalidationBatch: {
CallerReference: new Date().toString(),
Paths: {
Items: [flags['cloudfront-paths']!],
Quantity: 1,
}
}
})
}

log(`published ${version}`)
}

Expand Down
34 changes: 34 additions & 0 deletions src/commands/publish/win.ts
@@ -0,0 +1,34 @@
import {Command, flags} from '@oclif/command'
import * as qq from 'qqjs'

import aws from '../../aws'
import {log} from '../../log'
import * as Tarballs from '../../tarballs'

export default class PublishWin extends Command {
static description = 'publish windows installers built with pack:win'

static flags = {
root: flags.string({char: 'r', description: 'path to oclif CLI root', default: '.', required: true}),
}

async run() {
const {flags} = this.parse(PublishWin)
const buildConfig = await Tarballs.buildConfig(flags.root)
const {s3Config, version, config} = buildConfig
const S3Options = {
Bucket: s3Config.bucket!,
ACL: 'public-read',
}

let root = buildConfig.channel === 'stable' ? '' : `channels/${buildConfig.channel}/`
const uploadWin = async (arch: 'x64' | 'x86') => {
const exe = buildConfig.dist(`win/${config.bin}-v${buildConfig.version}-${arch}.exe`)
if (await qq.exists(exe)) await aws.s3.uploadFile(exe, {...S3Options, CacheControl: 'max-age=86400', Key: `${root}${config.bin}-${arch}.exe`})
}
await uploadWin('x64')
await uploadWin('x86')

log(`published win ${version}`)
}
}
32 changes: 32 additions & 0 deletions test/commands/publish/deb.test.ts
@@ -0,0 +1,32 @@
import {test} from '@oclif/test'
import * as qq from 'qqjs'

const pjson = require('../../../package.json')
const pjsonPath = require.resolve('../../../package.json')
const originalVersion = pjson.version

const skipIfWindows = process.platform === 'win32' ? test.skip() : test
const testRun = `test-${Math.random().toString().split('.')[1].slice(0, 4)}`

describe('publish:deb', () => {
beforeEach(async () => {
pjson.version = `${pjson.version}-${testRun}`
await qq.writeJSON(pjsonPath, pjson)
const root = qq.join(__dirname, '../../../tmp/test/publish')
await qq.emptyDir(root)
qq.cd(root)
})
afterEach(async () => {
qq.x(`aws s3 rm --recursive s3://oclif/dev-cli/channels/${testRun}`)
qq.cd([__dirname, '../../..'])
pjson.version = originalVersion
await qq.writeJSON(pjsonPath, pjson)
})

skipIfWindows
.command(['pack:deb'])
.command(['publish:deb'])
.it('publishes valid releases', async () => {
await qq.download(`https://oclif-staging.s3.amazonaws.com/channels/${testRun}/apt/Release`)
})
})
4 changes: 2 additions & 2 deletions test/commands/publish/index.test.ts
Expand Up @@ -51,7 +51,7 @@ describe('publish', () => {
await test(manifest.gz, manifest.sha256gz, nodeVersion)
await test(manifest.xz, manifest.sha256xz, nodeVersion)
}
await manifest(`https://oclif-staging.s3.amazonaws.com/@oclif/dev-cli/channels/${testRun}/version`, process.versions.node)
await manifest(`https://oclif-staging.s3.amazonaws.com/@oclif/dev-cli/channels/${testRun}/${target}`, pjson.oclif.update.node.version)
await manifest(`https://oclif-staging.s3.amazonaws.com/channels/${testRun}/version`, process.versions.node)
await manifest(`https://oclif-staging.s3.amazonaws.com/channels/${testRun}/${target}`, pjson.oclif.update.node.version)
})
})
36 changes: 36 additions & 0 deletions test/commands/publish/win.test.ts
@@ -0,0 +1,36 @@
import {test} from '@oclif/test'
import * as qq from 'qqjs'

import {gitSha} from '../../../src/tarballs'

const pjson = require('../../../package.json')
const pjsonPath = require.resolve('../../../package.json')
const originalVersion = pjson.version

const skipIfWindows = process.platform === 'win32' ? test.skip() : test
const testRun = `test-${Math.random().toString().split('.')[1].slice(0, 4)}`

describe('publish:win', () => {
beforeEach(async () => {
pjson.version = `${pjson.version}-${testRun}`
await qq.writeJSON(pjsonPath, pjson)
const root = qq.join(__dirname, '../../../tmp/test/publish')
await qq.emptyDir(root)
qq.cd(root)
})
afterEach(async () => {
qq.x(`aws s3 rm --recursive s3://oclif/dev-cli/channels/${testRun}`)
qq.cd([__dirname, '../../..'])
pjson.version = originalVersion
await qq.writeJSON(pjsonPath, pjson)
})

skipIfWindows
.command(['pack:win'])
.command(['publish:win'])
.it('publishes valid releases', async () => {
const sha = await gitSha(process.cwd(), {short: true})
await qq.download(`https://oclif-staging.s3.amazonaws.com/channels/${testRun}/oclif-dev-v${pjson.version}.${sha}-x64.exe`)
await qq.download(`https://oclif-staging.s3.amazonaws.com/channels/${testRun}/oclif-dev-v${pjson.version}.${sha}-x86.exe`)
})
})
6 changes: 3 additions & 3 deletions yarn.lock
Expand Up @@ -54,9 +54,9 @@
debug "^3.1.0"
semver "^5.5.0"

"@oclif/config@^1.6.0":
version "1.6.0"
resolved "https://registry.yarnpkg.com/@oclif/config/-/config-1.6.0.tgz#0d9a034a3364d0ff24368e039599f89e4c00f775"
"@oclif/config@^1.6.1":
version "1.6.1"
resolved "https://registry.yarnpkg.com/@oclif/config/-/config-1.6.1.tgz#561c8950a01fa3255821f7a6810974b625133b1b"
dependencies:
debug "^3.1.0"

Expand Down

0 comments on commit 145078c

Please sign in to comment.