Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/cli-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Global options:
-v, --verbose Log everything
-q, --quiet Log errors only
-s, --silent Log nothing
-l, --labels <string> Associates labels to the build (ex: --labels=dev,prod )
Comment thread
bhokaremoin marked this conversation as resolved.
-h, --help Display command help
```
<!-- commandsstop -->
144 changes: 134 additions & 10 deletions packages/cli-build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Commands for interacting with Percy builds
* [`percy build:finalize`](#percy-buildfinalize)
* [`percy build:wait`](#percy-buildwait)
* [`percy build:id`](#percy-buildid)
* [`percy build:approve`](#percy-buildapprove)
* [`percy build:unapprove`](#percy-buildunapprove)
* [`percy build:reject`](#percy-buildreject)
* [`percy build:delete`](#percy-builddelete)

### `percy build:finalize`

Expand All @@ -17,10 +21,11 @@ Usage:
$ percy build:finalize [options]

Global options:
-v, --verbose Log everything
-q, --quiet Log errors only
-s, --silent Log nothing
-h, --help Display command help
-v, --verbose Log everything
-q, --quiet Log errors only
-s, --silent Log nothing
-l, --labels <string> Associates labels to the build (ex: --labels=dev,prod )
-h, --help Display command help
```

### `percy build:wait`
Expand All @@ -38,12 +43,14 @@ Options:
-t, --timeout <ms> Timeout before exiting without updates, defaults to 10 minutes
-i, --interval <ms> Interval at which to poll for updates, defaults to 10 second
-f, --fail-on-changes Exit with an error when diffs are found
--pass-if-approved Doesn't Exit with an error if the build is approved, requires '--fail-on-changes'
--pass-if-approved Doesn't exit with an error if the build is approved, regardless of if
diffs are found.

Global options:
-v, --verbose Log everything
-q, --quiet Log errors only
-s, --silent Log nothing
-l, --labels <string> Associates labels to the build (ex: --labels=dev,prod )
-h, --help Display command help

Examples:
Expand All @@ -60,12 +67,129 @@ Usage:
$ percy build:id [options]

Percy options:
-P, --port [number] Local CLI server port (default: 5338)
-P, --port [number] Local CLI server port (default: 5338)

Global options:
-v, --verbose Log everything
-q, --quiet Log errors only
-s, --silent Log nothing
-l, --labels <string> Associates labels to the build (ex: --labels=dev,prod )
-h, --help Display command help
```

### `percy build:approve`

Approve Percy builds

```
Usage:
$ percy build:approve [options] <build-id>

Arguments:
build-id Build ID to approve

Options:
--username <string> Username for authentication (can also be set via BROWSERSTACK_USERNAME env
var)
--access-key <string> Access key for authentication (can also be set via BROWSERSTACK_ACCESS_KEY
env var)

Global options:
-v, --verbose Log everything
-q, --quiet Log errors only
-s, --silent Log nothing
-l, --labels <string> Associates labels to the build (ex: --labels=dev,prod )
-h, --help Display command help

Examples:
$ percy build:approve <build-id>
$ percy build:approve <build-id> --username username --access-key **key**
```

### `percy build:unapprove`

Unapprove Percy builds

```
Usage:
$ percy build:unapprove [options] <build-id>

Arguments:
build-id Build ID to approve

Options:
--username <string> Username for authentication (can also be set via BROWSERSTACK_USERNAME env
var)
--access-key <string> Access key for authentication (can also be set via BROWSERSTACK_ACCESS_KEY
env var)

Global options:
-v, --verbose Log everything
-q, --quiet Log errors only
-s, --silent Log nothing
-l, --labels <string> Associates labels to the build (ex: --labels=dev,prod )
-h, --help Display command help

Examples:
$ percy build:unapprove <build-id>
$ percy build:unapprove <build-id> --username username --access-key **key**
```

### `percy build:reject`

Reject Percy builds

```
Usage:
$ percy build:reject [options] <build-id>

Arguments:
build-id Build ID to approve

Options:
--username <string> Username for authentication (can also be set via BROWSERSTACK_USERNAME env
var)
--access-key <string> Access key for authentication (can also be set via BROWSERSTACK_ACCESS_KEY
env var)

Global options:
-v, --verbose Log everything
-q, --quiet Log errors only
-s, --silent Log nothing
-l, --labels <string> Associates labels to the build (ex: --labels=dev,prod )
-h, --help Display command help

Examples:
$ percy build:reject <build-id>
$ percy build:reject <build-id> --username username --access-key **key**
```

### `percy build:delete`

Delete Percy builds

```
Usage:
$ percy build:delete [options] <build-id>

Arguments:
build-id Build ID to approve

Options:
--username <string> Username for authentication (can also be set via BROWSERSTACK_USERNAME env
var)
--access-key <string> Access key for authentication (can also be set via BROWSERSTACK_ACCESS_KEY
env var)

Global options:
-v, --verbose Log everything
-q, --quiet Log errors only
-s, --silent Log nothing
-h, --help Display command help
-v, --verbose Log everything
-q, --quiet Log errors only
-s, --silent Log nothing
-l, --labels <string> Associates labels to the build (ex: --labels=dev,prod )
-h, --help Display command help

Examples:
$ percy build:delete <build-id>
$ percy build:delete <build-id> --username username --access-key **key**
```
<!-- commandsstop -->
5 changes: 4 additions & 1 deletion packages/cli-build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
],
"main": "./dist/index.js",
"type": "module",
"exports": "./dist/index.js",
"exports": {
".": "./dist/index.js",
"./utils": "./dist/utils.js"
},
"scripts": {
"build": "node ../../scripts/build",
"lint": "eslint --ignore-path ../../.gitignore .",
Expand Down
49 changes: 49 additions & 0 deletions packages/cli-build/src/approve.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import command from '@percy/cli-command';
import { fetchCredentials, reviewCommandConfig } from './utils.js';

/**
* Approve command definition for Percy builds
* Allows users to approve builds using build ID and authentication credentials
*/
export const approve = command('approve', {
description: 'Approve Percy builds',
...reviewCommandConfig
}, async ({ flags, args, percy, log, exit }) => {
// Early return if Percy is disabled
if (!percy) {
exit(0, 'Percy is disabled');
}

// Validate and get authentication credentials
const { username, accessKey } = fetchCredentials(flags);

if (!username || !accessKey) {
exit(1, 'Username and access key are required to approve builds.');
}

log.info(`Approving build ${args.buildId}...`);

try {
// Call the Percy API to approve the build
const buildApprovalResponse = await percy.client.approveBuild(
args.buildId,
username,
accessKey
);

const approvedBy = buildApprovalResponse.data.attributes['action-performed-by'] || {
user_email: 'unknown@example.com',
user_name: username
};
log.info(`Build ${args.buildId} approved successfully!`);
log.info(`Approved by: ${approvedBy.user_name} (${approvedBy.user_email})`);
} catch (error) {
log.error(`Failed to approve build ${args.buildId}`);
log.error(error);

// Provide user-friendly error message
exit(1, 'Failed to approve the build');
}
});

export default approve;
6 changes: 5 additions & 1 deletion packages/cli-build/src/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ import command from '@percy/cli-command';
import finalize from './finalize.js';
import wait from './wait.js';
import id from './id.js';
import approve from './approve.js';
import reject from './reject.js';
import unapprove from './unapprove.js';
import deleteBuild from './delete.js';

export const build = command('build', {
description: 'Finalize and wait on Percy builds',
commands: [finalize, wait, id]
commands: [finalize, wait, id, approve, unapprove, reject, deleteBuild]
});

export default build;
49 changes: 49 additions & 0 deletions packages/cli-build/src/delete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import command from '@percy/cli-command';
import { fetchCredentials, reviewCommandConfig } from './utils.js';

/**
* Delete command definition for Percy builds
* Allows users to delete builds using build ID and authentication credentials
*/
export const deleteBuild = command('delete', {
description: 'Delete Percy builds',
...reviewCommandConfig
}, async ({ flags, args, percy, log, exit }) => {
// Early return if Percy is disabled
if (!percy) {
exit(0, 'Percy is disabled');
}

// Validate and get authentication credentials
const { username, accessKey } = fetchCredentials(flags);

if (!username || !accessKey) {
exit(1, 'Username and access key are required to delete builds.');
}

log.info(`Deleting build ${args.buildId}...`);

try {
// Call the Percy API to delete the build
const buildDeletionResponse = await percy.client.deleteBuild(
args.buildId,
username,
accessKey
);
const deletedBy = buildDeletionResponse['action-performed-by'] || {
user_email: 'unknown@example.com',
user_name: username
};

log.info(`Build ${args.buildId} deleted successfully!`);
log.info(`Deleted by: ${deletedBy.user_name} (${deletedBy.user_email})`);
} catch (error) {
log.error(`Failed to delete build ${args.buildId}`);
log.error(error);

// Provide user-friendly error message
exit(1, 'Failed to delete the build');
}
});

export default deleteBuild;
4 changes: 4 additions & 0 deletions packages/cli-build/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ export { default, build } from './build.js';
export { finalize } from './finalize.js';
export { wait } from './wait.js';
export { id } from './id.js';
export { approve } from './approve.js';
export { reject } from './reject.js';
export { unapprove } from './unapprove.js';
export { deleteBuild } from './delete.js';
49 changes: 49 additions & 0 deletions packages/cli-build/src/reject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import command from '@percy/cli-command';
import { fetchCredentials, reviewCommandConfig } from './utils.js';

/**
* Reject command definition for Percy builds
* Allows users to reject builds using build ID and authentication credentials
*/
export const reject = command('reject', {
description: 'Reject Percy builds',
...reviewCommandConfig
}, async ({ flags, args, percy, log, exit }) => {
// Early return if Percy is disabled
if (!percy) {
exit(0, 'Percy is disabled');
}

// Validate and get authentication credentials
const { username, accessKey } = fetchCredentials(flags);

if (!username || !accessKey) {
exit(1, 'Username and access key are required to reject builds.');
}

log.info(`Rejecting build ${args.buildId}...`);

try {
// Call the Percy API to reject the build
const buildRejectionResponse = await percy.client.rejectBuild(
args.buildId,
username,
accessKey
);

const rejectedBy = buildRejectionResponse.data.attributes['action-performed-by'] || {
user_email: 'unknown@example.com',
user_name: username
};
log.info(`Build ${args.buildId} rejected successfully!`);
log.info(`Rejected by: ${rejectedBy.user_name} (${rejectedBy.user_email})`);
} catch (error) {
log.error(`Failed to reject build ${args.buildId}`);
log.error(error);

// Provide user-friendly error message
exit(1, 'Failed to reject the build');
}
});

export default reject;
Loading
Loading