Skip to content
Closed
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
node_modules


dist

# Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
# Logs
logs
Expand Down
53 changes: 42 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import * as core from '@actions/core';
import { generateFeaturesDocumentation, generateTemplateDocumentation } from './generateDocs';
import { ensureDevcontainerCliPresent, getGitHubMetadata } from './utils';
import { addRepoTagForPublishedTag, ensureDevcontainerCliPresent, getGitHubMetadata } from './utils';
import * as exec from '@actions/exec';

async function run(): Promise<void> {
Expand Down Expand Up @@ -52,19 +52,43 @@ async function run(): Promise<void> {
}

if (shouldPublishFeatures) {
core.info('Publishing features...');
if (!(await publish('feature', featuresBasePath, featuresOciRegistry, featuresNamespace, cliDebugMode))) {
core.setFailed('(!) Failed to publish features.');
core.info('Publishing Features...');
const publishedFeatures = await publish('feature', featuresBasePath, featuresOciRegistry, featuresNamespace, cliDebugMode);
if (!publishedFeatures) {
core.setFailed('(!) Failed to publish Features.');
return;
}

// Add repo tags at the current commit.
for (const featureId in publishedFeatures) {
const versions = publishedFeatures[featureId];
for (const version of versions) {
if (!(await addRepoTagForPublishedTag('feature', featureId, version))) {
core.setFailed('(!) Failed to add repo tag for a Feature release.');
continue;
}
}
}
}

if (shouldPublishTemplates) {
core.info('Publishing templates...');
if (!(await publish('template', templatesBasePath, templatesOciRegistry, templatesNamespace, cliDebugMode))) {
core.setFailed('(!) Failed to publish templates.');
core.info('Publishing Templates...');
const publishedTemplates = await publish('template', templatesBasePath, templatesOciRegistry, templatesNamespace, cliDebugMode);
if (!publishedTemplates) {
core.setFailed('(!) Failed to publish Templates.');
return;
}

// Add repo tags at the current commit.
for (const templateId in publishedTemplates) {
const versions = publishedTemplates[templateId];
for (const version of versions) {
if (!(await addRepoTagForPublishedTag('template', templateId, version))) {
core.setFailed('(!) Failed to add repo tag for a Template release.');
continue;
}
}
}
}

// -- Generate Documentation
Expand All @@ -80,11 +104,17 @@ async function run(): Promise<void> {
}
}

async function publish(collectionType: string, basePath: string, ociRegistry: string, namespace: string, cliDebugMode = false): Promise<boolean> {
async function publish(
collectionType: string,
basePath: string,
ociRegistry: string,
namespace: string,
cliDebugMode = false
): Promise<{ [featureId: string]: [string] } | undefined> {
// Ensures we have the devcontainer CLI installed.
if (!(await ensureDevcontainerCliPresent(cliDebugMode))) {
core.setFailed('Failed to install devcontainer CLI');
return false;
return;
}

try {
Expand All @@ -97,10 +127,11 @@ async function publish(collectionType: string, basePath: string, ociRegistry: st

// Fails on non-zero exit code from the invoked process
const res = await exec.getExecOutput(cmd, args, {});
return res.exitCode === 0;
const result = JSON.parse(res.stdout);
return result;
} catch (err: any) {
core.setFailed(err?.message);
return false;
return;
}
}

Expand Down
30 changes: 30 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,36 @@ 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 || '');
const tag = `${type}_${id}_v${version}`;
core.info(`Adding repo tag '${tag}'...`);

try {
await octokit.rest.git.createRef({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
ref: `refs/tags/${tag}`,
sha: github.context.sha
});

await octokit.rest.git.createTag({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
tag,
message: `${tag}`,
object: github.context.sha,
type: 'commit'
});
} catch (err) {
core.error(`Failed to add tag '${tag}' to repo: ${err}`);
return false;
}

core.info(`Tag '${tag}' added.`);
return true;
}

export async function ensureDevcontainerCliPresent(cliDebugMode = false): Promise<boolean> {
if (await isDevcontainerCliAvailable(cliDebugMode)) {
core.info('devcontainer CLI is already installed');
Expand Down