Skip to content

Commit

Permalink
FAI-1765 pull-request-number & timestamp passthrough (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
willmarks authored Apr 13, 2022
1 parent 033c0a7 commit e36bbf1
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 31 deletions.
16 changes: 8 additions & 8 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].2
uses: faros-ai/[email protected].3
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
run-ended-at: 1594948069000
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].2
uses: faros-ai/[email protected].3
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
deploy-ended-at: 1594938059000
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
run-ended-at: 1594948069000
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 action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ inputs:
run-status:
required: true
description: "CI or CD step's job run status. (Success, Failed, Canceled)"
pull-request-number:
required: false
description: "Manually associate the commit to a specific pull request number"
deploy:
required: false
description: 'The URI of the deployment. Required for CD events. (source://app/env/deploy)'
Expand Down
26 changes: 18 additions & 8 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.

39 changes: 25 additions & 14 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as core from '@actions/core';
import {execSync} from 'child_process';

const FAROS_CLI_VERSION = 'v0.3.2';
const FAROS_CLI_VERSION = 'v0.4.2';
const FAROS_SCRIPT_URL = `https://raw.githubusercontent.com/faros-ai/faros-events-cli/${FAROS_CLI_VERSION}/faros_event.sh`;
const FAROS_DEFAULT_URL = 'https://prod.api.faros.ai';
const FAROS_DEFAULT_GRAPH = 'default';
Expand All @@ -20,18 +20,19 @@ interface BaseEventInput {
readonly url: string;
readonly graph: string;
readonly commitUri: string;
readonly pullRequestNumber?: string;
readonly runUri: string;
readonly runStatus: Status;
readonly runStartTime?: bigint;
readonly runEndTime?: bigint;
readonly runStartTime?: string;
readonly runEndTime?: string;
readonly artifactUri?: string;
}

interface CDEventInput extends BaseEventInput {
readonly deployUri: string;
readonly deployStatus: Status;
readonly deployStartTime: bigint;
readonly deployEndTime: bigint;
readonly deployStartTime: string;
readonly deployEndTime: string;
readonly deployAppPlatform: string;
}

Expand Down Expand Up @@ -72,6 +73,7 @@ function resolveInput(): BaseEventInput {
const repo = splitRepo[1];
const sha = getEnvVar('GITHUB_SHA');
const commitUri = `GitHub://${org}/${repo}/${sha}`;
const pullRequestNumber = core.getInput('pull-request-number');

// Construct run URI
const runId = core.getInput('run-id') || getEnvVar('GITHUB_RUN_ID');
Expand All @@ -80,15 +82,16 @@ function resolveInput(): BaseEventInput {
const runUri = `GitHub://${org}/${pipelineId}/${runId}`;

const runStatus = toRunStatus(core.getInput('run-status', {required: true}));
const runStartTime = BigInt(core.getInput('run-started-at'));
const runEndTime = BigInt(core.getInput('run-ended-at'));
const runStartTime = core.getInput('run-started-at');
const runEndTime = core.getInput('run-ended-at');
const artifactUri = core.getInput('artifact');

return {
apiKey,
url,
graph,
commitUri,
pullRequestNumber,
runUri,
runStatus,
runStartTime,
Expand All @@ -107,8 +110,8 @@ async function downloadCLI(): Promise<void> {

function resolveCIEventInput(baseInput: BaseEventInput): BaseEventInput {
// Default run start/end to NOW if not provided
const runStartTime = baseInput.runStartTime || BigInt(Date.now());
const runEndTime = baseInput.runEndTime || BigInt(Date.now());
const runStartTime = baseInput.runStartTime || 'Now';
const runEndTime = baseInput.runEndTime || 'Now';

return {
...baseInput,
Expand All @@ -125,10 +128,8 @@ function resolveCDEventInput(baseInput: BaseEventInput): CDEventInput {
const deployAppPlatform = core.getInput('deploy-app-platform') || '';

// Default deploy start/end to NOW if not provided
const deployStartTime =
BigInt(core.getInput('deploy-started-at')) || BigInt(Date.now());
const deployEndTime =
BigInt(core.getInput('deploy-ended-at')) || BigInt(Date.now());
const deployStartTime = core.getInput('deploy-started-at') || 'Now';
const deployEndTime = core.getInput('deploy-ended-at') || 'Now';

// Default run start/end to deploy start/end if not provided
const runStartTime = baseInput.runStartTime || deployStartTime;
Expand Down Expand Up @@ -160,7 +161,12 @@ async function sendCIEvent(input: BaseEventInput): Promise<void> {

if (input.artifactUri) {
command += ` \
--artifact "${input.artifactUri}"`;
--artifact "${input.artifactUri}"`;
}

if (input.pullRequestNumber) {
command += ` \
--pull_request_number "${input.pullRequestNumber}"`;
}

execSync(command, {stdio: 'inherit'});
Expand Down Expand Up @@ -191,6 +197,11 @@ async function sendCDEvent(input: CDEventInput): Promise<void> {
--commit "${input.commitUri}"`;
}

if (input.pullRequestNumber) {
command += ` \
--pull_request_number "${input.pullRequestNumber}"`;
}

execSync(command, {stdio: 'inherit'});
}

Expand Down

0 comments on commit e36bbf1

Please sign in to comment.