diff --git a/README.md b/README.md index 8249943..721c433 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,18 @@ Read file contents. You can also get the file content in the branch ## Outputs - `content` text file content +- `type` +- `encoding` +- `name` +- `path` +- `sha` +- `size` file size +- `url` Format: uri +- `git_url` Format: uri +- `html_url` Format: uri +- `download_url` Format: uri +- `target` @example "actual/actual.md" +- `submodule_git_url` @example "git://example.com/defunkt/dotjs.git" ## Example Usage diff --git a/action.yml b/action.yml index 59b542a..3f95374 100644 --- a/action.yml +++ b/action.yml @@ -18,6 +18,30 @@ inputs: outputs: content: description: 'file content' + size: + description: 'file size' + type: + description: '' + encoding: + description: '' + name: + description: '' + path: + description: '' + sha: + description: '' + url: + description: '' + git_url: + description: '' + html_url: + description: '' + download_url: + description: '' + target: + description: '' + submodule_git_url: + description: '' runs: using: 'node16' diff --git a/dist/index.js b/dist/index.js index 146f0c1..e4dae63 100644 --- a/dist/index.js +++ b/dist/index.js @@ -11364,7 +11364,7 @@ __webpack_require__.r(__webpack_exports__); /* harmony import */ var _actions_github__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_actions_github__WEBPACK_IMPORTED_MODULE_0__); /* harmony import */ var _actions_core__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(8397); /* harmony import */ var _actions_core__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_actions_core__WEBPACK_IMPORTED_MODULE_1__); -var myToken=(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.getInput)('token');var octokit=(0,_actions_github__WEBPACK_IMPORTED_MODULE_0__.getOctokit)(myToken);function nodeBase64ToUtf8(data){return Buffer.from(data,"base64").toString("utf-8");}function getFileContents(_x){return _getFileContents.apply(this,arguments);}function _getFileContents(){_getFileContents=(0,_Users_wangchujiang_git_project_actions_github_action_read_file_node_modules_babel_runtime_helpers_esm_asyncToGenerator_js__WEBPACK_IMPORTED_MODULE_2__/* ["default"] */ .Z)(/*#__PURE__*/(0,_Users_wangchujiang_git_project_actions_github_action_read_file_node_modules_babel_runtime_helpers_esm_regeneratorRuntime_js__WEBPACK_IMPORTED_MODULE_3__/* ["default"] */ .Z)().mark(function _callee2(branch){var _getInputs,owner,repo,filepath,body,_yield$octokit$rest$r,data;return (0,_Users_wangchujiang_git_project_actions_github_action_read_file_node_modules_babel_runtime_helpers_esm_regeneratorRuntime_js__WEBPACK_IMPORTED_MODULE_3__/* ["default"] */ .Z)().wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:_getInputs=getInputs(),owner=_getInputs.owner,repo=_getInputs.repo,filepath=_getInputs.filepath;_context2.prev=1;body={owner:owner,repo:repo,ref:branch,path:filepath};(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.startGroup)("\uD83D\uDC49 File Content Parameters:");(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.info)("\uD83D\uDC49 ".concat(JSON.stringify(body,null,2)));(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.endGroup)();_context2.next=8;return octokit.rest.repos.getContent(body);case 8:_yield$octokit$rest$r=_context2.sent;data=_yield$octokit$rest$r.data;return _context2.abrupt("return",data);case 13:_context2.prev=13;_context2.t0=_context2["catch"](1);(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.warning)("\uD83D\uDC49 Get File Contents: ".concat(_context2.t0 instanceof Error?_context2.t0.message:_context2.t0));return _context2.abrupt("return");case 17:case"end":return _context2.stop();}}},_callee2,null,[[1,13]]);}));return _getFileContents.apply(this,arguments);}function getBranch(){return _getBranch.apply(this,arguments);}function _getBranch(){_getBranch=(0,_Users_wangchujiang_git_project_actions_github_action_read_file_node_modules_babel_runtime_helpers_esm_asyncToGenerator_js__WEBPACK_IMPORTED_MODULE_2__/* ["default"] */ .Z)(/*#__PURE__*/(0,_Users_wangchujiang_git_project_actions_github_action_read_file_node_modules_babel_runtime_helpers_esm_regeneratorRuntime_js__WEBPACK_IMPORTED_MODULE_3__/* ["default"] */ .Z)().mark(function _callee3(){var _getInputs2,branch,_yield$octokit$rest$r2,data;return (0,_Users_wangchujiang_git_project_actions_github_action_read_file_node_modules_babel_runtime_helpers_esm_regeneratorRuntime_js__WEBPACK_IMPORTED_MODULE_3__/* ["default"] */ .Z)().wrap(function _callee3$(_context3){while(1){switch(_context3.prev=_context3.next){case 0:_getInputs2=getInputs(),branch=_getInputs2.branch;if(!(branch!==null)){_context3.next=3;break;}return _context3.abrupt("return",Promise.resolve(branch));case 3:_context3.next=5;return octokit.rest.repos.get(_actions_github__WEBPACK_IMPORTED_MODULE_0__.context.repo);case 5:_yield$octokit$rest$r2=_context3.sent;data=_yield$octokit$rest$r2.data;return _context3.abrupt("return",data.default_branch);case 8:case"end":return _context3.stop();}}},_callee3);}));return _getBranch.apply(this,arguments);}var getInputs=function getInputs(){var branch=(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.getInput)('branch');var filepath=(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.getInput)('path')||'';return (0,_Users_wangchujiang_git_project_actions_github_action_read_file_node_modules_babel_runtime_helpers_esm_objectSpread2_js__WEBPACK_IMPORTED_MODULE_4__/* ["default"] */ .Z)((0,_Users_wangchujiang_git_project_actions_github_action_read_file_node_modules_babel_runtime_helpers_esm_objectSpread2_js__WEBPACK_IMPORTED_MODULE_4__/* ["default"] */ .Z)({},_actions_github__WEBPACK_IMPORTED_MODULE_0__.context.repo),{},{filepath:filepath,branch:branch});};(0,_Users_wangchujiang_git_project_actions_github_action_read_file_node_modules_babel_runtime_helpers_esm_asyncToGenerator_js__WEBPACK_IMPORTED_MODULE_2__/* ["default"] */ .Z)(/*#__PURE__*/(0,_Users_wangchujiang_git_project_actions_github_action_read_file_node_modules_babel_runtime_helpers_esm_regeneratorRuntime_js__WEBPACK_IMPORTED_MODULE_3__/* ["default"] */ .Z)().mark(function _callee(){var branch,currentFile,fileContent;return (0,_Users_wangchujiang_git_project_actions_github_action_read_file_node_modules_babel_runtime_helpers_esm_regeneratorRuntime_js__WEBPACK_IMPORTED_MODULE_3__/* ["default"] */ .Z)().wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:_context.next=2;return getBranch();case 2:branch=_context.sent;(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.info)("\uD83D\uDC49 branch: (".concat(branch||'-',")"));_context.next=6;return getFileContents(branch);case 6:currentFile=_context.sent;if(currentFile&&'content'in currentFile){fileContent=nodeBase64ToUtf8(currentFile.content||'');(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.setOutput)('content',fileContent);(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.startGroup)("\uD83D\uDC49 File Content (JSON):");(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.info)("\uD83D\uDC49 ".concat(JSON.stringify(currentFile,null,2)));(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.endGroup)();(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.startGroup)("\uD83D\uDC49 File Content:");(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.info)("\uD83D\uDC49 ".concat(fileContent));(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.endGroup)();}else{(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.startGroup)("\uD83D\uDC49 File Content:");(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.warning)("\uD83D\uDC49 ".concat(JSON.stringify(currentFile,null,2)));(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.endGroup)();}case 8:case"end":return _context.stop();}}},_callee);}))(); +var myToken=(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.getInput)('token');var octokit=(0,_actions_github__WEBPACK_IMPORTED_MODULE_0__.getOctokit)(myToken);function nodeBase64ToUtf8(data){return Buffer.from(data,"base64").toString("utf-8");}function getFileContents(_x){return _getFileContents.apply(this,arguments);}function _getFileContents(){_getFileContents=(0,_Users_wangchujiang_git_project_actions_github_action_read_file_node_modules_babel_runtime_helpers_esm_asyncToGenerator_js__WEBPACK_IMPORTED_MODULE_2__/* ["default"] */ .Z)(/*#__PURE__*/(0,_Users_wangchujiang_git_project_actions_github_action_read_file_node_modules_babel_runtime_helpers_esm_regeneratorRuntime_js__WEBPACK_IMPORTED_MODULE_3__/* ["default"] */ .Z)().mark(function _callee2(branch){var _getInputs,owner,repo,filepath,body,_yield$octokit$rest$r,data;return (0,_Users_wangchujiang_git_project_actions_github_action_read_file_node_modules_babel_runtime_helpers_esm_regeneratorRuntime_js__WEBPACK_IMPORTED_MODULE_3__/* ["default"] */ .Z)().wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:_getInputs=getInputs(),owner=_getInputs.owner,repo=_getInputs.repo,filepath=_getInputs.filepath;_context2.prev=1;body={owner:owner,repo:repo,ref:branch,path:filepath};(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.startGroup)("\uD83D\uDC49 File Content Parameters:");(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.info)("\uD83D\uDC49 ".concat(JSON.stringify(body,null,2)));(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.endGroup)();_context2.next=8;return octokit.rest.repos.getContent(body);case 8:_yield$octokit$rest$r=_context2.sent;data=_yield$octokit$rest$r.data;return _context2.abrupt("return",data);case 13:_context2.prev=13;_context2.t0=_context2["catch"](1);(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.warning)("\uD83D\uDC49 Get File Contents: ".concat(_context2.t0 instanceof Error?_context2.t0.message:_context2.t0));return _context2.abrupt("return");case 17:case"end":return _context2.stop();}}},_callee2,null,[[1,13]]);}));return _getFileContents.apply(this,arguments);}function getBranch(){return _getBranch.apply(this,arguments);}function _getBranch(){_getBranch=(0,_Users_wangchujiang_git_project_actions_github_action_read_file_node_modules_babel_runtime_helpers_esm_asyncToGenerator_js__WEBPACK_IMPORTED_MODULE_2__/* ["default"] */ .Z)(/*#__PURE__*/(0,_Users_wangchujiang_git_project_actions_github_action_read_file_node_modules_babel_runtime_helpers_esm_regeneratorRuntime_js__WEBPACK_IMPORTED_MODULE_3__/* ["default"] */ .Z)().mark(function _callee3(){var _getInputs2,branch,_yield$octokit$rest$r2,data;return (0,_Users_wangchujiang_git_project_actions_github_action_read_file_node_modules_babel_runtime_helpers_esm_regeneratorRuntime_js__WEBPACK_IMPORTED_MODULE_3__/* ["default"] */ .Z)().wrap(function _callee3$(_context3){while(1){switch(_context3.prev=_context3.next){case 0:_getInputs2=getInputs(),branch=_getInputs2.branch;if(!(branch!==null)){_context3.next=3;break;}return _context3.abrupt("return",Promise.resolve(branch));case 3:_context3.next=5;return octokit.rest.repos.get(_actions_github__WEBPACK_IMPORTED_MODULE_0__.context.repo);case 5:_yield$octokit$rest$r2=_context3.sent;data=_yield$octokit$rest$r2.data;return _context3.abrupt("return",data.default_branch);case 8:case"end":return _context3.stop();}}},_callee3);}));return _getBranch.apply(this,arguments);}var getInputs=function getInputs(){var branch=(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.getInput)('branch');var filepath=(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.getInput)('path')||'';return (0,_Users_wangchujiang_git_project_actions_github_action_read_file_node_modules_babel_runtime_helpers_esm_objectSpread2_js__WEBPACK_IMPORTED_MODULE_4__/* ["default"] */ .Z)((0,_Users_wangchujiang_git_project_actions_github_action_read_file_node_modules_babel_runtime_helpers_esm_objectSpread2_js__WEBPACK_IMPORTED_MODULE_4__/* ["default"] */ .Z)({},_actions_github__WEBPACK_IMPORTED_MODULE_0__.context.repo),{},{filepath:filepath,branch:branch});};(0,_Users_wangchujiang_git_project_actions_github_action_read_file_node_modules_babel_runtime_helpers_esm_asyncToGenerator_js__WEBPACK_IMPORTED_MODULE_2__/* ["default"] */ .Z)(/*#__PURE__*/(0,_Users_wangchujiang_git_project_actions_github_action_read_file_node_modules_babel_runtime_helpers_esm_regeneratorRuntime_js__WEBPACK_IMPORTED_MODULE_3__/* ["default"] */ .Z)().mark(function _callee(){var branch,currentFile,fileContent;return (0,_Users_wangchujiang_git_project_actions_github_action_read_file_node_modules_babel_runtime_helpers_esm_regeneratorRuntime_js__WEBPACK_IMPORTED_MODULE_3__/* ["default"] */ .Z)().wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:_context.next=2;return getBranch();case 2:branch=_context.sent;(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.info)("\uD83D\uDC49 branch: (".concat(branch||'-',")"));_context.next=6;return getFileContents(branch);case 6:currentFile=_context.sent;if(currentFile&&'content'in currentFile){fileContent=nodeBase64ToUtf8(currentFile.content||'');(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.setOutput)('content',fileContent);(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.setOutput)('size',currentFile.size);(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.setOutput)('encoding',currentFile.encoding);(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.setOutput)('name',currentFile.name);(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.setOutput)('path',currentFile.path);(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.setOutput)('sha',currentFile.sha);(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.setOutput)('url',currentFile.url);(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.setOutput)('git_url',currentFile.git_url);(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.setOutput)('html_url',currentFile.html_url);(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.setOutput)('download_url',currentFile.download_url);(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.setOutput)('target',currentFile.target);(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.setOutput)('submodule_git_url',currentFile.submodule_git_url);(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.startGroup)("\uD83D\uDC49 File Content (JSON):");(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.info)("\uD83D\uDC49 ".concat(JSON.stringify(currentFile,null,2)));(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.endGroup)();(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.startGroup)("\uD83D\uDC49 File Content:");(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.info)("\uD83D\uDC49 ".concat(fileContent));(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.endGroup)();}else{(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.startGroup)("\uD83D\uDC49 File Content:");(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.warning)("\uD83D\uDC49 ".concat(JSON.stringify(currentFile,null,2)));(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.endGroup)();}case 8:case"end":return _context.stop();}}},_callee);}))(); })(); module.exports = __webpack_exports__; diff --git a/src/index.ts b/src/index.ts index 15c14d0..195832a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -52,6 +52,17 @@ export const getInputs = () => { if (currentFile && 'content' in currentFile) { const fileContent = nodeBase64ToUtf8(currentFile.content || ''); setOutput('content', fileContent); + setOutput('size', currentFile.size); + setOutput('encoding', currentFile.encoding); + setOutput('name', currentFile.name); + setOutput('path', currentFile.path); + setOutput('sha', currentFile.sha); + setOutput('url', currentFile.url); + setOutput('git_url', currentFile.git_url); + setOutput('html_url', currentFile.html_url); + setOutput('download_url', currentFile.download_url); + setOutput('target', currentFile.target); + setOutput('submodule_git_url', currentFile.submodule_git_url); startGroup(`👉 File Content (JSON):`); info(`👉 ${JSON.stringify(currentFile, null, 2)}`); endGroup();