Skip to content

Commit

Permalink
fix: Add sha256 sum file for eclipse (#145)
Browse files Browse the repository at this point in the history
* fix: Add sha256 sum file for eclipse

Fix #110

* fix: typo in import alias

* Re-use sha256 function in eclipse and homebrew

* fix lint errors
  • Loading branch information
diogomatsubara authored May 27, 2024
1 parent a37183f commit c5fad54
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 55 deletions.
40 changes: 38 additions & 2 deletions dist/publish-crates-eclipse-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -127589,6 +127589,27 @@ function buildDebian(path, target, version) {
__webpack_async_result__();
} catch(e) { __webpack_async_result__(e); } }, 1);

/***/ }),

/***/ 36410:
/***/ ((__unused_webpack_module, __webpack_exports__, __nccwpck_require__) => {

"use strict";
/* harmony export */ __nccwpck_require__.d(__webpack_exports__, {
/* harmony export */ "J": () => (/* binding */ sha256)
/* harmony export */ });
/* harmony import */ var crypto__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(6113);
/* harmony import */ var crypto__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__nccwpck_require__.n(crypto__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var fs_promises__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(73292);
/* harmony import */ var fs_promises__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__nccwpck_require__.n(fs_promises__WEBPACK_IMPORTED_MODULE_1__);


async function sha256(path) {
const contents = await fs_promises__WEBPACK_IMPORTED_MODULE_1__.readFile(path);
return crypto__WEBPACK_IMPORTED_MODULE_0__.createHash("sha256").update(contents).digest("hex");
}


/***/ }),

/***/ 28121:
Expand Down Expand Up @@ -127772,6 +127793,9 @@ __nccwpck_require__.a(module, async (__webpack_handle_async_dependencies__, __we
/* harmony import */ var _command__WEBPACK_IMPORTED_MODULE_4__ = __nccwpck_require__(28121);
/* harmony import */ var _build_crates_debian__WEBPACK_IMPORTED_MODULE_5__ = __nccwpck_require__(22771);
/* harmony import */ var _build_crates_standalone__WEBPACK_IMPORTED_MODULE_6__ = __nccwpck_require__(32);
/* harmony import */ var _checksum__WEBPACK_IMPORTED_MODULE_7__ = __nccwpck_require__(36410);
/* harmony import */ var fs_promises__WEBPACK_IMPORTED_MODULE_8__ = __nccwpck_require__(73292);
/* harmony import */ var fs_promises__WEBPACK_IMPORTED_MODULE_8___default = /*#__PURE__*/__nccwpck_require__.n(fs_promises__WEBPACK_IMPORTED_MODULE_8__);
var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_build_crates_debian__WEBPACK_IMPORTED_MODULE_5__, _build_crates_standalone__WEBPACK_IMPORTED_MODULE_6__]);
([_build_crates_debian__WEBPACK_IMPORTED_MODULE_5__, _build_crates_standalone__WEBPACK_IMPORTED_MODULE_6__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);

Expand All @@ -127781,6 +127805,8 @@ var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_bui





const artifact = new _actions_artifact__WEBPACK_IMPORTED_MODULE_2__.DefaultArtifactClient();
function setup() {
const liveRun = _actions_core__WEBPACK_IMPORTED_MODULE_1__.getBooleanInput("live-run", { required: true });
Expand Down Expand Up @@ -127810,21 +127836,31 @@ async function main(input) {
return input.archiveRegExp.test(name);
}
};
const checksumFile = "sha256sums.txt";
const archiveDir = `${input.sshHostPath}/${input.version}`;
const results = await artifact.listArtifacts({ latest: true });
for (const result of results.artifacts) {
if (shouldPublishArtifact(result.name)) {
const { downloadPath } = await artifact.downloadArtifact(result.id);
const archive = path__WEBPACK_IMPORTED_MODULE_0__.join(downloadPath, result.name);
const archiveDir = `${input.sshHostPath}/${input.version}`;
_actions_core__WEBPACK_IMPORTED_MODULE_1__.info(`Uploading ${archive} to download.eclipse.org`);
const checksum = await (0,_checksum__WEBPACK_IMPORTED_MODULE_7__/* .sha256 */ .J)(archive);
// Write the sha256 checksum of the archive
await fs_promises__WEBPACK_IMPORTED_MODULE_8__.appendFile(checksumFile, `${checksum} ${archive}\n`);
if (input.liveRun) {
_actions_core__WEBPACK_IMPORTED_MODULE_1__.info(`Uploading ${archive} to download.eclipse.org`);
await _ssh__WEBPACK_IMPORTED_MODULE_3__/* .withIdentity */ .Y(input.sshPrivateKey, input.sshPassphrase, env => {
(0,_command__WEBPACK_IMPORTED_MODULE_4__.sh)(`ssh -v -o StrictHostKeyChecking=no ${input.sshHost} mkdir -p ${archiveDir}`, { env });
(0,_command__WEBPACK_IMPORTED_MODULE_4__.sh)(`scp -v -o StrictHostKeyChecking=no -r ${archive} ${input.sshHost}:${archiveDir}`, { env });
});
}
}
}
if (input.liveRun) {
_actions_core__WEBPACK_IMPORTED_MODULE_1__.info(`Uploading ${checksumFile} to download.eclipse.org`);
await _ssh__WEBPACK_IMPORTED_MODULE_3__/* .withIdentity */ .Y(input.sshPrivateKey, input.sshPassphrase, env => {
(0,_command__WEBPACK_IMPORTED_MODULE_4__.sh)(`scp -v -o StrictHostKeyChecking=no -r ${checksumFile} ${input.sshHost}:${archiveDir}`, { env });
});
}
cleanup();
}
catch (error) {
Expand Down
96 changes: 56 additions & 40 deletions dist/publish-crates-homebrew-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -127493,6 +127493,27 @@ function buildDebian(path, target, version) {
__webpack_async_result__();
} catch(e) { __webpack_async_result__(e); } }, 1);

/***/ }),

/***/ 36410:
/***/ ((__unused_webpack_module, __webpack_exports__, __nccwpck_require__) => {

"use strict";
/* harmony export */ __nccwpck_require__.d(__webpack_exports__, {
/* harmony export */ "J": () => (/* binding */ sha256)
/* harmony export */ });
/* harmony import */ var crypto__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(6113);
/* harmony import */ var crypto__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__nccwpck_require__.n(crypto__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var fs_promises__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(73292);
/* harmony import */ var fs_promises__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__nccwpck_require__.n(fs_promises__WEBPACK_IMPORTED_MODULE_1__);


async function sha256(path) {
const contents = await fs_promises__WEBPACK_IMPORTED_MODULE_1__.readFile(path);
return crypto__WEBPACK_IMPORTED_MODULE_0__.createHash("sha256").update(contents).digest("hex");
}


/***/ }),

/***/ 28121:
Expand Down Expand Up @@ -127667,13 +127688,12 @@ __nccwpck_require__.a(module, async (__webpack_handle_async_dependencies__, __we
/* unused harmony export cleanup */
/* harmony import */ var fs_promises__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(73292);
/* harmony import */ var fs_promises__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__nccwpck_require__.n(fs_promises__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var crypto__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(6113);
/* harmony import */ var crypto__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__nccwpck_require__.n(crypto__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var _actions_core__WEBPACK_IMPORTED_MODULE_2__ = __nccwpck_require__(42186);
/* harmony import */ var _actions_core__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__nccwpck_require__.n(_actions_core__WEBPACK_IMPORTED_MODULE_2__);
/* harmony import */ var _actions_artifact__WEBPACK_IMPORTED_MODULE_3__ = __nccwpck_require__(79450);
/* harmony import */ var _actions_artifact__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__nccwpck_require__.n(_actions_artifact__WEBPACK_IMPORTED_MODULE_3__);
/* harmony import */ var _command__WEBPACK_IMPORTED_MODULE_4__ = __nccwpck_require__(28121);
/* harmony import */ var _actions_core__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(42186);
/* harmony import */ var _actions_core__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__nccwpck_require__.n(_actions_core__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var _actions_artifact__WEBPACK_IMPORTED_MODULE_2__ = __nccwpck_require__(79450);
/* harmony import */ var _actions_artifact__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__nccwpck_require__.n(_actions_artifact__WEBPACK_IMPORTED_MODULE_2__);
/* harmony import */ var _command__WEBPACK_IMPORTED_MODULE_3__ = __nccwpck_require__(28121);
/* harmony import */ var _checksum__WEBPACK_IMPORTED_MODULE_4__ = __nccwpck_require__(36410);
/* harmony import */ var _ssh__WEBPACK_IMPORTED_MODULE_5__ = __nccwpck_require__(27149);
/* harmony import */ var _build_crates_standalone__WEBPACK_IMPORTED_MODULE_6__ = __nccwpck_require__(32);
/* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_7__ = __nccwpck_require__(81724);
Expand All @@ -127687,19 +127707,19 @@ _build_crates_standalone__WEBPACK_IMPORTED_MODULE_6__ = (__webpack_async_depende



const artifact = new _actions_artifact__WEBPACK_IMPORTED_MODULE_3__.DefaultArtifactClient();
const artifact = new _actions_artifact__WEBPACK_IMPORTED_MODULE_2__.DefaultArtifactClient();
function setup() {
const liveRun = _actions_core__WEBPACK_IMPORTED_MODULE_2__.getBooleanInput("live-run", { required: true });
const version = _actions_core__WEBPACK_IMPORTED_MODULE_2__.getInput("version", { required: true });
const repo = _actions_core__WEBPACK_IMPORTED_MODULE_2__.getInput("repo", { required: true });
const formulae = _actions_core__WEBPACK_IMPORTED_MODULE_2__.getInput("formulae", { required: true });
const tap = _actions_core__WEBPACK_IMPORTED_MODULE_2__.getInput("tap", { required: true });
const sshHost = _actions_core__WEBPACK_IMPORTED_MODULE_2__.getInput("ssh-host", { required: true });
const sshHostUrl = _actions_core__WEBPACK_IMPORTED_MODULE_2__.getInput("ssh-host-url", { required: true });
const sshHostPath = _actions_core__WEBPACK_IMPORTED_MODULE_2__.getInput("ssh-host-path", { required: true });
const sshPrivateKey = _actions_core__WEBPACK_IMPORTED_MODULE_2__.getInput("ssh-private-key", { required: true });
const sshPassphrase = _actions_core__WEBPACK_IMPORTED_MODULE_2__.getInput("ssh-passphrase", { required: true });
const githubToken = _actions_core__WEBPACK_IMPORTED_MODULE_2__.getInput("github-token", { required: true });
const liveRun = _actions_core__WEBPACK_IMPORTED_MODULE_1__.getBooleanInput("live-run", { required: true });
const version = _actions_core__WEBPACK_IMPORTED_MODULE_1__.getInput("version", { required: true });
const repo = _actions_core__WEBPACK_IMPORTED_MODULE_1__.getInput("repo", { required: true });
const formulae = _actions_core__WEBPACK_IMPORTED_MODULE_1__.getInput("formulae", { required: true });
const tap = _actions_core__WEBPACK_IMPORTED_MODULE_1__.getInput("tap", { required: true });
const sshHost = _actions_core__WEBPACK_IMPORTED_MODULE_1__.getInput("ssh-host", { required: true });
const sshHostUrl = _actions_core__WEBPACK_IMPORTED_MODULE_1__.getInput("ssh-host-url", { required: true });
const sshHostPath = _actions_core__WEBPACK_IMPORTED_MODULE_1__.getInput("ssh-host-path", { required: true });
const sshPrivateKey = _actions_core__WEBPACK_IMPORTED_MODULE_1__.getInput("ssh-private-key", { required: true });
const sshPassphrase = _actions_core__WEBPACK_IMPORTED_MODULE_1__.getInput("ssh-passphrase", { required: true });
const githubToken = _actions_core__WEBPACK_IMPORTED_MODULE_1__.getInput("github-token", { required: true });
return {
liveRun,
version,
Expand All @@ -127723,66 +127743,62 @@ const X86_64_SHA256 = "x86_64-sha256";
async function main(input) {
try {
const repo = input.repo.split("/").at(1);
const tapPath = `${(0,_command__WEBPACK_IMPORTED_MODULE_4__.sh)("brew --repository").trim()}/Library/Taps/${input.tap}`;
const tapPath = `${(0,_command__WEBPACK_IMPORTED_MODULE_3__.sh)("brew --repository").trim()}/Library/Taps/${input.tap}`;
const tapUrl = `https://${input.githubToken}@github.com/${input.tap}.git`;
for (const target of [X86_64_APPLE_DARWIN, AARCH64_APPLE_DARWIN]) {
const name = (0,_build_crates_standalone__WEBPACK_IMPORTED_MODULE_6__/* .artifactName */ .vz)(repo, input.version, target);
const result = await artifact.getArtifact(name);
await artifact.downloadArtifact(result.artifact.id);
if (input.liveRun) {
await _ssh__WEBPACK_IMPORTED_MODULE_5__/* .withIdentity */ .Y(input.sshPrivateKey, input.sshPassphrase, env => {
(0,_command__WEBPACK_IMPORTED_MODULE_4__.sh)(`ssh -v -o StrictHostKeyChecking=no ${input.sshHost} mkdir -p ${input.sshHostPath}`, { env });
(0,_command__WEBPACK_IMPORTED_MODULE_4__.sh)(`scp -v -o StrictHostKeyChecking=no -r ${name} ${input.sshHost}:${input.sshHostPath}`, { env });
(0,_command__WEBPACK_IMPORTED_MODULE_3__.sh)(`ssh -v -o StrictHostKeyChecking=no ${input.sshHost} mkdir -p ${input.sshHostPath}`, { env });
(0,_command__WEBPACK_IMPORTED_MODULE_3__.sh)(`scp -v -o StrictHostKeyChecking=no -r ${name} ${input.sshHost}:${input.sshHostPath}`, { env });
});
}
}
(0,_command__WEBPACK_IMPORTED_MODULE_4__.sh)(`brew untap ${input.tap}`, { check: false });
(0,_command__WEBPACK_IMPORTED_MODULE_4__.sh)(`brew tap ${input.tap} ${tapUrl}`);
(0,_command__WEBPACK_IMPORTED_MODULE_3__.sh)(`brew untap ${input.tap}`, { check: false });
(0,_command__WEBPACK_IMPORTED_MODULE_3__.sh)(`brew tap ${input.tap} ${tapUrl}`);
const releasePath = `${tapPath}/release.json`;
const releaseFile = await fs_promises__WEBPACK_IMPORTED_MODULE_0__.readFile(releasePath, "utf-8");
const release = JSON.parse(releaseFile);
const sha256 = async (target) => {
const contents = await fs_promises__WEBPACK_IMPORTED_MODULE_0__.readFile((0,_build_crates_standalone__WEBPACK_IMPORTED_MODULE_6__/* .artifactName */ .vz)(repo, input.version, target));
return crypto__WEBPACK_IMPORTED_MODULE_1__.createHash("sha256").update(contents).digest("hex");
};
const url = (target) => {
const baseUrl = input.liveRun ? input.sshHostUrl : `file://${process.cwd()}`;
return `${baseUrl}/${(0,_build_crates_standalone__WEBPACK_IMPORTED_MODULE_6__/* .artifactName */ .vz)(repo, input.version, target)}`;
};
for (const formula of input.formulae) {
release[formula] = {
[X86_64_URL]: url(X86_64_APPLE_DARWIN),
[X86_64_SHA256]: await sha256(X86_64_APPLE_DARWIN),
[X86_64_SHA256]: await (0,_checksum__WEBPACK_IMPORTED_MODULE_4__/* .sha256 */ .J)((0,_build_crates_standalone__WEBPACK_IMPORTED_MODULE_6__/* .artifactName */ .vz)(repo, input.version, X86_64_APPLE_DARWIN)),
[AARCH64_URL]: url(AARCH64_APPLE_DARWIN),
[AARCH64_SHA256]: await sha256(AARCH64_APPLE_DARWIN),
[AARCH64_SHA256]: await (0,_checksum__WEBPACK_IMPORTED_MODULE_4__/* .sha256 */ .J)((0,_build_crates_standalone__WEBPACK_IMPORTED_MODULE_6__/* .artifactName */ .vz)(repo, input.version, AARCH64_APPLE_DARWIN)),
};
}
await fs_promises__WEBPACK_IMPORTED_MODULE_0__.writeFile(releasePath, JSON.stringify(release, null, 2));
const message = `chore: Bump ${input.formulae.join(", ")} to \`${input.version}\``;
(0,_command__WEBPACK_IMPORTED_MODULE_4__.sh)(`git commit ${releasePath} --message '${message}'`, { cwd: tapPath, env: _config__WEBPACK_IMPORTED_MODULE_7__/* .gitEnv */ .B });
(0,_command__WEBPACK_IMPORTED_MODULE_3__.sh)(`git commit ${releasePath} --message '${message}'`, { cwd: tapPath, env: _config__WEBPACK_IMPORTED_MODULE_7__/* .gitEnv */ .B });
for (const formula of input.formulae) {
(0,_command__WEBPACK_IMPORTED_MODULE_4__.sh)(`brew audit ${formula}`);
(0,_command__WEBPACK_IMPORTED_MODULE_4__.sh)(`brew install --force ${formula}`);
(0,_command__WEBPACK_IMPORTED_MODULE_4__.sh)(`brew uninstall --force --ignore-dependencies ${formula}`);
(0,_command__WEBPACK_IMPORTED_MODULE_4__.sh)("brew autoremove");
(0,_command__WEBPACK_IMPORTED_MODULE_3__.sh)(`brew audit ${formula}`);
(0,_command__WEBPACK_IMPORTED_MODULE_3__.sh)(`brew install --force ${formula}`);
(0,_command__WEBPACK_IMPORTED_MODULE_3__.sh)(`brew uninstall --force --ignore-dependencies ${formula}`);
(0,_command__WEBPACK_IMPORTED_MODULE_3__.sh)("brew autoremove");
}
if (input.liveRun) {
(0,_command__WEBPACK_IMPORTED_MODULE_4__.sh)(`git pull ${tapUrl} --rebase`, { cwd: tapPath });
(0,_command__WEBPACK_IMPORTED_MODULE_4__.sh)(`git push ${tapUrl}`, { cwd: tapPath });
(0,_command__WEBPACK_IMPORTED_MODULE_3__.sh)(`git pull ${tapUrl} --rebase`, { cwd: tapPath });
(0,_command__WEBPACK_IMPORTED_MODULE_3__.sh)(`git push ${tapUrl}`, { cwd: tapPath });
}
cleanup(input);
}
catch (error) {
cleanup(input);
if (error instanceof Error)
_actions_core__WEBPACK_IMPORTED_MODULE_2__.setFailed(error.message);
_actions_core__WEBPACK_IMPORTED_MODULE_1__.setFailed(error.message);
}
}
function cleanup(input) {
for (const formula of input.formulae) {
(0,_command__WEBPACK_IMPORTED_MODULE_4__.sh)(`brew uninstall --force --ignore-dependencies ${formula}`, { check: false });
(0,_command__WEBPACK_IMPORTED_MODULE_3__.sh)(`brew uninstall --force --ignore-dependencies ${formula}`, { check: false });
}
(0,_command__WEBPACK_IMPORTED_MODULE_4__.sh)(`brew untap ${input.tap}`, { check: false });
(0,_command__WEBPACK_IMPORTED_MODULE_3__.sh)(`brew untap ${input.tap}`, { check: false });
}

__webpack_async_result__();
Expand Down
8 changes: 8 additions & 0 deletions src/checksum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { PathLike } from "node:fs";
import * as crypto from "crypto";
import * as fs from "fs/promises";

export async function sha256(path: PathLike | fs.FileHandle) {
const contents = await fs.readFile(path);
return crypto.createHash("sha256").update(contents).digest("hex");
}
Loading

0 comments on commit c5fad54

Please sign in to comment.