Socket
Socket
Sign inDemoInstall

ci-scripts

Package Overview
Dependencies
200
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.9.0 to 0.10.0

bin/ci-scripts.js

43

lib/cmd/cmd.js
const exec = require('../effects/exec');
/// `cmd` command allows you to execute any arbitrary command. It allows you
/// to construct command arguments and environment variables using variables
/// provided by [`cross-ci`](https://github.com/streamich/cross-ci). In your
/// `ci.config.js` create a new command definition, say "release":
///
/// ```js
/// module.exports = {
/// cmd: {
/// release: {
/// params: {
/// command: 'python',
/// args: ({PROJECT_NAME}) => ['./release.py', PROJECT_NAME, 'staging'],
/// env: ({PROJECT_NAME, BUILD_VERSION}) => ({
/// DEPLOY_PATH: `builds/${PROJECT_NAME}/${BUILD_VERSION}`
/// })
/// },
/// }
/// }
/// };
/// ```
///
/// Now you can execute this command.
///
/// ```
/// ci cmd release
/// ```
///
/// Or only print what will this command do, without executing.
///
/// ```
/// ci cmd release --plan
/// ```
const cmd = async (ci) => {
/// ### Parameters
///
/// - `--command` — command to execute.
/// - `--args` — array of arguments to supply to command.
/// - `--env` — a map of environemnt variables to add to the command.
/// - `--shell` — boolean, specifying whether to execute command in console.
/// - `--cwd` — current working directory, defaults to `process.cwd()`.
const {params} = ci;

@@ -36,7 +75,5 @@

const result = await exec(ci, opts);
return result;
await exec(ci, opts);
};
module.exports = cmd;

@@ -72,2 +72,5 @@ /* eslint-disable filenames/match-exported */

/// > Build version: __`x.y.z-pr-1.1`__
///
/// You can also add extra text arount the default text message using
/// the `--beforeText` and `--afterText` params.
let {text} = params;

@@ -79,2 +82,10 @@

if (params.beforeText) {
text = params.beforeText + '\n\n' + text;
}
if (params.afterText) {
text = text + '\n\n' + params.afterText;
}
const body = {

@@ -81,0 +92,0 @@ body: text,

14

lib/cmd/s3-upload.js

@@ -19,9 +19,9 @@ /* eslint-disable filenames/match-exported */

/// - `accessKeyId` — optional, AWS access key id.
/// - `secretAccessKey` — optional, AWS secrekt key.
/// - `src` — optional, source folder to upload, defaults to `dist/`.
/// - `bucket` — required, S3 bucket name.
/// - `dest` — optional, S3 destination path, defaults to '""'.
/// - `acl` — optional, access rights to all uploaded objects.
/// - `delete` — optional, whether to delete old files on S3, defaults to `false`.
/// - `--accessKeyId` — optional, AWS access key id.
/// - `--secretAccessKey` — optional, AWS secrekt key.
/// - `--src` — optional, source folder to upload, defaults to `dist/`.
/// - `--bucket` — required, S3 bucket name.
/// - `--dest` — optional, S3 destination path, defaults to '""'.
/// - `--acl` — optional, access rights to all uploaded objects.
/// - `--delete` — optional, whether to delete old files on S3, defaults to `false`.
const config = {

@@ -28,0 +28,0 @@ accessKeyId: params.accessKeyId,

@@ -64,2 +64,4 @@ /* eslint-disable complexity */

/// ```
///
/// You can also specify extra text messages using `--beforeText` and `--afterText` params.
text: params.text || defaultMessage(ci),

@@ -80,2 +82,10 @@

if (params.beforeText) {
body.text = params.beforeText + '\n\n' + body.text;
}
if (params.afterText) {
body.text = body.text + '\n\n' + params.afterText;
}
if (params.icon_url) {

@@ -82,0 +92,0 @@ /// Specify sender icon URL using `--icon_url` param.

@@ -35,8 +35,21 @@ const {spawnSync} = require('child_process');

return;
return undefined;
}
spawnSync(command, args, options);
const result = spawnSync(command, args, options);
if (result.error && ci.params.verbose) {
throw result.error;
}
if (result.status) {
// eslint-disable-next-line no-process-exit
process.exit(result.status);
} else if (result.error) {
throw result.error;
}
return result;
};
module.exports = exec;

@@ -10,2 +10,4 @@ const chalk = require('chalk');

/* eslint-enable no-console */
return;
}

@@ -12,0 +14,0 @@

@@ -26,2 +26,6 @@ /* eslint-disable no-console */

/* eslint-disable no-param-reassign */
if (typeof commands === 'string') {
commands = [commands];
}
if (params.version || params.v) {

@@ -52,16 +56,7 @@ commands = ['version'];

try {
const result = await fn(ci);
const result = await fn(ci);
return result;
} catch (error) {
// eslint-disable-next-line no-console
console.log(error);
// eslint-disable-next-line no-process-exit
process.exit(1);
}
return undefined;
return result;
};
module.exports = exec;
{
"name": "ci-scripts",
"version": "0.9.0",
"version": "0.10.0",
"bin": {

@@ -5,0 +5,0 @@ "ci": "./bin/ci.js"

@@ -45,2 +45,3 @@ # ci-scripts

- [`cmd`](#ci-cmd-script)
- [`echo`](#ci-echo-script)

@@ -72,2 +73,50 @@ - [`github-post`](#ci-github-post-script)

### `ci cmd` Script
`cmd` command allows you to execute any arbitrary command. It allows you
to construct command arguments and environment variables using variables
provided by [`cross-ci`](https://github.com/streamich/cross-ci). In your
`ci.config.js` create a new command definition, say "release":
```js
module.exports = {
cmd: {
release: {
params: {
command: 'python',
args: ({PROJECT_NAME}) => ['./release.py', PROJECT_NAME, 'staging'],
env: ({PROJECT_NAME, BUILD_VERSION}) => ({
DEPLOY_PATH: `builds/${PROJECT_NAME}/${BUILD_VERSION}`
})
},
}
}
};
```
Now you can execute this command.
```
ci cmd release
```
Or only print what will this command do, without executing.
```
ci cmd release --plan
```
### Parameters
- `--command` — command to execute.
- `--args` — array of arguments to supply to command.
- `--env` — a map of environemnt variables to add to the command.
- `--shell` — boolean, specifying whether to execute command in console.
- `--cwd` — current working directory, defaults to `process.cwd()`.
### `ci echo` Script

@@ -134,5 +183,8 @@

You can also add extra text arount the default text message using
the `--beforeText` and `--afterText` params.
### `ci github-upload` Script

@@ -176,9 +228,9 @@

- `accessKeyId` — optional, AWS access key id.
- `secretAccessKey` — optional, AWS secrekt key.
- `src` — optional, source folder to upload, defaults to `dist/`.
- `bucket` — required, S3 bucket name.
- `dest` — optional, S3 destination path, defaults to '""'.
- `acl` — optional, access rights to all uploaded objects.
- `delete` — optional, whether to delete old files on S3, defaults to `false`.
- `--accessKeyId` — optional, AWS access key id.
- `--secretAccessKey` — optional, AWS secrekt key.
- `--src` — optional, source folder to upload, defaults to `dist/`.
- `--bucket` — required, S3 bucket name.
- `--dest` — optional, S3 destination path, defaults to '""'.
- `--acl` — optional, access rights to all uploaded objects.
- `--delete` — optional, whether to delete old files on S3, defaults to `false`.

@@ -216,3 +268,5 @@

You can also specify extra text messages using `--beforeText` and `--afterText` params.
Use `--username` param to overwrite sender's display name, defaults to `ci-scripts`.

@@ -219,0 +273,0 @@

@@ -5,2 +5,3 @@ const log = require('../../lib/effects/log');

const createCi = require('../../lib/createCi');
const executeCommand = require('../../lib/exec');

@@ -78,2 +79,45 @@ jest.mock('../../lib/effects/log');

});
test('can specify text', async () => {
await executeCommand(['github-post'], {
token: '123',
text: 'foo'
});
expect(request).toHaveBeenCalledTimes(1);
const config = request.mock.calls[0][1];
const text = config.body.body;
expect(text).toBe('foo');
});
test('can specify extra text', async () => {
await executeCommand(['github-post'], {
token: '123',
beforeText: 'bar',
text: 'foo',
afterText: 'baz',
});
expect(request).toHaveBeenCalledTimes(1);
const config = request.mock.calls[0][1];
const text = config.body.body;
expect(text).toBe('bar\n\nfoo\n\nbaz');
});
test('specify extra text as function', async () => {
await executeCommand(['github-post'], {
token: '123',
text: 'foo',
afterText: ({PROJECT_NAME}) => PROJECT_NAME,
});
const config = request.mock.calls[0][1];
const text = config.body.body;
expect(text).toBe('foo\n\nci-scripts');
});
});

@@ -6,2 +6,3 @@ const slack = require('../../lib/cmd/slack');

const exec = require('../..').exec;
const executeCommand = require('../../lib/exec');

@@ -69,2 +70,34 @@ jest.mock('../../lib/effects/log');

});
test('can set before, after, and main text', async () => {
await executeCommand(['slack'], {
webhook,
beforeText: 'foo',
text: 'bar',
afterText: 'baz',
});
expect(request).toHaveBeenCalledTimes(1);
const config = request.mock.calls[0][1];
const text = config.body.text;
expect(text).toBe('foo\n\nbar\n\nbaz');
});
test('text can be a function', async () => {
await executeCommand(['slack'], {
webhook,
beforeText: 'foo',
text: ci => ci.PROJECT_NAME,
afterText: 'baz',
});
expect(request).toHaveBeenCalledTimes(1);
const config = request.mock.calls[0][1];
const text = config.body.text;
expect(text).toBe('foo\n\nci-scripts\n\nbaz');
});
});

@@ -6,2 +6,4 @@ const {spawnSync} = require('child_process');

spawnSync.mockImplementation(() => ({}));
describe('exec effect', () => {

@@ -8,0 +10,0 @@ test('exists', () => {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc