From 1a081835b1ba119586d2e453f112dd5ea0e789ae Mon Sep 17 00:00:00 2001 From: Josh Spicer Date: Fri, 31 Mar 2023 18:01:27 +0000 Subject: [PATCH 1/2] fail gracefully if no GITHUB_TOKEN --- src/main.ts | 8 ++------ src/utils.ts | 5 +++++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main.ts b/src/main.ts index 1735fae..313218d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -93,9 +93,7 @@ async function run(): Promise { core.debug(`No version available for '${featureId}', so no repo tag was added for Feature`); continue; } - if (!(await addRepoTagForPublishedTag('feature', featureId, version))) { - continue; - } + await addRepoTagForPublishedTag('feature', featureId, version); } } } @@ -116,9 +114,7 @@ async function run(): Promise { core.debug(`No version available for '${templateId}', so no repo tag was added for Feature`); continue; } - if (!(await addRepoTagForPublishedTag('template', templateId, version))) { - continue; - } + await addRepoTagForPublishedTag('template', templateId, version); } } } diff --git a/src/utils.ts b/src/utils.ts index 4bdd346..c2f179e 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -54,6 +54,11 @@ export async function isDevcontainerCliAvailable(cliDebugMode = false): Promise< } export async function addRepoTagForPublishedTag(type: string, id: string, version: string): Promise { + if (process.env.GITHUB_TOKEN === undefined || process.env.GITHUB_TOKEN === '') { + core.warning('GITHUB_TOKEN is not set, skipping adding repo tag.'); + return false; + } + const octokit = github.getOctokit(process.env.GITHUB_TOKEN || ''); const tag = `${type}_${id}_${version}`; core.info(`Adding repo tag '${tag}'...`); From 0cb976aff3f44568f6c74d69d5fd299ba7d2ae25 Mon Sep 17 00:00:00 2001 From: Josh Spicer Date: Tue, 4 Apr 2023 21:05:04 +0000 Subject: [PATCH 2/2] clean up changes --- src/main.ts | 42 +++++--- src/schemas/devContainerFeature.schema.json | 102 +++++++++++++++++++- src/utils.ts | 11 +-- 3 files changed, 131 insertions(+), 24 deletions(-) diff --git a/src/main.ts b/src/main.ts index 313218d..6a8cd8f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -85,15 +85,22 @@ async function run(): Promise { return; } - // Add repo tag for this version at the current commit. + // Add repo tag for newly published Feature(s) at the current commit. if (!disableRepoTagging) { - for (const featureId in publishedFeatures) { - const version = publishedFeatures[featureId]?.version; - if (!version) { - core.debug(`No version available for '${featureId}', so no repo tag was added for Feature`); - continue; + const authToken = process.env.GITHUB_TOKEN; + if (!authToken) { + core.warning(`Repo tagging will be skipped because a 'GITHUB_TOKEN' is not set on this action.`); + } else { + // Add the repo tags + for (const featureId in publishedFeatures) { + const version = publishedFeatures[featureId]?.version; + if (!version) { + core.debug(`No version available for '${featureId}', so no repo tag was added for Feature`); + continue; + } + + await addRepoTagForPublishedTag('feature', featureId, version, authToken); } - await addRepoTagForPublishedTag('feature', featureId, version); } } } @@ -106,15 +113,22 @@ async function run(): Promise { return; } - // Add repo tag for this version at the current commit. + // Add repo tag for newly published Template(s) at the current commit. if (!disableRepoTagging) { - for (const templateId in publishedTemplates) { - const version = publishedTemplates[templateId]?.version; - if (!version) { - core.debug(`No version available for '${templateId}', so no repo tag was added for Feature`); - continue; + const authToken = process.env.GITHUB_TOKEN; + if (!authToken) { + core.warning(`Repo tagging will be skipped because a 'GITHUB_TOKEN' is not set on this action.`); + } else { + // Add the repo tags + for (const templateId in publishedTemplates) { + const version = publishedTemplates[templateId]?.version; + if (!version) { + core.debug(`No version available for '${templateId}', so no repo tag was added for Feature`); + continue; + } + + await addRepoTagForPublishedTag('template', templateId, version, authToken); } - await addRepoTagForPublishedTag('template', templateId, version); } } } diff --git a/src/schemas/devContainerFeature.schema.json b/src/schemas/devContainerFeature.schema.json index ce8ed87..4724161 100644 --- a/src/schemas/devContainerFeature.schema.json +++ b/src/schemas/devContainerFeature.schema.json @@ -102,6 +102,106 @@ "deprecated": { "description": "Indicates that the Feature is deprecated, and will not receive any further updates/support. This property is intended to be used by the supporting tools for highlighting Feature deprecation.", "type": "boolean" + }, + "onCreateCommand": { + "type": [ + "string", + "array", + "object" + ], + "description": "A command to run when creating the container. This command is run after \"initializeCommand\" and before \"updateContentCommand\". If this is a single string, it will be run in a shell. If this is an array of strings, it will be run as a single command without shell. If this is an object, each provided command will be run in parallel.", + "items": { + "type": "string" + }, + "additionalProperties": { + "type": [ + "string", + "array" + ], + "items": { + "type": "string" + } + } + }, + "updateContentCommand": { + "type": [ + "string", + "array", + "object" + ], + "description": "A command to run when creating the container and rerun when the workspace content was updated while creating the container. This command is run after \"onCreateCommand\" and before \"postCreateCommand\". If this is a single string, it will be run in a shell. If this is an array of strings, it will be run as a single command without shell. If this is an object, each provided command will be run in parallel.", + "items": { + "type": "string" + }, + "additionalProperties": { + "type": [ + "string", + "array" + ], + "items": { + "type": "string" + } + } + }, + "postCreateCommand": { + "type": [ + "string", + "array", + "object" + ], + "description": "A command to run after creating the container. This command is run after \"updateContentCommand\" and before \"postStartCommand\". If this is a single string, it will be run in a shell. If this is an array of strings, it will be run as a single command without shell. If this is an object, each provided command will be run in parallel.", + "items": { + "type": "string" + }, + "additionalProperties": { + "type": [ + "string", + "array" + ], + "items": { + "type": "string" + } + } + }, + "postStartCommand": { + "type": [ + "string", + "array", + "object" + ], + "description": "A command to run after starting the container. This command is run after \"postCreateCommand\" and before \"postAttachCommand\". If this is a single string, it will be run in a shell. If this is an array of strings, it will be run as a single command without shell. If this is an object, each provided command will be run in parallel.", + "items": { + "type": "string" + }, + "additionalProperties": { + "type": [ + "string", + "array" + ], + "items": { + "type": "string" + } + } + }, + "postAttachCommand": { + "type": [ + "string", + "array", + "object" + ], + "description": "A command to run when attaching to the container. This command is run after \"postStartCommand\". If this is a single string, it will be run in a shell. If this is an array of strings, it will be run as a single command without shell. If this is an object, each provided command will be run in parallel.", + "items": { + "type": "string" + }, + "additionalProperties": { + "type": [ + "string", + "array" + ], + "items": { + "type": "string" + } + } } }, "required": [ @@ -234,4 +334,4 @@ "$ref": "#/definitions/Feature" } ] -} +} \ No newline at end of file diff --git a/src/utils.ts b/src/utils.ts index c2f179e..4e1a8a9 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -53,13 +53,8 @@ export async function isDevcontainerCliAvailable(cliDebugMode = false): Promise< } } -export async function addRepoTagForPublishedTag(type: string, id: string, version: string): Promise { - if (process.env.GITHUB_TOKEN === undefined || process.env.GITHUB_TOKEN === '') { - core.warning('GITHUB_TOKEN is not set, skipping adding repo tag.'); - return false; - } - - const octokit = github.getOctokit(process.env.GITHUB_TOKEN || ''); +export async function addRepoTagForPublishedTag(type: string, id: string, version: string, authToken: string): Promise { + const octokit = github.getOctokit(authToken); const tag = `${type}_${id}_${version}`; core.info(`Adding repo tag '${tag}'...`); @@ -82,11 +77,9 @@ export async function addRepoTagForPublishedTag(type: string, id: string, versio } catch (err) { core.warning(`Failed to automatically add repo tag, manually tag with: 'git tag ${tag} ${github.context.sha}'`); core.debug(`${err}`); - return false; } core.info(`Tag '${tag}' added.`); - return true; } export async function ensureDevcontainerCliPresent(cliDebugMode = false): Promise {