Skip to content

Commit

Permalink
fix: do hostname override in commands not in cli
Browse files Browse the repository at this point in the history
  • Loading branch information
ianwremmel committed Apr 16, 2022
1 parent 0e9b646 commit 44bc4ee
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 12 deletions.
1 change: 1 addition & 0 deletions integrations/action/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ 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
7 changes: 6 additions & 1 deletion integrations/action/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export async function findReports(): Promise<string[]> {
}

interface DoSplitInput {
readonly hostname: string;
readonly label: string;
readonly tests: string;
readonly token: string;
Expand All @@ -97,7 +98,7 @@ interface DoSplitInput {
/**
* Wrapper around split to adapt it for github actions
*/
async function doSplit({label, tests, token, url}: DoSplitInput) {
async function doSplit({hostname, label, tests, token, url}: DoSplitInput) {
const nodeCount = core.getInput('nodeCount');
const nodeIndex = core.getInput('nodeIndex');

Expand All @@ -112,6 +113,7 @@ async function doSplit({label, tests, token, url}: DoSplitInput) {
try {
const {filenames} = await split(
{
hostname,
label,
nodeCount: Number(nodeCount),
nodeIndex: Number(nodeIndex),
Expand Down Expand Up @@ -151,12 +153,14 @@ async function main() {
core.getInput('label') ||
`${github.context.workflow} / ${github.context.job}`;

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

const tests = core.getInput('tests');
if (tests) {
return await doSplit({
hostname,
label,
tests,
token,
Expand All @@ -171,6 +175,7 @@ async function main() {

await submit(
{
hostname,
label,
report: files,
root,
Expand Down
12 changes: 3 additions & 9 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,12 @@ export function cli(argv: string[]) {
"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 ({hostname, tests, url, ...args}) => {
async ({tests, ...args}) => {
const directlyUseOutput = !process.stdout.isTTY;

const u = new URL(url);
u.hostname = hostname;

try {
const result = await split(
{...args, tests: tests.map(String), url: u.toString()},
{...args, tests: tests.map(String)},
{logger: directlyUseOutput ? silentLogger : logger}
);
if (directlyUseOutput) {
Expand Down Expand Up @@ -136,14 +133,11 @@ export function cli(argv: string[]) {
"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 ({hostname, report, url, ...args}) => {
const u = new URL(url);
u.hostname = hostname;
async ({report, ...args}) => {
return submit(
{
...args,
report: report.map(String),
url: u.toString(),
},
{logger}
);
Expand Down
1 change: 1 addition & 0 deletions src/commands/split.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe('split()', () => {

const result = await split(
{
hostname: 'api.check-run-reporter.com',
label: 'foo',
nodeCount: 3,
nodeIndex: 2,
Expand Down
13 changes: 12 additions & 1 deletion src/commands/split.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {multiGlob} from '../lib/file';
import {Context} from '../lib/types';

interface SplitArgs {
readonly hostname: string;
/** list of filenames or globs that match all available test files */
readonly tests: readonly string[];
readonly label: string;
Expand All @@ -21,9 +22,19 @@ interface SplitArgs {
* appropriate to this node.
*/
export async function split(
{tests, label, nodeCount, nodeIndex, token, url}: SplitArgs,
{hostname, tests, label, nodeCount, nodeIndex, token, url}: SplitArgs,
context: Context
) {
const u = new URL(url);
if (hostname !== u.hostname) {
u.hostname = hostname;
context.logger.info('Overriding hostname', {
newUrl: u.href,
originalUrl: url,
});
url = u.href;
}

// This is just here to test the buildkite plugin. The only other option I can
// think of is to run a server locally that responds with this and use the
// `url` param, but that currently seems like more trouble than its worth for
Expand Down
2 changes: 2 additions & 0 deletions src/commands/submit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe('submit()', () => {

await submit(
{
hostname: 'api.check-run-reporter.com',
label: 'foo',
report: ['reports/junit/**/*.xml'],
root: '/',
Expand All @@ -59,6 +60,7 @@ describe('submit()', () => {

await submit(
{
hostname: 'api.check-run-reporter.com',
label: 'foo',
report: ['reports/junit/**/*.xml'],
root: '/',
Expand Down
14 changes: 13 additions & 1 deletion src/commands/submit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {multiStepUpload, singleStepUpload} from '../lib/upload';
import {getRequestId} from '../lib/axios';

interface SubmitArgs {
readonly hostname: string;
readonly label: Optional<string>;
readonly report: readonly string[];
readonly root: string;
Expand Down Expand Up @@ -55,9 +56,20 @@ export async function submit(input: SubmitArgs, context: Context) {
* efficient once the new version is released.
*/
async function tryMultiStepUploadOrFallbackToSingle(
input: SubmitArgs,
{hostname, url, ...rest}: SubmitArgs,
context: Context
) {
const u = new URL(url);
if (hostname !== u.hostname) {
u.hostname = hostname;
context.logger.info('Overriding hostname', {
newUrl: u.href,
originalUrl: url,
});
url = u.href;
}
const input = {url, ...rest};

try {
return await multiStepUpload(input, context);
} catch (err) {
Expand Down

0 comments on commit 44bc4ee

Please sign in to comment.