From 5efa2ebd8c8cfefd4d2d856388304e2371fe0583 Mon Sep 17 00:00:00 2001 From: Kenta Kubo <601636+kkebo@users.noreply.github.com> Date: Mon, 1 Dec 2025 21:55:01 +0900 Subject: [PATCH] Remove unused GPG functions The functions `setupKeys` and `refreshKeys` have not been used since the transition to Swiftly in #710. So the changes in #772 are meaningless. --- __tests__/gpg.test.ts | 65 ------------------------------------------- dist/index.js | 52 ---------------------------------- src/core/gpg.ts | 65 ------------------------------------------- src/core/os.ts | 2 -- 4 files changed, 184 deletions(-) delete mode 100644 __tests__/gpg.test.ts diff --git a/__tests__/gpg.test.ts b/__tests__/gpg.test.ts deleted file mode 100644 index 777ff182..00000000 --- a/__tests__/gpg.test.ts +++ /dev/null @@ -1,65 +0,0 @@ -import * as exec from "@actions/exec"; -import { refreshKeys } from "../src/core"; - -jest.mock("@actions/exec"); - -const mockExec = exec.exec as jest.Mock; - -describe("gpg", () => { - afterEach(() => { - mockExec.mockClear(); - }); - - it("uses the first responding keyserver in the pool", async () => { - mockExec.mockImplementation(() => Promise.resolve(0)); - await refreshKeys(); - expect(mockExec).toBeCalledTimes(1); - }); - - // NOTE: Currently disabled as the pool only contains one server - // it("uses the next keyserver in the pool if the previous fails", async () => { - // const failingServers = 3; - // let testedServers = 0; - - // mockExec.mockImplementation(() => { - // testedServers++; - // if (testedServers >= failingServers) { - // return Promise.resolve(0); - // } else { - // return Promise.resolve(1); - // } - // }); - - // await refreshKeys(); - // expect(mockExec).toBeCalledTimes(3); - // }); - - it("makes a second attempt if the keyserver fails", async () => { - const attempts = 2; - let tests = 0; - - mockExec.mockImplementation(() => { - tests++; - if (tests >= attempts) { - return Promise.resolve(0); - } else { - return Promise.resolve(1); - } - }); - - await refreshKeys(); - expect(mockExec).toBeCalledTimes(2); - }); - - it("throws an error if all servers in the pool fails", async () => { - mockExec.mockImplementation(() => Promise.resolve(1)); - - try { - await refreshKeys(); - } catch (e) { - expect(e).toEqual( - new Error("Failed to refresh keys from any server in the pool."), - ); - } - }); -}); diff --git a/dist/index.js b/dist/index.js index 9c98c293..fea81407 100644 --- a/dist/index.js +++ b/dist/index.js @@ -107,65 +107,13 @@ var __importStar = (this && this.__importStar) || (function () { }; })(); Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.setupKeys = setupKeys; exports.verify = verify; -exports.refreshKeys = refreshKeys; const exec_1 = __nccwpck_require__(5236); const core = __importStar(__nccwpck_require__(7484)); -const toolCache = __importStar(__nccwpck_require__(3472)); -async function setupKeys(os) { - core.debug("Fetching verification keys"); - let path = await toolCache.downloadTool("https://swift.org/keys/all-keys.asc"); - if (os === "linux" || os === "darwin") { - core.debug("Examining verification keys"); - await (0, exec_1.exec)(`file "${path}"`); - const isPlaintext = await (0, exec_1.exec)(`gunzip --test "${path}"`, undefined, { - silent: true, - ignoreReturnCode: true, - }); - core.debug("Importing verification keys"); - await (0, exec_1.exec)("bash", [ - "-c", - `${isPlaintext ? "cat" : "zcat"} "${path}" | gpg --import`, - ]); - } - if (os === "win32") { - core.debug("Importing verification keys"); - await (0, exec_1.exec)(`gpg --import "${path}"`); - } - core.debug("Refreshing keys"); - await refreshKeys(); -} async function verify(signaturePath, packagePath) { core.debug("Verifying signature"); await (0, exec_1.exec)("gpg", ["--verify", signaturePath, packagePath]); } -async function refreshKeys() { - const pool = ["hkp://keyserver.ubuntu.com"]; - for (const server of pool) { - core.debug(`Refreshing keys from ${server}`); - // 1st try... - if (await refreshKeysFromServer(server)) { - core.debug(`Refresh successful on first attempt`); - return; - } - // 2nd try... - if (await refreshKeysFromServer(server)) { - core.debug(`Refresh successful on second attempt`); - return; - } - core.debug(`Refresh failed`); - } - throw new Error("Failed to refresh keys from any server in the pool."); -} -function refreshKeysFromServer(server) { - return (0, exec_1.exec)(`gpg --keyserver ${server} --refresh-keys Swift`) - .then((code) => code === 0) - .catch((error) => { - core.warning(`An error occurred when trying to refresh keys from ${server}: ${error}`); - return false; - }); -} /***/ }), diff --git a/src/core/gpg.ts b/src/core/gpg.ts index 4a64686f..d1a9355b 100644 --- a/src/core/gpg.ts +++ b/src/core/gpg.ts @@ -1,72 +1,7 @@ import { exec } from "@actions/exec"; import * as core from "@actions/core"; -import * as toolCache from "@actions/tool-cache"; -import { OS } from "./os"; - -export async function setupKeys(os: OS) { - core.debug("Fetching verification keys"); - let path = await toolCache.downloadTool( - "https://swift.org/keys/all-keys.asc", - ); - - if (os === "linux" || os === "darwin") { - core.debug("Examining verification keys"); - await exec(`file "${path}"`); - const isPlaintext = await exec(`gunzip --test "${path}"`, undefined, { - silent: true, - ignoreReturnCode: true, - }); - - core.debug("Importing verification keys"); - await exec("bash", [ - "-c", - `${isPlaintext ? "cat" : "zcat"} "${path}" | gpg --import`, - ]); - } - - if (os === "win32") { - core.debug("Importing verification keys"); - await exec(`gpg --import "${path}"`); - } - - core.debug("Refreshing keys"); - await refreshKeys(); -} export async function verify(signaturePath: string, packagePath: string) { core.debug("Verifying signature"); await exec("gpg", ["--verify", signaturePath, packagePath]); } - -export async function refreshKeys() { - const pool = ["hkp://keyserver.ubuntu.com"]; - - for (const server of pool) { - core.debug(`Refreshing keys from ${server}`); - // 1st try... - if (await refreshKeysFromServer(server)) { - core.debug(`Refresh successful on first attempt`); - return; - } - - // 2nd try... - if (await refreshKeysFromServer(server)) { - core.debug(`Refresh successful on second attempt`); - return; - } - core.debug(`Refresh failed`); - } - - throw new Error("Failed to refresh keys from any server in the pool."); -} - -function refreshKeysFromServer(server: string): Promise { - return exec(`gpg --keyserver ${server} --refresh-keys Swift`) - .then((code) => code === 0) - .catch((error) => { - core.warning( - `An error occurred when trying to refresh keys from ${server}: ${error}`, - ); - return false; - }); -} diff --git a/src/core/os.ts b/src/core/os.ts index 3014ea96..484e36d1 100644 --- a/src/core/os.ts +++ b/src/core/os.ts @@ -9,5 +9,3 @@ export async function getOS() { return detectedSystem.os; } - -export type OS = getos.Os["os"];