Skip to content

Commit

Permalink
update action
Browse files Browse the repository at this point in the history
  • Loading branch information
joshspicer committed Jul 22, 2022
1 parent ac11091 commit da934c0
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 18 deletions.
38 changes: 30 additions & 8 deletions .github/devcontainers-action/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ function run() {
}
// -- Programatically add feature/template metadata to collections file.
core.info('Generating metadata file: devcontainer-collection.json');
yield (0, utils_1.addCollectionsMetadataFile)(featuresMetadata, templatesMetadata);
yield (0, utils_1.addCollectionsMetadataFile)(featuresMetadata, templatesMetadata, opts);
});
}
function packageFeatures(basePath, opts) {
Expand Down Expand Up @@ -328,7 +328,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getTemplatesAndPackage = exports.getFeaturesAndPackage = exports.addCollectionsMetadataFile = exports.tarDirectory = exports.renameLocal = exports.mkdirLocal = exports.writeLocalFile = exports.readLocalFile = void 0;
exports.getTemplatesAndPackage = exports.getFeaturesAndPackage = exports.pushCollectionsMetadataToOCI = exports.addCollectionsMetadataFile = exports.tarDirectory = exports.renameLocal = exports.mkdirLocal = exports.writeLocalFile = exports.readLocalFile = void 0;
const github = __importStar(__nccwpck_require__(5438));
const tar = __importStar(__nccwpck_require__(4674));
const fs = __importStar(__nccwpck_require__(7147));
Expand Down Expand Up @@ -428,7 +428,7 @@ function tagFeatureAtVersion(featureMetaData) {
}
});
}
function addCollectionsMetadataFile(featuresMetadata, templatesMetadata) {
function addCollectionsMetadataFile(featuresMetadata, templatesMetadata, opts) {
return __awaiter(this, void 0, void 0, function* () {
const p = path_1.default.join('.', 'devcontainer-collection.json');
const sourceInformation = getGitHubMetadata();
Expand All @@ -439,16 +439,19 @@ function addCollectionsMetadataFile(featuresMetadata, templatesMetadata) {
};
// Write to the file
yield (0, exports.writeLocalFile)(p, JSON.stringify(metadata, undefined, 4));
if (opts.shouldPublishToOCI) {
pushCollectionsMetadataToOCI(p);
}
});
}
exports.addCollectionsMetadataFile = addCollectionsMetadataFile;
function pushArtifactToOCI(repositoryOwner, version, featureName, artifactPath) {
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 sourceInfo = getGitHubMetadata();
yield Promise.all(versions.map((v) => __awaiter(this, void 0, void 0, function* () {
core.info(`Starting to push artifact (tag ${v}) to OCI...`);
const ociRepo = `${repositoryOwner}/${featureName}:${v}`;
const ociRepo = `${sourceInfo.owner}/${sourceInfo.repo}/${featureName}:${v}`;
try {
const cmd = `oras push ghcr.io/${ociRepo} \
--manifest-config /dev/null:application/vnd.devcontainers \
Expand All @@ -463,6 +466,25 @@ function pushArtifactToOCI(repositoryOwner, version, featureName, artifactPath)
})));
});
}
function pushCollectionsMetadataToOCI(collectionJsonPath) {
return __awaiter(this, void 0, void 0, function* () {
const exec = (0, util_1.promisify)(child_process.exec);
const sourceInfo = getGitHubMetadata();
const ociRepo = `${sourceInfo.owner}/${sourceInfo.repo}:latest`;
try {
const cmd = `oras push ghcr.io/${ociRepo} \
--manifest-config /dev/null:application/vnd.devcontainers \
./${collectionJsonPath}:application/vnd.devcontainers.collection.layer.v1+json`;
yield exec(cmd);
core.info(`Pushed collection metadata to '${ociRepo}'`);
}
catch (error) {
if (error instanceof Error)
core.setFailed(`Failed to push collection metadata '${ociRepo}': ${error.message}`);
}
});
}
exports.pushCollectionsMetadataToOCI = pushCollectionsMetadataToOCI;
function loginToGHCR() {
return __awaiter(this, void 0, void 0, function* () {
const exec = (0, util_1.promisify)(child_process.exec);
Expand All @@ -474,7 +496,7 @@ function loginToGHCR() {
}
try {
yield exec(`oras login ghcr.io -u USERNAME -p ${githubToken}`);
console.log('Oras logged in successfully!');
core.info('Oras logged in successfully!');
}
catch (error) {
if (error instanceof Error)
Expand Down Expand Up @@ -522,7 +544,7 @@ function getFeaturesAndPackage(basePath, opts) {
// ---- PUBLISH TO NPM ----
if (shouldPublishToOCI) {
core.info(`** Publishing to OCI`);
yield pushArtifactToOCI(sourceInfo.owner, featureMetadata.version, f, archiveName);
yield pushArtifactToOCI(featureMetadata.version, f, archiveName);
}
// ---- TAG INDIVIDUAL FEATURES ----
if (shouldTagIndividualFeatures) {
Expand Down
2 changes: 1 addition & 1 deletion .github/devcontainers-action/dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .github/devcontainers-action/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function run() {
}
// -- Programatically add feature/template metadata to collections file.
core.info('Generating metadata file: devcontainer-collection.json');
yield (0, utils_1.addCollectionsMetadataFile)(featuresMetadata, templatesMetadata);
yield (0, utils_1.addCollectionsMetadataFile)(featuresMetadata, templatesMetadata, opts);
});
}
function packageFeatures(basePath, opts) {
Expand Down
36 changes: 29 additions & 7 deletions .github/devcontainers-action/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTemplatesAndPackage = exports.getFeaturesAndPackage = exports.addCollectionsMetadataFile = exports.tarDirectory = exports.renameLocal = exports.mkdirLocal = exports.writeLocalFile = exports.readLocalFile = void 0;
exports.getTemplatesAndPackage = exports.getFeaturesAndPackage = exports.pushCollectionsMetadataToOCI = exports.addCollectionsMetadataFile = exports.tarDirectory = exports.renameLocal = exports.mkdirLocal = exports.writeLocalFile = exports.readLocalFile = void 0;
const github = __importStar(require("@actions/github"));
const tar = __importStar(require("tar"));
const fs = __importStar(require("fs"));
Expand Down Expand Up @@ -135,7 +135,7 @@ function tagFeatureAtVersion(featureMetaData) {
}
});
}
function addCollectionsMetadataFile(featuresMetadata, templatesMetadata) {
function addCollectionsMetadataFile(featuresMetadata, templatesMetadata, opts) {
return __awaiter(this, void 0, void 0, function* () {
const p = path_1.default.join('.', 'devcontainer-collection.json');
const sourceInformation = getGitHubMetadata();
Expand All @@ -146,16 +146,19 @@ function addCollectionsMetadataFile(featuresMetadata, templatesMetadata) {
};
// Write to the file
yield (0, exports.writeLocalFile)(p, JSON.stringify(metadata, undefined, 4));
if (opts.shouldPublishToOCI) {
pushCollectionsMetadataToOCI(p);
}
});
}
exports.addCollectionsMetadataFile = addCollectionsMetadataFile;
function pushArtifactToOCI(repositoryOwner, version, featureName, artifactPath) {
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 sourceInfo = getGitHubMetadata();
yield Promise.all(versions.map((v) => __awaiter(this, void 0, void 0, function* () {
core.info(`Starting to push artifact (tag ${v}) to OCI...`);
const ociRepo = `${repositoryOwner}/${featureName}:${v}`;
const ociRepo = `${sourceInfo.owner}/${sourceInfo.repo}/${featureName}:${v}`;
try {
const cmd = `oras push ghcr.io/${ociRepo} \
--manifest-config /dev/null:application/vnd.devcontainers \
Expand All @@ -170,6 +173,25 @@ function pushArtifactToOCI(repositoryOwner, version, featureName, artifactPath)
})));
});
}
function pushCollectionsMetadataToOCI(collectionJsonPath) {
return __awaiter(this, void 0, void 0, function* () {
const exec = (0, util_1.promisify)(child_process.exec);
const sourceInfo = getGitHubMetadata();
const ociRepo = `${sourceInfo.owner}/${sourceInfo.repo}:latest`;
try {
const cmd = `oras push ghcr.io/${ociRepo} \
--manifest-config /dev/null:application/vnd.devcontainers \
./${collectionJsonPath}:application/vnd.devcontainers.collection.layer.v1+json`;
yield exec(cmd);
core.info(`Pushed collection metadata to '${ociRepo}'`);
}
catch (error) {
if (error instanceof Error)
core.setFailed(`Failed to push collection metadata '${ociRepo}': ${error.message}`);
}
});
}
exports.pushCollectionsMetadataToOCI = pushCollectionsMetadataToOCI;
function loginToGHCR() {
return __awaiter(this, void 0, void 0, function* () {
const exec = (0, util_1.promisify)(child_process.exec);
Expand All @@ -181,7 +203,7 @@ function loginToGHCR() {
}
try {
yield exec(`oras login ghcr.io -u USERNAME -p ${githubToken}`);
console.log('Oras logged in successfully!');
core.info('Oras logged in successfully!');
}
catch (error) {
if (error instanceof Error)
Expand Down Expand Up @@ -229,7 +251,7 @@ function getFeaturesAndPackage(basePath, opts) {
// ---- PUBLISH TO NPM ----
if (shouldPublishToOCI) {
core.info(`** Publishing to OCI`);
yield pushArtifactToOCI(sourceInfo.owner, featureMetadata.version, f, archiveName);
yield pushArtifactToOCI(featureMetadata.version, f, archiveName);
}
// ---- TAG INDIVIDUAL FEATURES ----
if (shouldTagIndividualFeatures) {
Expand Down
3 changes: 2 additions & 1 deletion src/ruby/devcontainer-feature.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@
"MY_RUBY_HOME": "/usr/local/rvm/rubies/default",
"PATH": "/usr/local/rvm/gems/default/bin:/usr/local/rvm/gems/default@global/bin:/usr/local/rvm/rubies/default/bin:${PATH}"
}
}
}

0 comments on commit da934c0

Please sign in to comment.