Skip to content

Commit aead4e8

Browse files
authored
update to support tarball
1 parent fabcba0 commit aead4e8

7 files changed

Lines changed: 48 additions & 30 deletions

File tree

.github/devcontainers-action/action.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ inputs:
2424
required: false
2525
default: ''
2626
description: "Relative path to the 'src' folder containing dev container 'feature(s)'"
27+
oci-registry:
28+
required: false
29+
default: "ghcr.io"
30+
description: "Name of the OCI registry that implements the OCI Artifact Distribution Specification"
31+
features-namespace:
32+
required: false
33+
default: "<owner>/<repo>"
34+
description: "A unique indentifier for the collection of features"
2735

2836
# 'template' options
2937
base-path-to-templates:

.github/devcontainers-action/dist/index.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const FEATURES_README_TEMPLATE = `
5353

5454
\`\`\`json
5555
"features": {
56-
"#{Nwo}/#{Id}@#{VersionTag}": {
56+
"#{Registry}/#{Namespace}/#{Id}:#{Version}": {
5757
"version": "latest"
5858
}
5959
}
@@ -76,9 +76,9 @@ const TEMPLATE_README_TEMPLATE = `
7676

7777
#{OptionsTable}
7878
`;
79-
function generateFeaturesDocumentation(basePath) {
79+
function generateFeaturesDocumentation(basePath, ociRegistry, namespace) {
8080
return __awaiter(this, void 0, void 0, function* () {
81-
yield _generateDocumentation(basePath, FEATURES_README_TEMPLATE, 'devcontainer-feature.json');
81+
yield _generateDocumentation(basePath, FEATURES_README_TEMPLATE, 'devcontainer-feature.json', ociRegistry, namespace);
8282
});
8383
}
8484
exports.generateFeaturesDocumentation = generateFeaturesDocumentation;
@@ -88,7 +88,7 @@ function generateTemplateDocumentation(basePath) {
8888
});
8989
}
9090
exports.generateTemplateDocumentation = generateTemplateDocumentation;
91-
function _generateDocumentation(basePath, readmeTemplate, metadataFile) {
91+
function _generateDocumentation(basePath, readmeTemplate, metadataFile, ociRegistry = '', namespace = '') {
9292
return __awaiter(this, void 0, void 0, function* () {
9393
const directories = fs.readdirSync(basePath);
9494
yield Promise.all(directories.map((f) => __awaiter(this, void 0, void 0, function* () {
@@ -114,13 +114,15 @@ function _generateDocumentation(basePath, readmeTemplate, metadataFile) {
114114
return;
115115
}
116116
const srcInfo = (0, utils_1.getGitHubMetadata)();
117-
const ref = srcInfo.ref;
118117
const owner = srcInfo.owner;
119118
const repo = srcInfo.repo;
120-
// Add tag if parseable
121-
let versionTag = 'latest';
122-
if (ref && ref.includes('refs/tags/')) {
123-
versionTag = ref.replace('refs/tags/', '');
119+
// Add version
120+
let version = 'latest';
121+
const parsedVersion = parsedJson === null || parsedJson === void 0 ? void 0 : parsedJson.version;
122+
if (parsedVersion) {
123+
// example - 1.0.0
124+
const splitVersion = parsedVersion.split('.');
125+
version = splitVersion[0];
124126
}
125127
const generateOptionsMarkdown = () => {
126128
const options = parsedJson === null || parsedJson === void 0 ? void 0 : parsedJson.options;
@@ -148,8 +150,9 @@ function _generateDocumentation(basePath, readmeTemplate, metadataFile) {
148150
.replace('#{Description}', (_a = parsedJson.description) !== null && _a !== void 0 ? _a : '')
149151
.replace('#{OptionsTable}', generateOptionsMarkdown())
150152
// Features Only
151-
.replace('#{Nwo}', `${owner}/${repo}`)
152-
.replace('#{VersionTag}', versionTag)
153+
.replace('#{Registry}', ociRegistry)
154+
.replace('#{Namespace}', namespace == '<owner>/<repo>' ? `${owner}/${repo}` : namespace)
155+
.replace('#{Version}', version)
153156
// Templates Only
154157
.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 : '')
155158
.replace('#{RepoUrl}', urlToConfig);
@@ -232,6 +235,8 @@ function run() {
232235
};
233236
const featuresBasePath = core.getInput('base-path-to-features');
234237
const templatesBasePath = core.getInput('base-path-to-templates');
238+
const ociRegistry = core.getInput('oci-registry');
239+
const namespace = core.getInput('features-namespace');
235240
let featuresMetadata = undefined;
236241
let templatesMetadata = undefined;
237242
// -- Package Release Artifacts
@@ -246,7 +251,7 @@ function run() {
246251
// -- Generate Documentation
247252
if (shouldGenerateDocumentation && featuresBasePath) {
248253
core.info('Generating documentation for features...');
249-
yield (0, generateDocs_1.generateFeaturesDocumentation)(featuresBasePath);
254+
yield (0, generateDocs_1.generateFeaturesDocumentation)(featuresBasePath, ociRegistry, namespace);
250255
}
251256
if (shouldGenerateDocumentation && templatesBasePath) {
252257
core.info('Generating documentation for templates...');
@@ -456,7 +461,7 @@ exports.addCollectionsMetadataFile = addCollectionsMetadataFile;
456461
function pushArtifactToOCI(version, featureName, artifactPath) {
457462
return __awaiter(this, void 0, void 0, function* () {
458463
const exec = (0, util_1.promisify)(child_process.exec);
459-
const versions = [version, '1.0', '1']; // TODO: don't hardcode ofc.
464+
const versions = [version, '1.0', '1', 'latest']; // TODO: Generate semantic versions from 'version'
460465
const sourceInfo = getGitHubMetadata();
461466
yield Promise.all(versions.map((v) => __awaiter(this, void 0, void 0, function* () {
462467
const ociRepo = `${sourceInfo.owner}/${sourceInfo.repo}/${featureName}:${v}`;
@@ -543,7 +548,7 @@ function getFeaturesAndPackage(basePath, opts) {
543548
core.setFailed('Could not determine repository owner.');
544549
return;
545550
}
546-
const archiveName = `${f}.tgz`;
551+
const archiveName = `devcontainer-feature-${f}.tgz`;
547552
// ---- PUBLISH RELEASE ARTIFACTS (classic method) ----
548553
if (shouldPublishReleaseArtifacts || shouldPublishToOCI) {
549554
core.info(`** Tar'ing feature`);

.github/devcontainers-action/dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/devcontainers-action/lib/generateDocs.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const FEATURES_README_TEMPLATE = `
4646
4747
\`\`\`json
4848
"features": {
49-
"#{Nwo}/#{Id}@#{VersionTag}": {
49+
"#{Registry}/#{Namespace}/#{Id}:#{Version}": {
5050
"version": "latest"
5151
}
5252
}
@@ -69,9 +69,9 @@ const TEMPLATE_README_TEMPLATE = `
6969
7070
#{OptionsTable}
7171
`;
72-
function generateFeaturesDocumentation(basePath) {
72+
function generateFeaturesDocumentation(basePath, ociRegistry, namespace) {
7373
return __awaiter(this, void 0, void 0, function* () {
74-
yield _generateDocumentation(basePath, FEATURES_README_TEMPLATE, 'devcontainer-feature.json');
74+
yield _generateDocumentation(basePath, FEATURES_README_TEMPLATE, 'devcontainer-feature.json', ociRegistry, namespace);
7575
});
7676
}
7777
exports.generateFeaturesDocumentation = generateFeaturesDocumentation;
@@ -81,7 +81,7 @@ function generateTemplateDocumentation(basePath) {
8181
});
8282
}
8383
exports.generateTemplateDocumentation = generateTemplateDocumentation;
84-
function _generateDocumentation(basePath, readmeTemplate, metadataFile) {
84+
function _generateDocumentation(basePath, readmeTemplate, metadataFile, ociRegistry = '', namespace = '') {
8585
return __awaiter(this, void 0, void 0, function* () {
8686
const directories = fs.readdirSync(basePath);
8787
yield Promise.all(directories.map((f) => __awaiter(this, void 0, void 0, function* () {
@@ -107,13 +107,15 @@ function _generateDocumentation(basePath, readmeTemplate, metadataFile) {
107107
return;
108108
}
109109
const srcInfo = (0, utils_1.getGitHubMetadata)();
110-
const ref = srcInfo.ref;
111110
const owner = srcInfo.owner;
112111
const repo = srcInfo.repo;
113-
// Add tag if parseable
114-
let versionTag = 'latest';
115-
if (ref && ref.includes('refs/tags/')) {
116-
versionTag = ref.replace('refs/tags/', '');
112+
// Add version
113+
let version = 'latest';
114+
const parsedVersion = parsedJson === null || parsedJson === void 0 ? void 0 : parsedJson.version;
115+
if (parsedVersion) {
116+
// example - 1.0.0
117+
const splitVersion = parsedVersion.split('.');
118+
version = splitVersion[0];
117119
}
118120
const generateOptionsMarkdown = () => {
119121
const options = parsedJson === null || parsedJson === void 0 ? void 0 : parsedJson.options;
@@ -141,8 +143,9 @@ function _generateDocumentation(basePath, readmeTemplate, metadataFile) {
141143
.replace('#{Description}', (_a = parsedJson.description) !== null && _a !== void 0 ? _a : '')
142144
.replace('#{OptionsTable}', generateOptionsMarkdown())
143145
// Features Only
144-
.replace('#{Nwo}', `${owner}/${repo}`)
145-
.replace('#{VersionTag}', versionTag)
146+
.replace('#{Registry}', ociRegistry)
147+
.replace('#{Namespace}', namespace == '<owner>/<repo>' ? `${owner}/${repo}` : namespace)
148+
.replace('#{Version}', version)
146149
// Templates Only
147150
.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 : '')
148151
.replace('#{RepoUrl}', urlToConfig);

.github/devcontainers-action/lib/main.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ function run() {
5959
};
6060
const featuresBasePath = core.getInput('base-path-to-features');
6161
const templatesBasePath = core.getInput('base-path-to-templates');
62+
const ociRegistry = core.getInput('oci-registry');
63+
const namespace = core.getInput('features-namespace');
6264
let featuresMetadata = undefined;
6365
let templatesMetadata = undefined;
6466
// -- Package Release Artifacts
@@ -73,7 +75,7 @@ function run() {
7375
// -- Generate Documentation
7476
if (shouldGenerateDocumentation && featuresBasePath) {
7577
core.info('Generating documentation for features...');
76-
yield (0, generateDocs_1.generateFeaturesDocumentation)(featuresBasePath);
78+
yield (0, generateDocs_1.generateFeaturesDocumentation)(featuresBasePath, ociRegistry, namespace);
7779
}
7880
if (shouldGenerateDocumentation && templatesBasePath) {
7981
core.info('Generating documentation for templates...');

.github/devcontainers-action/lib/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ exports.addCollectionsMetadataFile = addCollectionsMetadataFile;
156156
function pushArtifactToOCI(version, featureName, artifactPath) {
157157
return __awaiter(this, void 0, void 0, function* () {
158158
const exec = (0, util_1.promisify)(child_process.exec);
159-
const versions = [version, '1.0', '1']; // TODO: don't hardcode ofc.
159+
const versions = [version, '1.0', '1', 'latest']; // TODO: Generate semantic versions from 'version'
160160
const sourceInfo = getGitHubMetadata();
161161
yield Promise.all(versions.map((v) => __awaiter(this, void 0, void 0, function* () {
162162
const ociRepo = `${sourceInfo.owner}/${sourceInfo.repo}/${featureName}:${v}`;
@@ -243,7 +243,7 @@ function getFeaturesAndPackage(basePath, opts) {
243243
core.setFailed('Could not determine repository owner.');
244244
return;
245245
}
246-
const archiveName = `${f}.tgz`;
246+
const archiveName = `devcontainer-feature-${f}.tgz`;
247247
// ---- PUBLISH RELEASE ARTIFACTS (classic method) ----
248248
if (shouldPublishReleaseArtifacts || shouldPublishToOCI) {
249249
core.info(`** Tar'ing feature`);

.github/workflows/publish-release-artifacts.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ jobs:
3333
with:
3434
allowUpdates: true # Lets us upload our own artifact from previous step
3535
artifactErrorsFailBuild: true
36-
artifacts: "devcontainer-collection.json"
36+
artifacts: "./devcontainer-*"
3737
token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)