Skip to content

Commit

Permalink
doc: add branch example document.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Nov 30, 2022
1 parent 2541e0b commit e429c6e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ jobs:
- name: Echo src/index.ts
run: echo "${{ steps.tsfile.outputs.content }}"

- name: Read README.md(gh-pages)
id: ghpages
# uses: jaywcjlove/github-action-read-file@main
uses: ./
with:
branch: gh-pages
path: README.md

- name: Echo README.md(gh-pages)
run: echo "${{ steps.ghpages.outputs.content }}"

- name: Converts Markdown to HTML
uses: jaywcjlove/markdown-to-html-cli@main
with:
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,28 @@ Read file contents. You can also get the file content in the branch
```yml
- name: Read README.md
id: package
uses: jaywcjlove/github-action-modify-file-content@main
uses: jaywcjlove/github-action-read-file@main
with:
path: package.json

- name: Echo package.json
run: echo "${{ steps.package.outputs.content }}"
```
Specify the **branch** to read the file content
```yml
- name: Read README.md(gh-pages)
id: ghpages
uses: jaywcjlove/github-action-read-file@main
with:
branch: gh-pages
path: README.md

- name: Echo README.md(gh-pages)
run: echo "${{ steps.ghpages.outputs.content }}"
```
## See Also
- [Github Release Changelog Generator](https://github.com/jaywcjlove/changelog-generator) A GitHub Action that compares the commit differences between two branches
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:");(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.info)("\uD83D\uDC49 ".concat(JSON.stringify(currentFile,null,2)));(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__.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__;
Expand Down
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ export const getInputs = () => {
if (currentFile && 'content' in currentFile) {
const fileContent = nodeBase64ToUtf8(currentFile.content || '');
setOutput('content', fileContent);
startGroup(`πŸ‘‰ File Content:`);
startGroup(`πŸ‘‰ File Content (JSON):`);
info(`πŸ‘‰ ${JSON.stringify(currentFile, null, 2)}`);
endGroup();
startGroup(`πŸ‘‰ File Content:`);
info(`πŸ‘‰ ${fileContent}`);
endGroup();
} else {
startGroup(`πŸ‘‰ File Content:`);
warning(`πŸ‘‰ ${JSON.stringify(currentFile, null, 2)}`);
Expand Down

0 comments on commit e429c6e

Please sign in to comment.