Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 37 additions & 6 deletions actions/rsync-cache/dist/commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -30778,7 +30778,7 @@ class Rsync {

// SSH settings:
this.ssh_key_dir = os$1.homedir() + "/.ssh";
this.ssh_key_file = this.ssh_key_dir + "/." + crypto$1.randomUUID();
this.ssh_key_file = this.ssh_key_dir + "/" + crypto$1.randomUUID();
this.ssh_key = this.core.getInput("ssh_key", { required: false });

if (
Expand Down Expand Up @@ -30814,6 +30814,11 @@ class Rsync {
if (!path$1.isAbsolute(this.path)) {
throw new Error(`path to cache must be absolute: ${this.path}`);
}

// SSH will reject the key if it doesn't end with a newline.
if (this.ssh_key && !this.ssh_key.endsWith("\n")) {
this.ssh_key += "\n";
}
}

// Prepare some variables.
Expand Down Expand Up @@ -30876,14 +30881,40 @@ class Rsync {
return exit_code;
}

// Fall back to rclone if the SSH key is missing. We can at least
// fetch the cache from the public HTTP view.
async fetch_only() {
this.core.notice(`Falling back to HTTP fetch...`);

const exit_code = await this.exec.exec(
"rclone",
[
"copy",
"--http-url",
`https://archive.openms.de/openms/${this.name}/${this.key}`,
":http:",
this.path,
],
{ ignoreReturnCode: true },
);

return exit_code;
}

// Pull the cache from the remote server.
async pull() {
const rsync_args = [
this.ssh_dir, // FROM
this.path, // TO
];
let exit_code = -1;

const exit_code = await this.run(rsync_args);
if (this.disabled) {
exit_code = this.fetch_only();
} else {
const rsync_args = [
this.ssh_dir, // FROM
this.path, // TO
];

exit_code = await this.run(rsync_args);
}

if (exit_code != 0) {
this.core.notice(`Cache ${this.name}: error fetching remote cache`);
Expand Down
2 changes: 1 addition & 1 deletion actions/rsync-cache/dist/commit.js.map

Large diffs are not rendered by default.

43 changes: 37 additions & 6 deletions actions/rsync-cache/dist/restore.js
Original file line number Diff line number Diff line change
Expand Up @@ -30778,7 +30778,7 @@ class Rsync {

// SSH settings:
this.ssh_key_dir = os$1.homedir() + "/.ssh";
this.ssh_key_file = this.ssh_key_dir + "/." + crypto$1.randomUUID();
this.ssh_key_file = this.ssh_key_dir + "/" + crypto$1.randomUUID();
this.ssh_key = this.core.getInput("ssh_key", { required: false });

if (
Expand Down Expand Up @@ -30814,6 +30814,11 @@ class Rsync {
if (!path$1.isAbsolute(this.path)) {
throw new Error(`path to cache must be absolute: ${this.path}`);
}

// SSH will reject the key if it doesn't end with a newline.
if (this.ssh_key && !this.ssh_key.endsWith("\n")) {
this.ssh_key += "\n";
}
}

// Prepare some variables.
Expand Down Expand Up @@ -30876,14 +30881,40 @@ class Rsync {
return exit_code;
}

// Fall back to rclone if the SSH key is missing. We can at least
// fetch the cache from the public HTTP view.
async fetch_only() {
this.core.notice(`Falling back to HTTP fetch...`);

const exit_code = await this.exec.exec(
"rclone",
[
"copy",
"--http-url",
`https://archive.openms.de/openms/${this.name}/${this.key}`,
":http:",
this.path,
],
{ ignoreReturnCode: true },
);

return exit_code;
}

// Pull the cache from the remote server.
async pull() {
const rsync_args = [
this.ssh_dir, // FROM
this.path, // TO
];
let exit_code = -1;

const exit_code = await this.run(rsync_args);
if (this.disabled) {
exit_code = this.fetch_only();
} else {
const rsync_args = [
this.ssh_dir, // FROM
this.path, // TO
];

exit_code = await this.run(rsync_args);
}

if (exit_code != 0) {
this.core.notice(`Cache ${this.name}: error fetching remote cache`);
Expand Down
2 changes: 1 addition & 1 deletion actions/rsync-cache/dist/restore.js.map

Large diffs are not rendered by default.

43 changes: 37 additions & 6 deletions actions/rsync-cache/src/rsync.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default class Rsync {

// SSH settings:
this.ssh_key_dir = os.homedir() + "/.ssh";
this.ssh_key_file = this.ssh_key_dir + "/." + crypto.randomUUID();
this.ssh_key_file = this.ssh_key_dir + "/" + crypto.randomUUID();
this.ssh_key = this.core.getInput("ssh_key", { required: false });

if (
Expand Down Expand Up @@ -60,6 +60,11 @@ export default class Rsync {
if (!path.isAbsolute(this.path)) {
throw new Error(`path to cache must be absolute: ${this.path}`);
}

// SSH will reject the key if it doesn't end with a newline.
if (this.ssh_key && !this.ssh_key.endsWith("\n")) {
this.ssh_key += "\n";
}
}

// Prepare some variables.
Expand Down Expand Up @@ -122,14 +127,40 @@ export default class Rsync {
return exit_code;
}

// Fall back to rclone if the SSH key is missing. We can at least
// fetch the cache from the public HTTP view.
async fetch_only() {
this.core.notice(`Falling back to HTTP fetch...`);

const exit_code = await this.exec.exec(
"rclone",
[
"copy",
"--http-url",
`https://archive.openms.de/openms/${this.name}/${this.key}`,
":http:",
this.path,
],
{ ignoreReturnCode: true },
);

return exit_code;
}

// Pull the cache from the remote server.
async pull() {
const rsync_args = [
this.ssh_dir, // FROM
this.path, // TO
];
let exit_code = -1;

const exit_code = await this.run(rsync_args);
if (this.disabled) {
exit_code = this.fetch_only();
} else {
const rsync_args = [
this.ssh_dir, // FROM
this.path, // TO
];

exit_code = await this.run(rsync_args);
}

if (exit_code != 0) {
this.core.notice(`Cache ${this.name}: error fetching remote cache`);
Expand Down
6 changes: 5 additions & 1 deletion actions/rsync-cache/test/rsync_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ test("creates and removes SSH key", async () => {
assert(file_name);
assert.equal(deps.fs.files.size, 1);
assert(deps.fs.files.has(file_name));
assert.equal(deps.fs.files.get(file_name), key_text);
assert.equal(deps.fs.files.get(file_name), key_text + "\n");
assert.equal(deps.fs.modes.get(file_name), 0o600);

// File was also deleted.
Expand Down Expand Up @@ -201,5 +201,9 @@ test("disabled on missing ssh key", async () => {
assert.equal(exit_code, 0);
assert.equal(deps.exec.commands.length, 0);
assert.equal(deps.core.notices.length, 1);

// But fetching should try to run rclone:
await rsync.pull();
deps.exec.assert_last_command("rclone");
}
});