From 95181030e3b4d574d027e8f4bb7d97fc62331c35 Mon Sep 17 00:00:00 2001 From: Robin Raju Date: Sun, 29 Aug 2021 22:47:30 +0200 Subject: [PATCH] Change option for downloading all assets to fileName with "*" (#291) * Change option for downloading all assets to fileName with "*" Add test on CI to download filew from private repo * Update CI workflow --- .github/workflows/ci.yml | 23 +++-- README.md | 11 +++ action.yml | 2 +- dist/index.js | 186 +++++++++++++++++++++++++++++++-------- src/download.ts | 4 +- 5 files changed, 178 insertions(+), 48 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 414ba342..2ead52f2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,10 +35,21 @@ jobs: repository: "eloots/course-management-tools" tag: "1.0.0" fileName: "course-management-tools.zip" - out-file-path: "." - - - run: | - unzip course-management-tools.zip + out-file-path: "./cmt" - - name: List working directory - run: ls -lrth + - name: List downloaded files + run: ls -lrth cmt + + - name: Test download from a private repo + uses: ./ + with: + repository: "robinraju/release-downloader-test" + latest: true + fileName: "*" + tarBall: true + zipBall: true + token: ${{ secrets.RELEASE_DOWNLOADER_TEST_TOKEN }} + out-file-path: "./downloader-test" + + - name: List downloaded files from private repo + run: ls -lrth downloader-test diff --git a/README.md b/README.md index c705a17e..cf7b288a 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ A Github Action to download assets from github release. It can download specifie # The name of the file to download. # Use this field only to specify filenames other than tarball or zipball, if any. + # Use '*' to download all assets fileName: "" # Download the attached tarball (*.tar.gz) @@ -92,3 +93,13 @@ A Github Action to download assets from github release. It can download specifie tarBall: true zipBall: true ``` + +### Download all assets if more than one files are available + +```yaml +- uses: robinraju/release-downloader@v1.1 + with: + repository: "user/repo" + latest: true + fileName: "*" +``` diff --git a/action.yml b/action.yml index e06d86dd..3446df76 100644 --- a/action.yml +++ b/action.yml @@ -15,7 +15,7 @@ inputs: default: "" required: false fileName: - description: "Name of the file to download (if empty it will download all assets)" + description: "Name of the file to download (use '*' to download all assets other than tarball or zipball)" default: "" required: false tarBall: diff --git a/dist/index.js b/dist/index.js index b7be0967..d46377f0 100644 --- a/dist/index.js +++ b/dist/index.js @@ -420,7 +420,7 @@ module.exports = __webpack_require__(669).inspect; // We use any as a valid input type /* eslint-disable @typescript-eslint/no-explicit-any */ Object.defineProperty(exports, "__esModule", { value: true }); -exports.toCommandValue = void 0; +exports.toCommandProperties = exports.toCommandValue = void 0; /** * Sanitizes an input into a string so it can be passed into issueCommand safely * @param input input to sanitize into a string @@ -435,6 +435,25 @@ function toCommandValue(input) { return JSON.stringify(input); } exports.toCommandValue = toCommandValue; +/** + * + * @param annotationProperties + * @returns The command properties to send with the actual annotation command + * See IssueCommandProperties: https://github.com/actions/runner/blob/main/src/Runner.Worker/ActionCommandManager.cs#L646 + */ +function toCommandProperties(annotationProperties) { + if (!Object.keys(annotationProperties).length) { + return {}; + } + return { + title: annotationProperties.title, + line: annotationProperties.startLine, + endLine: annotationProperties.endLine, + col: annotationProperties.startColumn, + endColumn: annotationProperties.endColumn + }; +} +exports.toCommandProperties = toCommandProperties; //# sourceMappingURL=utils.js.map /***/ }), @@ -772,6 +791,18 @@ if (process.env.NODE_DEBUG && /\btunnel\b/.test(process.env.NODE_DEBUG)) { exports.debug = debug; // for test +/***/ }), + +/***/ 173: +/***/ (function(__unusedmodule, exports) { + +"use strict"; + +Object.defineProperty(exports, "__esModule", { value: true }); +// Used by buildProxyBypassRegexFromEnv for escaping dot symbols in NO_PROXY hosts' strings +exports.searchRegExpToReplaceSpecialChars = new RegExp('(? 0 ? ' { ' + keys.join(', ') + ' }' : ''); } if (isSymbol(obj)) { - var symString = symToString.call(obj); - return typeof obj === 'object' ? markBoxed(symString) : symString; + var symString = hasShammedSymbols ? String(obj).replace(/^(Symbol\(.*\))_[^)]*$/, '$1') : symToString.call(obj); + return typeof obj === 'object' && !hasShammedSymbols ? markBoxed(symString) : symString; } if (isElement(obj)) { var s = '<' + String(obj.nodeName).toLowerCase(); @@ -2674,7 +2725,7 @@ module.exports = function inspect_(obj, options, depth, seen) { if (typeof obj === 'object' && customInspect) { if (inspectSymbol && typeof obj[inspectSymbol] === 'function') { return obj[inspectSymbol](); - } else if (typeof obj.inspect === 'function') { + } else if (customInspect !== 'symbol' && typeof obj.inspect === 'function') { return obj.inspect(); } } @@ -2698,6 +2749,9 @@ module.exports = function inspect_(obj, options, depth, seen) { if (isWeakSet(obj)) { return weakCollectionOf('WeakSet'); } + if (isWeakRef(obj)) { + return weakCollectionOf('WeakRef'); + } if (isNumber(obj)) { return markBoxed(inspect(Number(obj))); } @@ -2712,11 +2766,16 @@ module.exports = function inspect_(obj, options, depth, seen) { } if (!isDate(obj) && !isRegExp(obj)) { var ys = arrObjKeys(obj, inspect); - if (ys.length === 0) { return '{}'; } + var isPlainObject = gPO ? gPO(obj) === Object.prototype : obj instanceof Object || obj.constructor === Object; + var protoTag = obj instanceof Object ? '' : 'null prototype'; + var stringTag = !isPlainObject && toStringTag && Object(obj) === obj && toStringTag in obj ? toStr(obj).slice(8, -1) : protoTag ? 'Object' : ''; + var constructorTag = isPlainObject || typeof obj.constructor !== 'function' ? '' : obj.constructor.name ? obj.constructor.name + ' ' : ''; + var tag = constructorTag + (stringTag || protoTag ? '[' + [].concat(stringTag || [], protoTag || []).join(': ') + '] ' : ''); + if (ys.length === 0) { return tag + '{}'; } if (indent) { - return '{' + indentedJoin(ys, indent) + '}'; + return tag + '{' + indentedJoin(ys, indent) + '}'; } - return '{ ' + ys.join(', ') + ' }'; + return tag + '{ ' + ys.join(', ') + ' }'; } return String(obj); }; @@ -2730,15 +2789,42 @@ function quote(s) { return String(s).replace(/"/g, '"'); } -function isArray(obj) { return toStr(obj) === '[object Array]'; } -function isDate(obj) { return toStr(obj) === '[object Date]'; } -function isRegExp(obj) { return toStr(obj) === '[object RegExp]'; } -function isError(obj) { return toStr(obj) === '[object Error]'; } -function isSymbol(obj) { return toStr(obj) === '[object Symbol]'; } -function isString(obj) { return toStr(obj) === '[object String]'; } -function isNumber(obj) { return toStr(obj) === '[object Number]'; } -function isBigInt(obj) { return toStr(obj) === '[object BigInt]'; } -function isBoolean(obj) { return toStr(obj) === '[object Boolean]'; } +function isArray(obj) { return toStr(obj) === '[object Array]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj)); } +function isDate(obj) { return toStr(obj) === '[object Date]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj)); } +function isRegExp(obj) { return toStr(obj) === '[object RegExp]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj)); } +function isError(obj) { return toStr(obj) === '[object Error]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj)); } +function isString(obj) { return toStr(obj) === '[object String]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj)); } +function isNumber(obj) { return toStr(obj) === '[object Number]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj)); } +function isBoolean(obj) { return toStr(obj) === '[object Boolean]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj)); } + +// Symbol and BigInt do have Symbol.toStringTag by spec, so that can't be used to eliminate false positives +function isSymbol(obj) { + if (hasShammedSymbols) { + return obj && typeof obj === 'object' && obj instanceof Symbol; + } + if (typeof obj === 'symbol') { + return true; + } + if (!obj || typeof obj !== 'object' || !symToString) { + return false; + } + try { + symToString.call(obj); + return true; + } catch (e) {} + return false; +} + +function isBigInt(obj) { + if (!obj || typeof obj !== 'object' || !bigIntValueOf) { + return false; + } + try { + bigIntValueOf.call(obj); + return true; + } catch (e) {} + return false; +} var hasOwn = Object.prototype.hasOwnProperty || function (key) { return key in this; }; function has(obj, key) { @@ -2796,6 +2882,17 @@ function isWeakMap(x) { return false; } +function isWeakRef(x) { + if (!weakRefDeref || !x || typeof x !== 'object') { + return false; + } + try { + weakRefDeref.call(x); + return true; + } catch (e) {} + return false; +} + function isSet(x) { if (!setSize || !x || typeof x !== 'object') { return false; @@ -2912,17 +3009,28 @@ function arrObjKeys(obj, inspect) { xs[i] = has(obj, i) ? inspect(obj[i], obj) : ''; } } + var syms = typeof gOPS === 'function' ? gOPS(obj) : []; + var symMap; + if (hasShammedSymbols) { + symMap = {}; + for (var k = 0; k < syms.length; k++) { + symMap['$' + syms[k]] = syms[k]; + } + } + for (var key in obj) { // eslint-disable-line no-restricted-syntax if (!has(obj, key)) { continue; } // eslint-disable-line no-restricted-syntax, no-continue if (isArr && String(Number(key)) === key && key < obj.length) { continue; } // eslint-disable-line no-restricted-syntax, no-continue - if ((/[^\w$]/).test(key)) { + if (hasShammedSymbols && symMap['$' + key] instanceof Symbol) { + // this is to prevent shammed Symbols, which are stored as strings, from being included in the string key section + continue; // eslint-disable-line no-restricted-syntax, no-continue + } else if ((/[^\w$]/).test(key)) { xs.push(inspect(key, obj) + ': ' + inspect(obj[key], obj)); } else { xs.push(key + ': ' + inspect(obj[key], obj)); } } if (typeof gOPS === 'function') { - var syms = gOPS(obj); for (var j = 0; j < syms.length; j++) { if (isEnumerable.call(obj, syms[j])) { xs.push('[' + inspect(syms[j]) + ']: ' + inspect(obj[syms[j]], obj)); @@ -3456,7 +3564,7 @@ function getReleaseByTag(repoPath, tag, token) { function resolveAssets(_release, _settings) { const downloads = []; if (_release && _release.assets.length > 0) { - if (_settings.fileName.length === 0) { + if (_settings.fileName === "*") { // Download all assets for (const asset of _release.assets) { const dData = { @@ -3467,7 +3575,7 @@ function resolveAssets(_release, _settings) { downloads.push(dData); } } - else if (_settings.fileName.length > 0) { + else { const asset = _release.assets.find(a => a.name === _settings.fileName); if (asset) { const dData = { diff --git a/src/download.ts b/src/download.ts index 5f073014..4c3ac46d 100644 --- a/src/download.ts +++ b/src/download.ts @@ -119,7 +119,7 @@ function resolveAssets( const downloads: DownloadMetaData[] = [] if (_release && _release.assets.length > 0) { - if (_settings.fileName.length === 0) { + if (_settings.fileName === "*") { // Download all assets for (const asset of _release.assets) { const dData: DownloadMetaData = { @@ -129,7 +129,7 @@ function resolveAssets( } downloads.push(dData) } - } else if (_settings.fileName.length > 0) { + } else { const asset = _release.assets.find(a => a.name === _settings.fileName) if (asset) { const dData: DownloadMetaData = {