From 6549c6d230d00263ab1c9f46ce2f8166aeb996c0 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Mon, 4 May 2020 20:06:27 +0200 Subject: [PATCH] Drop Windows support --- .github/workflows/ci.yml | 1 - .github/workflows/test.yml | 1 - README.md | 2 +- dist/index.js | 330 ++----------------------------------- package.json | 4 +- src/gpg.ts | 31 +--- src/main.ts | 6 + 7 files changed, 22 insertions(+), 353 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 62cbd66..3b9f26e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,6 @@ jobs: os: - ubuntu-latest - macOS-latest - - windows-latest steps: - name: Checkout diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4aa0cb2..1134300 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,7 +17,6 @@ jobs: os: - ubuntu-latest - macOS-latest - - windows-latest steps: - # https://github.com/actions/checkout diff --git a/README.md b/README.md index 2cebd9b..6930968 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ If you are interested, [check out](https://git.io/Je09Y) my other :octocat: GitH ## Features -* Works on Linux, MacOS and Windows [virtual environments](https://help.github.com/en/articles/virtual-environments-for-github-actions#supported-virtual-environments-and-hardware-resources) +* Works on Linux and MacOS [virtual environments](https://help.github.com/en/articles/virtual-environments-for-github-actions#supported-virtual-environments-and-hardware-resources) * Allow to seed the internal cache of `gpg-agent` with provided passphrase * Purge imported GPG key and cache information from runner (security) diff --git a/dist/index.js b/dist/index.js index 90200ef..4880be4 100644 --- a/dist/index.js +++ b/dist/index.js @@ -987,54 +987,6 @@ if (!exports.IsPost) { } -/***/ }), - -/***/ 197: -/***/ (function(module, __unusedexports, __webpack_require__) { - -module.exports = isexe -isexe.sync = sync - -var fs = __webpack_require__(747) - -function isexe (path, options, cb) { - fs.stat(path, function (er, stat) { - cb(er, er ? false : checkStat(stat, options)) - }) -} - -function sync (path, options) { - return checkStat(fs.statSync(path), options) -} - -function checkStat (stat, options) { - return stat.isFile() && checkMode(stat, options) -} - -function checkMode (stat, options) { - var mod = stat.mode - var uid = stat.uid - var gid = stat.gid - - var myUid = options.uid !== undefined ? - options.uid : process.getuid && process.getuid() - var myGid = options.gid !== undefined ? - options.gid : process.getgid && process.getgid() - - var u = parseInt('100', 8) - var g = parseInt('010', 8) - var o = parseInt('001', 8) - var ug = u | g - - var ret = (mod & o) || - (mod & g) && gid === myGid || - (mod & u) && uid === myUid || - (mod & ug) && myUid === 0 - - return ret -} - - /***/ }), /***/ 198: @@ -1058,15 +1010,23 @@ var __importStar = (this && this.__importStar) || function (mod) { result["default"] = mod; return result; }; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; Object.defineProperty(exports, "__esModule", { value: true }); const core = __importStar(__webpack_require__(470)); const gpg = __importStar(__webpack_require__(207)); const openpgp = __importStar(__webpack_require__(781)); const stateHelper = __importStar(__webpack_require__(153)); const exec = __importStar(__webpack_require__(986)); +const os_1 = __importDefault(__webpack_require__(87)); function run() { return __awaiter(this, void 0, void 0, function* () { try { + if (os_1.default.platform() == 'win32') { + core.setFailed('Windows platform not supported'); + return; + } if (!process.env.SIGNING_KEY) { core.setFailed('Signing key required'); return; @@ -1156,50 +1116,27 @@ var __importStar = (this && this.__importStar) || function (mod) { result["default"] = mod; return result; }; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; Object.defineProperty(exports, "__esModule", { value: true }); const fs = __importStar(__webpack_require__(747)); const path = __importStar(__webpack_require__(622)); const os = __importStar(__webpack_require__(87)); const exec = __importStar(__webpack_require__(807)); -const which_1 = __importDefault(__webpack_require__(814)); exports.agentConfig = `default-cache-ttl 7200 max-cache-ttl 31536000 allow-preset-passphrase`; const getGpgPresetPassphrasePath = () => __awaiter(void 0, void 0, void 0, function* () { - let gpgPresetPassphrasePath; - gpgPresetPassphrasePath = yield which_1.default('gpg-preset-passphrase').then(resolvedPath => { - return resolvedPath; - }); - if (gpgPresetPassphrasePath != '') { - return gpgPresetPassphrasePath; - } const { libexecdir: libexecdir } = yield exports.getDirs(); - gpgPresetPassphrasePath = path.join(libexecdir, 'gpg-preset-passphrase'); + let gpgPresetPassphrasePath = path.join(libexecdir, 'gpg-preset-passphrase'); if (yield fs.existsSync(gpgPresetPassphrasePath)) { return gpgPresetPassphrasePath; } - gpgPresetPassphrasePath = path.join(process.env.HOMEDRIVE || '', libexecdir, 'gpg-preset-passphrase.exe'); - if (yield fs.existsSync(gpgPresetPassphrasePath)) { - return gpgPresetPassphrasePath; - } - gpgPresetPassphrasePath = path.join(`C:\\Program Files\\Git`, libexecdir, 'gpg-preset-passphrase.exe'); - if (yield fs.existsSync(gpgPresetPassphrasePath)) { - return gpgPresetPassphrasePath; - } - throw new Error('gpg-preset-passphrase not found'); + return 'gpg-preset-passphrase'; }); const getGnupgHome = () => __awaiter(void 0, void 0, void 0, function* () { if (process.env.GNUPGHOME) { return process.env.GNUPGHOME; } - let homedir = path.join(process.env.HOME || '', '.gnupg'); - if (os.platform() == 'win32' && !process.env.HOME) { - homedir = path.join(process.env.USERPROFILE || '', '.gnupg'); - } - return homedir; + return path.join(process.env.HOME || '', '.gnupg'); }); exports.getVersion = () => __awaiter(void 0, void 0, void 0, function* () { return yield exec.exec('gpg', ['--version'], true).then(res => { @@ -45624,70 +45561,6 @@ exports.default = AsyncProxy; }); -/***/ }), - -/***/ 742: -/***/ (function(module, __unusedexports, __webpack_require__) { - -var fs = __webpack_require__(747) -var core -if (process.platform === 'win32' || global.TESTING_WINDOWS) { - core = __webpack_require__(818) -} else { - core = __webpack_require__(197) -} - -module.exports = isexe -isexe.sync = sync - -function isexe (path, options, cb) { - if (typeof options === 'function') { - cb = options - options = {} - } - - if (!cb) { - if (typeof Promise !== 'function') { - throw new TypeError('callback not provided') - } - - return new Promise(function (resolve, reject) { - isexe(path, options || {}, function (er, is) { - if (er) { - reject(er) - } else { - resolve(is) - } - }) - }) - } - - core(path, options || {}, function (er, is) { - // ignore EACCES because that just means we aren't allowed to run it - if (er) { - if (er.code === 'EACCES' || options && options.ignoreErrors) { - er = null - is = false - } - } - cb(er, is) - }) -} - -function sync (path, options) { - // my kingdom for a filtered catch - try { - return core.sync(path, options || {}) - } catch (er) { - if (options && options.ignoreErrors || er.code === 'EACCES') { - return false - } else { - throw er - } - } -} - - /***/ }), /***/ 747: @@ -45799,187 +45672,6 @@ exports.exec = (command, args = [], silent) => __awaiter(void 0, void 0, void 0, }); -/***/ }), - -/***/ 814: -/***/ (function(module, __unusedexports, __webpack_require__) { - -const isWindows = process.platform === 'win32' || - process.env.OSTYPE === 'cygwin' || - process.env.OSTYPE === 'msys' - -const path = __webpack_require__(622) -const COLON = isWindows ? ';' : ':' -const isexe = __webpack_require__(742) - -const getNotFoundError = (cmd) => - Object.assign(new Error(`not found: ${cmd}`), { code: 'ENOENT' }) - -const getPathInfo = (cmd, opt) => { - const colon = opt.colon || COLON - - // If it has a slash, then we don't bother searching the pathenv. - // just check the file itself, and that's it. - const pathEnv = cmd.match(/\//) || isWindows && cmd.match(/\\/) ? [''] - : ( - [ - // windows always checks the cwd first - ...(isWindows ? [process.cwd()] : []), - ...(opt.path || process.env.PATH || - /* istanbul ignore next: very unusual */ '').split(colon), - ] - ) - const pathExtExe = isWindows - ? opt.pathExt || process.env.PATHEXT || '.EXE;.CMD;.BAT;.COM' - : '' - const pathExt = isWindows ? pathExtExe.split(colon) : [''] - - if (isWindows) { - if (cmd.indexOf('.') !== -1 && pathExt[0] !== '') - pathExt.unshift('') - } - - return { - pathEnv, - pathExt, - pathExtExe, - } -} - -const which = (cmd, opt, cb) => { - if (typeof opt === 'function') { - cb = opt - opt = {} - } - if (!opt) - opt = {} - - const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt) - const found = [] - - const step = i => new Promise((resolve, reject) => { - if (i === pathEnv.length) - return opt.all && found.length ? resolve(found) - : reject(getNotFoundError(cmd)) - - const ppRaw = pathEnv[i] - const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw - - const pCmd = path.join(pathPart, cmd) - const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd - : pCmd - - resolve(subStep(p, i, 0)) - }) - - const subStep = (p, i, ii) => new Promise((resolve, reject) => { - if (ii === pathExt.length) - return resolve(step(i + 1)) - const ext = pathExt[ii] - isexe(p + ext, { pathExt: pathExtExe }, (er, is) => { - if (!er && is) { - if (opt.all) - found.push(p + ext) - else - return resolve(p + ext) - } - return resolve(subStep(p, i, ii + 1)) - }) - }) - - return cb ? step(0).then(res => cb(null, res), cb) : step(0) -} - -const whichSync = (cmd, opt) => { - opt = opt || {} - - const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt) - const found = [] - - for (let i = 0; i < pathEnv.length; i ++) { - const ppRaw = pathEnv[i] - const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw - - const pCmd = path.join(pathPart, cmd) - const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd - : pCmd - - for (let j = 0; j < pathExt.length; j ++) { - const cur = p + pathExt[j] - try { - const is = isexe.sync(cur, { pathExt: pathExtExe }) - if (is) { - if (opt.all) - found.push(cur) - else - return cur - } - } catch (ex) {} - } - } - - if (opt.all && found.length) - return found - - if (opt.nothrow) - return null - - throw getNotFoundError(cmd) -} - -module.exports = which -which.sync = whichSync - - -/***/ }), - -/***/ 818: -/***/ (function(module, __unusedexports, __webpack_require__) { - -module.exports = isexe -isexe.sync = sync - -var fs = __webpack_require__(747) - -function checkPathExt (path, options) { - var pathext = options.pathExt !== undefined ? - options.pathExt : process.env.PATHEXT - - if (!pathext) { - return true - } - - pathext = pathext.split(';') - if (pathext.indexOf('') !== -1) { - return true - } - for (var i = 0; i < pathext.length; i++) { - var p = pathext[i].toLowerCase() - if (p && path.substr(-p.length).toLowerCase() === p) { - return true - } - } - return false -} - -function checkStat (stat, path, options) { - if (!stat.isSymbolicLink() && !stat.isFile()) { - return false - } - return checkPathExt(path, options) -} - -function isexe (path, options, cb) { - fs.stat(path, function (er, stat) { - cb(er, er ? false : checkStat(stat, path, options)) - }) -} - -function sync (path, options) { - return checkStat(fs.statSync(path), path, options) -} - - /***/ }), /***/ 986: diff --git a/package.json b/package.json index a53cb15..7aba938 100644 --- a/package.json +++ b/package.json @@ -25,14 +25,12 @@ "@actions/core": "^1.2.3", "@actions/exec": "^1.0.4", "@actions/github": "^2.1.1", - "openpgp": "^4.10.4", - "which": "^2.0.2" + "openpgp": "^4.10.4" }, "devDependencies": { "@types/jest": "^25.2.1", "@types/node": "^13.13.4", "@types/openpgp": "^4.4.10", - "@types/which": "^1.3.2", "@zeit/ncc": "^0.22.1", "jest": "^25.5.4", "jest-circus": "^25.5.4", diff --git a/src/gpg.ts b/src/gpg.ts index 71e188a..0c2cf1e 100644 --- a/src/gpg.ts +++ b/src/gpg.ts @@ -2,7 +2,6 @@ import * as fs from 'fs'; import * as path from 'path'; import * as os from 'os'; import * as exec from './exec'; -import which from 'which'; export const agentConfig = `default-cache-ttl 7200 max-cache-ttl 31536000 @@ -21,43 +20,19 @@ export interface Dirs { } const getGpgPresetPassphrasePath = async (): Promise => { - let gpgPresetPassphrasePath: string; - - gpgPresetPassphrasePath = await which('gpg-preset-passphrase').then(resolvedPath => { - return resolvedPath; - }); - if (gpgPresetPassphrasePath != '') { - return gpgPresetPassphrasePath; - } - const {libexecdir: libexecdir} = await getDirs(); - gpgPresetPassphrasePath = path.join(libexecdir, 'gpg-preset-passphrase'); + let gpgPresetPassphrasePath = path.join(libexecdir, 'gpg-preset-passphrase'); if (await fs.existsSync(gpgPresetPassphrasePath)) { return gpgPresetPassphrasePath; } - - gpgPresetPassphrasePath = path.join(process.env.HOMEDRIVE || '', libexecdir, 'gpg-preset-passphrase.exe'); - if (await fs.existsSync(gpgPresetPassphrasePath)) { - return gpgPresetPassphrasePath; - } - - gpgPresetPassphrasePath = path.join(`C:\\Program Files\\Git`, libexecdir, 'gpg-preset-passphrase.exe'); - if (await fs.existsSync(gpgPresetPassphrasePath)) { - return gpgPresetPassphrasePath; - } - - throw new Error('gpg-preset-passphrase not found'); + return 'gpg-preset-passphrase'; }; const getGnupgHome = async (): Promise => { if (process.env.GNUPGHOME) { return process.env.GNUPGHOME; } - let homedir: string = path.join(process.env.HOME || '', '.gnupg'); - if (os.platform() == 'win32' && !process.env.HOME) { - homedir = path.join(process.env.USERPROFILE || '', '.gnupg'); - } - return homedir; + return path.join(process.env.HOME || '', '.gnupg'); }; export const getVersion = async (): Promise => { diff --git a/src/main.ts b/src/main.ts index ace49c2..b6f9677 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,9 +3,15 @@ import * as gpg from './gpg'; import * as openpgp from './openpgp'; import * as stateHelper from './state-helper'; import * as exec from '@actions/exec'; +import os from 'os'; async function run(): Promise { try { + if (os.platform() == 'win32') { + core.setFailed('Windows platform not supported'); + return; + } + if (!process.env.SIGNING_KEY) { core.setFailed('Signing key required'); return;