From 6c067e1fa53686c119b66e5d2c8e5f806cee3d07 Mon Sep 17 00:00:00 2001 From: Beth Brennan Date: Wed, 8 Feb 2023 12:22:27 -0500 Subject: [PATCH] Share default runner label list --- .../src/value-providers/runs-on.ts | 19 ++---------- .../src/value-providers/default.ts | 31 ++++++++++--------- 2 files changed, 18 insertions(+), 32 deletions(-) diff --git a/actions-languageserver/src/value-providers/runs-on.ts b/actions-languageserver/src/value-providers/runs-on.ts index 732e464..f47de7c 100644 --- a/actions-languageserver/src/value-providers/runs-on.ts +++ b/actions-languageserver/src/value-providers/runs-on.ts @@ -1,31 +1,16 @@ import {Value} from "@github/actions-languageservice/value-providers/config"; +import {DEFAULT_RUNNER_LABELS} from "@github/actions-languageservice/value-providers/default"; import {Octokit} from "@octokit/rest"; import {TTLCache} from "../utils/cache"; // Limitation: getRunnerLabels returns default hosted labels and labels for repository self-hosted runners. // It doesn't return labels for organization runners visible to the repository. export async function getRunnerLabels(client: Octokit, cache: TTLCache, owner: string, name: string): Promise { - const defaultLabels = [ - "ubuntu-latest", - "ubuntu-22.04", - "ubuntu-20.04", - "ubuntu-18.04", - "windows-latest", - "windows-2022", - "windows-2019", - "windows-2016", - "macos-latest", - "macos-12", - "macos-11", - "macos-10.15", - "self-hosted" - ]; - const repoLabels = await cache.get(`${owner}/${name}/runner-labels`, undefined, () => fetchRunnerLabels(client, owner, name) ); - for (const label of defaultLabels) { + for (const label of DEFAULT_RUNNER_LABELS) { repoLabels.add(label); } diff --git a/actions-languageservice/src/value-providers/default.ts b/actions-languageservice/src/value-providers/default.ts index b0a0ea8..8081f45 100644 --- a/actions-languageservice/src/value-providers/default.ts +++ b/actions-languageservice/src/value-providers/default.ts @@ -4,6 +4,21 @@ import {needs} from "./needs"; import {reusableJobInputs} from "./reusable-job-inputs"; import {stringsToValues} from "./strings-to-values"; +export const DEFAULT_RUNNER_LABELS = [ + "ubuntu-latest", + "ubuntu-22.04", + "ubuntu-20.04", + "ubuntu-18.04", + "windows-latest", + "windows-2022", + "windows-2019", + "macos-latest", + "macos-12", + "macos-11", + "macos-10.15", + "self-hosted" +]; + export const defaultValueProviders: ValueProviderConfig = { needs: { kind: ValueProviderKind.AllowedValues, @@ -15,20 +30,6 @@ export const defaultValueProviders: ValueProviderConfig = { }, "runs-on": { kind: ValueProviderKind.SuggestedValues, - get: async (_: WorkflowContext) => - stringsToValues([ - "ubuntu-latest", - "ubuntu-22.04", - "ubuntu-20.04", - "ubuntu-18.04", - "windows-latest", - "windows-2022", - "windows-2019", - "macos-latest", - "macos-12", - "macos-11", - "macos-10.15", - "self-hosted" - ]) + get: async (_: WorkflowContext) => stringsToValues(DEFAULT_RUNNER_LABELS) } };