Skip to content

Commit da934c0

Browse files
committed
update action
1 parent ac11091 commit da934c0

5 files changed

Lines changed: 63 additions & 18 deletions

File tree

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

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ function run() {
247247
}
248248
// -- Programatically add feature/template metadata to collections file.
249249
core.info('Generating metadata file: devcontainer-collection.json');
250-
yield (0, utils_1.addCollectionsMetadataFile)(featuresMetadata, templatesMetadata);
250+
yield (0, utils_1.addCollectionsMetadataFile)(featuresMetadata, templatesMetadata, opts);
251251
});
252252
}
253253
function packageFeatures(basePath, opts) {
@@ -328,7 +328,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
328328
return (mod && mod.__esModule) ? mod : { "default": mod };
329329
};
330330
Object.defineProperty(exports, "__esModule", ({ value: true }));
331-
exports.getTemplatesAndPackage = exports.getFeaturesAndPackage = exports.addCollectionsMetadataFile = exports.tarDirectory = exports.renameLocal = exports.mkdirLocal = exports.writeLocalFile = exports.readLocalFile = void 0;
331+
exports.getTemplatesAndPackage = exports.getFeaturesAndPackage = exports.pushCollectionsMetadataToOCI = exports.addCollectionsMetadataFile = exports.tarDirectory = exports.renameLocal = exports.mkdirLocal = exports.writeLocalFile = exports.readLocalFile = void 0;
332332
const github = __importStar(__nccwpck_require__(5438));
333333
const tar = __importStar(__nccwpck_require__(4674));
334334
const fs = __importStar(__nccwpck_require__(7147));
@@ -428,7 +428,7 @@ function tagFeatureAtVersion(featureMetaData) {
428428
}
429429
});
430430
}
431-
function addCollectionsMetadataFile(featuresMetadata, templatesMetadata) {
431+
function addCollectionsMetadataFile(featuresMetadata, templatesMetadata, opts) {
432432
return __awaiter(this, void 0, void 0, function* () {
433433
const p = path_1.default.join('.', 'devcontainer-collection.json');
434434
const sourceInformation = getGitHubMetadata();
@@ -439,16 +439,19 @@ function addCollectionsMetadataFile(featuresMetadata, templatesMetadata) {
439439
};
440440
// Write to the file
441441
yield (0, exports.writeLocalFile)(p, JSON.stringify(metadata, undefined, 4));
442+
if (opts.shouldPublishToOCI) {
443+
pushCollectionsMetadataToOCI(p);
444+
}
442445
});
443446
}
444447
exports.addCollectionsMetadataFile = addCollectionsMetadataFile;
445-
function pushArtifactToOCI(repositoryOwner, version, featureName, artifactPath) {
448+
function pushArtifactToOCI(version, featureName, artifactPath) {
446449
return __awaiter(this, void 0, void 0, function* () {
447450
const exec = (0, util_1.promisify)(child_process.exec);
448451
const versions = [version, '1.0', '1']; // TODO: don't hardcode ofc.
452+
const sourceInfo = getGitHubMetadata();
449453
yield Promise.all(versions.map((v) => __awaiter(this, void 0, void 0, function* () {
450-
core.info(`Starting to push artifact (tag ${v}) to OCI...`);
451-
const ociRepo = `${repositoryOwner}/${featureName}:${v}`;
454+
const ociRepo = `${sourceInfo.owner}/${sourceInfo.repo}/${featureName}:${v}`;
452455
try {
453456
const cmd = `oras push ghcr.io/${ociRepo} \
454457
--manifest-config /dev/null:application/vnd.devcontainers \
@@ -463,6 +466,25 @@ function pushArtifactToOCI(repositoryOwner, version, featureName, artifactPath)
463466
})));
464467
});
465468
}
469+
function pushCollectionsMetadataToOCI(collectionJsonPath) {
470+
return __awaiter(this, void 0, void 0, function* () {
471+
const exec = (0, util_1.promisify)(child_process.exec);
472+
const sourceInfo = getGitHubMetadata();
473+
const ociRepo = `${sourceInfo.owner}/${sourceInfo.repo}:latest`;
474+
try {
475+
const cmd = `oras push ghcr.io/${ociRepo} \
476+
--manifest-config /dev/null:application/vnd.devcontainers \
477+
./${collectionJsonPath}:application/vnd.devcontainers.collection.layer.v1+json`;
478+
yield exec(cmd);
479+
core.info(`Pushed collection metadata to '${ociRepo}'`);
480+
}
481+
catch (error) {
482+
if (error instanceof Error)
483+
core.setFailed(`Failed to push collection metadata '${ociRepo}': ${error.message}`);
484+
}
485+
});
486+
}
487+
exports.pushCollectionsMetadataToOCI = pushCollectionsMetadataToOCI;
466488
function loginToGHCR() {
467489
return __awaiter(this, void 0, void 0, function* () {
468490
const exec = (0, util_1.promisify)(child_process.exec);
@@ -474,7 +496,7 @@ function loginToGHCR() {
474496
}
475497
try {
476498
yield exec(`oras login ghcr.io -u USERNAME -p ${githubToken}`);
477-
console.log('Oras logged in successfully!');
499+
core.info('Oras logged in successfully!');
478500
}
479501
catch (error) {
480502
if (error instanceof Error)
@@ -522,7 +544,7 @@ function getFeaturesAndPackage(basePath, opts) {
522544
// ---- PUBLISH TO NPM ----
523545
if (shouldPublishToOCI) {
524546
core.info(`** Publishing to OCI`);
525-
yield pushArtifactToOCI(sourceInfo.owner, featureMetadata.version, f, archiveName);
547+
yield pushArtifactToOCI(featureMetadata.version, f, archiveName);
526548
}
527549
// ---- TAG INDIVIDUAL FEATURES ----
528550
if (shouldTagIndividualFeatures) {

.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/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function run() {
8181
}
8282
// -- Programatically add feature/template metadata to collections file.
8383
core.info('Generating metadata file: devcontainer-collection.json');
84-
yield (0, utils_1.addCollectionsMetadataFile)(featuresMetadata, templatesMetadata);
84+
yield (0, utils_1.addCollectionsMetadataFile)(featuresMetadata, templatesMetadata, opts);
8585
});
8686
}
8787
function packageFeatures(basePath, opts) {

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

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3535
return (mod && mod.__esModule) ? mod : { "default": mod };
3636
};
3737
Object.defineProperty(exports, "__esModule", { value: true });
38-
exports.getTemplatesAndPackage = exports.getFeaturesAndPackage = exports.addCollectionsMetadataFile = exports.tarDirectory = exports.renameLocal = exports.mkdirLocal = exports.writeLocalFile = exports.readLocalFile = void 0;
38+
exports.getTemplatesAndPackage = exports.getFeaturesAndPackage = exports.pushCollectionsMetadataToOCI = exports.addCollectionsMetadataFile = exports.tarDirectory = exports.renameLocal = exports.mkdirLocal = exports.writeLocalFile = exports.readLocalFile = void 0;
3939
const github = __importStar(require("@actions/github"));
4040
const tar = __importStar(require("tar"));
4141
const fs = __importStar(require("fs"));
@@ -135,7 +135,7 @@ function tagFeatureAtVersion(featureMetaData) {
135135
}
136136
});
137137
}
138-
function addCollectionsMetadataFile(featuresMetadata, templatesMetadata) {
138+
function addCollectionsMetadataFile(featuresMetadata, templatesMetadata, opts) {
139139
return __awaiter(this, void 0, void 0, function* () {
140140
const p = path_1.default.join('.', 'devcontainer-collection.json');
141141
const sourceInformation = getGitHubMetadata();
@@ -146,16 +146,19 @@ function addCollectionsMetadataFile(featuresMetadata, templatesMetadata) {
146146
};
147147
// Write to the file
148148
yield (0, exports.writeLocalFile)(p, JSON.stringify(metadata, undefined, 4));
149+
if (opts.shouldPublishToOCI) {
150+
pushCollectionsMetadataToOCI(p);
151+
}
149152
});
150153
}
151154
exports.addCollectionsMetadataFile = addCollectionsMetadataFile;
152-
function pushArtifactToOCI(repositoryOwner, version, featureName, artifactPath) {
155+
function pushArtifactToOCI(version, featureName, artifactPath) {
153156
return __awaiter(this, void 0, void 0, function* () {
154157
const exec = (0, util_1.promisify)(child_process.exec);
155158
const versions = [version, '1.0', '1']; // TODO: don't hardcode ofc.
159+
const sourceInfo = getGitHubMetadata();
156160
yield Promise.all(versions.map((v) => __awaiter(this, void 0, void 0, function* () {
157-
core.info(`Starting to push artifact (tag ${v}) to OCI...`);
158-
const ociRepo = `${repositoryOwner}/${featureName}:${v}`;
161+
const ociRepo = `${sourceInfo.owner}/${sourceInfo.repo}/${featureName}:${v}`;
159162
try {
160163
const cmd = `oras push ghcr.io/${ociRepo} \
161164
--manifest-config /dev/null:application/vnd.devcontainers \
@@ -170,6 +173,25 @@ function pushArtifactToOCI(repositoryOwner, version, featureName, artifactPath)
170173
})));
171174
});
172175
}
176+
function pushCollectionsMetadataToOCI(collectionJsonPath) {
177+
return __awaiter(this, void 0, void 0, function* () {
178+
const exec = (0, util_1.promisify)(child_process.exec);
179+
const sourceInfo = getGitHubMetadata();
180+
const ociRepo = `${sourceInfo.owner}/${sourceInfo.repo}:latest`;
181+
try {
182+
const cmd = `oras push ghcr.io/${ociRepo} \
183+
--manifest-config /dev/null:application/vnd.devcontainers \
184+
./${collectionJsonPath}:application/vnd.devcontainers.collection.layer.v1+json`;
185+
yield exec(cmd);
186+
core.info(`Pushed collection metadata to '${ociRepo}'`);
187+
}
188+
catch (error) {
189+
if (error instanceof Error)
190+
core.setFailed(`Failed to push collection metadata '${ociRepo}': ${error.message}`);
191+
}
192+
});
193+
}
194+
exports.pushCollectionsMetadataToOCI = pushCollectionsMetadataToOCI;
173195
function loginToGHCR() {
174196
return __awaiter(this, void 0, void 0, function* () {
175197
const exec = (0, util_1.promisify)(child_process.exec);
@@ -181,7 +203,7 @@ function loginToGHCR() {
181203
}
182204
try {
183205
yield exec(`oras login ghcr.io -u USERNAME -p ${githubToken}`);
184-
console.log('Oras logged in successfully!');
206+
core.info('Oras logged in successfully!');
185207
}
186208
catch (error) {
187209
if (error instanceof Error)
@@ -229,7 +251,7 @@ function getFeaturesAndPackage(basePath, opts) {
229251
// ---- PUBLISH TO NPM ----
230252
if (shouldPublishToOCI) {
231253
core.info(`** Publishing to OCI`);
232-
yield pushArtifactToOCI(sourceInfo.owner, featureMetadata.version, f, archiveName);
254+
yield pushArtifactToOCI(featureMetadata.version, f, archiveName);
233255
}
234256
// ---- TAG INDIVIDUAL FEATURES ----
235257
if (shouldTagIndividualFeatures) {

src/ruby/devcontainer-feature.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@
2626
"MY_RUBY_HOME": "/usr/local/rvm/rubies/default",
2727
"PATH": "/usr/local/rvm/gems/default/bin:/usr/local/rvm/gems/default@global/bin:/usr/local/rvm/rubies/default/bin:${PATH}"
2828
}
29-
}
29+
}
30+

0 commit comments

Comments
 (0)