Skip to content

Commit

Permalink
Strip SSH signatures from tag annotation bodies
Browse files Browse the repository at this point in the history
Closes #31
  • Loading branch information
ezzatron committed Sep 1, 2022
1 parent b861779 commit 4228368
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/git.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { exec, getExecOutput } from "@actions/exec";

const SIGNATURE_PATTERN =
/-----BEGIN (\w+) SIGNATURE-----.*-----END \1 SIGNATURE-----/;

export async function determineRef({ group, info, silent = false }) {
return group("Determining the current Git ref", async () => {
const { stdout } = await getExecOutput(
Expand Down Expand Up @@ -78,8 +81,20 @@ export async function readTagAnnotation({ group, silent = false, tag }) {
}
);

return [true, tagSubject.trim(), tagBody.trim()];
return [true, tagSubject.trim(), trimTagBody(tagBody)];
} catch {
return [false, "", ""];
}
}

/**
* This function is unfortunately necessary because the version of Git on the
* Node.js Docker base image that I use is too old to understand SSH signatures,
* and does not automatically remove them from tag annotation bodies.
*
* Once the Git version used on the Node.js Docker image is 2.34.0 or greater,
* this function can be removed, and replaced with a simple trim operation.
*/
function trimTagBody(tagBody) {
return tagBody.replace(SIGNATURE_PATTERN, "").trim();
}

0 comments on commit 4228368

Please sign in to comment.