Skip to content

Instantly share code, notes, and snippets.

@pirogoeth
Last active July 10, 2025 03:55
Show Gist options
  • Select an option

  • Save pirogoeth/c307135f46c479c5c4ae6aba780627c3 to your computer and use it in GitHub Desktop.

Select an option

Save pirogoeth/c307135f46c479c5c4ae6aba780627c3 to your computer and use it in GitHub Desktop.
komodo utils
interface VersionUpdateResponse {
message: string;
oldVersion?: string;
newVersion: string;
associatedStacks: string[];
};
//@ts-expect-error(2739)
var output: VersionUpdateResponse = {};
if (varName === undefined) {
throw new Error('varName is undefined - please set it!');
}
if (repoSlug === undefined) {
throw new Error('repoSlug is undefined - please set it!')
}
const currentReleaseResp = await fetch(`https://api.github.com/repos/${repoSlug}/releases/latest`, {
headers: {
'accept': 'application/vnd.github+json',
'x-github-api-version': '2022-11-28',
},
});
const currentRelease = await currentReleaseResp.json();
if (currentRelease.message === "Not Found") {
throw new Error(`Releases endpoint for repo '${repoSlug}' returned not found - is the slug correct?`);
}
const currentReleaseTag = tagTransformer(currentRelease.tag_name);
// TODO: Find first regular release instead of bailing on prerelease
if (currentRelease.prerelease) {
output.message = `Avoiding prerelease version ${currentReleaseTag}`;
return console.error(JSON.stringify(output));
}
console.log(`Release: ${JSON.stringify(currentRelease)}`);
output.newVersion = currentReleaseTag;
try {
let previousVersion = await komodo.read('GetVariable', { name: varName });
output.oldVersion = previousVersion.value;
if (previousVersion?.value === currentReleaseTag) {
output.message = `No version update needed; latest ${currentReleaseTag}`;
return console.error(JSON.stringify(output));
}
console.log(`Updating ${varName} from ${previousVersion.value} -> ${currentReleaseTag}`);
await komodo.write('UpdateVariableValue', {
name: varName,
value: currentReleaseTag,
});
output.message = `Found new version for ${repoSlug} - updated existing variable ${varName}`;
} catch (err) {
console.log(`Creating variable ${varName} => ${currentReleaseTag}`);
await komodo.write('CreateVariable', {
name: varName,
value: currentReleaseTag,
description: `Version field for ${repoSlug}`,
is_secret: false,
});
output.message = `Version variable for ${repoSlug} did not exist, created ${varName}`;
}
// Find associated stacks
const stacks = await komodo.read('ListStacks', {
query: {
tags: [`associatedRepo-${repoSlug}`],
},
})
output.associatedStacks = stacks.map(stackInfo => stackInfo.name);
console.error(JSON.stringify(output));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment