diff --git a/__tests__/buildx.test.ts b/__tests__/buildx.test.ts index 741e29cba..84ff992b9 100644 --- a/__tests__/buildx.test.ts +++ b/__tests__/buildx.test.ts @@ -1,10 +1,10 @@ import * as fs from 'fs'; import * as path from 'path'; import * as semver from 'semver'; +import * as exec from '@actions/exec'; import * as buildx from '../src/buildx'; import * as context from '../src/context'; -import * as docker from '../src/docker'; const tmpNameSync = path.join('/tmp/.docker-build-push-jest', '.tmpname-jest').split(path.sep).join(path.posix.sep); const digest = 'sha256:bfb45ab72e46908183546477a08f8867fc40cebadd00af54b071b097aed127a9'; @@ -92,9 +92,26 @@ describe('isLocalOrTarExporter', () => { ); }); +describe('isAvailable', () => { + const execSpy: jest.SpyInstance = jest.spyOn(exec, 'getExecOutput'); + buildx.isAvailable(); + + expect(execSpy).toHaveBeenCalledWith(`docker`, ['buildx'], { + silent: true, + ignoreReturnCode: true + }); +}); + describe('getVersion', () => { async function isDaemonRunning() { - return await docker.isDaemonRunning(); + return await exec + .getExecOutput(`docker`, ['version', '--format', '{{.Server.Os}}'], { + ignoreReturnCode: true, + silent: true + }) + .then(res => { + return !res.stdout.includes(' ') && res.exitCode == 0; + }); } (isDaemonRunning() ? it : it.skip)( 'valid', diff --git a/dist/index.js b/dist/index.js index 87e80640f..e59017331 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2514,9 +2514,9 @@ Object.defineProperty(exports, "__esModule", { value: true }); const fs = __importStar(__webpack_require__(747)); const buildx = __importStar(__webpack_require__(295)); const context = __importStar(__webpack_require__(842)); -const exec = __importStar(__webpack_require__(757)); const stateHelper = __importStar(__webpack_require__(647)); const core = __importStar(__webpack_require__(186)); +const exec = __importStar(__webpack_require__(514)); function run() { return __awaiter(this, void 0, void 0, function* () { try { @@ -2533,9 +2533,13 @@ function run() { const defContext = context.defaultContext(); let inputs = yield context.getInputs(defContext); const args = yield context.getArgs(inputs, defContext, buildxVersion); - yield exec.exec('docker', args).then(res => { - if (res.stderr != '' && !res.success) { - throw new Error(`buildx call failed with: ${res.stderr.match(/(.*)\s*$/)[0]}`); + yield exec + .getExecOutput('docker', args, { + ignoreReturnCode: true + }) + .then(res => { + if (res.stderr.length > 0 && res.exitCode != 0) { + throw new Error(`buildx bake failed with: ${res.stderr.match(/(.*)\s*$/)[0].trim()}`); } }); const imageID = yield buildx.getImageID(); @@ -2991,7 +2995,7 @@ const os = __importStar(__webpack_require__(87)); const events = __importStar(__webpack_require__(614)); const child = __importStar(__webpack_require__(4)); const path = __importStar(__webpack_require__(622)); -const io = __importStar(__webpack_require__(436)); +const io = __importStar(__webpack_require__(351)); const ioUtil = __importStar(__webpack_require__(962)); const timers_1 = __webpack_require__(213); /* eslint-disable @typescript-eslint/unbound-method */ @@ -3728,7 +3732,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getState = exports.saveState = exports.group = exports.endGroup = exports.startGroup = exports.info = exports.warning = exports.error = exports.debug = exports.isDebug = exports.setFailed = exports.setCommandEcho = exports.setOutput = exports.getBooleanInput = exports.getMultilineInput = exports.getInput = exports.addPath = exports.setSecret = exports.exportVariable = exports.ExitCode = void 0; -const command_1 = __webpack_require__(351); +const command_1 = __webpack_require__(241); const file_command_1 = __webpack_require__(185); const utils_1 = __webpack_require__(278); const os = __importStar(__webpack_require__(87)); @@ -4647,6 +4651,105 @@ exports.request = request; //# sourceMappingURL=index.js.map +/***/ }), + +/***/ 241: +/***/ (function(__unusedmodule, exports, __webpack_require__) { + +"use strict"; + +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.issue = exports.issueCommand = void 0; +const os = __importStar(__webpack_require__(87)); +const utils_1 = __webpack_require__(278); +/** + * Commands + * + * Command Format: + * ::name key=value,key=value::message + * + * Examples: + * ::warning::This is the message + * ::set-env name=MY_VAR::some value + */ +function issueCommand(command, properties, message) { + const cmd = new Command(command, properties, message); + process.stdout.write(cmd.toString() + os.EOL); +} +exports.issueCommand = issueCommand; +function issue(name, message = '') { + issueCommand(name, {}, message); +} +exports.issue = issue; +const CMD_STRING = '::'; +class Command { + constructor(command, properties, message) { + if (!command) { + command = 'missing.command'; + } + this.command = command; + this.properties = properties; + this.message = message; + } + toString() { + let cmdStr = CMD_STRING + this.command; + if (this.properties && Object.keys(this.properties).length > 0) { + cmdStr += ' '; + let first = true; + for (const key in this.properties) { + if (this.properties.hasOwnProperty(key)) { + const val = this.properties[key]; + if (val) { + if (first) { + first = false; + } + else { + cmdStr += ','; + } + cmdStr += `${key}=${escapeProperty(val)}`; + } + } + } + } + cmdStr += `${CMD_STRING}${escapeData(this.message)}`; + return cmdStr; + } +} +function escapeData(s) { + return utils_1.toCommandValue(s) + .replace(/%/g, '%25') + .replace(/\r/g, '%0D') + .replace(/\n/g, '%0A'); +} +function escapeProperty(s) { + return utils_1.toCommandValue(s) + .replace(/%/g, '%25') + .replace(/\r/g, '%0D') + .replace(/\n/g, '%0A') + .replace(/:/g, '%3A') + .replace(/,/g, '%2C'); +} +//# sourceMappingURL=command.js.map + /***/ }), /***/ 278: @@ -4823,8 +4926,8 @@ const sync_1 = __importDefault(__webpack_require__(750)); const fs_1 = __importDefault(__webpack_require__(747)); const path_1 = __importDefault(__webpack_require__(622)); const semver = __importStar(__webpack_require__(383)); +const exec = __importStar(__webpack_require__(514)); const context = __importStar(__webpack_require__(842)); -const exec = __importStar(__webpack_require__(757)); function getImageIDFile() { return __awaiter(this, void 0, void 0, function* () { return path_1.default.join(context.tmpDir(), 'iidfile').split(path_1.default.sep).join(path_1.default.posix.sep); @@ -4907,20 +5010,30 @@ function hasGitAuthToken(secrets) { exports.hasGitAuthToken = hasGitAuthToken; function isAvailable() { return __awaiter(this, void 0, void 0, function* () { - return yield exec.exec(`docker`, ['buildx'], true).then(res => { - if (res.stderr != '' && !res.success) { + return yield exec + .getExecOutput('docker', ['buildx'], { + ignoreReturnCode: true, + silent: true + }) + .then(res => { + if (res.stderr.length > 0 && res.exitCode != 0) { return false; } - return res.success; + return res.exitCode == 0; }); }); } exports.isAvailable = isAvailable; function getVersion() { return __awaiter(this, void 0, void 0, function* () { - return yield exec.exec(`docker`, ['buildx', 'version'], true).then(res => { - if (res.stderr != '' && !res.success) { - throw new Error(res.stderr); + return yield exec + .getExecOutput('docker', ['buildx', 'version'], { + ignoreReturnCode: true, + silent: true + }) + .then(res => { + if (res.stderr.length > 0 && res.exitCode != 0) { + throw new Error(res.stderr.trim()); } return parseVersion(res.stdout); }); @@ -5063,426 +5176,91 @@ exports.createTokenAuth = createTokenAuth; "use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.issue = exports.issueCommand = void 0; -const os = __importStar(__webpack_require__(87)); -const utils_1 = __webpack_require__(278); +const childProcess = __webpack_require__(4); +const path = __webpack_require__(622); +const util_1 = __webpack_require__(669); +const ioUtil = __webpack_require__(962); +const exec = util_1.promisify(childProcess.exec); /** - * Commands - * - * Command Format: - * ::name key=value,key=value::message + * Copies a file or folder. + * Based off of shelljs - https://github.com/shelljs/shelljs/blob/9237f66c52e5daa40458f94f9565e18e8132f5a6/src/cp.js * - * Examples: - * ::warning::This is the message - * ::set-env name=MY_VAR::some value + * @param source source path + * @param dest destination path + * @param options optional. See CopyOptions. */ -function issueCommand(command, properties, message) { - const cmd = new Command(command, properties, message); - process.stdout.write(cmd.toString() + os.EOL); -} -exports.issueCommand = issueCommand; -function issue(name, message = '') { - issueCommand(name, {}, message); -} -exports.issue = issue; -const CMD_STRING = '::'; -class Command { - constructor(command, properties, message) { - if (!command) { - command = 'missing.command'; +function cp(source, dest, options = {}) { + return __awaiter(this, void 0, void 0, function* () { + const { force, recursive } = readCopyOptions(options); + const destStat = (yield ioUtil.exists(dest)) ? yield ioUtil.stat(dest) : null; + // Dest is an existing file, but not forcing + if (destStat && destStat.isFile() && !force) { + return; } - this.command = command; - this.properties = properties; - this.message = message; - } - toString() { - let cmdStr = CMD_STRING + this.command; - if (this.properties && Object.keys(this.properties).length > 0) { - cmdStr += ' '; - let first = true; - for (const key in this.properties) { - if (this.properties.hasOwnProperty(key)) { - const val = this.properties[key]; - if (val) { - if (first) { - first = false; - } - else { - cmdStr += ','; - } - cmdStr += `${key}=${escapeProperty(val)}`; - } - } + // If dest is an existing directory, should copy inside. + const newDest = destStat && destStat.isDirectory() + ? path.join(dest, path.basename(source)) + : dest; + if (!(yield ioUtil.exists(source))) { + throw new Error(`no such file or directory: ${source}`); + } + const sourceStat = yield ioUtil.stat(source); + if (sourceStat.isDirectory()) { + if (!recursive) { + throw new Error(`Failed to copy. ${source} is a directory, but tried to copy without recursive flag.`); + } + else { + yield cpDirRecursive(source, newDest, 0, force); } } - cmdStr += `${CMD_STRING}${escapeData(this.message)}`; - return cmdStr; - } + else { + if (path.relative(source, newDest) === '') { + // a file cannot be copied to itself + throw new Error(`'${newDest}' and '${source}' are the same file`); + } + yield copyFile(source, newDest, force); + } + }); } -function escapeData(s) { - return utils_1.toCommandValue(s) - .replace(/%/g, '%25') - .replace(/\r/g, '%0D') - .replace(/\n/g, '%0A'); -} -function escapeProperty(s) { - return utils_1.toCommandValue(s) - .replace(/%/g, '%25') - .replace(/\r/g, '%0D') - .replace(/\n/g, '%0A') - .replace(/:/g, '%3A') - .replace(/,/g, '%2C'); -} -//# sourceMappingURL=command.js.map - -/***/ }), - -/***/ 357: -/***/ (function(module) { - -module.exports = require("assert"); - -/***/ }), - -/***/ 373: -/***/ (function(module) { - -module.exports = require("crypto"); - -/***/ }), - -/***/ 380: -/***/ (function(module, __unusedexports, __webpack_require__) { - -// Determine if version is greater than all the versions possible in the range. -const outside = __webpack_require__(420) -const gtr = (version, range, options) => outside(version, range, '>', options) -module.exports = gtr - - -/***/ }), - -/***/ 383: -/***/ (function(module, __unusedexports, __webpack_require__) { - -// just pre-load all the stuff that index.js lazily exports -const internalRe = __webpack_require__(523) -module.exports = { - re: internalRe.re, - src: internalRe.src, - tokens: internalRe.t, - SEMVER_SPEC_VERSION: __webpack_require__(293).SEMVER_SPEC_VERSION, - SemVer: __webpack_require__(88), - compareIdentifiers: __webpack_require__(463).compareIdentifiers, - rcompareIdentifiers: __webpack_require__(463).rcompareIdentifiers, - parse: __webpack_require__(925), - valid: __webpack_require__(601), - clean: __webpack_require__(848), - inc: __webpack_require__(900), - diff: __webpack_require__(297), - major: __webpack_require__(688), - minor: __webpack_require__(447), - patch: __webpack_require__(866), - prerelease: __webpack_require__(16), - compare: __webpack_require__(309), - rcompare: __webpack_require__(417), - compareLoose: __webpack_require__(804), - compareBuild: __webpack_require__(156), - sort: __webpack_require__(426), - rsort: __webpack_require__(701), - gt: __webpack_require__(123), - lt: __webpack_require__(194), - eq: __webpack_require__(898), - neq: __webpack_require__(17), - gte: __webpack_require__(522), - lte: __webpack_require__(520), - cmp: __webpack_require__(98), - coerce: __webpack_require__(466), - Comparator: __webpack_require__(532), - Range: __webpack_require__(828), - satisfies: __webpack_require__(55), - toComparators: __webpack_require__(706), - maxSatisfying: __webpack_require__(579), - minSatisfying: __webpack_require__(832), - minVersion: __webpack_require__(179), - validRange: __webpack_require__(741), - outside: __webpack_require__(420), - gtr: __webpack_require__(380), - ltr: __webpack_require__(323), - intersects: __webpack_require__(8), - simplifyRange: __webpack_require__(561), - subset: __webpack_require__(863), -} - - -/***/ }), - -/***/ 413: -/***/ (function(module) { - -module.exports = require("stream"); - -/***/ }), - -/***/ 417: -/***/ (function(module, __unusedexports, __webpack_require__) { - -const compare = __webpack_require__(309) -const rcompare = (a, b, loose) => compare(b, a, loose) -module.exports = rcompare - - -/***/ }), - -/***/ 420: -/***/ (function(module, __unusedexports, __webpack_require__) { - -const SemVer = __webpack_require__(88) -const Comparator = __webpack_require__(532) -const {ANY} = Comparator -const Range = __webpack_require__(828) -const satisfies = __webpack_require__(55) -const gt = __webpack_require__(123) -const lt = __webpack_require__(194) -const lte = __webpack_require__(520) -const gte = __webpack_require__(522) - -const outside = (version, range, hilo, options) => { - version = new SemVer(version, options) - range = new Range(range, options) - - let gtfn, ltefn, ltfn, comp, ecomp - switch (hilo) { - case '>': - gtfn = gt - ltefn = lte - ltfn = lt - comp = '>' - ecomp = '>=' - break - case '<': - gtfn = lt - ltefn = gte - ltfn = gt - comp = '<' - ecomp = '<=' - break - default: - throw new TypeError('Must provide a hilo val of "<" or ">"') - } - - // If it satisfies the range it is not outside - if (satisfies(version, range, options)) { - return false - } - - // From now on, variable terms are as if we're in "gtr" mode. - // but note that everything is flipped for the "ltr" function. - - for (let i = 0; i < range.set.length; ++i) { - const comparators = range.set[i] - - let high = null - let low = null - - comparators.forEach((comparator) => { - if (comparator.semver === ANY) { - comparator = new Comparator('>=0.0.0') - } - high = high || comparator - low = low || comparator - if (gtfn(comparator.semver, high.semver, options)) { - high = comparator - } else if (ltfn(comparator.semver, low.semver, options)) { - low = comparator - } - }) - - // If the edge version comparator has a operator then our version - // isn't outside it - if (high.operator === comp || high.operator === ecomp) { - return false - } - - // If the lowest version comparator has an operator and our version - // is less than it then it isn't higher than the range - if ((!low.operator || low.operator === comp) && - ltefn(version, low.semver)) { - return false - } else if (low.operator === ecomp && ltfn(version, low.semver)) { - return false - } - } - return true -} - -module.exports = outside - - -/***/ }), - -/***/ 426: -/***/ (function(module, __unusedexports, __webpack_require__) { - -const compareBuild = __webpack_require__(156) -const sort = (list, loose) => list.sort((a, b) => compareBuild(a, b, loose)) -module.exports = sort - - -/***/ }), - -/***/ 427: -/***/ (function(module) { - -const debug = ( - typeof process === 'object' && - process.env && - process.env.NODE_DEBUG && - /\bsemver\b/i.test(process.env.NODE_DEBUG) -) ? (...args) => console.error('SEMVER', ...args) - : () => {} - -module.exports = debug - - -/***/ }), - -/***/ 429: -/***/ (function(__unusedmodule, exports) { - -"use strict"; - - -Object.defineProperty(exports, '__esModule', { value: true }); - -function getUserAgent() { - if (typeof navigator === "object" && "userAgent" in navigator) { - return navigator.userAgent; - } - - if (typeof process === "object" && "version" in process) { - return `Node.js/${process.version.substr(1)} (${process.platform}; ${process.arch})`; - } - - return ""; -} - -exports.getUserAgent = getUserAgent; -//# sourceMappingURL=index.js.map - - -/***/ }), - -/***/ 436: -/***/ (function(__unusedmodule, exports, __webpack_require__) { - -"use strict"; - -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const childProcess = __webpack_require__(4); -const path = __webpack_require__(622); -const util_1 = __webpack_require__(669); -const ioUtil = __webpack_require__(962); -const exec = util_1.promisify(childProcess.exec); -/** - * Copies a file or folder. - * Based off of shelljs - https://github.com/shelljs/shelljs/blob/9237f66c52e5daa40458f94f9565e18e8132f5a6/src/cp.js - * - * @param source source path - * @param dest destination path - * @param options optional. See CopyOptions. - */ -function cp(source, dest, options = {}) { - return __awaiter(this, void 0, void 0, function* () { - const { force, recursive } = readCopyOptions(options); - const destStat = (yield ioUtil.exists(dest)) ? yield ioUtil.stat(dest) : null; - // Dest is an existing file, but not forcing - if (destStat && destStat.isFile() && !force) { - return; - } - // If dest is an existing directory, should copy inside. - const newDest = destStat && destStat.isDirectory() - ? path.join(dest, path.basename(source)) - : dest; - if (!(yield ioUtil.exists(source))) { - throw new Error(`no such file or directory: ${source}`); - } - const sourceStat = yield ioUtil.stat(source); - if (sourceStat.isDirectory()) { - if (!recursive) { - throw new Error(`Failed to copy. ${source} is a directory, but tried to copy without recursive flag.`); - } - else { - yield cpDirRecursive(source, newDest, 0, force); - } - } - else { - if (path.relative(source, newDest) === '') { - // a file cannot be copied to itself - throw new Error(`'${newDest}' and '${source}' are the same file`); - } - yield copyFile(source, newDest, force); - } - }); -} -exports.cp = cp; -/** - * Moves a path. - * - * @param source source path - * @param dest destination path - * @param options optional. See MoveOptions. - */ -function mv(source, dest, options = {}) { - return __awaiter(this, void 0, void 0, function* () { - if (yield ioUtil.exists(dest)) { - let destExists = true; - if (yield ioUtil.isDirectory(dest)) { - // If dest is directory copy src into dest - dest = path.join(dest, path.basename(source)); - destExists = yield ioUtil.exists(dest); - } - if (destExists) { - if (options.force == null || options.force) { - yield rmRF(dest); - } - else { - throw new Error('Destination already exists'); - } - } - } - yield mkdirP(path.dirname(dest)); - yield ioUtil.rename(source, dest); - }); +exports.cp = cp; +/** + * Moves a path. + * + * @param source source path + * @param dest destination path + * @param options optional. See MoveOptions. + */ +function mv(source, dest, options = {}) { + return __awaiter(this, void 0, void 0, function* () { + if (yield ioUtil.exists(dest)) { + let destExists = true; + if (yield ioUtil.isDirectory(dest)) { + // If dest is directory copy src into dest + dest = path.join(dest, path.basename(source)); + destExists = yield ioUtil.exists(dest); + } + if (destExists) { + if (options.force == null || options.force) { + yield rmRF(dest); + } + else { + throw new Error('Destination already exists'); + } + } + } + yield mkdirP(path.dirname(dest)); + yield ioUtil.rename(source, dest); + }); } exports.mv = mv; /** @@ -5636,57 +5414,293 @@ function readCopyOptions(options) { const recursive = Boolean(options.recursive); return { force, recursive }; } -function cpDirRecursive(sourceDir, destDir, currentDepth, force) { - return __awaiter(this, void 0, void 0, function* () { - // Ensure there is not a run away recursive copy - if (currentDepth >= 255) - return; - currentDepth++; - yield mkdirP(destDir); - const files = yield ioUtil.readdir(sourceDir); - for (const fileName of files) { - const srcFile = `${sourceDir}/${fileName}`; - const destFile = `${destDir}/${fileName}`; - const srcFileStat = yield ioUtil.lstat(srcFile); - if (srcFileStat.isDirectory()) { - // Recurse - yield cpDirRecursive(srcFile, destFile, currentDepth, force); - } - else { - yield copyFile(srcFile, destFile, force); - } - } - // Change the mode for the newly created directory - yield ioUtil.chmod(destDir, (yield ioUtil.stat(sourceDir)).mode); - }); +function cpDirRecursive(sourceDir, destDir, currentDepth, force) { + return __awaiter(this, void 0, void 0, function* () { + // Ensure there is not a run away recursive copy + if (currentDepth >= 255) + return; + currentDepth++; + yield mkdirP(destDir); + const files = yield ioUtil.readdir(sourceDir); + for (const fileName of files) { + const srcFile = `${sourceDir}/${fileName}`; + const destFile = `${destDir}/${fileName}`; + const srcFileStat = yield ioUtil.lstat(srcFile); + if (srcFileStat.isDirectory()) { + // Recurse + yield cpDirRecursive(srcFile, destFile, currentDepth, force); + } + else { + yield copyFile(srcFile, destFile, force); + } + } + // Change the mode for the newly created directory + yield ioUtil.chmod(destDir, (yield ioUtil.stat(sourceDir)).mode); + }); +} +// Buffered file copy +function copyFile(srcFile, destFile, force) { + return __awaiter(this, void 0, void 0, function* () { + if ((yield ioUtil.lstat(srcFile)).isSymbolicLink()) { + // unlink/re-link it + try { + yield ioUtil.lstat(destFile); + yield ioUtil.unlink(destFile); + } + catch (e) { + // Try to override file permission + if (e.code === 'EPERM') { + yield ioUtil.chmod(destFile, '0666'); + yield ioUtil.unlink(destFile); + } + // other errors = it doesn't exist, no work to do + } + // Copy over symlink + const symlinkFull = yield ioUtil.readlink(srcFile); + yield ioUtil.symlink(symlinkFull, destFile, ioUtil.IS_WINDOWS ? 'junction' : null); + } + else if (!(yield ioUtil.exists(destFile)) || force) { + yield ioUtil.copyFile(srcFile, destFile); + } + }); +} +//# sourceMappingURL=io.js.map + +/***/ }), + +/***/ 357: +/***/ (function(module) { + +module.exports = require("assert"); + +/***/ }), + +/***/ 373: +/***/ (function(module) { + +module.exports = require("crypto"); + +/***/ }), + +/***/ 380: +/***/ (function(module, __unusedexports, __webpack_require__) { + +// Determine if version is greater than all the versions possible in the range. +const outside = __webpack_require__(420) +const gtr = (version, range, options) => outside(version, range, '>', options) +module.exports = gtr + + +/***/ }), + +/***/ 383: +/***/ (function(module, __unusedexports, __webpack_require__) { + +// just pre-load all the stuff that index.js lazily exports +const internalRe = __webpack_require__(523) +module.exports = { + re: internalRe.re, + src: internalRe.src, + tokens: internalRe.t, + SEMVER_SPEC_VERSION: __webpack_require__(293).SEMVER_SPEC_VERSION, + SemVer: __webpack_require__(88), + compareIdentifiers: __webpack_require__(463).compareIdentifiers, + rcompareIdentifiers: __webpack_require__(463).rcompareIdentifiers, + parse: __webpack_require__(925), + valid: __webpack_require__(601), + clean: __webpack_require__(848), + inc: __webpack_require__(900), + diff: __webpack_require__(297), + major: __webpack_require__(688), + minor: __webpack_require__(447), + patch: __webpack_require__(866), + prerelease: __webpack_require__(16), + compare: __webpack_require__(309), + rcompare: __webpack_require__(417), + compareLoose: __webpack_require__(804), + compareBuild: __webpack_require__(156), + sort: __webpack_require__(426), + rsort: __webpack_require__(701), + gt: __webpack_require__(123), + lt: __webpack_require__(194), + eq: __webpack_require__(898), + neq: __webpack_require__(17), + gte: __webpack_require__(522), + lte: __webpack_require__(520), + cmp: __webpack_require__(98), + coerce: __webpack_require__(466), + Comparator: __webpack_require__(532), + Range: __webpack_require__(828), + satisfies: __webpack_require__(55), + toComparators: __webpack_require__(706), + maxSatisfying: __webpack_require__(579), + minSatisfying: __webpack_require__(832), + minVersion: __webpack_require__(179), + validRange: __webpack_require__(741), + outside: __webpack_require__(420), + gtr: __webpack_require__(380), + ltr: __webpack_require__(323), + intersects: __webpack_require__(8), + simplifyRange: __webpack_require__(561), + subset: __webpack_require__(863), +} + + +/***/ }), + +/***/ 413: +/***/ (function(module) { + +module.exports = require("stream"); + +/***/ }), + +/***/ 417: +/***/ (function(module, __unusedexports, __webpack_require__) { + +const compare = __webpack_require__(309) +const rcompare = (a, b, loose) => compare(b, a, loose) +module.exports = rcompare + + +/***/ }), + +/***/ 420: +/***/ (function(module, __unusedexports, __webpack_require__) { + +const SemVer = __webpack_require__(88) +const Comparator = __webpack_require__(532) +const {ANY} = Comparator +const Range = __webpack_require__(828) +const satisfies = __webpack_require__(55) +const gt = __webpack_require__(123) +const lt = __webpack_require__(194) +const lte = __webpack_require__(520) +const gte = __webpack_require__(522) + +const outside = (version, range, hilo, options) => { + version = new SemVer(version, options) + range = new Range(range, options) + + let gtfn, ltefn, ltfn, comp, ecomp + switch (hilo) { + case '>': + gtfn = gt + ltefn = lte + ltfn = lt + comp = '>' + ecomp = '>=' + break + case '<': + gtfn = lt + ltefn = gte + ltfn = gt + comp = '<' + ecomp = '<=' + break + default: + throw new TypeError('Must provide a hilo val of "<" or ">"') + } + + // If it satisfies the range it is not outside + if (satisfies(version, range, options)) { + return false + } + + // From now on, variable terms are as if we're in "gtr" mode. + // but note that everything is flipped for the "ltr" function. + + for (let i = 0; i < range.set.length; ++i) { + const comparators = range.set[i] + + let high = null + let low = null + + comparators.forEach((comparator) => { + if (comparator.semver === ANY) { + comparator = new Comparator('>=0.0.0') + } + high = high || comparator + low = low || comparator + if (gtfn(comparator.semver, high.semver, options)) { + high = comparator + } else if (ltfn(comparator.semver, low.semver, options)) { + low = comparator + } + }) + + // If the edge version comparator has a operator then our version + // isn't outside it + if (high.operator === comp || high.operator === ecomp) { + return false + } + + // If the lowest version comparator has an operator and our version + // is less than it then it isn't higher than the range + if ((!low.operator || low.operator === comp) && + ltefn(version, low.semver)) { + return false + } else if (low.operator === ecomp && ltfn(version, low.semver)) { + return false + } + } + return true } -// Buffered file copy -function copyFile(srcFile, destFile, force) { - return __awaiter(this, void 0, void 0, function* () { - if ((yield ioUtil.lstat(srcFile)).isSymbolicLink()) { - // unlink/re-link it - try { - yield ioUtil.lstat(destFile); - yield ioUtil.unlink(destFile); - } - catch (e) { - // Try to override file permission - if (e.code === 'EPERM') { - yield ioUtil.chmod(destFile, '0666'); - yield ioUtil.unlink(destFile); - } - // other errors = it doesn't exist, no work to do - } - // Copy over symlink - const symlinkFull = yield ioUtil.readlink(srcFile); - yield ioUtil.symlink(symlinkFull, destFile, ioUtil.IS_WINDOWS ? 'junction' : null); - } - else if (!(yield ioUtil.exists(destFile)) || force) { - yield ioUtil.copyFile(srcFile, destFile); - } - }); + +module.exports = outside + + +/***/ }), + +/***/ 426: +/***/ (function(module, __unusedexports, __webpack_require__) { + +const compareBuild = __webpack_require__(156) +const sort = (list, loose) => list.sort((a, b) => compareBuild(a, b, loose)) +module.exports = sort + + +/***/ }), + +/***/ 427: +/***/ (function(module) { + +const debug = ( + typeof process === 'object' && + process.env && + process.env.NODE_DEBUG && + /\bsemver\b/i.test(process.env.NODE_DEBUG) +) ? (...args) => console.error('SEMVER', ...args) + : () => {} + +module.exports = debug + + +/***/ }), + +/***/ 429: +/***/ (function(__unusedmodule, exports) { + +"use strict"; + + +Object.defineProperty(exports, '__esModule', { value: true }); + +function getUserAgent() { + if (typeof navigator === "object" && "userAgent" in navigator) { + return navigator.userAgent; + } + + if (typeof process === "object" && "version" in process) { + return `Node.js/${process.version.substr(1)} (${process.platform}; ${process.arch})`; + } + + return ""; } -//# sourceMappingURL=io.js.map + +exports.getUserAgent = getUserAgent; +//# sourceMappingURL=index.js.map + /***/ }), @@ -11109,68 +11123,6 @@ module.exports = function(data, options={}){ } -/***/ }), - -/***/ 757: -/***/ (function(__unusedmodule, exports, __webpack_require__) { - -"use strict"; - -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.exec = void 0; -const aexec = __importStar(__webpack_require__(514)); -exports.exec = (command, args = [], silent) => __awaiter(void 0, void 0, void 0, function* () { - let stdout = ''; - let stderr = ''; - const options = { - silent: silent, - ignoreReturnCode: true - }; - options.listeners = { - stdout: (data) => { - stdout += data.toString(); - }, - stderr: (data) => { - stderr += data.toString(); - } - }; - const returnCode = yield aexec.exec(command, args, options); - return { - success: returnCode === 0, - stdout: stdout.trim(), - stderr: stderr.trim() - }; -}); -//# sourceMappingURL=exec.js.map - /***/ }), /***/ 758: @@ -13513,7 +13465,7 @@ const path = __importStar(__webpack_require__(622)); const semver = __importStar(__webpack_require__(383)); const tmp = __importStar(__webpack_require__(517)); const core = __importStar(__webpack_require__(186)); -const command_1 = __webpack_require__(351); +const command_1 = __webpack_require__(241); const github = __importStar(__webpack_require__(438)); const buildx = __importStar(__webpack_require__(295)); let _defaultContext, _tmpDir; diff --git a/src/buildx.ts b/src/buildx.ts index 061271096..b36bffe08 100644 --- a/src/buildx.ts +++ b/src/buildx.ts @@ -2,9 +2,9 @@ import csvparse from 'csv-parse/lib/sync'; import fs from 'fs'; import path from 'path'; import * as semver from 'semver'; +import * as exec from '@actions/exec'; import * as context from './context'; -import * as exec from './exec'; export async function getImageIDFile(): Promise { return path.join(context.tmpDir(), 'iidfile').split(path.sep).join(path.posix.sep); @@ -80,21 +80,31 @@ export function hasGitAuthToken(secrets: string[]): Boolean { } export async function isAvailable(): Promise { - return await exec.exec(`docker`, ['buildx'], true).then(res => { - if (res.stderr != '' && !res.success) { - return false; - } - return res.success; - }); + return await exec + .getExecOutput('docker', ['buildx'], { + ignoreReturnCode: true, + silent: true + }) + .then(res => { + if (res.stderr.length > 0 && res.exitCode != 0) { + return false; + } + return res.exitCode == 0; + }); } export async function getVersion(): Promise { - return await exec.exec(`docker`, ['buildx', 'version'], true).then(res => { - if (res.stderr != '' && !res.success) { - throw new Error(res.stderr); - } - return parseVersion(res.stdout); - }); + return await exec + .getExecOutput('docker', ['buildx', 'version'], { + ignoreReturnCode: true, + silent: true + }) + .then(res => { + if (res.stderr.length > 0 && res.exitCode != 0) { + throw new Error(res.stderr.trim()); + } + return parseVersion(res.stdout); + }); } export async function parseVersion(stdout: string): Promise { diff --git a/src/docker.ts b/src/docker.ts deleted file mode 100644 index a35b384bc..000000000 --- a/src/docker.ts +++ /dev/null @@ -1,7 +0,0 @@ -import * as exec from './exec'; - -export async function isDaemonRunning(): Promise { - return await exec.exec(`docker`, ['version', '--format', '{{.Server.Os}}'], true).then(res => { - return !res.stdout.includes(' ') && res.success; - }); -} diff --git a/src/exec.ts b/src/exec.ts deleted file mode 100644 index 00257e1aa..000000000 --- a/src/exec.ts +++ /dev/null @@ -1,34 +0,0 @@ -import * as aexec from '@actions/exec'; -import {ExecOptions} from '@actions/exec'; - -export interface ExecResult { - success: boolean; - stdout: string; - stderr: string; -} - -export const exec = async (command: string, args: string[] = [], silent?: boolean): Promise => { - let stdout: string = ''; - let stderr: string = ''; - - const options: ExecOptions = { - silent: silent, - ignoreReturnCode: true - }; - options.listeners = { - stdout: (data: Buffer) => { - stdout += data.toString(); - }, - stderr: (data: Buffer) => { - stderr += data.toString(); - } - }; - - const returnCode: number = await aexec.exec(command, args, options); - - return { - success: returnCode === 0, - stdout: stdout.trim(), - stderr: stderr.trim() - }; -}; diff --git a/src/main.ts b/src/main.ts index 6a82ad085..3453c5338 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,9 +1,9 @@ import * as fs from 'fs'; import * as buildx from './buildx'; import * as context from './context'; -import * as exec from './exec'; import * as stateHelper from './state-helper'; import * as core from '@actions/core'; +import * as exec from '@actions/exec'; async function run(): Promise { try { @@ -23,11 +23,15 @@ async function run(): Promise { let inputs: context.Inputs = await context.getInputs(defContext); const args: string[] = await context.getArgs(inputs, defContext, buildxVersion); - await exec.exec('docker', args).then(res => { - if (res.stderr != '' && !res.success) { - throw new Error(`buildx call failed with: ${res.stderr.match(/(.*)\s*$/)![0]}`); - } - }); + await exec + .getExecOutput('docker', args, { + ignoreReturnCode: true + }) + .then(res => { + if (res.stderr.length > 0 && res.exitCode != 0) { + throw new Error(`buildx bake failed with: ${res.stderr.match(/(.*)\s*$/)![0].trim()}`); + } + }); const imageID = await buildx.getImageID(); if (imageID) {