Skip to content

Commit

Permalink
Merge pull request #110 from check-run-reporter/better-url-handling-a…
Browse files Browse the repository at this point in the history
…nd-more-logging

better url handling and more logging
  • Loading branch information
ianwremmel authored Apr 19, 2022
2 parents 6266797 + 38dcf7f commit 20a7e72
Show file tree
Hide file tree
Showing 19 changed files with 181 additions and 151 deletions.
8 changes: 0 additions & 8 deletions integrations/action/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ branding:
color: 'orange'
inputs:
hostname:
default: api.check-run-reporter.com
description: Internal. Do not use unless directed. Supercedes --url
required: false
label:
Expand Down Expand Up @@ -37,13 +36,6 @@ inputs:
Repo token to authenticate the upload. You can get your tokens from
[https://www.check-run-reporter.com/repos](https://www.check-run-reporter.com/repos).
required: true
url:
default: 'https://api.check-run-reporter.com/api/v1'
description:
Mostly here for future use, this let's us specify an alternate endpoint
for testing new features. Unless specifically told to do so by support,
please don't change this value.
required: false
outputs:
tests:
description: The names of the test files to test on this node
Expand Down
34 changes: 18 additions & 16 deletions integrations/action/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import axios from 'axios';

import {submit} from '../../../src';
import {split} from '../../../src/commands/split';
import {makeClient} from '../../../src/lib/axios';
import {Context} from '../../../src/lib/types';

const logger = {
debug: core.debug.bind(core),
Expand Down Expand Up @@ -88,17 +90,15 @@ export async function findReports(): Promise<string[]> {
}

interface DoSplitInput {
readonly hostname: string;
readonly label: string;
readonly tests: string;
readonly token: string;
readonly url: string;
}

/**
* Wrapper around split to adapt it for github actions
*/
async function doSplit({hostname, label, tests, token, url}: DoSplitInput) {
async function doSplit({label, tests, token}: DoSplitInput, {client}: Context) {
const nodeCount = core.getInput('nodeCount');
const nodeIndex = core.getInput('nodeIndex');

Expand All @@ -113,15 +113,13 @@ async function doSplit({hostname, label, tests, token, url}: DoSplitInput) {
try {
const {filenames} = await split(
{
hostname,
label,
nodeCount: Number(nodeCount),
nodeIndex: Number(nodeIndex),
tests: [tests],
token,
url,
},
{logger}
{client, logger}
);

core.info(
Expand Down Expand Up @@ -155,17 +153,22 @@ async function main() {

const hostname = core.getInput('hostname');
const token = core.getInput('token');
const url = core.getInput('url');

const client = makeClient({hostname});

const tests = core.getInput('tests');
if (tests) {
return await doSplit({
hostname,
label,
tests,
token,
url: `${url}/split`,
});
return await doSplit(
{
label,
tests,
token,
},
{
client,
logger,
}
);
}

const root = determineRoot();
Expand All @@ -175,15 +178,14 @@ async function main() {

await submit(
{
hostname,
label,
report: files,
root,
sha,
token,
url: `${url}/submissions`,
},
{
client,
logger,
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,11 @@ log () {
echo "$@" 1>&2
}

HOSTNAME=${BUILDKITE_PLUGIN_CHECK_RUN_REPORTER_HOSTNAME:-api.check-run-reporter.com}
HOSTNAME=${BUILDKITE_PLUGIN_CHECK_RUN_REPORTER_HOSTNAME:-''}
LABEL=${BUILDKITE_PLUGIN_CHECK_RUN_REPORTER_LABEL:-$BUILDKITE_LABEL}
ROOT=${BUILDKITE_PLUGIN_CHECK_RUN_REPORTER_ROOT:-$(find_root)}
SHA=$BUILDKITE_COMMIT
TOKEN=$BUILDKITE_PLUGIN_CHECK_RUN_REPORTER_TOKEN
URL=${BUILDKITE_PLUGIN_CHECK_RUN_REPORTER_URL:-https://api.check-run-reporter.com/api/v1/submissions}
REPORT_DIR=$BUILDKITE_PLUGIN_CHECK_RUN_REPORTER_REPORT

log 'Running check-run-reporter-buildkite-plugin with the following parameters'
Expand All @@ -71,7 +70,6 @@ $BIN submit \
--report="$REPORT_DIR" \
--root="$ROOT" \
--sha="$SHA" \
--token="$TOKEN" \
--url="$URL"
--token="$TOKEN"

echo "Uploaded reports to Check Run Reporter"
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ log () {
echo "$@" 1>&2
}

HOSTNAME=${BUILDKITE_PLUGIN_CHECK_RUN_REPORTER_HOSTNAME:-api.check-run-reporter.com}
HOSTNAME=${BUILDKITE_PLUGIN_CHECK_RUN_REPORTER_HOSTNAME:-''}
LABEL=${BUILDKITE_PLUGIN_CHECK_RUN_REPORTER_LABEL:-$BUILDKITE_LABEL}
TOKEN=$BUILDKITE_PLUGIN_CHECK_RUN_REPORTER_TOKEN
TESTS=${BUILDKITE_PLUGIN_CHECK_RUN_REPORTER_TESTS:-''}
URL=${BUILDKITE_PLUGIN_CHECK_RUN_REPORTER_URL:-https://api.check-run-reporter.com/api/v1/split}

if [ -z "$TESTS" ]; then
exit 0
Expand Down Expand Up @@ -45,7 +44,6 @@ CHECK_RUN_REPORTER_TESTS_FOR_THIS_AGENT=$($BIN split \
--nodeCount="$NODE_COUNT" \
--nodeIndex="$NODE_INDEX" \
--tests="$TESTS" \
--token="$TOKEN" \
--url="$URL")
--token="$TOKEN")

echo "Got distributed tests for this node from Check Run Reporter"
56 changes: 50 additions & 6 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
},
"dependencies": {
"axios": "^0.24.0",
"axios-debug-log": "^0.8.4",
"axios-retry": "^3.1.9",
"ci-info": "^3.2.0",
"form-data": "^4.0.0",
Expand Down
32 changes: 12 additions & 20 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {hideBin} from 'yargs/helpers';

import {split} from './commands/split';
import {submit} from './commands/submit';
import {makeClient} from './lib/axios';
import {logger, silentLogger} from './lib/logger';

/**
Expand All @@ -19,9 +20,8 @@ export function cli(argv: string[]) {
(y) =>
y.options({
hostname: {
default: 'api.check-run-reporter.com',
description:
'Internal. Do not use unless directed. Supercedes --url',
description: 'Internal. Do not use unless directed.',
type: 'string',
},
json: {
default: false,
Expand Down Expand Up @@ -53,19 +53,17 @@ export function cli(argv: string[]) {
description: 'Repo token with which to authenticate the upload.',
type: 'string',
},
url: {
default: 'https://api.check-run-reporter.com/api/v1/split',
description:
"Mostly here for future use, this let's us specify an alternate endpoint for testing new features. Unless specifically told to do so by support, please don't change this value.",
},
}),
async ({tests, ...args}) => {
async ({hostname, tests, ...args}) => {
const directlyUseOutput = !process.stdout.isTTY;

try {
const result = await split(
{...args, tests: tests.map(String)},
{logger: directlyUseOutput ? silentLogger : logger}
{
client: makeClient({hostname}),
logger: directlyUseOutput ? silentLogger : logger,
}
);
if (directlyUseOutput) {
console.log(result.filenames.join('\n'));
Expand Down Expand Up @@ -96,9 +94,8 @@ export function cli(argv: string[]) {
(y) =>
y.options({
hostname: {
default: 'api.check-run-reporter.com',
description:
'Internal. Do not use unless directed. Supercedes --url',
description: 'Internal. Do not use unless directed.',
type: 'string',
},
label: {
description: 'Label that should appear in the GitHub check run.',
Expand Down Expand Up @@ -127,19 +124,14 @@ export function cli(argv: string[]) {
description: 'Repo token with which to authenticate the upload.',
type: 'string',
},
url: {
default: 'https://api.check-run-reporter.com/api/v1/submissions',
description:
"Mostly here for future use, this let's us specify an alternate endpoint for testing new features. Unless specifically told to do so by support, please don't change this value.",
},
}),
async ({report, ...args}) => {
async ({hostname, report, ...args}) => {
return submit(
{
...args,
report: report.map(String),
},
{logger}
{client: makeClient({hostname}), logger}
);
}
)
Expand Down
Loading

0 comments on commit 20a7e72

Please sign in to comment.