Skip to content

Commit

Permalink
Merge branch 'main' of github.com:HubSpot/hubspot-cli into jy/hs-proj…
Browse files Browse the repository at this point in the history
…ects-logs-fix
  • Loading branch information
joe-yeager committed Aug 28, 2024
2 parents f88732c + c44c609 commit 2b6f7c6
Show file tree
Hide file tree
Showing 27 changed files with 516 additions and 261 deletions.
22 changes: 12 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
on: [push]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Build Failure Slack Report
if: ${{ github.ref == 'refs/heads/main' }}
uses: ravsamhq/notify-slack-action@master
with:
status: ${{ job.status }}
notify_when: 'failure'
env:
SLACK_WEBHOOK_URL: ${{ secrets.ACTION_MONITORING_SLACK }}
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v2
Expand Down Expand Up @@ -47,3 +37,15 @@ jobs:
env:
PORTAL_ID: ${{ secrets.ACCEPTANCE_TEST_PORTAL_ID }}
PERSONAL_ACCESS_KEY: ${{ secrets.ACCEPTANCE_TEST_PERSONAL_ACCESS_KEY }}
- name: Build Failure Slack Report
uses: ravsamhq/notify-slack-action@v2
if: ${{ always() && github.ref_name == 'main' }}
with:
status: ${{ job.status }}
notify_when: 'failure'
mention_groups: 'S07FLKPAPAS'
notification_title: 'CLI build failure'
message_format: '{emoji} *Build* {status_message} in <{repo_url}|{repo}> on <{commit_url}|{commit_sha}>'
footer: '<{run_url}|View Run>'
env:
SLACK_WEBHOOK_URL: ${{ secrets.ACTION_MONITORING_SLACK }}
41 changes: 41 additions & 0 deletions .github/workflows/latestPublish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
on:
workflow_dispatch:
push:
tags:
- '*'
# Scheduled jobs will only run on the default branch
schedule:
- cron: '0 */5 * * *' # Run every 5 hours
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# Sleep when triggered by new tag to wait for npm publish
- name: Sleep For 3 Mins
run: sleep 180s
shell: bash
- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: 16.x
- name: Install Deps
run: npm install
- name: Test Latest CLI Release
run: |
npm run test-cli --cliVersion="latest"
env:
PORTAL_ID: ${{ secrets.ACCEPTANCE_TEST_PORTAL_ID }}
PERSONAL_ACCESS_KEY: ${{ secrets.ACCEPTANCE_TEST_PERSONAL_ACCESS_KEY }}
- name: Release Failure Slack Report
uses: ravsamhq/notify-slack-action@v2
if: ${{ always() && github.ref_name == 'main' }}
with:
status: ${{ job.status }}
notify_when: 'failure'
mention_groups: 'S07FLKPAPAS'
notification_title: 'CLI latest release failure'
message_format: '{emoji} *NPM Release* {status_message}'
footer: '<{run_url}|View Run> | <https://www.npmjs.com/package/@hubspot/cli?activeTab=versions|View in NPM>'
env:
SLACK_WEBHOOK_URL: ${{ secrets.ACTION_MONITORING_SLACK }}
10 changes: 9 additions & 1 deletion acceptance-tests/lib/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const getEnvValue = envVariable => {
const setArgsOverrides = args => {
args.portalId && (argsOverrides.portalId = args.portalId);
args.cliPath && (argsOverrides.cliPath = args.cliPath);
args.cliVersion && (argsOverrides.cliVersion = args.cliVersion);
args.personalAccessKey &&
(argsOverrides.personalAccessKey = args.personalAccessKey);
argsOverrides.qa = args.qa;
Expand All @@ -45,6 +46,7 @@ const envOverrides = getTruthyValuesOnly({
portalId: getEnvValue('PORTAL_ID') || getEnvValue('ACCOUNT_ID'),
cliPath: getEnvValue('CLI_PATH'),
personalAccessKey: getEnvValue('PERSONAL_ACCESS_KEY'),
cliVersion: getEnvValue('CLI_VERSION'),
});

const getTestConfig = () => {
Expand All @@ -57,7 +59,13 @@ const getTestConfig = () => {
);
}

if (!config.cliPath) {
if (config.cliPath && config.cliVersion) {
throw new Error(
'You cannot specify both a cliPath and a cliVersion. Remove one and try again.'
);
}

if (!config.cliPath && !config.cliVersion) {
const defaultPath = path.join(process.cwd(), DEFAULT_CLI_PATH);

if (existsSync(defaultPath)) {
Expand Down
2 changes: 1 addition & 1 deletion acceptance-tests/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "acceptance-tests",
"version": "5.2.1-beta.12",
"version": "5.4.0",
"description": "Acceptance tests for cli",
"private": true,
"homepage": "https://github.com/HubSpot/hubspot-cli#readme",
Expand Down
12 changes: 8 additions & 4 deletions acceptance-tests/run-tests
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ setArgsOverrides(
.option('accountId', {
alias: ['p', 'portalId', 'a'],
type: 'string',
description: 'Account ID',
description: 'The account ID to use',
})
.option('cliPath', {
alias: 'c',
type: 'string',
description: 'CLI path',
description: 'The path to the CLI',
})
.option('cliVersion', {
type: "string",
description: "The npm version to use. The test will use npx to download and run the CLI."
})
.option('personalAccessKey', {
alias: 'pak',
Expand All @@ -33,7 +37,7 @@ setArgsOverrides(
.option('qa', {
type: 'boolean',
default: false,
description: 'Set this if you are using a app.hubspotqa.com site',
description: 'Set this if you are using an app.hubspotqa.com account',
})
.option('headless', {
type: 'boolean',
Expand All @@ -55,7 +59,7 @@ setArgsOverrides(
testRunner.addReporter(reporter);

global.config = getTestConfig();
global.cli = cmd.createCli(global.config.cliPath);
global.cli = cmd.createCli(global.config.cliPath, global.config.cliVersion);

await global.cli.execute(
['init', `--c="${CONFIG_FILE_NAME}"`],
Expand Down
40 changes: 28 additions & 12 deletions acceptance-tests/tests/helpers/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,31 @@ const PATH = process.env.PATH;

/**
* Creates a child process with script path
* @param {string} processPath Path of the process to execute
* @param {string} cliPath Path of the CLI process to execute
* @param {string} cliVersion NPM Version number
* @param {Array} args Arguments to the command
* @param {Object} env (optional) Environment variables
*/
function createProcess(processPath, args = [], env = null) {
// Ensure that path exists
if (!processPath || !existsSync(processPath)) {
throw new Error('Invalid process path');
}
function createProcess(cliPath, cliVersion, args = [], env = null) {
let processCommand;

args = [processPath].concat(args);
if (cliVersion) {
processCommand = 'npx';
args = ['--yes', '--package', `@hubspot/cli@${cliVersion}`, 'hs'].concat(
args
);
} else {
// Ensure that path exists
if (!cliPath || !existsSync(cliPath)) {
throw new Error(`Invalid process path ${cliPath}`);
}
processCommand = 'node';
args = [cliPath].concat(args);
}

// This works for node based CLIs, but can easily be adjusted to
// any other process installed in the system
return spawn('node', args, {
return spawn(processCommand, args, {
env: Object.assign(
{
NODE_ENV: 'test',
Expand All @@ -48,7 +58,13 @@ function createProcess(processPath, args = [], env = null) {
* @param {Array} inputs (Optional) Array of inputs (user responses)
* @param {Object} opts (optional) Environment variables
*/
function executeWithInput(processPath, args = [], inputs = [], opts = {}) {
function executeWithInput(
cliPath,
cliVersion,
args = [],
inputs = [],
opts = {}
) {
if (!Array.isArray(inputs)) {
opts = inputs;
inputs = [];
Expand All @@ -59,7 +75,7 @@ function executeWithInput(processPath, args = [], inputs = [], opts = {}) {
}

const { env = opts.env, timeout = 500, maxTimeout = 10000 } = opts;
const childProcess = createProcess(processPath, args, env);
const childProcess = createProcess(cliPath, cliVersion, args, env);
childProcess.stdin.setEncoding('utf-8');

let currentInputTimeout, killIOTimeout;
Expand Down Expand Up @@ -171,8 +187,8 @@ function executeWithInput(processPath, args = [], inputs = [], opts = {}) {

module.exports = {
createProcess,
createCli: processPath => ({
execute: (...args) => executeWithInput(processPath, ...args),
createCli: (cliPath, cliVersion) => ({
execute: (...args) => executeWithInput(cliPath, cliVersion, ...args),
}),
DOWN: '\x1B\x5B\x42',
UP: '\x1B\x5B\x41',
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"npmClient": "yarn",
"useWorkspaces": true,
"packages": ["packages/*", "acceptance-tests"],
"version": "5.2.1-beta.13"
"version": "5.4.0"
}
29 changes: 24 additions & 5 deletions packages/cli/bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const {
const { getIsInProject } = require('../lib/projects');
const pkg = require('../package.json');
const { i18n } = require('../lib/lang');
const { EXIT_CODES } = require('../lib/enums/exitCodes');
const { UI_COLORS, uiCommandReference } = require('../lib/ui');

const removeCommand = require('../commands/remove');
const initCommand = require('../commands/init');
Expand All @@ -41,7 +43,6 @@ const accountsCommand = require('../commands/accounts');
const sandboxesCommand = require('../commands/sandbox');
const cmsCommand = require('../commands/cms');
const feedbackCommand = require('../commands/feedback');
const { EXIT_CODES } = require('../lib/enums/exitCodes');

const notifier = updateNotifier({
pkg: { ...pkg, name: '@hubspot/cli' },
Expand All @@ -51,12 +52,30 @@ const notifier = updateNotifier({

const i18nKey = 'commands.generalErrors';

const CLI_UPGRADE_MESSAGE =
chalk.bold('The CMS CLI is now the HubSpot CLI') +
'\n\nTo upgrade, run:\n\nnpm uninstall -g @hubspot/cms-cli\nand npm install -g @hubspot/cli';
const CMS_CLI_PACKAGE_NAME = '@hubspot/cms-cli';

notifier.notify({
message: pkg.name === '@hubspot/cms-cli' ? CLI_UPGRADE_MESSAGE : null,
message:
pkg.name === CMS_CLI_PACKAGE_NAME
? i18n(`${i18nKey}.updateNotify.cmsUpdateNotification`, {
packageName: CMS_CLI_PACKAGE_NAME,
updateCommand: uiCommandReference('{updateCommand}'),
})
: i18n(`${i18nKey}.updateNotify.cliUpdateNotification`, {
updateCommand: uiCommandReference('{updateCommand}'),
}),
defer: false,
boxenOptions: {
borderColor: UI_COLORS.MARIGOLD_DARK,
margin: 1,
padding: 1,
textAlignment: 'center',
borderStyle: 'round',
title:
pkg.name === CMS_CLI_PACKAGE_NAME
? null
: chalk.bold(i18n(`${i18nKey}.updateNotify.notifyTitle`)),
},
});

const getTerminalWidth = () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/bin/hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env node --no-deprecation
#!/usr/bin/env node

require('./cli');
20 changes: 13 additions & 7 deletions packages/cli/commands/cms/convertFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const {

const { trackConvertFieldsUsage } = require('../../lib/usageTracking');
const { logErrorInstance } = require('../../lib/errorHandlers/standardErrors');
const { EXIT_CODES } = require('../../lib/enums/exitCodes');
const i18nKey = 'commands.convertFields';

exports.command = 'convert-fields';
Expand All @@ -24,23 +25,27 @@ const invalidPath = src => {
path: src,
})
);
process.exit(EXIT_CODES.ERROR);
};

exports.handler = async options => {
const src = path.resolve(getCwd(), options.src);
const themeJSONPath = getThemeJSONPath(src);
const projectRoot = themeJSONPath
? path.dirname(themeJSONPath)
: path.dirname(getCwd());
let stats;
let projectRoot;
let src;

try {
src = path.resolve(getCwd(), options.src);
const themeJSONPath = getThemeJSONPath(options.src);
projectRoot = themeJSONPath
? path.dirname(themeJSONPath)
: path.dirname(getCwd());
stats = fs.statSync(src);
if (!stats.isFile() && !stats.isDirectory()) {
invalidPath(src);
invalidPath(options.src);
return;
}
} catch (e) {
invalidPath(src);
invalidPath(options.src);
}

trackConvertFieldsUsage('process');
Expand Down Expand Up @@ -88,6 +93,7 @@ exports.builder = yargs => {
yargs.option('src', {
describe: i18n(`${i18nKey}.positionals.src.describe`),
type: 'string',
demandOption: i18n(`${i18nKey}.errors.missingSrc`),
});
yargs.option('fieldOptions', {
describe: i18n(`${i18nKey}.options.options.describe`),
Expand Down
Loading

0 comments on commit 2b6f7c6

Please sign in to comment.