Skip to content

Commit

Permalink
Allow sending details for run status, deploy status and env (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
tovbinm authored May 1, 2024
1 parent 267c6a7 commit a541964
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 53 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,7 @@ Thumbs.db

# Ignore built ts files
__tests__/runner/*
lib/**/*
lib/**/*

# Downloaded in a test
faros_event.sh
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ To report a code build to Faros specify `CI` in the `event` parameter and includ
```yaml
- name: Report code build to Faros
id: send-ci-event
uses: faros-ai/[email protected].7
uses: faros-ai/[email protected].8
with:
api-key: ${{ secrets.FAROS_API_KEY }}
event: CI
artifact: Docker://my-org/my-repo/artifactId
run-status: ${{ job.status }} # possible values - Success, Failed, Canceled
run-started-at: 1594938057000 # millis since epoch, ISO-8601 string or 'Now'
run-ended-at: 1594948069000 # millis since epoch, ISO-8601 string or 'Now'
run-status: ${{ job.status }} # possible values - Success, Failed, Canceled
run-started-at: 1594938057000 # millis since epoch, ISO-8601 string or 'Now'
run-ended-at: 1594948069000 # millis since epoch, ISO-8601 string or 'Now'
```
### Report a code deployment (CD Event) To Faros
Expand All @@ -30,18 +30,18 @@ To report an artifact deployment to Faros specify `CD` in the `event` parameter
```yaml
- name: Report deployment to Faros
id: send-cd-event
uses: faros-ai/[email protected].7
uses: faros-ai/[email protected].8
with:
api-key: ${{ secrets.FAROS_API_KEY }}
event: CD
artifact: Docker://my-org/my-repo/artifactId
deploy: CodeDeploy://MyService/<env>/deploymentId # possible env values - Dev, Prod, Staging, QA
deploy-status: Success # possible values - Success, Failed, Canceled
deploy-started-at: 1594938057000 # millis since epoch, ISO-8601 string or 'Now'
deploy-ended-at: 1594938059000 # millis since epoch, ISO-8601 string or 'Now'
run-status: ${{ job.status }} # possible values - Success, Failed, Canceled
run-started-at: 1594938057000 # millis since epoch, ISO-8601 string or 'Now'
run-ended-at: 1594948069000 # millis since epoch, ISO-8601 string or 'Now'
deploy-status: Success # possible values - Success, Failed, Canceled
deploy-started-at: 1594938057000 # millis since epoch, ISO-8601 string or 'Now'
deploy-ended-at: 1594938059000 # millis since epoch, ISO-8601 string or 'Now'
run-status: ${{ job.status }} # possible values - Success, Failed, Canceled
run-started-at: 1594938057000 # millis since epoch, ISO-8601 string or 'Now'
run-ended-at: 1594948069000 # millis since epoch, ISO-8601 string or 'Now'
```

## Authentication
Expand Down
3 changes: 3 additions & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe('Emit to Faros action', () => {
process.env['INPUT_GRAPH'] = 'unit-test';
process.env['INPUT_EVENT'] = 'CI';
process.env['INPUT_RUN-STATUS'] = 'Success';
process.env['INPUT_RUN-STATUS-DETAILS'] = 'Everything is fine';
process.env['GITHUB_REPOSITORY'] = 'faros-ai/faros-cicd-github-action';
process.env['GITHUB_RUN_ID'] = '71882192';
process.env['GITHUB_RUN_NUMBER'] = '10';
Expand All @@ -37,6 +38,8 @@ describe('Emit to Faros action', () => {
process.env['INPUT_API-URL'] = 'http://localhost:8080';
process.env['INPUT_DEPLOY'] = 'Spinnaker://emitter/Dev/deployId';
process.env['INPUT_DEPLOY-APP-PLATFORM'] = 'ECS';
process.env['INPUT_DEPLOY-ENV-DETAILS'] = 'AWS us-east-1';
process.env['INPUT_DEPLOY-STATUS-DETAILS'] = 'Everything is fine';
process.env['INPUT_DEPLOY_STARTED-AT'] = '1594938057000';
process.env['INPUT_DEPLOY_ENDED-AT'] = '1605748281000';
process.env['INPUT_GRAPH'] = 'unit-test';
Expand Down
13 changes: 11 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ inputs:
description: 'Unique identifier of the job executing the CI or CD process. (Default: GITHUB_RUN_ID)'
run-status:
required: true
description: "CI or CD step's job run status. (Success, Failed, Canceled)"
description: "CI or CD step's job run status. (Success, Failed, Canceled, Queued, Running, Unknown, Custom)"
run-status-details:
required: false
description: "Any extra details about the status of the job run."
pull-request-number:
required: false
description: "Manually associate the commit to a specific pull request number"
Expand All @@ -22,10 +25,16 @@ inputs:
description: 'The URI of the deployment. Required for CD events. (source://app/env/deploy)'
deploy-status:
required: false
description: 'The status of the deployment. Required for CD events. (Success, Failed, Canceled)'
description: 'The status of the deployment. Required for CD events. (Success, Failed, Canceled, Queued, Running, RolledBack, Custom)'
deploy-status-details:
required: false
description: "Any extra details about the status of the deployment."
deploy-app-platform:
required: false
description: 'The platform the application is being deployed on. (e.g. ECS, K8s)'
deploy-env-details:
required: false
description: 'Any extra details about the deployment environment.'
deploy-started-at:
required: false
description: 'Deployment process start time in millis. (e.g. 1626804346019)'
Expand Down
41 changes: 22 additions & 19 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

46 changes: 27 additions & 19 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ interface BaseEventInput {
interface CDEventInput extends BaseEventInput {
readonly deployUri: string;
readonly deployStatus: Status;
readonly deployEnvDetails: string;
readonly deployStartTime: string;
readonly deployEndTime: string;
readonly deployAppPlatform: string;
Expand Down Expand Up @@ -85,7 +86,10 @@ function resolveInput(): BaseEventInput {
const runPipeline = core.getInput('pipeline-id') || `${repo}_${workflow}`;
const runSource = 'GitHub';

const runStatus = toRunStatus(core.getInput('run-status', {required: true}));
const runStatus = toRunStatus(
core.getInput('run-status', {required: true}),
core.getInput('run-status-details')
);
const runStartTime = core.getInput('run-started-at');
const runEndTime = core.getInput('run-ended-at');
const artifactUri = core.getInput('artifact');
Expand Down Expand Up @@ -130,9 +134,11 @@ function resolveCIEventInput(baseInput: BaseEventInput): BaseEventInput {
function resolveCDEventInput(baseInput: BaseEventInput): CDEventInput {
const deployUri = core.getInput('deploy', {required: true});
const deployStatus = toDeployStatus(
core.getInput('deploy-status', {required: true})
core.getInput('deploy-status', {required: true}),
core.getInput('deploy-status-details')
);
const deployAppPlatform = core.getInput('deploy-app-platform') || '';
const deployAppPlatform = core.getInput('deploy-app-platform');
const deployEnvDetails = core.getInput('deploy-env-details');

// Default deploy start/end to NOW if not provided
const deployStartTime = core.getInput('deploy-started-at') || 'Now';
Expand All @@ -149,6 +155,7 @@ function resolveCDEventInput(baseInput: BaseEventInput): CDEventInput {
deployStartTime,
deployEndTime,
deployAppPlatform,
deployEnvDetails,
runStartTime,
runEndTime
};
Expand Down Expand Up @@ -193,6 +200,7 @@ async function sendCDEvent(input: CDEventInput): Promise<void> {
--deploy_start_time "${input.deployStartTime}" \
--deploy_end_time "${input.deployEndTime}" \
--deploy_app_platform "${input.deployAppPlatform}" \
--deploy_env_details "${input.deployEnvDetails}" \
--run_id "${input.runId}" \
--run_pipeline "${input.runPipeline}" \
--run_org "${input.runOrg}" \
Expand All @@ -218,43 +226,43 @@ async function sendCDEvent(input: CDEventInput): Promise<void> {
execSync(command, {stdio: 'inherit'});
}

function toRunStatus(status: string): Status {
function toRunStatus(status: string, detail: string): Status {
if (!status) {
return {category: 'Unknown', detail: 'undefined'};
return {category: 'Unknown', detail: detail || 'undefined'};
}
switch (status.toLowerCase()) {
case 'cancelled':
return {category: 'Canceled', detail: status};
return {category: 'Canceled', detail: detail || status};
case 'failure':
return {category: 'Failed', detail: status};
return {category: 'Failed', detail: detail || status};
case 'success':
return {category: 'Success', detail: status};
return {category: 'Success', detail: detail || status};
case 'canceled':
return {category: 'Canceled', detail: status};
return {category: 'Canceled', detail: detail || status};
case 'failed':
return {category: 'Failed', detail: status};
return {category: 'Failed', detail: detail || status};
default:
return {category: 'Custom', detail: status};
return {category: 'Custom', detail: detail || status};
}
}

function toDeployStatus(status: string): Status {
function toDeployStatus(status: string, detail: string): Status {
if (!status) {
return {category: 'Custom', detail: 'undefined'};
return {category: 'Custom', detail: detail || 'undefined'};
}
switch (status.toLowerCase()) {
case 'cancelled':
return {category: 'Canceled', detail: status};
return {category: 'Canceled', detail: detail || status};
case 'failure':
return {category: 'Failed', detail: status};
return {category: 'Failed', detail: detail || status};
case 'success':
return {category: 'Success', detail: status};
return {category: 'Success', detail: detail || status};
case 'canceled':
return {category: 'Canceled', detail: status};
return {category: 'Canceled', detail: detail || status};
case 'failed':
return {category: 'Failed', detail: status};
return {category: 'Failed', detail: detail || status};
default:
return {category: 'Custom', detail: status};
return {category: 'Custom', detail: detail || status};
}
}

Expand Down

0 comments on commit a541964

Please sign in to comment.