Skip to content

Commit

Permalink
Merge pull request #167 from adhocteam/main
Browse files Browse the repository at this point in the history
S3 buckets and Circle CI export script
  • Loading branch information
rahearn authored Nov 23, 2020
2 parents 7c438f7 + 5f5fc52 commit 3934c1e
Show file tree
Hide file tree
Showing 17 changed files with 529 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ parameters:
default: "main"
type: string
sandbox_git_branch: # change to feature branch to test deployment
default: "sj-bind-rds"
default: "sj-tf-s3-init"
type: string
jobs:
build:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ coverage
junit.xml
reports
yarn-error.log
docs/circleci/test_report.md

# Build related
build/
Expand Down
1 change: 1 addition & 0 deletions deployment_config/dev_vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ NODE_ENV: production
# This env variable should go away soon in favor of TTA_SMART_HUB_URI
REDIRECT_URI_HOST: https://tta-smarthub-dev.app.cloud.gov
rds_instance: ttahub-dev
s3_doc_upload_bucket: ttahub-document-upload-dev
SESSION_SECRET: ((SESSION_SECRET))
TTA_SMART_HUB_URI: https://tta-smarthub-dev.app.cloud.gov
1 change: 1 addition & 0 deletions deployment_config/prod_vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ NODE_ENV: production
# This env variable should go away soon in favor of TTA_SMART_HUB_URI
REDIRECT_URI_HOST: https://tta-smarthub-prod.app.cloud.gov
rds_instance: ttahub-prod
s3_doc_upload_bucket: ttahub-document-upload-prod
SESSION_SECRET: ((SESSION_SECRET))
TTA_SMART_HUB_URI: https://tta-smarthub-prod.app.cloud.gov
1 change: 1 addition & 0 deletions deployment_config/sandbox_vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ NODE_ENV: production
# This env variable should go away soon in favor of TTA_SMART_HUB_URI
REDIRECT_URI_HOST: https://tta-smarthub-sandbox.app.cloud.gov
rds_instance: ttahub-sandbox
s3_doc_upload_bucket: ttahub-document-upload-sandbox
SESSION_SECRET: ((SESSION_SECRET))
TTA_SMART_HUB_URI: https://tta-smarthub-sandbox.app.cloud.gov
1 change: 1 addition & 0 deletions deployment_config/staging_vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ NODE_ENV: production
# This env variable should go away soon in favor of TTA_SMART_HUB_URI
REDIRECT_URI_HOST: https://tta-smarthub-staging.app.cloud.gov
rds_instance: ttahub-staging
s3_doc_upload_bucket: ttahub-document-upload-staging
SESSION_SECRET: ((SESSION_SECRET))
TTA_SMART_HUB_URI: https://tta-smarthub-staging.app.cloud.gov
14 changes: 14 additions & 0 deletions docs/circleci/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# CircleCI Export Script

This script exports the test results and artifacts from CircleCI to a markdown file for including in governance documents.

## Setup

Set `CIRCLECI_AUTH_TOKEN` environment variable with your [personal auth token](https://circleci.com/docs/2.0/managing-api-tokens/#creating-a-personal-api-token).

## Things to potentially update:

in `src/circleci.js`

1) `artifactFileNames` regex to determine which artifacts to include
2) `buildJobsInWorkflow` count to select the number of jobs in a single workflow
4 changes: 4 additions & 0 deletions docs/circleci/bin/export-ci.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env node

require = require('esm')(module /*, options*/);
require("../index.js").exportLastMainTests();
33 changes: 33 additions & 0 deletions docs/circleci/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { getLastTest, getTestMetadata, getTestArtifacts } from './src/circleci';
import fs from 'fs';

const exportLastMainTests = async (fileName = "test_report.md") => {
const lastTestPipeline = await getLastTest();
let data = "# Test Results Report\n";
for (let job of lastTestPipeline) {
let { success, other, exceptions } = await getTestMetadata(job.build_num);
let artifacts = await getTestArtifacts(job.build_num);
const hasTestReults = success.length > 0 || other.length > 0 || exceptions != null;
const hasArtifacts = artifacts.length > 0;
if (hasTestReults || hasArtifacts) {
data += `\n## ${job.workflows.job_name}\n`;
if (hasTestReults) {
data += "### Test Results:\n"
data += `#### Success:\n\`\`\`\n${JSON.stringify(success, null, 2)}\n\`\`\`\n`;
data += `#### Failure:\n\`\`\`\n${JSON.stringify(other, null, 2)}\n\`\`\`\n`
data += `#### Exceptions:\n\`\`\`\n${JSON.stringify(exceptions, null, 2)}\n\`\`\`\n`
}
if (hasArtifacts) {
data += `### Artifacts:\n\`\`\`\n${JSON.stringify(artifacts, null, 2)}\n\`\`\`\n`;
}
}
}
fs.writeFile(fileName, data, (err) => {
if (err) throw err;
console.log("Done");
})
}

export {
exportLastMainTests
}
15 changes: 15 additions & 0 deletions docs/circleci/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "circleci-export",
"version": "0.0.1",
"description": "Export build results out of CircleCI to package for documentation",
"main": "index.js",
"license": "MIT",
"bin": {
"export-ci": "bin/export-ci.js"
},
"dependencies": {
"circleci": "^0.3.3",
"esm": "^3.2.25",
"lodash": "^4.17.20"
}
}
55 changes: 55 additions & 0 deletions docs/circleci/src/circleci.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import CircleCI from 'circleci';
import { filter, take, partition } from 'lodash';

const artifactFileNames = /(?:(?:lcov-report\/index|cucumber_report)\.html)|(?:^reports\/.*\.png)$/;
const buildJobsInWorkflow = 7;
const workflowName = "build_test_deploy";

const ci = new CircleCI({
auth: process.env.CIRCLECI_AUTH_TOKEN
});

const getLastTest = async () => {
const lastBuilds = await ci.getBranchBuilds({
username: "HHS",
project: "Head-Start-TTADP",
branch: "main",
});
return take(
filter(
lastBuilds,
(b) => (b.workflows.workflow_name === workflowName)
),
buildJobsInWorkflow);
}

const getTestMetadata = async (buildNum) => {
const { tests, exceptions } = await ci.getTestMetadata({
username: "HHS",
project: "Head-Start-TTADP",
build_num: buildNum
});
const [ success, other ] = partition(tests, ({result}) => (result === "success"));

return {
success,
other,
exceptions
}
}

const getTestArtifacts = async (buildNum) => {
const artifacts = await ci.getBuildArtifacts({
username: "HHS",
project: "Head-Start-TTADP",
build_num: buildNum
});
return filter(artifacts, ({path}) => (path.match(artifactFileNames)));
}

export default ci;
export {
getLastTest,
getTestMetadata,
getTestArtifacts
}
Loading

0 comments on commit 3934c1e

Please sign in to comment.