update dist
This commit is contained in:
+62
-55
@@ -72611,52 +72611,59 @@ exports.removeDir = removeDir;
|
|||||||
async function createArchives(distPath, archiveTargetPath = createTempDir()) {
|
async function createArchives(distPath, archiveTargetPath = createTempDir()) {
|
||||||
const zipPath = path.join(archiveTargetPath, `archive.zip`);
|
const zipPath = path.join(archiveTargetPath, `archive.zip`);
|
||||||
const tarPath = path.join(archiveTargetPath, `archive.tar.gz`);
|
const tarPath = path.join(archiveTargetPath, `archive.tar.gz`);
|
||||||
return Promise.all([
|
const createZipPromise = new Promise((resolve, reject) => {
|
||||||
new Promise((resolve, reject) => {
|
const output = fs.createWriteStream(zipPath);
|
||||||
const output = fs.createWriteStream(zipPath);
|
const archive = archiver.create('zip');
|
||||||
const archive = archiver.create('zip');
|
output.on('error', (err) => {
|
||||||
output.on('error', (err) => {
|
reject(err);
|
||||||
reject(err);
|
});
|
||||||
});
|
archive.on('error', (err) => {
|
||||||
archive.on('error', (err) => {
|
reject(err);
|
||||||
reject(err);
|
});
|
||||||
});
|
output.on('close', () => {
|
||||||
output.on('close', () => {
|
resolve(fileMetadata(zipPath));
|
||||||
resolve(fileMetadata(zipPath));
|
});
|
||||||
});
|
archive.pipe(output);
|
||||||
archive.pipe(output);
|
archive.directory(distPath, false);
|
||||||
archive.directory(distPath, false);
|
archive.finalize();
|
||||||
archive.finalize();
|
});
|
||||||
}),
|
const createTarPromise = new Promise((resolve, reject) => {
|
||||||
new Promise((resolve, reject) => {
|
tar
|
||||||
const tarStream = tar
|
.c({
|
||||||
.c({
|
file: tarPath,
|
||||||
file: tarPath,
|
C: distPath,
|
||||||
C: distPath,
|
gzip: true
|
||||||
gzip: true
|
}, ['.'])
|
||||||
}, ['.'])
|
// eslint-disable-next-line github/no-then
|
||||||
.then(() => {
|
.catch(err => {
|
||||||
resolve(fileMetadata(tarPath));
|
reject(err);
|
||||||
})
|
|
||||||
.catch((err) => reject(err));
|
|
||||||
})
|
})
|
||||||
]).then(([zipFile, tarFile]) => ({ zipFile, tarFile }));
|
// eslint-disable-next-line github/no-then
|
||||||
|
.then(() => {
|
||||||
|
resolve(fileMetadata(tarPath));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
const [zipFile, tarFile] = await Promise.all([
|
||||||
|
createZipPromise,
|
||||||
|
createTarPromise
|
||||||
|
]);
|
||||||
|
return { zipFile, tarFile };
|
||||||
}
|
}
|
||||||
exports.createArchives = createArchives;
|
exports.createArchives = createArchives;
|
||||||
function isDirectory(path) {
|
function isDirectory(dirPath) {
|
||||||
return fs.existsSync(path) && fs.lstatSync(path).isDirectory();
|
return fs.existsSync(dirPath) && fs.lstatSync(dirPath).isDirectory();
|
||||||
}
|
}
|
||||||
exports.isDirectory = isDirectory;
|
exports.isDirectory = isDirectory;
|
||||||
function readFileContents(path) {
|
function readFileContents(filePath) {
|
||||||
return fs.readFileSync(path);
|
return fs.readFileSync(filePath);
|
||||||
}
|
}
|
||||||
exports.readFileContents = readFileContents;
|
exports.readFileContents = readFileContents;
|
||||||
// Converts a file path to a filemetadata object by querying the fs for relevant metadata.
|
// Converts a file path to a filemetadata object by querying the fs for relevant metadata.
|
||||||
async function fileMetadata(path) {
|
async function fileMetadata(filePath) {
|
||||||
const stats = fs.statSync(path);
|
const stats = fs.statSync(filePath);
|
||||||
const size = stats.size;
|
const size = stats.size;
|
||||||
const hash = crypto.createHash('sha256');
|
const hash = crypto.createHash('sha256');
|
||||||
const fileStream = fs.createReadStream(path);
|
const fileStream = fs.createReadStream(filePath);
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
fileStream.on('data', data => {
|
fileStream.on('data', data => {
|
||||||
hash.update(data);
|
hash.update(data);
|
||||||
@@ -72664,9 +72671,9 @@ async function fileMetadata(path) {
|
|||||||
fileStream.on('end', () => {
|
fileStream.on('end', () => {
|
||||||
const sha256 = hash.digest('hex');
|
const sha256 = hash.digest('hex');
|
||||||
resolve({
|
resolve({
|
||||||
path: path,
|
path: filePath,
|
||||||
size: size,
|
size,
|
||||||
sha256: 'sha256:' + sha256
|
sha256: `sha256:${sha256}`
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
fileStream.on('error', err => {
|
fileStream.on('error', err => {
|
||||||
@@ -72725,7 +72732,7 @@ async function publishOCIArtifact(token, registry, repository, releaseId, semver
|
|||||||
const uploadBlobEndpoint = new URL(`v2/${repository}/blobs/uploads/`, registry).toString();
|
const uploadBlobEndpoint = new URL(`v2/${repository}/blobs/uploads/`, registry).toString();
|
||||||
const manifestEndpoint = new URL(`v2/${repository}/manifests/${semver}`, registry).toString();
|
const manifestEndpoint = new URL(`v2/${repository}/manifests/${semver}`, registry).toString();
|
||||||
core.info(`Creating GHCR package for release with semver:${semver} with path:"${zipFile.path}" and "${tarFile.path}".`);
|
core.info(`Creating GHCR package for release with semver:${semver} with path:"${zipFile.path}" and "${tarFile.path}".`);
|
||||||
let layerUploads = manifest.layers.map(layer => {
|
const layerUploads = manifest.layers.map(async (layer) => {
|
||||||
switch (layer.mediaType) {
|
switch (layer.mediaType) {
|
||||||
case 'application/vnd.github.actions.package.layer.v1.tar+gzip':
|
case 'application/vnd.github.actions.package.layer.v1.tar+gzip':
|
||||||
return uploadLayer(layer, tarFile, registry, checkBlobEndpoint, uploadBlobEndpoint, b64Token);
|
return uploadLayer(layer, tarFile, registry, checkBlobEndpoint, uploadBlobEndpoint, b64Token);
|
||||||
@@ -72747,7 +72754,7 @@ async function uploadLayer(layer, file, registryURL, checkBlobEndpoint, uploadBl
|
|||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${b64Token}`
|
Authorization: `Bearer ${b64Token}`
|
||||||
},
|
},
|
||||||
validateStatus: function (status) {
|
validateStatus: () => {
|
||||||
return true; // Allow non 2xx responses
|
return true; // Allow non 2xx responses
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -72764,22 +72771,22 @@ async function uploadLayer(layer, file, registryURL, checkBlobEndpoint, uploadBl
|
|||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${b64Token}`
|
Authorization: `Bearer ${b64Token}`
|
||||||
},
|
},
|
||||||
validateStatus: function (status) {
|
validateStatus: () => {
|
||||||
return true; // Allow non 2xx responses
|
return true; // Allow non 2xx responses
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (initiateUploadResponse.status != 202) {
|
if (initiateUploadResponse.status !== 202) {
|
||||||
core.error(`Unexpected response from upload post ${uploadBlobEndpoint}: ${initiateUploadResponse.status}`);
|
core.error(`Unexpected response from upload post ${uploadBlobEndpoint}: ${initiateUploadResponse.status}`);
|
||||||
throw new Error(`Unexpected response from POST upload ${initiateUploadResponse.status}`);
|
throw new Error(`Unexpected response from POST upload ${initiateUploadResponse.status}`);
|
||||||
}
|
}
|
||||||
const locationResponseHeader = initiateUploadResponse.headers['location'];
|
const locationResponseHeader = initiateUploadResponse.headers['location'];
|
||||||
if (locationResponseHeader == undefined) {
|
if (locationResponseHeader === undefined) {
|
||||||
throw new Error(`No location header in response from upload post ${uploadBlobEndpoint} for layer ${layer.digest}`);
|
throw new Error(`No location header in response from upload post ${uploadBlobEndpoint} for layer ${layer.digest}`);
|
||||||
}
|
}
|
||||||
let pathname = locationResponseHeader + '?digest=' + layer.digest;
|
const pathname = `${locationResponseHeader}?digest=${layer.digest}`;
|
||||||
const uploadBlobUrl = new URL(pathname, registryURL).toString();
|
const uploadBlobUrl = new URL(pathname, registryURL).toString();
|
||||||
// TODO: must we handle the empty config layer? Maybe we can just skip calling this at all
|
// TODO: must we handle the empty config layer? Maybe we can just skip calling this at all
|
||||||
var data;
|
let data;
|
||||||
if (file.size === 0) {
|
if (file.size === 0) {
|
||||||
data = Buffer.alloc(0);
|
data = Buffer.alloc(0);
|
||||||
}
|
}
|
||||||
@@ -72793,11 +72800,11 @@ async function uploadLayer(layer, file, registryURL, checkBlobEndpoint, uploadBl
|
|||||||
'Accept-Encoding': 'gzip',
|
'Accept-Encoding': 'gzip',
|
||||||
'Content-Length': layer.size.toString()
|
'Content-Length': layer.size.toString()
|
||||||
},
|
},
|
||||||
validateStatus: function (status) {
|
validateStatus: () => {
|
||||||
return true; // Allow non 2xx responses
|
return true; // Allow non 2xx responses
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (putResponse.status != 201) {
|
if (putResponse.status !== 201) {
|
||||||
throw new Error(`Unexpected response from PUT upload ${putResponse.status} for layer ${layer.digest}`);
|
throw new Error(`Unexpected response from PUT upload ${putResponse.status} for layer ${layer.digest}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -72808,23 +72815,23 @@ async function uploadManifest(manifestJSON, manifestEndpoint, b64Token) {
|
|||||||
Authorization: `Bearer ${b64Token}`,
|
Authorization: `Bearer ${b64Token}`,
|
||||||
'Content-Type': 'application/vnd.oci.image.manifest.v1+json'
|
'Content-Type': 'application/vnd.oci.image.manifest.v1+json'
|
||||||
},
|
},
|
||||||
validateStatus: function (status) {
|
validateStatus: () => {
|
||||||
return true; // Allow non 2xx responses
|
return true; // Allow non 2xx responses
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (putResponse.status != 201) {
|
if (putResponse.status !== 201) {
|
||||||
throw new Error(`Unexpected response from PUT manifest ${putResponse.status}`);
|
throw new Error(`Unexpected response from PUT manifest ${putResponse.status}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function configureRequestDebugLogging() {
|
function configureRequestDebugLogging() {
|
||||||
(0, axios_debug_log_1.default)({
|
(0, axios_debug_log_1.default)({
|
||||||
request: function (debug, config) {
|
request: (debug, config) => {
|
||||||
core.debug(`Request with ${config}`);
|
core.debug(`Request with ${config}`);
|
||||||
},
|
},
|
||||||
response: function (debug, response) {
|
response: (debug, response) => {
|
||||||
core.debug(`Response with ${response}`);
|
core.debug(`Response with ${response}`);
|
||||||
},
|
},
|
||||||
error: function (debug, error) {
|
error: (debug, error) => {
|
||||||
core.debug(`Error with ${error}`);
|
core.debug(`Error with ${error}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -72893,7 +72900,7 @@ async function run() {
|
|||||||
const releaseTag = github.context.payload.release.tag_name;
|
const releaseTag = github.context.payload.release.tag_name;
|
||||||
// Strip any leading 'v' from the tag in case the release format is e.g. 'v1.0.0' as recommended by GitHub docs
|
// Strip any leading 'v' from the tag in case the release format is e.g. 'v1.0.0' as recommended by GitHub docs
|
||||||
// https://docs.github.com/en/actions/creating-actions/releasing-and-maintaining-actions
|
// https://docs.github.com/en/actions/creating-actions/releasing-and-maintaining-actions
|
||||||
let targetVersion = semver_1.default.parse(releaseTag.replace(/^v/, ''));
|
const targetVersion = semver_1.default.parse(releaseTag.replace(/^v/, ''));
|
||||||
if (!targetVersion) {
|
if (!targetVersion) {
|
||||||
core.setFailed(`${releaseTag} is not a valid semantic version, and so cannot be uploaded as an Immutable Action.`);
|
core.setFailed(`${releaseTag} is not a valid semantic version, and so cannot be uploaded as an Immutable Action.`);
|
||||||
return;
|
return;
|
||||||
@@ -72910,7 +72917,7 @@ async function run() {
|
|||||||
tmpDir = fsHelper.createTempDir();
|
tmpDir = fsHelper.createTempDir();
|
||||||
const archives = await fsHelper.createArchives(path);
|
const archives = await fsHelper.createArchives(path);
|
||||||
const manifest = ociContainer.createActionPackageManifest(archives.tarFile, archives.zipFile, repository, targetVersion.raw, new Date());
|
const manifest = ociContainer.createActionPackageManifest(archives.tarFile, archives.zipFile, repository, targetVersion.raw, new Date());
|
||||||
let packageURL = await ghcr.publishOCIArtifact(token, registryURL, repository, releaseId.toString(), targetVersion.raw, archives.zipFile, archives.tarFile, manifest, true);
|
const packageURL = await ghcr.publishOCIArtifact(token, registryURL, repository, releaseId.toString(), targetVersion.raw, archives.zipFile, archives.tarFile, manifest, true);
|
||||||
core.setOutput('package-url', packageURL.toString());
|
core.setOutput('package-url', packageURL.toString());
|
||||||
// TODO: We might need to do some attestation stuff here, but unsure how to integrate it yet.
|
// TODO: We might need to do some attestation stuff here, but unsure how to integrate it yet.
|
||||||
// We might need to return the manifest JSON from the Action and link it to another action,
|
// We might need to return the manifest JSON from the Action and link it to another action,
|
||||||
|
|||||||
Reference in New Issue
Block a user