diff options
author | Josh Spicer <joshspicer@github.com> | 2022-06-22 21:51:23 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-22 21:51:23 +0300 |
commit | 43fd91f7b38f4ba8674ccafb10e8f392a0f433b4 (patch) | |
tree | 698b8deb64ed409d3cbc305da40737a49b7dd467 /.github/devcontainers-action/lib | |
parent | 6f107d547e2ee4d261bf45437294e9758e6027a2 (diff) |
no-ci - update action (generate features collection artifact)
Diffstat (limited to '.github/devcontainers-action/lib')
-rw-r--r-- | .github/devcontainers-action/lib/main.js | 14 | ||||
-rw-r--r-- | .github/devcontainers-action/lib/utils.js | 20 |
2 files changed, 24 insertions, 10 deletions
diff --git a/.github/devcontainers-action/lib/main.js b/.github/devcontainers-action/lib/main.js index c0327d7..2c0ea73 100644 --- a/.github/devcontainers-action/lib/main.js +++ b/.github/devcontainers-action/lib/main.js @@ -46,14 +46,17 @@ function run() { const shouldPublishFeatures = core.getInput('publish-features').toLowerCase() === 'true'; const shouldPublishTemplate = core.getInput('publish-templates').toLowerCase() === 'true'; const shouldGenerateDocumentation = core.getInput('generate-docs').toLowerCase() === 'true'; + let featuresMetadata = undefined; + let templatesMetadata = undefined; if (shouldPublishFeatures) { core.info('Publishing features...'); const featuresBasePath = core.getInput('base-path-to-features'); - yield packageFeatures(featuresBasePath); + featuresMetadata = yield packageFeatures(featuresBasePath); } if (shouldPublishTemplate) { core.info('Publishing template...'); const basePathToDefinitions = core.getInput('base-path-to-templates'); + templatesMetadata = undefined; // TODO yield packageTemplates(basePathToDefinitions); } if (shouldGenerateDocumentation) { @@ -69,20 +72,23 @@ function run() { } // TODO: Programatically add feature/template fino with relevant metadata for UX clients. core.info('Generation metadata file: devcontainer-collection.json'); - yield (0, utils_1.addCollectionsMetadataFile)(); + yield (0, utils_1.addCollectionsMetadataFile)(featuresMetadata, templatesMetadata); }); } function packageFeatures(basePath) { return __awaiter(this, void 0, void 0, function* () { try { core.info(`Archiving all features in ${basePath}`); - yield (0, utils_1.getFeaturesAndPackage)(basePath); + const metadata = yield (0, utils_1.getFeaturesAndPackage)(basePath); core.info('Packaging features has finished.'); + return metadata; } catch (error) { - if (error instanceof Error) + if (error instanceof Error) { core.setFailed(error.message); + } } + return; }); } function packageTemplates(basePath) { diff --git a/.github/devcontainers-action/lib/utils.js b/.github/devcontainers-action/lib/utils.js index 7253a8d..44d7978 100644 --- a/.github/devcontainers-action/lib/utils.js +++ b/.github/devcontainers-action/lib/utils.js @@ -62,7 +62,7 @@ function tarDirectory(path, tgzName) { }); } exports.tarDirectory = tarDirectory; -function addCollectionsMetadataFile() { +function addCollectionsMetadataFile(featuresMetadata, templatesMetadata) { return __awaiter(this, void 0, void 0, function* () { const p = path_1.default.join('.', 'devcontainer-collection.json'); // Insert github repo metadata @@ -81,8 +81,8 @@ function addCollectionsMetadataFile() { } const metadata = { sourceInformation, - features: [], - templates: [] + features: featuresMetadata || [], + templates: templatesMetadata || [] }; // Write to the file yield (0, exports.writeLocalFile)(p, JSON.stringify(metadata, undefined, 4)); @@ -91,7 +91,7 @@ function addCollectionsMetadataFile() { exports.addCollectionsMetadataFile = addCollectionsMetadataFile; function getFeaturesAndPackage(basePath) { return __awaiter(this, void 0, void 0, function* () { - let archives = []; + let metadatas = []; fs.readdir(basePath, (err, files) => { if (err) { core.error(err.message); @@ -101,13 +101,21 @@ function getFeaturesAndPackage(basePath) { files.forEach(file => { core.info(`feature ==> ${file}`); if (file !== '.' && file !== '..') { + const featureFolder = path_1.default.join(basePath, file); const archiveName = `${file}.tgz`; tarDirectory(`${basePath}/${file}`, archiveName); - archives.push(archiveName); + const featureJsonPath = path_1.default.join(featureFolder, "devcontainer-feature.json"); + if (!fs.existsSync(featureJsonPath)) { + core.error(`Feature ${file} is missing a devcontainer-feature.json`); + core.setFailed('All features must have a devcontainer-feature.json'); + return; + } + const featureMetadata = JSON.parse(fs.readFileSync(featureJsonPath, "utf8")); + metadatas.push(featureMetadata); } }); }); - return archives; + return metadatas; }); } exports.getFeaturesAndPackage = getFeaturesAndPackage; |