Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/sync'
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwebbio committed Apr 21, 2023
2 parents e0d62a0 + 528466f commit 4d45650
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 38 deletions.
8 changes: 8 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
This project uses [conventional changelog](https://conventionalcommits.org) and commits will need to fit the correct format for CI to pass and the change to be entered into the [CHANGELOG](./CHANGELOG.md) correctly.

## Test

The `test/integration` requires Github Actions to run on the various OS under test.

These tests requires keys for uploading and promoting artifacts to S3 (and testing optional functions like signing).

In GHA, set `PRESERVE_ARTIFCATS` to `true` to prevent the tests from deleting the artifacts. This is useful if you want to retrieve them from their buckets to manually test on different systems.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
## [3.8.1](https://github.com/oclif/oclif/compare/3.8.0...3.8.1) (2023-04-14)


### Bug Fixes

* **promote:deb:** skip i386 deb pkg if node < 10 ([#1140](https://github.com/oclif/oclif/issues/1140)) ([dd50d78](https://github.com/oclif/oclif/commit/dd50d78ed486e37209789a201e60b35679a7ffdf))



# [3.8.0](https://github.com/oclif/oclif/compare/3.7.3...3.8.0) (2023-04-12)


### Features

* binAliases (support for multiple bin for the same CLI) for all OS ([a9ee96e](https://github.com/oclif/oclif/commit/a9ee96e7cd954a1a33db595e8be22e91070e8a93))



## [3.7.3](https://github.com/oclif/oclif/compare/3.7.2...3.7.3) (2023-03-28)


Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "@appfolio/oclif",
"description": "oclif: create your own CLI",
"version": "3.7.3",
"version": "3.8.1",
"author": "Salesforce",
"bin": {
"oclif": "bin/run"
"oclif": "bin/run",
"oclif2": "bin/run"
},
"bugs": "https://github.com/oclif/oclif/issues",
"dependencies": {
Expand Down Expand Up @@ -91,6 +92,9 @@
"@oclif/plugin-not-found"
],
"bin": "oclif",
"binAliases": [
"oclif2"
],
"dirname": "oclif",
"topicSeparator": " ",
"macos": {
Expand Down
8 changes: 5 additions & 3 deletions src/commands/pack/deb.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import {Command, Flags} from '@oclif/core'
import {Interfaces} from '@oclif/core'
import {Command, Flags, Interfaces} from '@oclif/core'
import * as fs from 'fs-extra'
import * as _ from 'lodash'
import * as path from 'path'
import * as Tarballs from '../../tarballs'
import {templateShortKey, debVersion, debArch} from '../../upload-util'
import {debArch, debVersion, templateShortKey} from '../../upload-util'
import {exec as execSync} from 'child_process'
import {promisify} from 'node:util'

Expand Down Expand Up @@ -40,6 +39,7 @@ Priority: standard
Architecture: ${arch}
Maintainer: ${config.config.scopedEnvVar('AUTHOR') || config.config.pjson.author}
Description: ${config.config.pjson.description}
Aliases: ${config.config.binAliases?.join(', ')}
`,
ftparchive: (config: Interfaces.Config,
) => `
Expand Down Expand Up @@ -83,6 +83,8 @@ export default class PackDeb extends Command {
])
// symlink usr/bin/oclif points to usr/lib/oclif/bin/oclif
await exec(`ln -s "${path.join('..', 'lib', config.dirname, 'bin', config.bin)}" "${config.bin}"`, {cwd: path.join(workspace, 'usr', 'bin')})

config.binAliases?.map(alias => exec(`ln -sf "${path.join('..', 'lib', config.dirname, 'bin', config.bin)}" "${alias}"`, {cwd: path.join(workspace, 'usr', 'bin')}))
await exec(`sudo chown -R root "${workspace}"`)
await exec(`sudo chgrp -R root "${workspace}"`)
await exec(`dpkg --build "${workspace}" "${path.join(dist, versionedDebBase)}"`)
Expand Down
9 changes: 6 additions & 3 deletions src/commands/pack/win.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {Command, Flags} from '@oclif/core'
import {Interfaces} from '@oclif/core'
import {Command, Flags, Interfaces} from '@oclif/core'
import * as path from 'path'
import * as fs from 'fs-extra'
import * as Tarballs from '../../tarballs'
Expand Down Expand Up @@ -240,7 +239,11 @@ the CLI should already exist in a directory named after the CLI that is the root
fs.writeFile(path.join(installerBase, 'bin', `${config.bin}.cmd`), scripts.cmd(config)),
fs.writeFile(path.join(installerBase, 'bin', `${config.bin}`), scripts.sh(config)),
fs.writeFile(path.join(installerBase, `${config.bin}.nsi`), scripts.nsis(config, arch)),
].concat(flags['additional-cli'] ? [
].concat(config.binAliases ? config.binAliases.flatMap(alias =>
// write duplicate files for windows aliases
// this avoids mklink which can require admin privileges which not everyone has
[fs.writeFile(path.join(installerBase, 'bin', `${alias}.cmd`), scripts.cmd(config)), fs.writeFile(path.join(installerBase, 'bin', `${alias}`), scripts.sh(config))]) : [])
.concat(flags['additional-cli'] ? [
fs.writeFile(path.join(installerBase, 'bin', `${flags['additional-cli']}.cmd`), scripts.cmd(config, flags['additional-cli'])),
fs.writeFile(path.join(installerBase, 'bin', `${flags['additional-cli']}`), scripts.sh({bin: flags['additional-cli']} as Interfaces.Config)),
] : []))
Expand Down
14 changes: 13 additions & 1 deletion src/commands/promote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as path from 'path'
import * as _ from 'lodash'

import {ux, Command, Flags} from '@oclif/core'
import { lte } from 'semver'

import aws from '../aws'
import * as Tarballs from '../tarballs'
Expand Down Expand Up @@ -153,14 +154,25 @@ export default class Promote extends Command {
// copy debian artifacts
const debArtifacts = [
templateShortKey('deb', {bin: config.bin, versionShaRevision: debVersion(buildConfig), arch: 'amd64' as any}),
templateShortKey('deb', {bin: config.bin, versionShaRevision: debVersion(buildConfig), arch: 'i386' as any}),
'Packages.gz',
'Packages.xz',
'Packages.bz2',
'Release',
'InRelease',
'Release.gpg',
]

// start
// TODO: remove in next major release
// node dropped 32-bit support for linux a long time ago, see:
// https://github.com/oclif/oclif/issues/770#issuecomment-1508719530
const arches = buildConfig.targets.filter(t => t.platform === 'linux')

if (arches.find(a=> a.arch.includes('x86')) && lte(buildConfig.nodeVersion, '9.11.2')) {
debArtifacts.push(templateShortKey('deb', {bin: config.bin, versionShaRevision: debVersion(buildConfig), arch: 'i386' as any}))
}
// end

this.log(`Promoting debian artifacts to ${flags.channel}`)
await Promise.all(debArtifacts.flatMap(artifact => {
const debCopySource = cloudBucketCommitKey(`apt/${artifact}`)
Expand Down
29 changes: 17 additions & 12 deletions src/tarballs/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@
import {Interfaces} from '@oclif/core'
import * as fs from 'fs'
import * as path from 'path'
import {exec as execSync} from 'node:child_process'
import {promisify} from 'node:util'

export async function writeBinScripts({config, baseWorkspace, nodeVersion}: {config: Interfaces.Config
; baseWorkspace: string; nodeVersion: string;}): Promise<void> {
const exec = promisify(execSync)

export async function writeBinScripts({config, baseWorkspace, nodeVersion}: {
config: Interfaces.Config; baseWorkspace: string; nodeVersion: string;
}): Promise<void> {
const binPathEnvVar = config.scopedEnvVarKey('BINPATH')
const redirectedEnvVar = config.scopedEnvVarKey('REDIRECTED')
const clientHomeEnvVar = config.scopedEnvVarKey('OCLIF_CLIENT_HOME')
const writeWin32 = async () => {
const {bin} = config
await fs.promises.writeFile(path.join(baseWorkspace, 'bin', `${config.bin}.cmd`), `@echo off
const writeWin32 = async (bin: string) => {
await fs.promises.writeFile(path.join(baseWorkspace, 'bin', `${bin}.cmd`), `@echo off
setlocal enableextensions
if not "%${redirectedEnvVar}%"=="1" if exist "%LOCALAPPDATA%\\${bin}\\client\\bin\\${bin}.cmd" (
Expand All @@ -28,12 +32,6 @@ if exist "%~dp0..\\bin\\node.exe" (
node "%~dp0..\\bin\\run" %*
)
`)
// await qq.write([output, 'bin', config.bin], `#!/bin/sh
// basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
// "$basedir/../client/bin/${config.bin}.cmd" "$@"
// ret=$?
// exit $ret
// `)
}

const writeUnix = async () => {
Expand Down Expand Up @@ -86,5 +84,12 @@ fi
`, {mode: 0o755})
}

await Promise.all([writeWin32(), writeUnix()])
await Promise.all([
writeWin32(config.bin),
writeUnix(),
...config.binAliases?.map(
alias => process.platform === 'win32' ?
writeWin32(alias) :
exec(`ln -sf ${config.bin} ${alias}`, {cwd: path.join(baseWorkspace, 'bin')})) ?? [],
])
}
2 changes: 1 addition & 1 deletion src/tarballs/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ux, Interfaces, Config} from '@oclif/core'
import {Config, Interfaces, ux} from '@oclif/core'

import * as path from 'path'
import * as semver from 'semver'
Expand Down
7 changes: 6 additions & 1 deletion test/integration/deb.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ describe('publish:deb', () => {
await fs.emptyDir(root)
})
afterEach(async () => {
await deleteFolder(bucket, `${basePrefix}/versions/${pjson.version}/`)
if (!process.env.PRESERVE_ARTIFACTS) {
await deleteFolder(bucket, `${basePrefix}/versions/${pjson.version}/`)
}

pjson.version = originalVersion
await fs.writeJSON(pjsonPath, pjson, {spaces: 2})
})
Expand All @@ -45,6 +48,8 @@ describe('publish:deb', () => {
await exec('sudo apt-get update')
await exec('sudo apt-get install -y oclif')
await exec('oclif --version')
// test the binAliases section
expect((await exec('oclif2 --version')).stdout).to.contain(`oclif/${pjson.version} ${target} node-v${pjson.oclif.update.node.version}`)
const {stdout} = await exec('oclif --version')
expect(stdout).to.contain(`oclif/${pjson.version} ${target} node-v${pjson.oclif.update.node.version}`)
})
Expand Down
17 changes: 13 additions & 4 deletions test/integration/macos.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {test} from '@oclif/test'
import {findDistFileSha, developerSalesforceCom, deleteFolder} from '../helpers/helper'
import {expect, test} from '@oclif/test'
import {deleteFolder, developerSalesforceCom, findDistFileSha} from '../helpers/helper'
import * as fs from 'fs-extra'
import * as path from 'path'
import {promisify} from 'node:util'
import {pipeline as pipelineSync} from 'node:stream'
import got from 'got'
import {exec} from 'shelljs'

const pipeline = promisify(pipelineSync)
const pjson = require('../../package.json')
Expand Down Expand Up @@ -32,15 +33,23 @@ describe('publish:macos', () => {
await fs.emptyDir(root)
})
afterEach(async () => {
await deleteFolder(bucket, `${basePrefix}/versions/${pjson.version}/`)
if (!process.env.PRESERVE_ARTIFACTS) {
await deleteFolder(bucket, `${basePrefix}/versions/${pjson.version}/`)
}

pjson.version = originalVersion
await fs.writeJSON(pjsonPath, pjson, {spaces: 2})
})

onlyMacos
.command(['pack:macos'])
.do(async () => {
[pkg, sha] = await findDistFileSha(cwd, 'macos', f => f.endsWith('pkg'))
// install the intel silicon pkg
[pkg, sha] = await findDistFileSha(cwd, 'macos', f => f.endsWith('x64.pkg'))
await exec(`sudo installer -pkg ${path.join(cwd, 'dist', 'macos', pkg)} -target /`)
expect(exec('oclif --version').stdout).to.contain(`oclif/${pjson.version}`)
// tests binAlias
expect(exec('oclif2 --version').stdout).to.contain(`oclif/${pjson.version}`)
})
.command(['upload:macos'])
.it('publishes valid releases', async () => {
Expand Down
19 changes: 11 additions & 8 deletions test/integration/publish.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@ import {pipeline as pipelineSync} from 'node:stream'
import got from 'got'
import {exec as execSync} from 'child_process'
import {hash} from '../../src/util'
import aws from '../../src/aws'
import {deleteFolder, developerSalesforceCom, gitShaSync} from '../helpers/helper'
import {Interfaces} from '@oclif/core'

const exec = promisify(execSync)

const pipeline = promisify(pipelineSync)
import aws from '../../src/aws'
import {
developerSalesforceCom,
gitShaSync,
deleteFolder,
} from '../helpers/helper'
import {Interfaces} from '@oclif/core'

const pjson = require('../../package.json')
const pjsonPath = require.resolve('../../package.json')
Expand Down Expand Up @@ -57,6 +53,10 @@ const manifest = async (path: string, nodeVersion: string) => {

const {stdout} = await exec('./oclif/bin/oclif --version', {cwd: root})
expect(stdout).to.contain(`oclif/${pjson.version} ${target} node-v${nodeVersion}`)

// check alias
const stdout2 = (await exec('./oclif/bin/oclif2 --version', {cwd: root})).stdout
expect(stdout2).to.contain(`oclif/${pjson.version} ${target} node-v${nodeVersion}`)
await fs.promises.rm(join(root, 'oclif'), {recursive: true})
}

Expand All @@ -76,7 +76,10 @@ describe('upload tarballs', async () => {
await fs.emptyDir(root)
})
afterEach(async () => {
await folderCleanup()
if (!process.env.PRESERVE_ARTIFACTS) {
await folderCleanup()
}

pjson.version = originalVersion
await fs.writeJSON(pjsonPath, pjson, {spaces: 2})
})
Expand Down
11 changes: 8 additions & 3 deletions test/integration/win.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ describe('publish:win', () => {
await fs.emptyDir(root)
})
afterEach(async () => {
await deleteFolder(bucket, `${basePrefix}/versions/${pjson.version}/`)
pjson.version = originalVersion
await fs.writeJSON(pjsonPath, pjson, {spaces: 2})
if (!process.env.PRESERVE_ARTIFACTS) {
// set this env var to keep the packed windows CLI in the bucket
// useful for downloading and testing the CLI on windows
await deleteFolder(bucket, `${basePrefix}/versions/${pjson.version}/`)
pjson.version = originalVersion
await fs.writeJSON(pjsonPath, pjson, {spaces: 2})
}
})

skipIfWindows
Expand All @@ -48,6 +52,7 @@ describe('publish:win', () => {
expect(sha).to.be.ok
})
.it('publishes valid releases', async () => {
console.log(`https://${developerSalesforceCom}/${oclifTestingVersionsURI}/${pjson.version}/${sha}/${pkg}`)
await pipeline(
got.stream(`https://${developerSalesforceCom}/${oclifTestingVersionsURI}/${pjson.version}/${sha}/${pkg}`),
fs.createWriteStream(pkg),
Expand Down

0 comments on commit 4d45650

Please sign in to comment.