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

Commit

Permalink
Merge 14e8ccf into 8cfa0f1
Browse files Browse the repository at this point in the history
  • Loading branch information
Alorel committed Jul 10, 2019
2 parents 8cfa0f1 + 14e8ccf commit ed4d7f7
Show file tree
Hide file tree
Showing 10 changed files with 683 additions and 649 deletions.
19 changes: 0 additions & 19 deletions .alobuild-prep-release.sh

This file was deleted.

5 changes: 1 addition & 4 deletions .travis.yml
Expand Up @@ -6,7 +6,6 @@ node_js:

before_install:
- npm i -g yarn greenkeeper-lockfile
- &prepKey if [[ $GH_TOKEN ]]; then ./.alobuild-prep-release.sh; fi;
- greenkeeper-lockfile-update

install: yarn install --check-files --ignore-engines
Expand All @@ -33,9 +32,7 @@ jobs:
include:
- stage: Release
node_js: stable
before_install:
- npm i -g yarn
- *prepKey
before_install: npm i -g yarn
before_script:
- yarn run build
- ls dist -l
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -49,7 +49,7 @@
"rollup-plugin-typescript2": "^0.21.0",
"tmp": "~0.1.0",
"tslib": "^1.9.0",
"tslint": "~5.16.0",
"tslint": "~5.18.0",
"typescript": "^3.4.5",
"uglify-es": "~3.3.9",
"yamljs": "^0.3.0",
Expand Down
2 changes: 1 addition & 1 deletion src/commons/addPkgMgr.ts
Expand Up @@ -13,7 +13,7 @@ function getDef(): Options {
}

export function addPkgMgrToOptions<T extends Obj<Options>>(opts: T): T {
opts[NAME] = getDef();
(<any>opts)[NAME] = getDef();

return opts;
}
25 changes: 0 additions & 25 deletions src/commons/travisRelease.ts
Expand Up @@ -10,14 +10,6 @@ export enum TravisEndpoint {
export interface HasTravisRelease {
ghEmail: string;

gpgKeyId: string;

gpgKeyPwd: string;

gpgPrivkey: string;

gpgPubkey: string;

releaseGhToken: string;

releaseNpmToken: string;
Expand All @@ -32,28 +24,11 @@ export interface HasTravisRelease {
}

export function addTravisRelease(opts: Obj<Options> = {}): Obj<Options> {
const gpg = ' for the GPG key used for signing release commits.';
const assigned: Obj<Options> = {
'gh-email': {
describe: 'Your GitHub email',
type: 'string'
},
'gpg-key-id': {
describe: `Key ID${gpg}`,
type: 'string'
},
'gpg-key-pwd': {
describe: `Password${gpg}`,
type: 'string'
},
'gpg-privkey': {
describe: `Private key contents${gpg}`,
type: 'string'
},
'gpg-pubkey': {
describe: `Public key contents${gpg}`,
type: 'string'
},
'release-gh-token': {
describe: 'GitHub token for making releases. This should differ from the gh-token parameter and be local to '
+ 'this repo.',
Expand Down
32 changes: 6 additions & 26 deletions src/lib/PromptableConfig.ts
Expand Up @@ -129,7 +129,7 @@ export class PromptableConfig<T extends { [k: string]: any }> {
return this.get<any>(prop);
} else if (!IS_CI && this.ghRepoFromMetadata) {
if (rl.keyInYNStrict(`Is your GitHub repo ${Colour.cyan(this.ghRepoFromMetadata)}? `)) {
this.data[prop] = this.ghRepoFromMetadata;
(<any>this.data)[prop] = this.ghRepoFromMetadata;

return this.ghRepoFromMetadata;
} else {
Expand All @@ -156,7 +156,7 @@ export class PromptableConfig<T extends { [k: string]: any }> {
return this.get<any>(prop);
} else if (!IS_CI && this.ghUserFromMetadata) {
if (rl.keyInYNStrict(`Is your GitHub username ${Colour.cyan(this.ghUserFromMetadata)}? `)) {
this.data[prop] = this.ghUserFromMetadata;
(<any>this.data)[prop] = this.ghUserFromMetadata;

return this.ghUserFromMetadata;
} else {
Expand All @@ -167,33 +167,13 @@ export class PromptableConfig<T extends { [k: string]: any }> {
return this.getPrompt(prop, `${msg}? `);
}

@Memo
public promptedGpgKeyId(prop = 'gpgKeyId'): string {
return this.getPromptHidden(prop, 'What\'s GPG key ID? ');
}

@Memo
public promptedGpgKeyPwd(prop = 'gpgKeyPwd'): string {
return this.getPromptHidden(prop, 'What\'s GPG key password? ');
}

@Memo
public promptedGpgPrivkey(prop = 'gpgPrivkey'): string {
return this.getPromptHidden(prop, 'Paste your GPG private key contents: ');
}

@Memo
public promptedGpgPubkey(prop = 'gpgPubkey'): string {
return this.getPrompt(prop, 'Paste your GPG public key contents: ');
}

@Memo
public promptedLicense(prop = 'license'): License {
let pjson: null | PackageJson;
if (this.has(prop)) {
return this.get(prop);
} else if ((pjson = readJson()) && isLicense(pjson.license)) {
this.data[prop] = pjson.license;
(<any>this.data)[prop] = pjson.license;

return pjson.license;
}
Expand Down Expand Up @@ -233,7 +213,7 @@ export class PromptableConfig<T extends { [k: string]: any }> {
const ghProjRemote = getGhRepoData(tok, user, repo);

if (ghProjRemote && ghProjRemote.description) {
this.data[prop] = ghProjRemote.description;
(<any>this.data)[prop] = ghProjRemote.description;

return this.data[prop];
}
Expand All @@ -254,11 +234,11 @@ export class PromptableConfig<T extends { [k: string]: any }> {
if (this.has(prop)) {
return this.get(prop);
} else if (this.ghRepoFromMetadata && ask(this.ghRepoFromMetadata)) {
this.data[prop] = this.ghRepoFromMetadata;
(<any>this.data)[prop] = this.ghRepoFromMetadata;

return this.ghRepoFromMetadata;
} else if (ask((dir = lastDirname()))) {
this.data[prop] = dir;
(<any>this.data)[prop] = dir;

return dir;
} else {
Expand Down
19 changes: 0 additions & 19 deletions src/lib/init/01_travis_release.ts
@@ -1,21 +1,12 @@
import * as fs from 'fs-extra';
import {forEach} from 'lodash';
import {EOL} from 'os';
import {addGhRepo, addGhUser} from '../../commons/identity';
import {addTravisRelease, TravisEndpoint} from '../../commons/travisRelease';
import {Chmod} from '../../const/Chmod';
import {InitConf} from '../../interfaces/InitConf';
import {Base64} from '../Base64';
import {Fixture} from '../Fixture';
import {Git} from '../Git';
import {Log} from '../Log';
import {PromptableConfig} from '../PromptableConfig';
import {BaseArgs, envVarExists, setEnvVar, setStdSettings} from '../sync-request/travis/travis';

export const enum TravisReleaseInitConf {
PREP_FILE = '.alobuild-prep-release.sh'
}

export const options = addTravisRelease();
addGhRepo(options);
addGhUser(options);
Expand All @@ -40,10 +31,6 @@ export function handle(c: PromptableConfig<InitConf>): void {

setStdSettings(ort);
const envVarsToSet: { [k: string]: () => string } = {
BUILD_GPG_KEY_ID: () => c.promptedGpgKeyId(),
BUILD_GPG_KEY_PWD: () => c.promptedGpgKeyPwd(),
BUILD_GPG_PRIV_KEY: () => Base64.encodeString(c.promptedGpgPrivkey()),
BUILD_GPG_PUB_KEY: () => Base64.encodeString(c.promptedGpgPubkey()),
GH_TOKEN: () => c.promptedReleaseGhToken(),
GIT_COMMITTER_EMAIL: () => c.promptedGhEmail(),
GIT_COMMITTER_NAME: () => c.promptedName(),
Expand All @@ -61,12 +48,6 @@ export function handle(c: PromptableConfig<InitConf>): void {
}
});

if (!fs.existsSync(TravisReleaseInitConf.PREP_FILE)) {
const fx = new Fixture('init');
fx.copy(TravisReleaseInitConf.PREP_FILE, TravisReleaseInitConf.PREP_FILE, Chmod.C_755);
Git.add(TravisReleaseInitConf.PREP_FILE);
}

Log.success('Set up Travis release');
} catch (e) {
process.stderr.write(<string>(e.stack || e.message || e.toString()) + EOL + EOL);
Expand Down
30 changes: 18 additions & 12 deletions src/lib/init/01_travis_yml.ts
Expand Up @@ -8,7 +8,6 @@ import {ObjectWriter, ObjectWriterFormat} from '../ObjectWriter';
import {PromptableConfig} from '../PromptableConfig';

const enum Conf {
PREP_KEY = 'if [[ $GH_TOKEN ]]; then ./.alobuild-prep-release.sh; fi;',
TRAVIS_YML = '.travis.yml'
}

Expand All @@ -27,16 +26,10 @@ export function handle(c: PromptableConfig<InitConf>) {
w.set('language', 'node_js');
w.set('node_js', TRAVIS_NODE_VERSIONS);

const beforeInstall: string[] = [];
if (isYarn) {
beforeInstall.push('npm i -g yarn greenkeeper-lockfile');
} else {
beforeInstall.push('npm i -g greenkeeper-lockfile');
}
beforeInstall.push(
Conf.PREP_KEY,
const beforeInstall: string[] = [
isYarn ? 'npm i -g yarn greenkeeper-lockfile' : 'npm i -g greenkeeper-lockfile',
'greenkeeper-lockfile-update'
);
];

w.set('before_install', beforeInstall);
w.set('install', isYarn ? 'yarn install --check-files' : 'npm install');
Expand All @@ -59,7 +52,7 @@ export function handle(c: PromptableConfig<InitConf>) {

if (!shouldSkipRelease) {
Log.info('Generating release info @ .travis.yml');
const bfi: string[] = [Conf.PREP_KEY];
const bfi: string[] = [];
if (isYarn) {
bfi.unshift('npm i -g yarn');
}
Expand All @@ -72,10 +65,23 @@ export function handle(c: PromptableConfig<InitConf>) {
if: 'branch = master AND type = push AND (NOT tag IS present)'
}
]);
let finalReleaseBeforeInstall: string | string[];

switch (bfi.length) {
case 0:
finalReleaseBeforeInstall = [];
break;
case 1:
finalReleaseBeforeInstall = bfi[0];
break;
default:
finalReleaseBeforeInstall = bfi;
}

w.set('jobs.include', [{
stage: 'Release',
node_js: 'stable',
before_install: bfi,
before_install: finalReleaseBeforeInstall,
before_script: [
`${c.promptedPkgMgr()} run build`,
'alo copy-files'
Expand Down
12 changes: 2 additions & 10 deletions test/commands/init.ts
Expand Up @@ -350,7 +350,6 @@ generateNotes:
describe('.travis.yml', () => {
//tslint:disable:object-literal-sort-keys
let contents: { [k: string]: any };
const prepKey = 'if [[ $GH_TOKEN ]]; then ./.alobuild-prep-release.sh; fi;';

function withPkgMgrNpm(args: string[] = baseArgs): string[] {
const copy = args.slice(0);
Expand All @@ -367,7 +366,6 @@ generateNotes:
node_js: TRAVIS_NODE_VERSIONS,
before_install: [
'npm i -g greenkeeper-lockfile',
prepKey,
'greenkeeper-lockfile-update'
],
install: 'npm install',
Expand Down Expand Up @@ -395,7 +393,6 @@ generateNotes:
node_js: TRAVIS_NODE_VERSIONS,
before_install: [
'npm i -g yarn greenkeeper-lockfile',
prepKey,
'greenkeeper-lockfile-update'
],
install: 'yarn install --check-files',
Expand Down Expand Up @@ -468,10 +465,7 @@ generateNotes:
include: [{
stage: 'Release',
node_js: 'stable',
before_install: [
'npm i -g yarn',
prepKey
],
before_install: 'npm i -g yarn',
before_script: [
'yarn run build',
'alo copy-files'
Expand Down Expand Up @@ -504,9 +498,7 @@ generateNotes:
include: [{
stage: 'Release',
node_js: 'stable',
before_install: [
prepKey
],
before_install: [],
before_script: [
'npm run build',
'alo copy-files'
Expand Down

0 comments on commit ed4d7f7

Please sign in to comment.