Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ inputs:
description: 'Max execution time in seconds'
required: false
default: '1200'
configPath:
description: 'Path to Redocly config file'
required: false
githubToken:
description: 'Token to authenticate with'
required: true
Expand Down
60 changes: 54 additions & 6 deletions src/__tests__/helpers.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import * as core from '@actions/core';
import { Context } from '@actions/github/lib/context';
import { parseInputData, parseEventData, getRedoclyConfig } from '../helpers';
import { loadConfig } from '@redocly/openapi-core';
import { Context } from '@actions/github/lib/context';

jest.mock('@redocly/openapi-core', () => ({
loadConfig: jest.fn(),
}));

let getInputMock: jest.SpiedFunction<typeof core.getInput>;

Expand Down Expand Up @@ -64,7 +68,7 @@ describe('helpers', () => {
});

describe('parseInputData', () => {
it('should return parsed input data', () => {
it('should return parsed input data without config', () => {
getInputMock.mockImplementation(
getGetInputMock({
organization: 'test-org-slug',
Expand All @@ -77,7 +81,7 @@ describe('helpers', () => {
);
const parsedInputData = parseInputData();

expect(getInputMock).toHaveBeenCalledTimes(6);
expect(getInputMock).toHaveBeenCalledTimes(7);
expect(parsedInputData).toEqual({
redoclyOrgSlug: 'test-org-slug',
redoclyProjectSlug: 'test-project-slug',
Expand All @@ -88,6 +92,36 @@ describe('helpers', () => {
],
mountPath: 'test/mount/path',
maxExecutionTime: 100,
configPath: undefined,
});
});

it('should return parsed input data with custom config', () => {
getInputMock.mockImplementation(
getGetInputMock({
organization: 'test-org-slug',
project: 'test-project-slug',
domain: 'redocly-domain.com',
files: 'testFolder testOpenApiFile.yaml',
mountPath: 'test/mount/path',
maxExecutionTime: '100',
configPath: 'custom/path/redocly.yaml',
}),
);
const parsedInputData = parseInputData();

expect(getInputMock).toHaveBeenCalledTimes(7);
expect(parsedInputData).toEqual({
redoclyOrgSlug: 'test-org-slug',
redoclyProjectSlug: 'test-project-slug',
redoclyDomain: 'redocly-domain.com',
files: [
'/home/runner/work/reunite-push-action/testFolder',
'/home/runner/work/reunite-push-action/testOpenApiFile.yaml',
],
mountPath: 'test/mount/path',
maxExecutionTime: 100,
configPath: 'custom/path/redocly.yaml',
});
});
});
Expand All @@ -114,9 +148,23 @@ describe('helpers', () => {
});

describe('getRedoclyConfig', () => {
it('should return redocly config', async () => {
const redoclyConfig = await getRedoclyConfig();
expect(typeof redoclyConfig).toBe(typeof loadConfig({}));
const mockLoadConfig = loadConfig as jest.MockedFunction<typeof loadConfig>;

beforeEach(() => {
mockLoadConfig.mockResolvedValue({} as ReturnType<typeof loadConfig>);
});

it('should return redocly config with default path', async () => {
await getRedoclyConfig();
expect(mockLoadConfig).toHaveBeenCalledWith(undefined);
});

it('should return redocly config with custom path', async () => {
const customConfigPath = 'custom/path/redocly.yaml';
await getRedoclyConfig(customConfigPath);
expect(mockLoadConfig).toHaveBeenCalledWith({
configPath: customConfigPath,
});
});
});
});
Expand Down
12 changes: 9 additions & 3 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export function parseInputData(): ParsedInputData {
const redoclyDomain =
core.getInput('domain') || 'https://app.cloud.redocly.com';
const maxExecutionTime = Number(core.getInput('maxExecutionTime')) || 1200;
const configPath = core.getInput('configPath') || undefined;

const absoluteFilePaths = files.map(_path =>
path.join(process.env.GITHUB_WORKSPACE || '', _path),
Expand All @@ -25,6 +26,7 @@ export function parseInputData(): ParsedInputData {
files: absoluteFilePaths,
redoclyDomain,
maxExecutionTime,
configPath,
};
}

Expand Down Expand Up @@ -124,9 +126,13 @@ function getCommitSha(): string | undefined {
}
}

// Returns parsed config from the root or default config if not found
export async function getRedoclyConfig(): ReturnType<typeof loadConfig> {
const redoclyConfig = await loadConfig();
// Returns parsed config from the specified path or default config if not found
export async function getRedoclyConfig(
configPath?: string,
): ReturnType<typeof loadConfig> {
const redoclyConfig = await loadConfig(
configPath ? { configPath } : undefined,
);

return redoclyConfig;
}
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function run(): Promise<void> {
console.debug('Parsed input data', inputData);
console.debug('Parsed GitHub event', ghEvent);

const config = await getRedoclyConfig();
const config = await getRedoclyConfig(inputData.configPath);

const pushData = await handlePush({
argv: {
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface ParsedInputData {
files: string[];
mountPath: string;
maxExecutionTime: number;
configPath?: string;
}

export interface ParsedEventData {
Expand Down