-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #167 from adhocteam/main
S3 buckets and Circle CI export script
- Loading branch information
Showing
17 changed files
with
529 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ coverage | |
junit.xml | ||
reports | ||
yarn-error.log | ||
docs/circleci/test_report.md | ||
|
||
# Build related | ||
build/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.