Skip to content

Commit

Permalink
update to support tarball
Browse files Browse the repository at this point in the history
  • Loading branch information
joshspicer authored Aug 8, 2022
1 parent fabcba0 commit aead4e8
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 30 deletions.
8 changes: 8 additions & 0 deletions .github/devcontainers-action/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ inputs:
required: false
default: ''
description: "Relative path to the 'src' folder containing dev container 'feature(s)'"
oci-registry:
required: false
default: "ghcr.io"
description: "Name of the OCI registry that implements the OCI Artifact Distribution Specification"
features-namespace:
required: false
default: "<owner>/<repo>"
description: "A unique indentifier for the collection of features"

# 'template' options
base-path-to-templates:
Expand Down
33 changes: 19 additions & 14 deletions .github/devcontainers-action/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const FEATURES_README_TEMPLATE = `

\`\`\`json
"features": {
"#{Nwo}/#{Id}@#{VersionTag}": {
"#{Registry}/#{Namespace}/#{Id}:#{Version}": {
"version": "latest"
}
}
Expand All @@ -76,9 +76,9 @@ const TEMPLATE_README_TEMPLATE = `

#{OptionsTable}
`;
function generateFeaturesDocumentation(basePath) {
function generateFeaturesDocumentation(basePath, ociRegistry, namespace) {
return __awaiter(this, void 0, void 0, function* () {
yield _generateDocumentation(basePath, FEATURES_README_TEMPLATE, 'devcontainer-feature.json');
yield _generateDocumentation(basePath, FEATURES_README_TEMPLATE, 'devcontainer-feature.json', ociRegistry, namespace);
});
}
exports.generateFeaturesDocumentation = generateFeaturesDocumentation;
Expand All @@ -88,7 +88,7 @@ function generateTemplateDocumentation(basePath) {
});
}
exports.generateTemplateDocumentation = generateTemplateDocumentation;
function _generateDocumentation(basePath, readmeTemplate, metadataFile) {
function _generateDocumentation(basePath, readmeTemplate, metadataFile, ociRegistry = '', namespace = '') {
return __awaiter(this, void 0, void 0, function* () {
const directories = fs.readdirSync(basePath);
yield Promise.all(directories.map((f) => __awaiter(this, void 0, void 0, function* () {
Expand All @@ -114,13 +114,15 @@ function _generateDocumentation(basePath, readmeTemplate, metadataFile) {
return;
}
const srcInfo = (0, utils_1.getGitHubMetadata)();
const ref = srcInfo.ref;
const owner = srcInfo.owner;
const repo = srcInfo.repo;
// Add tag if parseable
let versionTag = 'latest';
if (ref && ref.includes('refs/tags/')) {
versionTag = ref.replace('refs/tags/', '');
// Add version
let version = 'latest';
const parsedVersion = parsedJson === null || parsedJson === void 0 ? void 0 : parsedJson.version;
if (parsedVersion) {
// example - 1.0.0
const splitVersion = parsedVersion.split('.');
version = splitVersion[0];
}
const generateOptionsMarkdown = () => {
const options = parsedJson === null || parsedJson === void 0 ? void 0 : parsedJson.options;
Expand Down Expand Up @@ -148,8 +150,9 @@ function _generateDocumentation(basePath, readmeTemplate, metadataFile) {
.replace('#{Description}', (_a = parsedJson.description) !== null && _a !== void 0 ? _a : '')
.replace('#{OptionsTable}', generateOptionsMarkdown())
// Features Only
.replace('#{Nwo}', `${owner}/${repo}`)
.replace('#{VersionTag}', versionTag)
.replace('#{Registry}', ociRegistry)
.replace('#{Namespace}', namespace == '<owner>/<repo>' ? `${owner}/${repo}` : namespace)
.replace('#{Version}', version)
// 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('#{RepoUrl}', urlToConfig);
Expand Down Expand Up @@ -232,6 +235,8 @@ function run() {
};
const featuresBasePath = core.getInput('base-path-to-features');
const templatesBasePath = core.getInput('base-path-to-templates');
const ociRegistry = core.getInput('oci-registry');
const namespace = core.getInput('features-namespace');
let featuresMetadata = undefined;
let templatesMetadata = undefined;
// -- Package Release Artifacts
Expand All @@ -246,7 +251,7 @@ function run() {
// -- Generate Documentation
if (shouldGenerateDocumentation && featuresBasePath) {
core.info('Generating documentation for features...');
yield (0, generateDocs_1.generateFeaturesDocumentation)(featuresBasePath);
yield (0, generateDocs_1.generateFeaturesDocumentation)(featuresBasePath, ociRegistry, namespace);
}
if (shouldGenerateDocumentation && templatesBasePath) {
core.info('Generating documentation for templates...');
Expand Down Expand Up @@ -456,7 +461,7 @@ exports.addCollectionsMetadataFile = addCollectionsMetadataFile;
function pushArtifactToOCI(version, featureName, artifactPath) {
return __awaiter(this, void 0, void 0, function* () {
const exec = (0, util_1.promisify)(child_process.exec);
const versions = [version, '1.0', '1']; // TODO: don't hardcode ofc.
const versions = [version, '1.0', '1', 'latest']; // TODO: Generate semantic versions from 'version'
const sourceInfo = getGitHubMetadata();
yield Promise.all(versions.map((v) => __awaiter(this, void 0, void 0, function* () {
const ociRepo = `${sourceInfo.owner}/${sourceInfo.repo}/${featureName}:${v}`;
Expand Down Expand Up @@ -543,7 +548,7 @@ function getFeaturesAndPackage(basePath, opts) {
core.setFailed('Could not determine repository owner.');
return;
}
const archiveName = `${f}.tgz`;
const archiveName = `devcontainer-feature-${f}.tgz`;
// ---- PUBLISH RELEASE ARTIFACTS (classic method) ----
if (shouldPublishReleaseArtifacts || shouldPublishToOCI) {
core.info(`** Tar'ing feature`);
Expand Down
2 changes: 1 addition & 1 deletion .github/devcontainers-action/dist/index.js.map

Large diffs are not rendered by default.

25 changes: 14 additions & 11 deletions .github/devcontainers-action/lib/generateDocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const FEATURES_README_TEMPLATE = `
\`\`\`json
"features": {
"#{Nwo}/#{Id}@#{VersionTag}": {
"#{Registry}/#{Namespace}/#{Id}:#{Version}": {
"version": "latest"
}
}
Expand All @@ -69,9 +69,9 @@ const TEMPLATE_README_TEMPLATE = `
#{OptionsTable}
`;
function generateFeaturesDocumentation(basePath) {
function generateFeaturesDocumentation(basePath, ociRegistry, namespace) {
return __awaiter(this, void 0, void 0, function* () {
yield _generateDocumentation(basePath, FEATURES_README_TEMPLATE, 'devcontainer-feature.json');
yield _generateDocumentation(basePath, FEATURES_README_TEMPLATE, 'devcontainer-feature.json', ociRegistry, namespace);
});
}
exports.generateFeaturesDocumentation = generateFeaturesDocumentation;
Expand All @@ -81,7 +81,7 @@ function generateTemplateDocumentation(basePath) {
});
}
exports.generateTemplateDocumentation = generateTemplateDocumentation;
function _generateDocumentation(basePath, readmeTemplate, metadataFile) {
function _generateDocumentation(basePath, readmeTemplate, metadataFile, ociRegistry = '', namespace = '') {
return __awaiter(this, void 0, void 0, function* () {
const directories = fs.readdirSync(basePath);
yield Promise.all(directories.map((f) => __awaiter(this, void 0, void 0, function* () {
Expand All @@ -107,13 +107,15 @@ function _generateDocumentation(basePath, readmeTemplate, metadataFile) {
return;
}
const srcInfo = (0, utils_1.getGitHubMetadata)();
const ref = srcInfo.ref;
const owner = srcInfo.owner;
const repo = srcInfo.repo;
// Add tag if parseable
let versionTag = 'latest';
if (ref && ref.includes('refs/tags/')) {
versionTag = ref.replace('refs/tags/', '');
// Add version
let version = 'latest';
const parsedVersion = parsedJson === null || parsedJson === void 0 ? void 0 : parsedJson.version;
if (parsedVersion) {
// example - 1.0.0
const splitVersion = parsedVersion.split('.');
version = splitVersion[0];
}
const generateOptionsMarkdown = () => {
const options = parsedJson === null || parsedJson === void 0 ? void 0 : parsedJson.options;
Expand Down Expand Up @@ -141,8 +143,9 @@ function _generateDocumentation(basePath, readmeTemplate, metadataFile) {
.replace('#{Description}', (_a = parsedJson.description) !== null && _a !== void 0 ? _a : '')
.replace('#{OptionsTable}', generateOptionsMarkdown())
// Features Only
.replace('#{Nwo}', `${owner}/${repo}`)
.replace('#{VersionTag}', versionTag)
.replace('#{Registry}', ociRegistry)
.replace('#{Namespace}', namespace == '<owner>/<repo>' ? `${owner}/${repo}` : namespace)
.replace('#{Version}', version)
// 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('#{RepoUrl}', urlToConfig);
Expand Down
4 changes: 3 additions & 1 deletion .github/devcontainers-action/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ function run() {
};
const featuresBasePath = core.getInput('base-path-to-features');
const templatesBasePath = core.getInput('base-path-to-templates');
const ociRegistry = core.getInput('oci-registry');
const namespace = core.getInput('features-namespace');
let featuresMetadata = undefined;
let templatesMetadata = undefined;
// -- Package Release Artifacts
Expand All @@ -73,7 +75,7 @@ function run() {
// -- Generate Documentation
if (shouldGenerateDocumentation && featuresBasePath) {
core.info('Generating documentation for features...');
yield (0, generateDocs_1.generateFeaturesDocumentation)(featuresBasePath);
yield (0, generateDocs_1.generateFeaturesDocumentation)(featuresBasePath, ociRegistry, namespace);
}
if (shouldGenerateDocumentation && templatesBasePath) {
core.info('Generating documentation for templates...');
Expand Down
4 changes: 2 additions & 2 deletions .github/devcontainers-action/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ exports.addCollectionsMetadataFile = addCollectionsMetadataFile;
function pushArtifactToOCI(version, featureName, artifactPath) {
return __awaiter(this, void 0, void 0, function* () {
const exec = (0, util_1.promisify)(child_process.exec);
const versions = [version, '1.0', '1']; // TODO: don't hardcode ofc.
const versions = [version, '1.0', '1', 'latest']; // TODO: Generate semantic versions from 'version'
const sourceInfo = getGitHubMetadata();
yield Promise.all(versions.map((v) => __awaiter(this, void 0, void 0, function* () {
const ociRepo = `${sourceInfo.owner}/${sourceInfo.repo}/${featureName}:${v}`;
Expand Down Expand Up @@ -243,7 +243,7 @@ function getFeaturesAndPackage(basePath, opts) {
core.setFailed('Could not determine repository owner.');
return;
}
const archiveName = `${f}.tgz`;
const archiveName = `devcontainer-feature-${f}.tgz`;
// ---- PUBLISH RELEASE ARTIFACTS (classic method) ----
if (shouldPublishReleaseArtifacts || shouldPublishToOCI) {
core.info(`** Tar'ing feature`);
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-release-artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ jobs:
with:
allowUpdates: true # Lets us upload our own artifact from previous step
artifactErrorsFailBuild: true
artifacts: "devcontainer-collection.json"
artifacts: "./devcontainer-*"
token: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit aead4e8

Please sign in to comment.