Unverified Commit 4ecc275a authored by Josh Spicer's avatar Josh Spicer Committed by GitHub

update action to a82f06a29168a3c6594fb7206dd0afd3af8efdf2

parent ef87daf5
name: 'Dev Container' name: 'Dev Container'
description: 'Publish custom development container feature(s) and/or templates(s)' description: 'Publish custom development container assets'
author: 'GitHub' author: 'GitHub'
branding: branding:
icon: box icon: box
...@@ -10,10 +10,6 @@ inputs: ...@@ -10,10 +10,6 @@ inputs:
required: false required: false
default: "false" default: "false"
description: "['true'/'false'] Publish dev container 'feature' artifacts" description: "['true'/'false'] Publish dev container 'feature' artifacts"
publish-templates:
required: false
default: "false"
description: "['true'/'false'] Publish dev container 'template' artifacts"
generate-docs: generate-docs:
required: false required: false
default: "false" default: "false"
...@@ -26,37 +22,11 @@ inputs: ...@@ -26,37 +22,11 @@ inputs:
description: "Relative path to the 'src' folder containing dev container 'feature(s)'" description: "Relative path to the 'src' folder containing dev container 'feature(s)'"
oci-registry: oci-registry:
required: false required: false
default: "ghcr.io"
description: "Name of the OCI registry that implements the OCI Artifact Distribution Specification" description: "Name of the OCI registry that implements the OCI Artifact Distribution Specification"
features-namespace: features-namespace:
required: false required: false
default: "<owner>/<repo>"
description: "A unique indentifier for the collection of features" description: "A unique indentifier for the collection of features"
# 'template' options
base-path-to-templates:
required: false
default: ''
description: "Relative path to the folder containing dev container 'template(s)'"
# EXPERIMENTAL
tag-individual-features:
required: false
default: "false"
description: "Tag individual features"
publish-to-npm:
required: false
default: "false"
description: "Should publish features to NPM?"
publish-release-artifacts:
required: false
default: "false"
description: "Publish release artifacts (classic)"
publish-to-oci:
required: false
default: "false"
description: "Publish to OCI?"
runs: runs:
using: 'node16' using: 'node16'
main: 'dist/index.js' main: 'dist/index.js'
This diff is collapsed.
...@@ -56,9 +56,11 @@ const FEATURES_README_TEMPLATE = ` ...@@ -56,9 +56,11 @@ const FEATURES_README_TEMPLATE = `
#{OptionsTable} #{OptionsTable}
#{Notes}
--- ---
_Note: This file was auto-generated from the [devcontainer-feature.json](#{RepoUrl})._ _Note: This file was auto-generated from the [devcontainer-feature.json](#{RepoUrl}). Add additional notes to a \`NOTES.md\`._
`; `;
const TEMPLATE_README_TEMPLATE = ` const TEMPLATE_README_TEMPLATE = `
# #{Name} # #{Name}
...@@ -107,8 +109,6 @@ function _generateDocumentation(basePath, readmeTemplate, metadataFile, ociRegis ...@@ -107,8 +109,6 @@ function _generateDocumentation(basePath, readmeTemplate, metadataFile, ociRegis
return; return;
} }
const srcInfo = (0, utils_1.getGitHubMetadata)(); const srcInfo = (0, utils_1.getGitHubMetadata)();
const owner = srcInfo.owner;
const repo = srcInfo.repo;
// Add version // Add version
let version = 'latest'; let version = 'latest';
const parsedVersion = parsedJson === null || parsedJson === void 0 ? void 0 : parsedJson.version; const parsedVersion = parsedJson === null || parsedJson === void 0 ? void 0 : parsedJson.version;
...@@ -131,6 +131,10 @@ function _generateDocumentation(basePath, readmeTemplate, metadataFile, ociRegis ...@@ -131,6 +131,10 @@ function _generateDocumentation(basePath, readmeTemplate, metadataFile, ociRegis
.join('\n'); .join('\n');
return '| Options Id | Description | Type | Default Value |\n' + '|-----|-----|-----|-----|\n' + contents; return '| Options Id | Description | Type | Default Value |\n' + '|-----|-----|-----|-----|\n' + contents;
}; };
const generateNotesMarkdown = () => {
const notesPath = path.join(basePath, f, 'NOTES.md');
return fs.existsSync(notesPath) ? fs.readFileSync(path.join(notesPath), 'utf8') : '';
};
let urlToConfig = './devcontainer-feature.json'; let urlToConfig = './devcontainer-feature.json';
const basePathTrimmed = basePath.startsWith('./') ? basePath.substring(2) : basePath; const basePathTrimmed = basePath.startsWith('./') ? basePath.substring(2) : basePath;
if (srcInfo.owner && srcInfo.repo) { if (srcInfo.owner && srcInfo.repo) {
...@@ -142,9 +146,10 @@ function _generateDocumentation(basePath, readmeTemplate, metadataFile, ociRegis ...@@ -142,9 +146,10 @@ function _generateDocumentation(basePath, readmeTemplate, metadataFile, ociRegis
.replace('#{Name}', parsedJson.name ? `${parsedJson.name} (${parsedJson.id})` : `${parsedJson.id}`) .replace('#{Name}', parsedJson.name ? `${parsedJson.name} (${parsedJson.id})` : `${parsedJson.id}`)
.replace('#{Description}', (_a = parsedJson.description) !== null && _a !== void 0 ? _a : '') .replace('#{Description}', (_a = parsedJson.description) !== null && _a !== void 0 ? _a : '')
.replace('#{OptionsTable}', generateOptionsMarkdown()) .replace('#{OptionsTable}', generateOptionsMarkdown())
.replace('#{Notes}', generateNotesMarkdown())
// Features Only // Features Only
.replace('#{Registry}', ociRegistry) .replace('#{Registry}', ociRegistry)
.replace('#{Namespace}', namespace == '<owner>/<repo>' ? `${owner}/${repo}` : namespace) .replace('#{Namespace}', namespace)
.replace('#{Version}', version) .replace('#{Version}', version)
// Templates Only // Templates Only
.replace('#{ManifestName}', (_c = (_b = parsedJson === null || parsedJson === void 0 ? void 0 : parsedJson.image) === null || _b === void 0 ? void 0 : _b.manifest) !== null && _c !== void 0 ? _c : '') .replace('#{ManifestName}', (_c = (_b = parsedJson === null || parsedJson === void 0 ? void 0 : parsedJson.image) === null || _b === void 0 ? void 0 : _b.manifest) !== null && _c !== void 0 ? _c : '')
......
...@@ -39,83 +39,55 @@ Object.defineProperty(exports, "__esModule", { value: true }); ...@@ -39,83 +39,55 @@ Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(require("@actions/core")); const core = __importStar(require("@actions/core"));
const generateDocs_1 = require("./generateDocs"); const generateDocs_1 = require("./generateDocs");
const utils_1 = require("./utils"); const utils_1 = require("./utils");
const exec = __importStar(require("@actions/exec"));
function run() { function run() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
core.debug('Reading input parameters...'); core.debug('Reading input parameters...');
// Read inputs // Read inputs
const shouldPublishFeatures = core.getInput('publish-features').toLowerCase() === 'true'; const shouldPublishFeatures = core.getInput('publish-features').toLowerCase() === 'true';
const shouldPublishTemplates = core.getInput('publish-templates').toLowerCase() === 'true';
const shouldGenerateDocumentation = core.getInput('generate-docs').toLowerCase() === 'true'; const shouldGenerateDocumentation = core.getInput('generate-docs').toLowerCase() === 'true';
// Experimental
const shouldTagIndividualFeatures = core.getInput('tag-individual-features').toLowerCase() === 'true';
const shouldPublishToNPM = core.getInput('publish-to-npm').toLowerCase() === 'true';
const shouldPublishReleaseArtifacts = core.getInput('publish-release-artifacts').toLowerCase() === 'true';
const shouldPublishToOCI = core.getInput('publish-to-oci').toLowerCase() === 'true';
const opts = {
shouldTagIndividualFeatures,
shouldPublishToNPM,
shouldPublishReleaseArtifacts,
shouldPublishToOCI
};
const featuresBasePath = core.getInput('base-path-to-features'); const featuresBasePath = core.getInput('base-path-to-features');
const templatesBasePath = core.getInput('base-path-to-templates'); const sourceMetadata = (0, utils_1.getGitHubMetadata)();
const ociRegistry = core.getInput('oci-registry'); const inputOciRegistry = core.getInput('oci-registry');
const namespace = core.getInput('features-namespace'); const ociRegistry = inputOciRegistry && inputOciRegistry !== '' ? inputOciRegistry : 'ghcr.io';
let featuresMetadata = undefined; const inputNamespace = core.getInput('namespace');
let templatesMetadata = undefined; const namespace = inputNamespace && inputNamespace !== '' ? inputNamespace : `${sourceMetadata.owner}/${sourceMetadata.repo}`;
// -- Package Release Artifacts const cliDebugMode = core.getInput('devcontainer-cli-debug-mode').toLowerCase() === 'true';
// -- Publish
if (shouldPublishFeatures) { if (shouldPublishFeatures) {
core.info('Publishing features...'); core.info('Publishing features...');
featuresMetadata = yield packageFeatures(featuresBasePath, opts); yield publishFeatures(featuresBasePath, ociRegistry, namespace, cliDebugMode);
}
if (shouldPublishTemplates) {
core.info('Publishing template...');
templatesMetadata = yield packageTemplates(templatesBasePath);
} }
// -- Generate Documentation // -- Generate Documentation
if (shouldGenerateDocumentation && featuresBasePath) { if (shouldGenerateDocumentation && featuresBasePath) {
core.info('Generating documentation for features...'); core.info('Generating documentation for features...');
yield (0, generateDocs_1.generateFeaturesDocumentation)(featuresBasePath, ociRegistry, namespace); yield (0, generateDocs_1.generateFeaturesDocumentation)(featuresBasePath, ociRegistry, namespace);
} }
if (shouldGenerateDocumentation && templatesBasePath) {
core.info('Generating documentation for templates...');
yield (0, generateDocs_1.generateTemplateDocumentation)(templatesBasePath);
}
// -- Programatically add feature/template metadata to collections file.
core.info('Generating metadata file: devcontainer-collection.json');
yield (0, utils_1.addCollectionsMetadataFile)(featuresMetadata, templatesMetadata, opts);
}); });
} }
function packageFeatures(basePath, opts) { function publishFeatures(basePath, ociRegistry, namespace, cliDebugMode = false) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try { // Ensures we have the devcontainer CLI installed.
core.info(`Archiving all features in ${basePath}`); if (!(yield (0, utils_1.ensureDevcontainerCliPresent)(cliDebugMode))) {
const metadata = yield (0, utils_1.getFeaturesAndPackage)(basePath, opts); core.setFailed('Failed to install devcontainer CLI');
core.info('Packaging features has finished.'); return false;
return metadata;
}
catch (error) {
if (error instanceof Error) {
core.setFailed(error.message);
}
} }
return;
});
}
function packageTemplates(basePath) {
return __awaiter(this, void 0, void 0, function* () {
try { try {
core.info(`Archiving all templates in ${basePath}`); let cmd = 'devcontainer';
const metadata = yield (0, utils_1.getTemplatesAndPackage)(basePath); let args = ['features', 'publish', '-r', ociRegistry, '-n', namespace, basePath];
core.info('Packaging templates has finished.'); if (cliDebugMode) {
return metadata; cmd = 'npx';
} args = ['-y', './devcontainer.tgz', ...args];
catch (error) {
if (error instanceof Error) {
core.setFailed(error.message);
} }
const res = yield exec.getExecOutput(cmd, args, {
ignoreReturnCode: true
});
return res.exitCode === 0;
}
catch (err) {
core.setFailed(err === null || err === void 0 ? void 0 : err.message);
return false;
} }
return;
}); });
} }
run(); run();
This diff is collapsed.
...@@ -8,20 +8,11 @@ jobs: ...@@ -8,20 +8,11 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Install Oras
run: |
curl -LO https://github.com/oras-project/oras/releases/download/v0.13.0/oras_0.13.0_linux_amd64.tar.gz
mkdir -p oras-install/
tar -zxf oras_0.13.0_*.tar.gz -C oras-install/
mv oras-install/oras /usr/local/bin/
rm -rf oras_0.13.0_*.tar.gz oras-install/
- name: "Publish features to OCI" - name: "Publish features to OCI"
uses: ./.github/devcontainers-action # TODO: Once 'devcontainers/action' is published, use that. uses: ./.github/devcontainers-action # TODO: Once 'devcontainers/action' is published, use that.
with: with:
publish-features: "true" publish-features: "true"
publish-to-oci: "true"
base-path-to-features: "./src" base-path-to-features: "./src"
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment