Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail gracefully if no GITHUB_TOKEN #167

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
46 changes: 28 additions & 18 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,21 @@ async function run(): Promise<void> {
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;
}
if (!(await addRepoTagForPublishedTag('feature', featureId, version))) {
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);
}
}
}
Expand All @@ -108,16 +113,21 @@ async function run(): Promise<void> {
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;
}
if (!(await addRepoTagForPublishedTag('template', templateId, version))) {
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);
}
}
}
Expand Down
102 changes: 101 additions & 1 deletion src/schemas/devContainerFeature.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -234,4 +334,4 @@
"$ref": "#/definitions/Feature"
}
]
}
}
6 changes: 2 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export async function isDevcontainerCliAvailable(cliDebugMode = false): Promise<
}
}

export async function addRepoTagForPublishedTag(type: string, id: string, version: string): Promise<boolean> {
const octokit = github.getOctokit(process.env.GITHUB_TOKEN || '');
export async function addRepoTagForPublishedTag(type: string, id: string, version: string, authToken: string): Promise<void> {
const octokit = github.getOctokit(authToken);
const tag = `${type}_${id}_${version}`;
core.info(`Adding repo tag '${tag}'...`);

Expand All @@ -77,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<boolean> {
Expand Down