From b80212f4abc0a7f2b9cac539c0b532e5c7d5427d Mon Sep 17 00:00:00 2001 From: Amir Szekely Date: Tue, 14 Jun 2022 21:06:53 -0700 Subject: [PATCH] feat: No more default provider label (#42) Removed the concept of default provider label as it was confusing and easily caused runners to be left behind. For example, if the user had a typo in the label on the workflow side, the default provider would spin up and never start the job because the labels don't match. BREAKING CHANGE: `GitHubRunners` no longer takes `defaultProviderLabel` and all workflows must always specify the label they need instead of just `self-hosted` --- API.md | 30 ------------------------------ README.md | 1 - src/runner.ts | 36 ++---------------------------------- 3 files changed, 2 insertions(+), 65 deletions(-) diff --git a/API.md b/API.md index 378b7918..7951d8f1 100644 --- a/API.md +++ b/API.md @@ -488,7 +488,6 @@ new GitHubRunners( 'runners', { providers: [myProvider], - defaultProviderLabel: 'my-codebuild', } ); ``` @@ -574,7 +573,6 @@ Any object. | **Name** | **Type** | **Description** | | --- | --- | --- | | node | constructs.Node | The tree node. | -| defaultProvider | IRunnerProvider | Default provider as set by {@link GitHubRunnersProps.defaultProviderLabel}. | | props | GitHubRunnersProps | *No description.* | | providers | IRunnerProvider[] | Configured runner providers. | | secrets | Secrets | Secrets for GitHub communication including webhook secret and runner authentication. | @@ -593,18 +591,6 @@ The tree node. --- -##### `defaultProvider`Required - -```typescript -public readonly defaultProvider: IRunnerProvider; -``` - -- *Type:* IRunnerProvider - -Default provider as set by {@link GitHubRunnersProps.defaultProviderLabel}. - ---- - ##### `props`Required ```typescript @@ -1351,26 +1337,10 @@ const gitHubRunnersProps: GitHubRunnersProps = { ... } | **Name** | **Type** | **Description** | | --- | --- | --- | -| defaultProviderLabel | string | Label of default provider in case the workflow job doesn't specify any known label. | | providers | IRunnerProvider[] | List of runner providers to use. | --- -##### `defaultProviderLabel`Optional - -```typescript -public readonly defaultProviderLabel: string; -``` - -- *Type:* string -- *Default:* 'codebuild' - -Label of default provider in case the workflow job doesn't specify any known label. - -A provider with that label must be configured. - ---- - ##### `providers`Optional ```typescript diff --git a/README.md b/README.md index 1ab7addd..9df45acc 100644 --- a/README.md +++ b/README.md @@ -126,7 +126,6 @@ new GitHubRunners( 'runners', { providers: [myProvider], - defaultProviderLabel: 'my-codebuild', } ); diff --git a/src/runner.ts b/src/runner.ts index a2dffa01..75256096 100644 --- a/src/runner.ts +++ b/src/runner.ts @@ -14,14 +14,6 @@ import { GithubWebhookHandler } from './webhook'; * Properties for GitHubRunners */ export interface GitHubRunnersProps { - - /** - * Label of default provider in case the workflow job doesn't specify any known label. A provider with that label must be configured. - * - * @default 'codebuild' - */ - readonly defaultProviderLabel?: string; - /** * List of runner providers to use. At least one provider is required. Provider will be selected when its label matches the labels requested by the workflow job. * @@ -66,7 +58,6 @@ export interface GitHubRunnersProps { * 'runners', * { * providers: [myProvider], - * defaultProviderLabel: 'my-codebuild', * } * ); * ``` @@ -78,11 +69,6 @@ export class GitHubRunners extends Construct { */ readonly providers: IRunnerProvider[]; - /** - * Default provider as set by {@link GitHubRunnersProps.defaultProviderLabel}. - */ - readonly defaultProvider: IRunnerProvider; - /** * Secrets for GitHub communication including webhook secret and runner authentication. */ @@ -107,13 +93,6 @@ export class GitHubRunners extends Construct { ]; } - const defaultProvider = this.getDefaultProvider(); - if (!defaultProvider) { - throw new Error(`No provider was found for the default label "${this.props.defaultProviderLabel}"`); - } else { - this.defaultProvider = defaultProvider; - } - this.orchestrator = this.stateMachine(); this.webhook = new GithubWebhookHandler(this, 'Webhook Handler', { orchestrator: this.orchestrator, @@ -124,16 +103,6 @@ export class GitHubRunners extends Construct { this.statusFunction(); } - private getDefaultProvider(): IRunnerProvider | null { - for (const provider of this.providers) { - if ((this.props.defaultProviderLabel || 'codebuild') == provider.label) { - return provider; - } - } - - return null; - } - private stateMachine() { const tokenRetrieverTask = new stepfunctions_tasks.LambdaInvoke( this, @@ -177,11 +146,10 @@ export class GitHubRunners extends Construct { stepfunctions.Condition.isPresent(`$.labels.${provider.label}`), providerTask, ); - if (this.defaultProvider == provider) { - providerChooser.otherwise(providerTask); - } } + providerChooser.otherwise(new stepfunctions.Fail(this, 'Unknown label')); + const work = tokenRetrieverTask.next( new stepfunctions.Parallel(this, 'Error Catcher', { resultPath: '$.result' }) .branch(providerChooser)