From 8999daa35d82a040ab4acf5e5f70c3e8073c4ea4 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 24 Nov 2022 05:33:35 +0000 Subject: [PATCH 01/42] doc: modify README.md. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ce4f7e6..fc477e4 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Modify File Content Replace text content and submit content -Here is the example: update time 2022-11-24 05:28:32 +Here is the example: update time 2022-11-24 05:33:35 Here is the different delimiter example: different `GAMFC_TABEL` & `GAMFC_TABEL-END` (test) @@ -37,10 +37,10 @@ Here is the different delimiter example: different `GAMFC_TABE `README.md` file content ```markdown -update time 2022-11-24 05:28:32 +update time 2022-11-24 05:33:35 ``` -Replace the content between `2022-11-24 05:28:32`. +Replace the content between `2022-11-24 05:33:35`. ### format date From d74d14aa7028da33a11ae3ffd645c65d2b673dcb Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Tue, 29 Nov 2022 09:42:46 +0800 Subject: [PATCH 02/42] feat: add sha/branch input parameters #2 --- action.yml | 10 +++++++++- dist/index.js | 4 +++- src/utils.ts | 16 ++++++++++++++-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/action.yml b/action.yml index 9bc6d09..2558619 100644 --- a/action.yml +++ b/action.yml @@ -15,7 +15,15 @@ inputs: default: '' required: false ref: - description: 'The fully-formed ref of the branch or tag that triggered the workflow run.' + description: 'The name of the commit/branch/tag. Default: the repository’s default branch (usually `master`)' + default: '' + required: false + sha: + description: 'The blob SHA of the file being replaced.' + default: '' + required: false + branch: + description: 'The person that committed the file. Default: the authenticated user.' default: '' required: false message: diff --git a/dist/index.js b/dist/index.js index e1bde8f..f12d8de 100644 --- a/dist/index.js +++ b/dist/index.js @@ -14266,7 +14266,9 @@ var external_path_default = /*#__PURE__*/__webpack_require__.n(external_path_); // EXTERNAL MODULE: ./node_modules/@actions/github/lib/github.js var github = __webpack_require__(1374); ;// CONCATENATED MODULE: ./src/utils.ts -var myToken=(0,core.getInput)('token');var octokit=(0,github.getOctokit)(myToken);var getInputs=function getInputs(){var body=(0,core.getInput)('body')||'';var ref=(0,core.getInput)('ref')||github.context.ref;var overwrite=(0,core.getInput)('overwrite')||'false';var sync_local_file=(0,core.getInput)('sync_local_file')||'true';var filepath=(0,core.getInput)('path')||'';var message=(0,core.getInput)('message')||'';var committer_name=(0,core.getInput)('committer_name')||'';var committer_email=(0,core.getInput)('committer_email')||'';var openDelimiter=(0,core.getInput)('openDelimiter')||'';var closeDelimiter=(0,core.getInput)('closeDelimiter')||'';return (0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({},github.context.repo),{},{body:body,filepath:filepath,ref:ref,message:message,committer_name:committer_name,committer_email:committer_email,openDelimiter:openDelimiter,closeDelimiter:closeDelimiter,overwrite:overwrite,sync_local_file:sync_local_file});};function getReposPathContents(_x){return _getReposPathContents.apply(this,arguments);}function _getReposPathContents(){_getReposPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee(filePath){var _getInputs,owner,repo,ref,result;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:_getInputs=getInputs(),owner=_getInputs.owner,repo=_getInputs.repo,ref=_getInputs.ref;_context.next=3;return octokit.rest.repos.getContent({owner:owner,repo:repo,path:filePath,ref:ref});case 3:result=_context.sent;return _context.abrupt("return",result);case 5:case"end":return _context.stop();}}},_callee);}));return _getReposPathContents.apply(this,arguments);}function modifyPathContents(){return _modifyPathContents.apply(this,arguments);}function _modifyPathContents(){_modifyPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee2(){var options,content,other,_getInputs2,owner,repo,openDelimiter,closeDelimiter,message,committer_name,committer_email,overwrite,sync_local_file,ref,fullPath,isExists,body,fileResult,fileContent,oldFileContent,REG,reuslt,match,new_content,_args2=arguments;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:options=_args2.length>0&&_args2[0]!==undefined?_args2[0]:{};content=_args2.length>1?_args2[1]:undefined;other=Object.assign({},(_objectDestructuringEmpty(options),options));_getInputs2=getInputs(),owner=_getInputs2.owner,repo=_getInputs2.repo,openDelimiter=_getInputs2.openDelimiter,closeDelimiter=_getInputs2.closeDelimiter,message=_getInputs2.message,committer_name=_getInputs2.committer_name,committer_email=_getInputs2.committer_email,overwrite=_getInputs2.overwrite,sync_local_file=_getInputs2.sync_local_file,ref=_getInputs2.ref;if(options.path){_context2.next=6;break;}throw new Error("modifyPathContents: file directory parameter does not exist");case 6:fullPath=external_path_default().resolve(options.path);isExists=lib_default().existsSync(fullPath);(0,core.info)("\uD83D\uDC49 Modify Path (".concat(options.path,")"));body=(0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({owner:owner,repo:repo,path:options.path,message:message||"doc: ".concat(isExists?'modify':'create'," ").concat(options.path,"."),committer:{name:committer_name||'github-actions[bot]',email:committer_email||'github-actions[bot]@users.noreply.github.com'}},other),{},{content:Buffer.from(content).toString("base64")});if(!isExists){_context2.next=38;break;}_context2.next=13;return getReposPathContents(options.path);case 13:fileResult=_context2.sent;if(!(fileResult.status===200&&fileResult.data.sha)){_context2.next=38;break;}body.sha=fileResult.data.sha;fileContent=fileResult.data.content||'';oldFileContent=Buffer.from(fileContent,'base64').toString();REG=new RegExp("".concat(openDelimiter,"([\\s\\S]*?)").concat(closeDelimiter),'ig');reuslt=oldFileContent.replace(REG,"".concat(openDelimiter).concat(content).concat(closeDelimiter));match=oldFileContent.match(REG);(0,core.startGroup)("\uD83D\uDC49 Text old content: ".concat(match===null||match===void 0?void 0:match.length," ").concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(oldFileContent));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(match,null,2)));(0,core.endGroup)();(0,core.startGroup)("\uD83D\uDC49 Text new content: ".concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(fileResult.data,null,2)));(0,core.info)("\uD83D\uDC49 ".concat(reuslt));(0,core.endGroup)();(0,core.setOutput)('content',reuslt);if(!(oldFileContent==reuslt)){_context2.next=33;break;}(0,core.warning)("\uD83D\uDC49 Content has not changed!!!!!");return _context2.abrupt("return");case 33:new_content=Buffer.from(content).toString("base64");if(overwrite.toString()==='true'){body.content=new_content;}else{body.content=Buffer.from(reuslt).toString("base64");new_content=reuslt;}if(!(sync_local_file.toString()==='true'&&ref===github.context.ref)){_context2.next=38;break;}_context2.next=38;return lib_default().writeFile(fullPath,new_content);case 38:(0,core.startGroup)("modifyPathContents Body:");(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(body,null,2)));(0,core.endGroup)();return _context2.abrupt("return",octokit.request('PUT /repos/{owner}/{repo}/contents/{path}',(0,objectSpread2/* default */.Z)({},body)));case 42:case"end":return _context2.stop();}}},_callee2);}));return _modifyPathContents.apply(this,arguments);} +var myToken=(0,core.getInput)('token');var octokit=(0,github.getOctokit)(myToken);var getInputs=function getInputs(){var body=(0,core.getInput)('body')||'';var ref=(0,core.getInput)('ref')||github.context.ref;var branch=(0,core.getInput)('branch');var sha=(0,core.getInput)('sha');var overwrite=(0,core.getInput)('overwrite')||'false';var sync_local_file=(0,core.getInput)('sync_local_file')||'true';var filepath=(0,core.getInput)('path')||'';var message=(0,core.getInput)('message')||'';var committer_name=(0,core.getInput)('committer_name')||'';var committer_email=(0,core.getInput)('committer_email')||'';var openDelimiter=(0,core.getInput)('openDelimiter')||'';var closeDelimiter=(0,core.getInput)('closeDelimiter')||'';return (0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({},github.context.repo),{},{body:body,filepath:filepath,ref:ref,branch:branch,sha:sha,message:message,committer_name:committer_name,committer_email:committer_email,openDelimiter:openDelimiter,closeDelimiter:closeDelimiter,overwrite:overwrite,sync_local_file:sync_local_file});};function getReposPathContents(_x){return _getReposPathContents.apply(this,arguments);}function _getReposPathContents(){_getReposPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee(filePath){var _getInputs,owner,repo,ref,result;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:_getInputs=getInputs(),owner=_getInputs.owner,repo=_getInputs.repo,ref=_getInputs.ref;_context.next=3;return octokit.rest.repos.getContent({owner:owner,repo:repo,path:filePath,/** + * The name of the commit/branch/tag. Default: the repository’s default branch (usually `master`) + */ref:ref});case 3:result=_context.sent;return _context.abrupt("return",result);case 5:case"end":return _context.stop();}}},_callee);}));return _getReposPathContents.apply(this,arguments);}function modifyPathContents(){return _modifyPathContents.apply(this,arguments);}function _modifyPathContents(){_modifyPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee2(){var options,content,other,_getInputs2,owner,repo,openDelimiter,closeDelimiter,message,committer_name,committer_email,overwrite,sync_local_file,ref,sha,branch,fullPath,isExists,body,fileResult,fileContent,oldFileContent,REG,reuslt,match,new_content,_args2=arguments;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:options=_args2.length>0&&_args2[0]!==undefined?_args2[0]:{};content=_args2.length>1?_args2[1]:undefined;other=Object.assign({},(_objectDestructuringEmpty(options),options));_getInputs2=getInputs(),owner=_getInputs2.owner,repo=_getInputs2.repo,openDelimiter=_getInputs2.openDelimiter,closeDelimiter=_getInputs2.closeDelimiter,message=_getInputs2.message,committer_name=_getInputs2.committer_name,committer_email=_getInputs2.committer_email,overwrite=_getInputs2.overwrite,sync_local_file=_getInputs2.sync_local_file,ref=_getInputs2.ref,sha=_getInputs2.sha,branch=_getInputs2.branch;if(options.path){_context2.next=6;break;}throw new Error("modifyPathContents: file directory parameter does not exist");case 6:fullPath=external_path_default().resolve(options.path);isExists=lib_default().existsSync(fullPath);(0,core.info)("\uD83D\uDC49 Modify Path (".concat(options.path,")"));body=(0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({owner:owner,repo:repo,path:options.path,message:message||"doc: ".concat(isExists?'modify':'create'," ").concat(options.path,"."),committer:{name:committer_name||'github-actions[bot]',email:committer_email||'github-actions[bot]@users.noreply.github.com'}},other),{},{content:Buffer.from(content).toString("base64")});if(sha){body.sha=sha;}if(branch){body.branch=branch;}if(!isExists){_context2.next=41;break;}_context2.next=15;return getReposPathContents(options.path);case 15:fileResult=_context2.sent;if(!(fileResult.status===200&&fileResult.data.sha)){_context2.next=41;break;}body.sha=fileResult.data.sha;fileContent=fileResult.data.content||'';oldFileContent=Buffer.from(fileContent,'base64').toString();REG=new RegExp("".concat(openDelimiter,"([\\s\\S]*?)").concat(closeDelimiter),'ig');reuslt=oldFileContent.replace(REG,"".concat(openDelimiter).concat(content).concat(closeDelimiter));match=oldFileContent.match(REG);(0,core.startGroup)("\uD83D\uDC49 Text old content: ".concat(match===null||match===void 0?void 0:match.length," ").concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(oldFileContent));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(match,null,2)));(0,core.endGroup)();(0,core.startGroup)("\uD83D\uDC49 Text new content: ".concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(fileResult.data,null,2)));(0,core.info)("\uD83D\uDC49 ".concat(reuslt));(0,core.endGroup)();(0,core.setOutput)('content',reuslt);if(!(oldFileContent==reuslt)){_context2.next=35;break;}(0,core.warning)("\uD83D\uDC49 Content has not changed!!!!!");return _context2.abrupt("return");case 35:new_content=Buffer.from(content).toString("base64");if(overwrite.toString()==='true'){body.content=new_content;}else{body.content=Buffer.from(reuslt).toString("base64");new_content=reuslt;}(0,core.setOutput)('context.ref',github.context.ref);if(!(sync_local_file.toString()==='true'&&ref===github.context.ref)){_context2.next=41;break;}_context2.next=41;return lib_default().writeFile(fullPath,new_content);case 41:(0,core.startGroup)("modifyPathContents Body:");(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(body,null,2)));(0,core.endGroup)();return _context2.abrupt("return",octokit.request('PUT /repos/{owner}/{repo}/contents/{path}',(0,objectSpread2/* default */.Z)({},body)));case 45:case"end":return _context2.stop();}}},_callee2);}));return _modifyPathContents.apply(this,arguments);} ;// CONCATENATED MODULE: ./node_modules/@uiw/formatter/esm/index.js /**! * @uiw/formatter v1.3.3 diff --git a/src/utils.ts b/src/utils.ts index d433345..1fe9a6f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -13,6 +13,8 @@ export const octokit = getOctokit(myToken); export const getInputs = () => { const body = getInput('body') || ''; const ref = getInput('ref') || context.ref; + const branch = getInput('branch'); + const sha = getInput('sha'); const overwrite = getInput('overwrite') || 'false'; const sync_local_file = getInput('sync_local_file') || 'true'; const filepath = getInput('path') || ''; @@ -24,7 +26,7 @@ export const getInputs = () => { return { ...context.repo, - body, filepath, ref, + body, filepath, ref, branch, sha, message, committer_name, committer_email, @@ -40,6 +42,9 @@ export async function getReposPathContents(filePath: string) { const result = await octokit.rest.repos.getContent({ owner, repo, path: filePath, + /** + * The name of the commit/branch/tag. Default: the repository’s default branch (usually `master`) + */ ref, }) return result @@ -47,7 +52,7 @@ export async function getReposPathContents(filePath: string) { export async function modifyPathContents(options: Partial = {}, content: string) { const { ...other} = options; - const {owner, repo, openDelimiter, closeDelimiter, message, committer_name, committer_email, overwrite, sync_local_file, ref} = getInputs(); + const { owner, repo, openDelimiter, closeDelimiter, message, committer_name, committer_email, overwrite, sync_local_file, ref, sha, branch} = getInputs(); if (!options.path) { throw new Error(`modifyPathContents: file directory parameter does not exist`) } @@ -65,6 +70,12 @@ export async function modifyPathContents(options: Partial = {}, co ...other, content: Buffer.from(content).toString("base64"), } + if (sha) { + body.sha = sha; + } + if (branch) { + body.branch = branch; + } if (isExists) { const fileResult = await getReposPathContents(options.path) if (fileResult.status === 200 && (fileResult.data as any).sha) { @@ -94,6 +105,7 @@ export async function modifyPathContents(options: Partial = {}, co body.content = Buffer.from(reuslt).toString("base64"); new_content = reuslt; } + setOutput('context.ref', context.ref); if (sync_local_file.toString() === 'true' && ref === context.ref) { await FS.writeFile(fullPath, new_content); } From 128a99952777ad567a7a14dddea63d7da7e94d92 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 29 Nov 2022 01:44:16 +0000 Subject: [PATCH 03/42] doc: modify README.md. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index fc477e4..868678e 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Modify File Content Replace text content and submit content -Here is the example: update time 2022-11-24 05:33:35 +Here is the example: update time 2022-11-29 01:44:16 Here is the different delimiter example: different `GAMFC_TABEL` & `GAMFC_TABEL-END` (test) @@ -37,10 +37,10 @@ Here is the different delimiter example: different `GAMFC_TABE `README.md` file content ```markdown -update time 2022-11-24 05:33:35 +update time 2022-11-29 01:44:16 ``` -Replace the content between `2022-11-24 05:33:35`. +Replace the content between `2022-11-29 01:44:16`. ### format date From 48a985a8e62c5daeadecbf046935a47d0e44ef1b Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Tue, 29 Nov 2022 09:45:09 +0800 Subject: [PATCH 04/42] doc: Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 868678e..a4b0c51 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,9 @@ Here is the different delimiter example: different `GAMFC_TABE - `token` Your `GITHUB_TOKEN`. This is required. Why do we need `token`? Read more here: [About the GITHUB_TOKEN secret](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/authenticating-with-the-github_token#about-the-github_token-secret). Default: `${{ github.token }}` - `body` what needs to be replaced - `path` file to be replaced -- `ref` The fully-formed ref of the branch or tag that triggered the workflow run. +- `sha` The blob SHA of the file being replaced +- `branch` The person that committed the file. Default: the authenticated user +- `ref` The name of the commit/branch/tag. Default: the repository’s default branch (usually `master`) - `overwrite` Overwrite the entire file content, by default `false` - `sync_local_file` Sync local file content, by default `true` - `message` The commit message. by default `doc: update .` From d4dc80cfab1dfb995896adfc103ab25ab51ebe8f Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Tue, 29 Nov 2022 09:55:24 +0800 Subject: [PATCH 05/42] chore: update workflows config. --- .github/workflows/ci.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2d22fc0..5c355e2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -60,6 +60,15 @@ jobs: id: tag_version uses: jaywcjlove/changelog-generator@main + - name: gh-pages README.md + working-directory: build + run: | + cat > README.md << EOF + Website: https://jaywcjlove.github.io/github-action-modify-file-content + + TEST: 2022-11-29 01:44:16 + EOF + - name: Deploy uses: peaceiris/actions-gh-pages@v3 with: From 656ebae75030497523566a6f5fa845da004c85fd Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 29 Nov 2022 01:56:31 +0000 Subject: [PATCH 06/42] doc: modify README.md. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a4b0c51..124ecef 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Modify File Content Replace text content and submit content -Here is the example: update time 2022-11-29 01:44:16 +Here is the example: update time 2022-11-29 01:56:31 Here is the different delimiter example: different `GAMFC_TABEL` & `GAMFC_TABEL-END` (test) @@ -39,10 +39,10 @@ Here is the different delimiter example: different `GAMFC_TABE `README.md` file content ```markdown -update time 2022-11-29 01:44:16 +update time 2022-11-29 01:56:31 ``` -Replace the content between `2022-11-29 01:44:16`. +Replace the content between `2022-11-29 01:56:31`. ### format date From b8e1ced4610f6ea214c7097957ed91ea72223846 Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Tue, 29 Nov 2022 10:14:19 +0800 Subject: [PATCH 07/42] chore: update workflows config. --- .github/workflows/ci.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5c355e2..438ee1e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -76,6 +76,14 @@ jobs: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./build + - name: Modify README.md + # uses: github-action-modify-file-content@main + uses: ./ + with: + path: README.md + branch: gh-pages + body: "{{date:YYYY-MM-DD HH:mm:ss}}" + - name: Generate Changelog id: changelog uses: jaywcjlove/changelog-generator@main From ecfb842ed1baa77fcb9fefd0d1a95d62a3c33715 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 29 Nov 2022 02:15:53 +0000 Subject: [PATCH 08/42] doc: modify README.md. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 124ecef..4569636 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Modify File Content Replace text content and submit content -Here is the example: update time 2022-11-29 01:56:31 +Here is the example: update time 2022-11-29 02:15:52 Here is the different delimiter example: different `GAMFC_TABEL` & `GAMFC_TABEL-END` (test) @@ -39,10 +39,10 @@ Here is the different delimiter example: different `GAMFC_TABE `README.md` file content ```markdown -update time 2022-11-29 01:56:31 +update time 2022-11-29 02:15:52 ``` -Replace the content between `2022-11-29 01:56:31`. +Replace the content between `2022-11-29 02:15:52`. ### format date From 5dbc913ae2117be9e3efce3305c2cec31b3957ec Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Tue, 29 Nov 2022 10:27:02 +0800 Subject: [PATCH 09/42] fix: sha/branch input parameters. --- action.yml | 2 +- dist/index.js | 2 +- src/utils.ts | 9 +++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/action.yml b/action.yml index 2558619..8de1ec9 100644 --- a/action.yml +++ b/action.yml @@ -20,7 +20,7 @@ inputs: required: false sha: description: 'The blob SHA of the file being replaced.' - default: '' + default: ${{ github.sha }} required: false branch: description: 'The person that committed the file. Default: the authenticated user.' diff --git a/dist/index.js b/dist/index.js index f12d8de..a9da5b9 100644 --- a/dist/index.js +++ b/dist/index.js @@ -14268,7 +14268,7 @@ var github = __webpack_require__(1374); ;// CONCATENATED MODULE: ./src/utils.ts var myToken=(0,core.getInput)('token');var octokit=(0,github.getOctokit)(myToken);var getInputs=function getInputs(){var body=(0,core.getInput)('body')||'';var ref=(0,core.getInput)('ref')||github.context.ref;var branch=(0,core.getInput)('branch');var sha=(0,core.getInput)('sha');var overwrite=(0,core.getInput)('overwrite')||'false';var sync_local_file=(0,core.getInput)('sync_local_file')||'true';var filepath=(0,core.getInput)('path')||'';var message=(0,core.getInput)('message')||'';var committer_name=(0,core.getInput)('committer_name')||'';var committer_email=(0,core.getInput)('committer_email')||'';var openDelimiter=(0,core.getInput)('openDelimiter')||'';var closeDelimiter=(0,core.getInput)('closeDelimiter')||'';return (0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({},github.context.repo),{},{body:body,filepath:filepath,ref:ref,branch:branch,sha:sha,message:message,committer_name:committer_name,committer_email:committer_email,openDelimiter:openDelimiter,closeDelimiter:closeDelimiter,overwrite:overwrite,sync_local_file:sync_local_file});};function getReposPathContents(_x){return _getReposPathContents.apply(this,arguments);}function _getReposPathContents(){_getReposPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee(filePath){var _getInputs,owner,repo,ref,result;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:_getInputs=getInputs(),owner=_getInputs.owner,repo=_getInputs.repo,ref=_getInputs.ref;_context.next=3;return octokit.rest.repos.getContent({owner:owner,repo:repo,path:filePath,/** * The name of the commit/branch/tag. Default: the repository’s default branch (usually `master`) - */ref:ref});case 3:result=_context.sent;return _context.abrupt("return",result);case 5:case"end":return _context.stop();}}},_callee);}));return _getReposPathContents.apply(this,arguments);}function modifyPathContents(){return _modifyPathContents.apply(this,arguments);}function _modifyPathContents(){_modifyPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee2(){var options,content,other,_getInputs2,owner,repo,openDelimiter,closeDelimiter,message,committer_name,committer_email,overwrite,sync_local_file,ref,sha,branch,fullPath,isExists,body,fileResult,fileContent,oldFileContent,REG,reuslt,match,new_content,_args2=arguments;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:options=_args2.length>0&&_args2[0]!==undefined?_args2[0]:{};content=_args2.length>1?_args2[1]:undefined;other=Object.assign({},(_objectDestructuringEmpty(options),options));_getInputs2=getInputs(),owner=_getInputs2.owner,repo=_getInputs2.repo,openDelimiter=_getInputs2.openDelimiter,closeDelimiter=_getInputs2.closeDelimiter,message=_getInputs2.message,committer_name=_getInputs2.committer_name,committer_email=_getInputs2.committer_email,overwrite=_getInputs2.overwrite,sync_local_file=_getInputs2.sync_local_file,ref=_getInputs2.ref,sha=_getInputs2.sha,branch=_getInputs2.branch;if(options.path){_context2.next=6;break;}throw new Error("modifyPathContents: file directory parameter does not exist");case 6:fullPath=external_path_default().resolve(options.path);isExists=lib_default().existsSync(fullPath);(0,core.info)("\uD83D\uDC49 Modify Path (".concat(options.path,")"));body=(0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({owner:owner,repo:repo,path:options.path,message:message||"doc: ".concat(isExists?'modify':'create'," ").concat(options.path,"."),committer:{name:committer_name||'github-actions[bot]',email:committer_email||'github-actions[bot]@users.noreply.github.com'}},other),{},{content:Buffer.from(content).toString("base64")});if(sha){body.sha=sha;}if(branch){body.branch=branch;}if(!isExists){_context2.next=41;break;}_context2.next=15;return getReposPathContents(options.path);case 15:fileResult=_context2.sent;if(!(fileResult.status===200&&fileResult.data.sha)){_context2.next=41;break;}body.sha=fileResult.data.sha;fileContent=fileResult.data.content||'';oldFileContent=Buffer.from(fileContent,'base64').toString();REG=new RegExp("".concat(openDelimiter,"([\\s\\S]*?)").concat(closeDelimiter),'ig');reuslt=oldFileContent.replace(REG,"".concat(openDelimiter).concat(content).concat(closeDelimiter));match=oldFileContent.match(REG);(0,core.startGroup)("\uD83D\uDC49 Text old content: ".concat(match===null||match===void 0?void 0:match.length," ").concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(oldFileContent));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(match,null,2)));(0,core.endGroup)();(0,core.startGroup)("\uD83D\uDC49 Text new content: ".concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(fileResult.data,null,2)));(0,core.info)("\uD83D\uDC49 ".concat(reuslt));(0,core.endGroup)();(0,core.setOutput)('content',reuslt);if(!(oldFileContent==reuslt)){_context2.next=35;break;}(0,core.warning)("\uD83D\uDC49 Content has not changed!!!!!");return _context2.abrupt("return");case 35:new_content=Buffer.from(content).toString("base64");if(overwrite.toString()==='true'){body.content=new_content;}else{body.content=Buffer.from(reuslt).toString("base64");new_content=reuslt;}(0,core.setOutput)('context.ref',github.context.ref);if(!(sync_local_file.toString()==='true'&&ref===github.context.ref)){_context2.next=41;break;}_context2.next=41;return lib_default().writeFile(fullPath,new_content);case 41:(0,core.startGroup)("modifyPathContents Body:");(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(body,null,2)));(0,core.endGroup)();return _context2.abrupt("return",octokit.request('PUT /repos/{owner}/{repo}/contents/{path}',(0,objectSpread2/* default */.Z)({},body)));case 45:case"end":return _context2.stop();}}},_callee2);}));return _modifyPathContents.apply(this,arguments);} + */ref:ref});case 3:result=_context.sent;return _context.abrupt("return",result);case 5:case"end":return _context.stop();}}},_callee);}));return _getReposPathContents.apply(this,arguments);}function modifyPathContents(){return _modifyPathContents.apply(this,arguments);}function _modifyPathContents(){_modifyPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee2(){var options,content,other,_getInputs2,owner,repo,openDelimiter,closeDelimiter,message,committer_name,committer_email,overwrite,sync_local_file,ref,sha,branch,fullPath,isExists,body,fileResult,fileContent,oldFileContent,REG,reuslt,match,new_content,_args2=arguments;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:options=_args2.length>0&&_args2[0]!==undefined?_args2[0]:{};content=_args2.length>1?_args2[1]:undefined;other=Object.assign({},(_objectDestructuringEmpty(options),options));_getInputs2=getInputs(),owner=_getInputs2.owner,repo=_getInputs2.repo,openDelimiter=_getInputs2.openDelimiter,closeDelimiter=_getInputs2.closeDelimiter,message=_getInputs2.message,committer_name=_getInputs2.committer_name,committer_email=_getInputs2.committer_email,overwrite=_getInputs2.overwrite,sync_local_file=_getInputs2.sync_local_file,ref=_getInputs2.ref,sha=_getInputs2.sha,branch=_getInputs2.branch;if(options.path){_context2.next=6;break;}throw new Error("modifyPathContents: file directory parameter does not exist");case 6:fullPath=external_path_default().resolve(options.path);isExists=lib_default().existsSync(fullPath);(0,core.info)("\uD83D\uDC49 Modify Path (".concat(options.path,")"));body=(0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({owner:owner,repo:repo,path:options.path,message:message||"doc: ".concat(isExists?'modify':'create'," ").concat(options.path,"."),committer:{name:committer_name||'github-actions[bot]',email:committer_email||'github-actions[bot]@users.noreply.github.com'}},other),{},{content:Buffer.from(content).toString("base64")});if(branch){body.branch=branch;}else if(sha){body.sha=sha;}if(!isExists){_context2.next=40;break;}_context2.next=14;return getReposPathContents(options.path);case 14:fileResult=_context2.sent;if(!(fileResult.status===200&&fileResult.data.sha)){_context2.next=40;break;}if(!branch){body.sha=sha||fileResult.data.sha;}fileContent=fileResult.data.content||'';oldFileContent=Buffer.from(fileContent,'base64').toString();REG=new RegExp("".concat(openDelimiter,"([\\s\\S]*?)").concat(closeDelimiter),'ig');reuslt=oldFileContent.replace(REG,"".concat(openDelimiter).concat(content).concat(closeDelimiter));match=oldFileContent.match(REG);(0,core.startGroup)("\uD83D\uDC49 Text old content: ".concat(match===null||match===void 0?void 0:match.length," ").concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(oldFileContent));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(match,null,2)));(0,core.endGroup)();(0,core.startGroup)("\uD83D\uDC49 Text new content: ".concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(fileResult.data,null,2)));(0,core.info)("\uD83D\uDC49 ".concat(reuslt));(0,core.endGroup)();(0,core.setOutput)('content',reuslt);if(!(oldFileContent==reuslt)){_context2.next=34;break;}(0,core.warning)("\uD83D\uDC49 Content has not changed!!!!!");return _context2.abrupt("return");case 34:new_content=Buffer.from(content).toString("base64");if(overwrite.toString()==='true'){body.content=new_content;}else{body.content=Buffer.from(reuslt).toString("base64");new_content=reuslt;}(0,core.setOutput)('context.ref',github.context.ref);if(!(sync_local_file.toString()==='true'&&ref===github.context.ref)){_context2.next=40;break;}_context2.next=40;return lib_default().writeFile(fullPath,new_content);case 40:(0,core.startGroup)("modifyPathContents Body:");(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(body,null,2)));(0,core.endGroup)();return _context2.abrupt("return",octokit.request('PUT /repos/{owner}/{repo}/contents/{path}',(0,objectSpread2/* default */.Z)({},body)));case 44:case"end":return _context2.stop();}}},_callee2);}));return _modifyPathContents.apply(this,arguments);} ;// CONCATENATED MODULE: ./node_modules/@uiw/formatter/esm/index.js /**! * @uiw/formatter v1.3.3 diff --git a/src/utils.ts b/src/utils.ts index 1fe9a6f..4981445 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -70,16 +70,17 @@ export async function modifyPathContents(options: Partial = {}, co ...other, content: Buffer.from(content).toString("base64"), } - if (sha) { - body.sha = sha; - } if (branch) { body.branch = branch; + } else if (sha) { + body.sha = sha; } if (isExists) { const fileResult = await getReposPathContents(options.path) if (fileResult.status === 200 && (fileResult.data as any).sha) { - body.sha = (fileResult.data as any).sha; + if (!branch) { + body.sha = sha || (fileResult.data as any).sha; + } const fileContent: string = (fileResult.data as any).content || ''; const oldFileContent = Buffer.from(fileContent, 'base64').toString(); const REG = new RegExp(`${openDelimiter}([\\s\\S]*?)${closeDelimiter}`, 'ig') From 986a7d879b1fa042dcf6a30350a890c4554d4da8 Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Tue, 29 Nov 2022 10:29:44 +0800 Subject: [PATCH 10/42] fix: sha input parameters. --- dist/index.js | 2 +- src/utils.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index a9da5b9..8150b8f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -14268,7 +14268,7 @@ var github = __webpack_require__(1374); ;// CONCATENATED MODULE: ./src/utils.ts var myToken=(0,core.getInput)('token');var octokit=(0,github.getOctokit)(myToken);var getInputs=function getInputs(){var body=(0,core.getInput)('body')||'';var ref=(0,core.getInput)('ref')||github.context.ref;var branch=(0,core.getInput)('branch');var sha=(0,core.getInput)('sha');var overwrite=(0,core.getInput)('overwrite')||'false';var sync_local_file=(0,core.getInput)('sync_local_file')||'true';var filepath=(0,core.getInput)('path')||'';var message=(0,core.getInput)('message')||'';var committer_name=(0,core.getInput)('committer_name')||'';var committer_email=(0,core.getInput)('committer_email')||'';var openDelimiter=(0,core.getInput)('openDelimiter')||'';var closeDelimiter=(0,core.getInput)('closeDelimiter')||'';return (0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({},github.context.repo),{},{body:body,filepath:filepath,ref:ref,branch:branch,sha:sha,message:message,committer_name:committer_name,committer_email:committer_email,openDelimiter:openDelimiter,closeDelimiter:closeDelimiter,overwrite:overwrite,sync_local_file:sync_local_file});};function getReposPathContents(_x){return _getReposPathContents.apply(this,arguments);}function _getReposPathContents(){_getReposPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee(filePath){var _getInputs,owner,repo,ref,result;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:_getInputs=getInputs(),owner=_getInputs.owner,repo=_getInputs.repo,ref=_getInputs.ref;_context.next=3;return octokit.rest.repos.getContent({owner:owner,repo:repo,path:filePath,/** * The name of the commit/branch/tag. Default: the repository’s default branch (usually `master`) - */ref:ref});case 3:result=_context.sent;return _context.abrupt("return",result);case 5:case"end":return _context.stop();}}},_callee);}));return _getReposPathContents.apply(this,arguments);}function modifyPathContents(){return _modifyPathContents.apply(this,arguments);}function _modifyPathContents(){_modifyPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee2(){var options,content,other,_getInputs2,owner,repo,openDelimiter,closeDelimiter,message,committer_name,committer_email,overwrite,sync_local_file,ref,sha,branch,fullPath,isExists,body,fileResult,fileContent,oldFileContent,REG,reuslt,match,new_content,_args2=arguments;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:options=_args2.length>0&&_args2[0]!==undefined?_args2[0]:{};content=_args2.length>1?_args2[1]:undefined;other=Object.assign({},(_objectDestructuringEmpty(options),options));_getInputs2=getInputs(),owner=_getInputs2.owner,repo=_getInputs2.repo,openDelimiter=_getInputs2.openDelimiter,closeDelimiter=_getInputs2.closeDelimiter,message=_getInputs2.message,committer_name=_getInputs2.committer_name,committer_email=_getInputs2.committer_email,overwrite=_getInputs2.overwrite,sync_local_file=_getInputs2.sync_local_file,ref=_getInputs2.ref,sha=_getInputs2.sha,branch=_getInputs2.branch;if(options.path){_context2.next=6;break;}throw new Error("modifyPathContents: file directory parameter does not exist");case 6:fullPath=external_path_default().resolve(options.path);isExists=lib_default().existsSync(fullPath);(0,core.info)("\uD83D\uDC49 Modify Path (".concat(options.path,")"));body=(0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({owner:owner,repo:repo,path:options.path,message:message||"doc: ".concat(isExists?'modify':'create'," ").concat(options.path,"."),committer:{name:committer_name||'github-actions[bot]',email:committer_email||'github-actions[bot]@users.noreply.github.com'}},other),{},{content:Buffer.from(content).toString("base64")});if(branch){body.branch=branch;}else if(sha){body.sha=sha;}if(!isExists){_context2.next=40;break;}_context2.next=14;return getReposPathContents(options.path);case 14:fileResult=_context2.sent;if(!(fileResult.status===200&&fileResult.data.sha)){_context2.next=40;break;}if(!branch){body.sha=sha||fileResult.data.sha;}fileContent=fileResult.data.content||'';oldFileContent=Buffer.from(fileContent,'base64').toString();REG=new RegExp("".concat(openDelimiter,"([\\s\\S]*?)").concat(closeDelimiter),'ig');reuslt=oldFileContent.replace(REG,"".concat(openDelimiter).concat(content).concat(closeDelimiter));match=oldFileContent.match(REG);(0,core.startGroup)("\uD83D\uDC49 Text old content: ".concat(match===null||match===void 0?void 0:match.length," ").concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(oldFileContent));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(match,null,2)));(0,core.endGroup)();(0,core.startGroup)("\uD83D\uDC49 Text new content: ".concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(fileResult.data,null,2)));(0,core.info)("\uD83D\uDC49 ".concat(reuslt));(0,core.endGroup)();(0,core.setOutput)('content',reuslt);if(!(oldFileContent==reuslt)){_context2.next=34;break;}(0,core.warning)("\uD83D\uDC49 Content has not changed!!!!!");return _context2.abrupt("return");case 34:new_content=Buffer.from(content).toString("base64");if(overwrite.toString()==='true'){body.content=new_content;}else{body.content=Buffer.from(reuslt).toString("base64");new_content=reuslt;}(0,core.setOutput)('context.ref',github.context.ref);if(!(sync_local_file.toString()==='true'&&ref===github.context.ref)){_context2.next=40;break;}_context2.next=40;return lib_default().writeFile(fullPath,new_content);case 40:(0,core.startGroup)("modifyPathContents Body:");(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(body,null,2)));(0,core.endGroup)();return _context2.abrupt("return",octokit.request('PUT /repos/{owner}/{repo}/contents/{path}',(0,objectSpread2/* default */.Z)({},body)));case 44:case"end":return _context2.stop();}}},_callee2);}));return _modifyPathContents.apply(this,arguments);} + */ref:ref});case 3:result=_context.sent;return _context.abrupt("return",result);case 5:case"end":return _context.stop();}}},_callee);}));return _getReposPathContents.apply(this,arguments);}function modifyPathContents(){return _modifyPathContents.apply(this,arguments);}function _modifyPathContents(){_modifyPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee2(){var options,content,other,_getInputs2,owner,repo,openDelimiter,closeDelimiter,message,committer_name,committer_email,overwrite,sync_local_file,ref,sha,branch,fullPath,isExists,body,fileResult,fileContent,oldFileContent,REG,reuslt,match,new_content,_args2=arguments;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:options=_args2.length>0&&_args2[0]!==undefined?_args2[0]:{};content=_args2.length>1?_args2[1]:undefined;other=Object.assign({},(_objectDestructuringEmpty(options),options));_getInputs2=getInputs(),owner=_getInputs2.owner,repo=_getInputs2.repo,openDelimiter=_getInputs2.openDelimiter,closeDelimiter=_getInputs2.closeDelimiter,message=_getInputs2.message,committer_name=_getInputs2.committer_name,committer_email=_getInputs2.committer_email,overwrite=_getInputs2.overwrite,sync_local_file=_getInputs2.sync_local_file,ref=_getInputs2.ref,sha=_getInputs2.sha,branch=_getInputs2.branch;if(options.path){_context2.next=6;break;}throw new Error("modifyPathContents: file directory parameter does not exist");case 6:fullPath=external_path_default().resolve(options.path);isExists=lib_default().existsSync(fullPath);(0,core.info)("\uD83D\uDC49 Modify Path (".concat(options.path,")"));body=(0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({owner:owner,repo:repo,path:options.path,message:message||"doc: ".concat(isExists?'modify':'create'," ").concat(options.path,"."),committer:{name:committer_name||'github-actions[bot]',email:committer_email||'github-actions[bot]@users.noreply.github.com'}},other),{},{content:Buffer.from(content).toString("base64")});if(branch){body.branch=branch;}else if(sha){body.sha=sha;}if(!isExists){_context2.next=40;break;}_context2.next=14;return getReposPathContents(options.path);case 14:fileResult=_context2.sent;if(!(fileResult.status===200&&fileResult.data.sha)){_context2.next=40;break;}if(!branch){body.sha=fileResult.data.sha||sha;}fileContent=fileResult.data.content||'';oldFileContent=Buffer.from(fileContent,'base64').toString();REG=new RegExp("".concat(openDelimiter,"([\\s\\S]*?)").concat(closeDelimiter),'ig');reuslt=oldFileContent.replace(REG,"".concat(openDelimiter).concat(content).concat(closeDelimiter));match=oldFileContent.match(REG);(0,core.startGroup)("\uD83D\uDC49 Text old content: ".concat(match===null||match===void 0?void 0:match.length," ").concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(oldFileContent));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(match,null,2)));(0,core.endGroup)();(0,core.startGroup)("\uD83D\uDC49 Text new content: ".concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(fileResult.data,null,2)));(0,core.info)("\uD83D\uDC49 ".concat(reuslt));(0,core.endGroup)();(0,core.setOutput)('content',reuslt);if(!(oldFileContent==reuslt)){_context2.next=34;break;}(0,core.warning)("\uD83D\uDC49 Content has not changed!!!!!");return _context2.abrupt("return");case 34:new_content=Buffer.from(content).toString("base64");if(overwrite.toString()==='true'){body.content=new_content;}else{body.content=Buffer.from(reuslt).toString("base64");new_content=reuslt;}(0,core.setOutput)('context.ref',github.context.ref);if(!(sync_local_file.toString()==='true'&&ref===github.context.ref)){_context2.next=40;break;}_context2.next=40;return lib_default().writeFile(fullPath,new_content);case 40:(0,core.startGroup)("modifyPathContents Body:");(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(body,null,2)));(0,core.endGroup)();return _context2.abrupt("return",octokit.request('PUT /repos/{owner}/{repo}/contents/{path}',(0,objectSpread2/* default */.Z)({},body)));case 44:case"end":return _context2.stop();}}},_callee2);}));return _modifyPathContents.apply(this,arguments);} ;// CONCATENATED MODULE: ./node_modules/@uiw/formatter/esm/index.js /**! * @uiw/formatter v1.3.3 diff --git a/src/utils.ts b/src/utils.ts index 4981445..0418965 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -79,7 +79,7 @@ export async function modifyPathContents(options: Partial = {}, co const fileResult = await getReposPathContents(options.path) if (fileResult.status === 200 && (fileResult.data as any).sha) { if (!branch) { - body.sha = sha || (fileResult.data as any).sha; + body.sha = (fileResult.data as any).sha || sha; } const fileContent: string = (fileResult.data as any).content || ''; const oldFileContent = Buffer.from(fileContent, 'base64').toString(); From 9ad6548b0078e97323256c01c39d448aba6d318d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 29 Nov 2022 02:31:14 +0000 Subject: [PATCH 11/42] doc: modify README.md. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4569636..ee77c18 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Modify File Content Replace text content and submit content -Here is the example: update time 2022-11-29 02:15:52 +Here is the example: update time 2022-11-29 02:31:14 Here is the different delimiter example: different `GAMFC_TABEL` & `GAMFC_TABEL-END` (test) @@ -39,10 +39,10 @@ Here is the different delimiter example: different `GAMFC_TABE `README.md` file content ```markdown -update time 2022-11-29 02:15:52 +update time 2022-11-29 02:31:14 ``` -Replace the content between `2022-11-29 02:15:52`. +Replace the content between `2022-11-29 02:31:14`. ### format date From 06691b8164c1f43cb63ff795a2f4efa647b95075 Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Tue, 29 Nov 2022 13:42:44 +0800 Subject: [PATCH 12/42] fix: fix branch sha issue. --- dist/index.js | 2 +- src/utils.ts | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/dist/index.js b/dist/index.js index 8150b8f..f53a0d3 100644 --- a/dist/index.js +++ b/dist/index.js @@ -14268,7 +14268,7 @@ var github = __webpack_require__(1374); ;// CONCATENATED MODULE: ./src/utils.ts var myToken=(0,core.getInput)('token');var octokit=(0,github.getOctokit)(myToken);var getInputs=function getInputs(){var body=(0,core.getInput)('body')||'';var ref=(0,core.getInput)('ref')||github.context.ref;var branch=(0,core.getInput)('branch');var sha=(0,core.getInput)('sha');var overwrite=(0,core.getInput)('overwrite')||'false';var sync_local_file=(0,core.getInput)('sync_local_file')||'true';var filepath=(0,core.getInput)('path')||'';var message=(0,core.getInput)('message')||'';var committer_name=(0,core.getInput)('committer_name')||'';var committer_email=(0,core.getInput)('committer_email')||'';var openDelimiter=(0,core.getInput)('openDelimiter')||'';var closeDelimiter=(0,core.getInput)('closeDelimiter')||'';return (0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({},github.context.repo),{},{body:body,filepath:filepath,ref:ref,branch:branch,sha:sha,message:message,committer_name:committer_name,committer_email:committer_email,openDelimiter:openDelimiter,closeDelimiter:closeDelimiter,overwrite:overwrite,sync_local_file:sync_local_file});};function getReposPathContents(_x){return _getReposPathContents.apply(this,arguments);}function _getReposPathContents(){_getReposPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee(filePath){var _getInputs,owner,repo,ref,result;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:_getInputs=getInputs(),owner=_getInputs.owner,repo=_getInputs.repo,ref=_getInputs.ref;_context.next=3;return octokit.rest.repos.getContent({owner:owner,repo:repo,path:filePath,/** * The name of the commit/branch/tag. Default: the repository’s default branch (usually `master`) - */ref:ref});case 3:result=_context.sent;return _context.abrupt("return",result);case 5:case"end":return _context.stop();}}},_callee);}));return _getReposPathContents.apply(this,arguments);}function modifyPathContents(){return _modifyPathContents.apply(this,arguments);}function _modifyPathContents(){_modifyPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee2(){var options,content,other,_getInputs2,owner,repo,openDelimiter,closeDelimiter,message,committer_name,committer_email,overwrite,sync_local_file,ref,sha,branch,fullPath,isExists,body,fileResult,fileContent,oldFileContent,REG,reuslt,match,new_content,_args2=arguments;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:options=_args2.length>0&&_args2[0]!==undefined?_args2[0]:{};content=_args2.length>1?_args2[1]:undefined;other=Object.assign({},(_objectDestructuringEmpty(options),options));_getInputs2=getInputs(),owner=_getInputs2.owner,repo=_getInputs2.repo,openDelimiter=_getInputs2.openDelimiter,closeDelimiter=_getInputs2.closeDelimiter,message=_getInputs2.message,committer_name=_getInputs2.committer_name,committer_email=_getInputs2.committer_email,overwrite=_getInputs2.overwrite,sync_local_file=_getInputs2.sync_local_file,ref=_getInputs2.ref,sha=_getInputs2.sha,branch=_getInputs2.branch;if(options.path){_context2.next=6;break;}throw new Error("modifyPathContents: file directory parameter does not exist");case 6:fullPath=external_path_default().resolve(options.path);isExists=lib_default().existsSync(fullPath);(0,core.info)("\uD83D\uDC49 Modify Path (".concat(options.path,")"));body=(0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({owner:owner,repo:repo,path:options.path,message:message||"doc: ".concat(isExists?'modify':'create'," ").concat(options.path,"."),committer:{name:committer_name||'github-actions[bot]',email:committer_email||'github-actions[bot]@users.noreply.github.com'}},other),{},{content:Buffer.from(content).toString("base64")});if(branch){body.branch=branch;}else if(sha){body.sha=sha;}if(!isExists){_context2.next=40;break;}_context2.next=14;return getReposPathContents(options.path);case 14:fileResult=_context2.sent;if(!(fileResult.status===200&&fileResult.data.sha)){_context2.next=40;break;}if(!branch){body.sha=fileResult.data.sha||sha;}fileContent=fileResult.data.content||'';oldFileContent=Buffer.from(fileContent,'base64').toString();REG=new RegExp("".concat(openDelimiter,"([\\s\\S]*?)").concat(closeDelimiter),'ig');reuslt=oldFileContent.replace(REG,"".concat(openDelimiter).concat(content).concat(closeDelimiter));match=oldFileContent.match(REG);(0,core.startGroup)("\uD83D\uDC49 Text old content: ".concat(match===null||match===void 0?void 0:match.length," ").concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(oldFileContent));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(match,null,2)));(0,core.endGroup)();(0,core.startGroup)("\uD83D\uDC49 Text new content: ".concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(fileResult.data,null,2)));(0,core.info)("\uD83D\uDC49 ".concat(reuslt));(0,core.endGroup)();(0,core.setOutput)('content',reuslt);if(!(oldFileContent==reuslt)){_context2.next=34;break;}(0,core.warning)("\uD83D\uDC49 Content has not changed!!!!!");return _context2.abrupt("return");case 34:new_content=Buffer.from(content).toString("base64");if(overwrite.toString()==='true'){body.content=new_content;}else{body.content=Buffer.from(reuslt).toString("base64");new_content=reuslt;}(0,core.setOutput)('context.ref',github.context.ref);if(!(sync_local_file.toString()==='true'&&ref===github.context.ref)){_context2.next=40;break;}_context2.next=40;return lib_default().writeFile(fullPath,new_content);case 40:(0,core.startGroup)("modifyPathContents Body:");(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(body,null,2)));(0,core.endGroup)();return _context2.abrupt("return",octokit.request('PUT /repos/{owner}/{repo}/contents/{path}',(0,objectSpread2/* default */.Z)({},body)));case 44:case"end":return _context2.stop();}}},_callee2);}));return _modifyPathContents.apply(this,arguments);} + */ref:ref});case 3:result=_context.sent;return _context.abrupt("return",result);case 5:case"end":return _context.stop();}}},_callee);}));return _getReposPathContents.apply(this,arguments);}function modifyPathContents(){return _modifyPathContents.apply(this,arguments);}function _modifyPathContents(){_modifyPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee2(){var options,content,other,_getInputs2,owner,repo,openDelimiter,closeDelimiter,message,committer_name,committer_email,overwrite,sync_local_file,ref,sha,branch,fullPath,isExists,body,bh,fileResult,fileContent,oldFileContent,REG,reuslt,match,new_content,_args2=arguments;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:options=_args2.length>0&&_args2[0]!==undefined?_args2[0]:{};content=_args2.length>1?_args2[1]:undefined;other=Object.assign({},(_objectDestructuringEmpty(options),options));_getInputs2=getInputs(),owner=_getInputs2.owner,repo=_getInputs2.repo,openDelimiter=_getInputs2.openDelimiter,closeDelimiter=_getInputs2.closeDelimiter,message=_getInputs2.message,committer_name=_getInputs2.committer_name,committer_email=_getInputs2.committer_email,overwrite=_getInputs2.overwrite,sync_local_file=_getInputs2.sync_local_file,ref=_getInputs2.ref,sha=_getInputs2.sha,branch=_getInputs2.branch;if(options.path){_context2.next=6;break;}throw new Error("modifyPathContents: file directory parameter does not exist");case 6:fullPath=external_path_default().resolve(options.path);isExists=lib_default().existsSync(fullPath);(0,core.info)("\uD83D\uDC49 Modify Path (".concat(options.path,")"));body=(0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({owner:owner,repo:repo,path:options.path,message:message||"doc: ".concat(isExists?'modify':'create'," ").concat(options.path,"."),committer:{name:committer_name||'github-actions[bot]',email:committer_email||'github-actions[bot]@users.noreply.github.com'}},other),{},{content:Buffer.from(content).toString("base64")});if(!branch){_context2.next=18;break;}body.branch=branch;_context2.next=14;return octokit.rest.repos.getBranch({owner:owner,repo:repo,branch:branch});case 14:bh=_context2.sent;body.sha=bh.data.commit.sha;_context2.next=19;break;case 18:if(sha){body.sha=sha;}case 19:if(!isExists){_context2.next=48;break;}_context2.next=22;return getReposPathContents(options.path);case 22:fileResult=_context2.sent;if(!(fileResult.status===200&&fileResult.data.sha)){_context2.next=48;break;}if(!branch){body.sha=fileResult.data.sha||sha;}fileContent=fileResult.data.content||'';oldFileContent=Buffer.from(fileContent,'base64').toString();REG=new RegExp("".concat(openDelimiter,"([\\s\\S]*?)").concat(closeDelimiter),'ig');reuslt=oldFileContent.replace(REG,"".concat(openDelimiter).concat(content).concat(closeDelimiter));match=oldFileContent.match(REG);(0,core.startGroup)("\uD83D\uDC49 Text old content: ".concat(match===null||match===void 0?void 0:match.length," ").concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(oldFileContent));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(match,null,2)));(0,core.endGroup)();(0,core.startGroup)("\uD83D\uDC49 Text new content: ".concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(fileResult.data,null,2)));(0,core.info)("\uD83D\uDC49 ".concat(reuslt));(0,core.endGroup)();(0,core.setOutput)('content',reuslt);if(!(oldFileContent==reuslt)){_context2.next=42;break;}(0,core.warning)("\uD83D\uDC49 Content has not changed!!!!!");return _context2.abrupt("return");case 42:new_content=Buffer.from(content).toString("base64");if(overwrite.toString()==='true'){body.content=new_content;}else{body.content=Buffer.from(reuslt).toString("base64");new_content=reuslt;}(0,core.setOutput)('context.ref',github.context.ref);if(!(sync_local_file.toString()==='true'&&ref===github.context.ref)){_context2.next=48;break;}_context2.next=48;return lib_default().writeFile(fullPath,new_content);case 48:(0,core.startGroup)("modifyPathContents Body:");(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(body,null,2)));(0,core.endGroup)();return _context2.abrupt("return",octokit.request('PUT /repos/{owner}/{repo}/contents/{path}',(0,objectSpread2/* default */.Z)({},body)));case 52:case"end":return _context2.stop();}}},_callee2);}));return _modifyPathContents.apply(this,arguments);} ;// CONCATENATED MODULE: ./node_modules/@uiw/formatter/esm/index.js /**! * @uiw/formatter v1.3.3 diff --git a/src/utils.ts b/src/utils.ts index 0418965..06ab39e 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -72,6 +72,8 @@ export async function modifyPathContents(options: Partial = {}, co } if (branch) { body.branch = branch; + const bh = await octokit.rest.repos.getBranch({ owner, repo, branch }) + body.sha = bh.data.commit.sha; } else if (sha) { body.sha = sha; } From eb2917237bfdd3248d6a82e36f8d997c39224b69 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 29 Nov 2022 05:44:24 +0000 Subject: [PATCH 13/42] doc: modify README.md. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ee77c18..742dc2a 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Modify File Content Replace text content and submit content -Here is the example: update time 2022-11-29 02:31:14 +Here is the example: update time 2022-11-29 05:44:24 Here is the different delimiter example: different `GAMFC_TABEL` & `GAMFC_TABEL-END` (test) @@ -39,10 +39,10 @@ Here is the different delimiter example: different `GAMFC_TABE `README.md` file content ```markdown -update time 2022-11-29 02:31:14 +update time 2022-11-29 05:44:24 ``` -Replace the content between `2022-11-29 02:31:14`. +Replace the content between `2022-11-29 05:44:24`. ### format date From d4719ec2e081f05aa330ffed14e4cb9cfe57cc5c Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Tue, 29 Nov 2022 13:47:42 +0800 Subject: [PATCH 14/42] chore: update workflows config. --- .github/workflows/ci.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 438ee1e..39fd184 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -69,13 +69,6 @@ jobs: TEST: 2022-11-29 01:44:16 EOF - - name: Deploy - uses: peaceiris/actions-gh-pages@v3 - with: - commit_message: ${{steps.tag_version.outputs.tag}} ${{ github.event.head_commit.message }} - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./build - - name: Modify README.md # uses: github-action-modify-file-content@main uses: ./ @@ -84,6 +77,13 @@ jobs: branch: gh-pages body: "{{date:YYYY-MM-DD HH:mm:ss}}" + - name: Deploy + uses: peaceiris/actions-gh-pages@v3 + with: + commit_message: ${{steps.tag_version.outputs.tag}} ${{ github.event.head_commit.message }} + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./build + - name: Generate Changelog id: changelog uses: jaywcjlove/changelog-generator@main From 5a77cace0d7581d9435602c6ab08c6bb7553486f Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 29 Nov 2022 05:49:16 +0000 Subject: [PATCH 15/42] doc: modify README.md. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 742dc2a..469c13e 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Modify File Content Replace text content and submit content -Here is the example: update time 2022-11-29 05:44:24 +Here is the example: update time 2022-11-29 05:49:16 Here is the different delimiter example: different `GAMFC_TABEL` & `GAMFC_TABEL-END` (test) @@ -39,10 +39,10 @@ Here is the different delimiter example: different `GAMFC_TABE `README.md` file content ```markdown -update time 2022-11-29 05:44:24 +update time 2022-11-29 05:49:16 ``` -Replace the content between `2022-11-29 05:44:24`. +Replace the content between `2022-11-29 05:49:16`. ### format date From 5c1ab369dd2346c0b1100f240bebc1872bb3ede8 Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Tue, 29 Nov 2022 13:52:43 +0800 Subject: [PATCH 16/42] chore: add branch log. --- dist/index.js | 2 +- src/utils.ts | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/dist/index.js b/dist/index.js index f53a0d3..25e8a4f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -14268,7 +14268,7 @@ var github = __webpack_require__(1374); ;// CONCATENATED MODULE: ./src/utils.ts var myToken=(0,core.getInput)('token');var octokit=(0,github.getOctokit)(myToken);var getInputs=function getInputs(){var body=(0,core.getInput)('body')||'';var ref=(0,core.getInput)('ref')||github.context.ref;var branch=(0,core.getInput)('branch');var sha=(0,core.getInput)('sha');var overwrite=(0,core.getInput)('overwrite')||'false';var sync_local_file=(0,core.getInput)('sync_local_file')||'true';var filepath=(0,core.getInput)('path')||'';var message=(0,core.getInput)('message')||'';var committer_name=(0,core.getInput)('committer_name')||'';var committer_email=(0,core.getInput)('committer_email')||'';var openDelimiter=(0,core.getInput)('openDelimiter')||'';var closeDelimiter=(0,core.getInput)('closeDelimiter')||'';return (0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({},github.context.repo),{},{body:body,filepath:filepath,ref:ref,branch:branch,sha:sha,message:message,committer_name:committer_name,committer_email:committer_email,openDelimiter:openDelimiter,closeDelimiter:closeDelimiter,overwrite:overwrite,sync_local_file:sync_local_file});};function getReposPathContents(_x){return _getReposPathContents.apply(this,arguments);}function _getReposPathContents(){_getReposPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee(filePath){var _getInputs,owner,repo,ref,result;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:_getInputs=getInputs(),owner=_getInputs.owner,repo=_getInputs.repo,ref=_getInputs.ref;_context.next=3;return octokit.rest.repos.getContent({owner:owner,repo:repo,path:filePath,/** * The name of the commit/branch/tag. Default: the repository’s default branch (usually `master`) - */ref:ref});case 3:result=_context.sent;return _context.abrupt("return",result);case 5:case"end":return _context.stop();}}},_callee);}));return _getReposPathContents.apply(this,arguments);}function modifyPathContents(){return _modifyPathContents.apply(this,arguments);}function _modifyPathContents(){_modifyPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee2(){var options,content,other,_getInputs2,owner,repo,openDelimiter,closeDelimiter,message,committer_name,committer_email,overwrite,sync_local_file,ref,sha,branch,fullPath,isExists,body,bh,fileResult,fileContent,oldFileContent,REG,reuslt,match,new_content,_args2=arguments;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:options=_args2.length>0&&_args2[0]!==undefined?_args2[0]:{};content=_args2.length>1?_args2[1]:undefined;other=Object.assign({},(_objectDestructuringEmpty(options),options));_getInputs2=getInputs(),owner=_getInputs2.owner,repo=_getInputs2.repo,openDelimiter=_getInputs2.openDelimiter,closeDelimiter=_getInputs2.closeDelimiter,message=_getInputs2.message,committer_name=_getInputs2.committer_name,committer_email=_getInputs2.committer_email,overwrite=_getInputs2.overwrite,sync_local_file=_getInputs2.sync_local_file,ref=_getInputs2.ref,sha=_getInputs2.sha,branch=_getInputs2.branch;if(options.path){_context2.next=6;break;}throw new Error("modifyPathContents: file directory parameter does not exist");case 6:fullPath=external_path_default().resolve(options.path);isExists=lib_default().existsSync(fullPath);(0,core.info)("\uD83D\uDC49 Modify Path (".concat(options.path,")"));body=(0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({owner:owner,repo:repo,path:options.path,message:message||"doc: ".concat(isExists?'modify':'create'," ").concat(options.path,"."),committer:{name:committer_name||'github-actions[bot]',email:committer_email||'github-actions[bot]@users.noreply.github.com'}},other),{},{content:Buffer.from(content).toString("base64")});if(!branch){_context2.next=18;break;}body.branch=branch;_context2.next=14;return octokit.rest.repos.getBranch({owner:owner,repo:repo,branch:branch});case 14:bh=_context2.sent;body.sha=bh.data.commit.sha;_context2.next=19;break;case 18:if(sha){body.sha=sha;}case 19:if(!isExists){_context2.next=48;break;}_context2.next=22;return getReposPathContents(options.path);case 22:fileResult=_context2.sent;if(!(fileResult.status===200&&fileResult.data.sha)){_context2.next=48;break;}if(!branch){body.sha=fileResult.data.sha||sha;}fileContent=fileResult.data.content||'';oldFileContent=Buffer.from(fileContent,'base64').toString();REG=new RegExp("".concat(openDelimiter,"([\\s\\S]*?)").concat(closeDelimiter),'ig');reuslt=oldFileContent.replace(REG,"".concat(openDelimiter).concat(content).concat(closeDelimiter));match=oldFileContent.match(REG);(0,core.startGroup)("\uD83D\uDC49 Text old content: ".concat(match===null||match===void 0?void 0:match.length," ").concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(oldFileContent));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(match,null,2)));(0,core.endGroup)();(0,core.startGroup)("\uD83D\uDC49 Text new content: ".concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(fileResult.data,null,2)));(0,core.info)("\uD83D\uDC49 ".concat(reuslt));(0,core.endGroup)();(0,core.setOutput)('content',reuslt);if(!(oldFileContent==reuslt)){_context2.next=42;break;}(0,core.warning)("\uD83D\uDC49 Content has not changed!!!!!");return _context2.abrupt("return");case 42:new_content=Buffer.from(content).toString("base64");if(overwrite.toString()==='true'){body.content=new_content;}else{body.content=Buffer.from(reuslt).toString("base64");new_content=reuslt;}(0,core.setOutput)('context.ref',github.context.ref);if(!(sync_local_file.toString()==='true'&&ref===github.context.ref)){_context2.next=48;break;}_context2.next=48;return lib_default().writeFile(fullPath,new_content);case 48:(0,core.startGroup)("modifyPathContents Body:");(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(body,null,2)));(0,core.endGroup)();return _context2.abrupt("return",octokit.request('PUT /repos/{owner}/{repo}/contents/{path}',(0,objectSpread2/* default */.Z)({},body)));case 52:case"end":return _context2.stop();}}},_callee2);}));return _modifyPathContents.apply(this,arguments);} + */ref:ref});case 3:result=_context.sent;return _context.abrupt("return",result);case 5:case"end":return _context.stop();}}},_callee);}));return _getReposPathContents.apply(this,arguments);}function modifyPathContents(){return _modifyPathContents.apply(this,arguments);}function _modifyPathContents(){_modifyPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee2(){var options,content,other,_getInputs2,owner,repo,openDelimiter,closeDelimiter,message,committer_name,committer_email,overwrite,sync_local_file,ref,sha,branch,fullPath,isExists,body,_bh$data$commit$autho,bh,fileResult,fileContent,oldFileContent,REG,reuslt,match,new_content,_args2=arguments;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:options=_args2.length>0&&_args2[0]!==undefined?_args2[0]:{};content=_args2.length>1?_args2[1]:undefined;other=Object.assign({},(_objectDestructuringEmpty(options),options));_getInputs2=getInputs(),owner=_getInputs2.owner,repo=_getInputs2.repo,openDelimiter=_getInputs2.openDelimiter,closeDelimiter=_getInputs2.closeDelimiter,message=_getInputs2.message,committer_name=_getInputs2.committer_name,committer_email=_getInputs2.committer_email,overwrite=_getInputs2.overwrite,sync_local_file=_getInputs2.sync_local_file,ref=_getInputs2.ref,sha=_getInputs2.sha,branch=_getInputs2.branch;if(options.path){_context2.next=6;break;}throw new Error("modifyPathContents: file directory parameter does not exist");case 6:fullPath=external_path_default().resolve(options.path);isExists=lib_default().existsSync(fullPath);(0,core.info)("\uD83D\uDC49 Modify Path (".concat(options.path,")"));body=(0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({owner:owner,repo:repo,path:options.path,message:message||"doc: ".concat(isExists?'modify':'create'," ").concat(options.path,"."),committer:{name:committer_name||'github-actions[bot]',email:committer_email||'github-actions[bot]@users.noreply.github.com'}},other),{},{content:Buffer.from(content).toString("base64")});if(!branch){_context2.next=21;break;}body.branch=branch;_context2.next=14;return octokit.rest.repos.getBranch({owner:owner,repo:repo,branch:branch});case 14:bh=_context2.sent;body.sha=bh.data.commit.sha;(0,core.startGroup)("\uD83D\uDC49 Branch content: ".concat(bh.data.commit.commit," ").concat((_bh$data$commit$autho=bh.data.commit.author)===null||_bh$data$commit$autho===void 0?void 0:_bh$data$commit$autho.name));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(bh,null,2)));(0,core.endGroup)();_context2.next=22;break;case 21:if(sha){body.sha=sha;}case 22:if(!isExists){_context2.next=51;break;}_context2.next=25;return getReposPathContents(options.path);case 25:fileResult=_context2.sent;if(!(fileResult.status===200&&fileResult.data.sha)){_context2.next=51;break;}if(!branch){body.sha=fileResult.data.sha||sha;}fileContent=fileResult.data.content||'';oldFileContent=Buffer.from(fileContent,'base64').toString();REG=new RegExp("".concat(openDelimiter,"([\\s\\S]*?)").concat(closeDelimiter),'ig');reuslt=oldFileContent.replace(REG,"".concat(openDelimiter).concat(content).concat(closeDelimiter));match=oldFileContent.match(REG);(0,core.startGroup)("\uD83D\uDC49 Text old content: ".concat(match===null||match===void 0?void 0:match.length," ").concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(oldFileContent));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(match,null,2)));(0,core.endGroup)();(0,core.startGroup)("\uD83D\uDC49 Text new content: ".concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(fileResult.data,null,2)));(0,core.info)("\uD83D\uDC49 ".concat(reuslt));(0,core.endGroup)();(0,core.setOutput)('content',reuslt);if(!(oldFileContent==reuslt)){_context2.next=45;break;}(0,core.warning)("\uD83D\uDC49 Content has not changed!!!!!");return _context2.abrupt("return");case 45:new_content=Buffer.from(content).toString("base64");if(overwrite.toString()==='true'){body.content=new_content;}else{body.content=Buffer.from(reuslt).toString("base64");new_content=reuslt;}(0,core.setOutput)('context.ref',github.context.ref);if(!(sync_local_file.toString()==='true'&&ref===github.context.ref)){_context2.next=51;break;}_context2.next=51;return lib_default().writeFile(fullPath,new_content);case 51:(0,core.startGroup)("modifyPathContents Body:");(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(body,null,2)));(0,core.endGroup)();return _context2.abrupt("return",octokit.request('PUT /repos/{owner}/{repo}/contents/{path}',(0,objectSpread2/* default */.Z)({},body)));case 55:case"end":return _context2.stop();}}},_callee2);}));return _modifyPathContents.apply(this,arguments);} ;// CONCATENATED MODULE: ./node_modules/@uiw/formatter/esm/index.js /**! * @uiw/formatter v1.3.3 diff --git a/src/utils.ts b/src/utils.ts index 06ab39e..901b3f3 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -74,6 +74,9 @@ export async function modifyPathContents(options: Partial = {}, co body.branch = branch; const bh = await octokit.rest.repos.getBranch({ owner, repo, branch }) body.sha = bh.data.commit.sha; + startGroup(`👉 Branch content: ${bh.data.commit.commit} ${bh.data.commit.author?.name}`); + info(`👉 ${JSON.stringify(bh, null, 2)}`); + endGroup(); } else if (sha) { body.sha = sha; } From c0cadb92faa573f336c8d3fad7cd2f47a56446be Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 29 Nov 2022 05:54:21 +0000 Subject: [PATCH 17/42] doc: modify README.md. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 469c13e..4f652a1 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Modify File Content Replace text content and submit content -Here is the example: update time 2022-11-29 05:49:16 +Here is the example: update time 2022-11-29 05:54:20 Here is the different delimiter example: different `GAMFC_TABEL` & `GAMFC_TABEL-END` (test) @@ -39,10 +39,10 @@ Here is the different delimiter example: different `GAMFC_TABE `README.md` file content ```markdown -update time 2022-11-29 05:49:16 +update time 2022-11-29 05:54:20 ``` -Replace the content between `2022-11-29 05:49:16`. +Replace the content between `2022-11-29 05:54:20`. ### format date From efccfd4af271653a877f1e834c40b6d70f6dbed0 Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Tue, 29 Nov 2022 14:07:37 +0800 Subject: [PATCH 18/42] chore: add log. --- dist/index.js | 2 +- src/utils.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index 25e8a4f..77e154a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -14268,7 +14268,7 @@ var github = __webpack_require__(1374); ;// CONCATENATED MODULE: ./src/utils.ts var myToken=(0,core.getInput)('token');var octokit=(0,github.getOctokit)(myToken);var getInputs=function getInputs(){var body=(0,core.getInput)('body')||'';var ref=(0,core.getInput)('ref')||github.context.ref;var branch=(0,core.getInput)('branch');var sha=(0,core.getInput)('sha');var overwrite=(0,core.getInput)('overwrite')||'false';var sync_local_file=(0,core.getInput)('sync_local_file')||'true';var filepath=(0,core.getInput)('path')||'';var message=(0,core.getInput)('message')||'';var committer_name=(0,core.getInput)('committer_name')||'';var committer_email=(0,core.getInput)('committer_email')||'';var openDelimiter=(0,core.getInput)('openDelimiter')||'';var closeDelimiter=(0,core.getInput)('closeDelimiter')||'';return (0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({},github.context.repo),{},{body:body,filepath:filepath,ref:ref,branch:branch,sha:sha,message:message,committer_name:committer_name,committer_email:committer_email,openDelimiter:openDelimiter,closeDelimiter:closeDelimiter,overwrite:overwrite,sync_local_file:sync_local_file});};function getReposPathContents(_x){return _getReposPathContents.apply(this,arguments);}function _getReposPathContents(){_getReposPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee(filePath){var _getInputs,owner,repo,ref,result;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:_getInputs=getInputs(),owner=_getInputs.owner,repo=_getInputs.repo,ref=_getInputs.ref;_context.next=3;return octokit.rest.repos.getContent({owner:owner,repo:repo,path:filePath,/** * The name of the commit/branch/tag. Default: the repository’s default branch (usually `master`) - */ref:ref});case 3:result=_context.sent;return _context.abrupt("return",result);case 5:case"end":return _context.stop();}}},_callee);}));return _getReposPathContents.apply(this,arguments);}function modifyPathContents(){return _modifyPathContents.apply(this,arguments);}function _modifyPathContents(){_modifyPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee2(){var options,content,other,_getInputs2,owner,repo,openDelimiter,closeDelimiter,message,committer_name,committer_email,overwrite,sync_local_file,ref,sha,branch,fullPath,isExists,body,_bh$data$commit$autho,bh,fileResult,fileContent,oldFileContent,REG,reuslt,match,new_content,_args2=arguments;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:options=_args2.length>0&&_args2[0]!==undefined?_args2[0]:{};content=_args2.length>1?_args2[1]:undefined;other=Object.assign({},(_objectDestructuringEmpty(options),options));_getInputs2=getInputs(),owner=_getInputs2.owner,repo=_getInputs2.repo,openDelimiter=_getInputs2.openDelimiter,closeDelimiter=_getInputs2.closeDelimiter,message=_getInputs2.message,committer_name=_getInputs2.committer_name,committer_email=_getInputs2.committer_email,overwrite=_getInputs2.overwrite,sync_local_file=_getInputs2.sync_local_file,ref=_getInputs2.ref,sha=_getInputs2.sha,branch=_getInputs2.branch;if(options.path){_context2.next=6;break;}throw new Error("modifyPathContents: file directory parameter does not exist");case 6:fullPath=external_path_default().resolve(options.path);isExists=lib_default().existsSync(fullPath);(0,core.info)("\uD83D\uDC49 Modify Path (".concat(options.path,")"));body=(0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({owner:owner,repo:repo,path:options.path,message:message||"doc: ".concat(isExists?'modify':'create'," ").concat(options.path,"."),committer:{name:committer_name||'github-actions[bot]',email:committer_email||'github-actions[bot]@users.noreply.github.com'}},other),{},{content:Buffer.from(content).toString("base64")});if(!branch){_context2.next=21;break;}body.branch=branch;_context2.next=14;return octokit.rest.repos.getBranch({owner:owner,repo:repo,branch:branch});case 14:bh=_context2.sent;body.sha=bh.data.commit.sha;(0,core.startGroup)("\uD83D\uDC49 Branch content: ".concat(bh.data.commit.commit," ").concat((_bh$data$commit$autho=bh.data.commit.author)===null||_bh$data$commit$autho===void 0?void 0:_bh$data$commit$autho.name));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(bh,null,2)));(0,core.endGroup)();_context2.next=22;break;case 21:if(sha){body.sha=sha;}case 22:if(!isExists){_context2.next=51;break;}_context2.next=25;return getReposPathContents(options.path);case 25:fileResult=_context2.sent;if(!(fileResult.status===200&&fileResult.data.sha)){_context2.next=51;break;}if(!branch){body.sha=fileResult.data.sha||sha;}fileContent=fileResult.data.content||'';oldFileContent=Buffer.from(fileContent,'base64').toString();REG=new RegExp("".concat(openDelimiter,"([\\s\\S]*?)").concat(closeDelimiter),'ig');reuslt=oldFileContent.replace(REG,"".concat(openDelimiter).concat(content).concat(closeDelimiter));match=oldFileContent.match(REG);(0,core.startGroup)("\uD83D\uDC49 Text old content: ".concat(match===null||match===void 0?void 0:match.length," ").concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(oldFileContent));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(match,null,2)));(0,core.endGroup)();(0,core.startGroup)("\uD83D\uDC49 Text new content: ".concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(fileResult.data,null,2)));(0,core.info)("\uD83D\uDC49 ".concat(reuslt));(0,core.endGroup)();(0,core.setOutput)('content',reuslt);if(!(oldFileContent==reuslt)){_context2.next=45;break;}(0,core.warning)("\uD83D\uDC49 Content has not changed!!!!!");return _context2.abrupt("return");case 45:new_content=Buffer.from(content).toString("base64");if(overwrite.toString()==='true'){body.content=new_content;}else{body.content=Buffer.from(reuslt).toString("base64");new_content=reuslt;}(0,core.setOutput)('context.ref',github.context.ref);if(!(sync_local_file.toString()==='true'&&ref===github.context.ref)){_context2.next=51;break;}_context2.next=51;return lib_default().writeFile(fullPath,new_content);case 51:(0,core.startGroup)("modifyPathContents Body:");(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(body,null,2)));(0,core.endGroup)();return _context2.abrupt("return",octokit.request('PUT /repos/{owner}/{repo}/contents/{path}',(0,objectSpread2/* default */.Z)({},body)));case 55:case"end":return _context2.stop();}}},_callee2);}));return _modifyPathContents.apply(this,arguments);} + */ref:ref});case 3:result=_context.sent;return _context.abrupt("return",result);case 5:case"end":return _context.stop();}}},_callee);}));return _getReposPathContents.apply(this,arguments);}function modifyPathContents(){return _modifyPathContents.apply(this,arguments);}function _modifyPathContents(){_modifyPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee2(){var options,content,other,_getInputs2,owner,repo,openDelimiter,closeDelimiter,message,committer_name,committer_email,overwrite,sync_local_file,ref,sha,branch,fullPath,isExists,body,bh,fileResult,fileContent,oldFileContent,REG,reuslt,match,new_content,_args2=arguments;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:options=_args2.length>0&&_args2[0]!==undefined?_args2[0]:{};content=_args2.length>1?_args2[1]:undefined;other=Object.assign({},(_objectDestructuringEmpty(options),options));_getInputs2=getInputs(),owner=_getInputs2.owner,repo=_getInputs2.repo,openDelimiter=_getInputs2.openDelimiter,closeDelimiter=_getInputs2.closeDelimiter,message=_getInputs2.message,committer_name=_getInputs2.committer_name,committer_email=_getInputs2.committer_email,overwrite=_getInputs2.overwrite,sync_local_file=_getInputs2.sync_local_file,ref=_getInputs2.ref,sha=_getInputs2.sha,branch=_getInputs2.branch;if(options.path){_context2.next=6;break;}throw new Error("modifyPathContents: file directory parameter does not exist");case 6:fullPath=external_path_default().resolve(options.path);isExists=lib_default().existsSync(fullPath);(0,core.info)("\uD83D\uDC49 Modify Path (".concat(options.path,")"));(0,core.info)("\uD83D\uDC49 Context.ref: (".concat(github.context.ref,")"));body=(0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({owner:owner,repo:repo,path:options.path,message:message||"doc: ".concat(isExists?'modify':'create'," ").concat(options.path,"."),committer:{name:committer_name||'github-actions[bot]',email:committer_email||'github-actions[bot]@users.noreply.github.com'}},other),{},{content:Buffer.from(content).toString("base64")});if(!branch){_context2.next=22;break;}body.branch=branch;_context2.next=15;return octokit.rest.repos.getBranch({owner:owner,repo:repo,branch:branch});case 15:bh=_context2.sent;body.sha=sha||bh.data.commit.sha;(0,core.startGroup)("\uD83D\uDC49 Branch content: ".concat(bh.data.commit.commit.message," ").concat(bh.data.commit.commit.author));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(bh,null,2)));(0,core.endGroup)();_context2.next=23;break;case 22:if(sha){body.sha=sha;}case 23:if(!isExists){_context2.next=51;break;}_context2.next=26;return getReposPathContents(options.path);case 26:fileResult=_context2.sent;if(!(fileResult.status===200&&fileResult.data.sha)){_context2.next=51;break;}if(!branch){body.sha=fileResult.data.sha||sha;}fileContent=fileResult.data.content||'';oldFileContent=Buffer.from(fileContent,'base64').toString();REG=new RegExp("".concat(openDelimiter,"([\\s\\S]*?)").concat(closeDelimiter),'ig');reuslt=oldFileContent.replace(REG,"".concat(openDelimiter).concat(content).concat(closeDelimiter));match=oldFileContent.match(REG);(0,core.startGroup)("\uD83D\uDC49 Text old content: ".concat(match===null||match===void 0?void 0:match.length," ").concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(oldFileContent));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(match,null,2)));(0,core.endGroup)();(0,core.startGroup)("\uD83D\uDC49 Text new content: ".concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(fileResult.data,null,2)));(0,core.info)("\uD83D\uDC49 ".concat(reuslt));(0,core.endGroup)();(0,core.setOutput)('content',reuslt);if(!(oldFileContent==reuslt)){_context2.next=46;break;}(0,core.warning)("\uD83D\uDC49 Content has not changed!!!!!");return _context2.abrupt("return");case 46:new_content=Buffer.from(content).toString("base64");if(overwrite.toString()==='true'){body.content=new_content;}else{body.content=Buffer.from(reuslt).toString("base64");new_content=reuslt;}if(!(sync_local_file.toString()==='true'&&ref===github.context.ref)){_context2.next=51;break;}_context2.next=51;return lib_default().writeFile(fullPath,new_content);case 51:(0,core.startGroup)("modifyPathContents Body:");(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(body,null,2)));(0,core.endGroup)();return _context2.abrupt("return",octokit.request('PUT /repos/{owner}/{repo}/contents/{path}',(0,objectSpread2/* default */.Z)({},body)));case 55:case"end":return _context2.stop();}}},_callee2);}));return _modifyPathContents.apply(this,arguments);} ;// CONCATENATED MODULE: ./node_modules/@uiw/formatter/esm/index.js /**! * @uiw/formatter v1.3.3 diff --git a/src/utils.ts b/src/utils.ts index 901b3f3..b831fa0 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -59,6 +59,7 @@ export async function modifyPathContents(options: Partial = {}, co const fullPath = path.resolve(options.path); const isExists = FS.existsSync(fullPath) info(`👉 Modify Path (${options.path})`) + info(`👉 Context.ref: (${context.ref})`); const body: FilePutQuery = { owner, repo, path: options.path, @@ -73,8 +74,8 @@ export async function modifyPathContents(options: Partial = {}, co if (branch) { body.branch = branch; const bh = await octokit.rest.repos.getBranch({ owner, repo, branch }) - body.sha = bh.data.commit.sha; - startGroup(`👉 Branch content: ${bh.data.commit.commit} ${bh.data.commit.author?.name}`); + body.sha = sha || bh.data.commit.sha; + startGroup(`👉 Branch content: ${bh.data.commit.commit.message} ${bh.data.commit.commit.author}`); info(`👉 ${JSON.stringify(bh, null, 2)}`); endGroup(); } else if (sha) { @@ -111,7 +112,6 @@ export async function modifyPathContents(options: Partial = {}, co body.content = Buffer.from(reuslt).toString("base64"); new_content = reuslt; } - setOutput('context.ref', context.ref); if (sync_local_file.toString() === 'true' && ref === context.ref) { await FS.writeFile(fullPath, new_content); } From 54d871c528024ede11013faf0953cc5ce70c93bd Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 29 Nov 2022 06:09:37 +0000 Subject: [PATCH 19/42] doc: modify README.md. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4f652a1..2acbfd3 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Modify File Content Replace text content and submit content -Here is the example: update time 2022-11-29 05:54:20 +Here is the example: update time 2022-11-29 06:09:37 Here is the different delimiter example: different `GAMFC_TABEL` & `GAMFC_TABEL-END` (test) @@ -39,10 +39,10 @@ Here is the different delimiter example: different `GAMFC_TABE `README.md` file content ```markdown -update time 2022-11-29 05:54:20 +update time 2022-11-29 06:09:37 ``` -Replace the content between `2022-11-29 05:54:20`. +Replace the content between `2022-11-29 06:09:37`. ### format date From f768a91c7eee62fd1761944e88b1a3b1ae174a6d Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Tue, 29 Nov 2022 14:16:48 +0800 Subject: [PATCH 20/42] chore: add log. --- .github/workflows/ci.yml | 2 +- dist/index.js | 2 +- src/utils.ts | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 39fd184..dac554d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -69,7 +69,7 @@ jobs: TEST: 2022-11-29 01:44:16 EOF - - name: Modify README.md + - name: Modify gh-pages README.md # uses: github-action-modify-file-content@main uses: ./ with: diff --git a/dist/index.js b/dist/index.js index 77e154a..52408af 100644 --- a/dist/index.js +++ b/dist/index.js @@ -14268,7 +14268,7 @@ var github = __webpack_require__(1374); ;// CONCATENATED MODULE: ./src/utils.ts var myToken=(0,core.getInput)('token');var octokit=(0,github.getOctokit)(myToken);var getInputs=function getInputs(){var body=(0,core.getInput)('body')||'';var ref=(0,core.getInput)('ref')||github.context.ref;var branch=(0,core.getInput)('branch');var sha=(0,core.getInput)('sha');var overwrite=(0,core.getInput)('overwrite')||'false';var sync_local_file=(0,core.getInput)('sync_local_file')||'true';var filepath=(0,core.getInput)('path')||'';var message=(0,core.getInput)('message')||'';var committer_name=(0,core.getInput)('committer_name')||'';var committer_email=(0,core.getInput)('committer_email')||'';var openDelimiter=(0,core.getInput)('openDelimiter')||'';var closeDelimiter=(0,core.getInput)('closeDelimiter')||'';return (0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({},github.context.repo),{},{body:body,filepath:filepath,ref:ref,branch:branch,sha:sha,message:message,committer_name:committer_name,committer_email:committer_email,openDelimiter:openDelimiter,closeDelimiter:closeDelimiter,overwrite:overwrite,sync_local_file:sync_local_file});};function getReposPathContents(_x){return _getReposPathContents.apply(this,arguments);}function _getReposPathContents(){_getReposPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee(filePath){var _getInputs,owner,repo,ref,result;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:_getInputs=getInputs(),owner=_getInputs.owner,repo=_getInputs.repo,ref=_getInputs.ref;_context.next=3;return octokit.rest.repos.getContent({owner:owner,repo:repo,path:filePath,/** * The name of the commit/branch/tag. Default: the repository’s default branch (usually `master`) - */ref:ref});case 3:result=_context.sent;return _context.abrupt("return",result);case 5:case"end":return _context.stop();}}},_callee);}));return _getReposPathContents.apply(this,arguments);}function modifyPathContents(){return _modifyPathContents.apply(this,arguments);}function _modifyPathContents(){_modifyPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee2(){var options,content,other,_getInputs2,owner,repo,openDelimiter,closeDelimiter,message,committer_name,committer_email,overwrite,sync_local_file,ref,sha,branch,fullPath,isExists,body,bh,fileResult,fileContent,oldFileContent,REG,reuslt,match,new_content,_args2=arguments;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:options=_args2.length>0&&_args2[0]!==undefined?_args2[0]:{};content=_args2.length>1?_args2[1]:undefined;other=Object.assign({},(_objectDestructuringEmpty(options),options));_getInputs2=getInputs(),owner=_getInputs2.owner,repo=_getInputs2.repo,openDelimiter=_getInputs2.openDelimiter,closeDelimiter=_getInputs2.closeDelimiter,message=_getInputs2.message,committer_name=_getInputs2.committer_name,committer_email=_getInputs2.committer_email,overwrite=_getInputs2.overwrite,sync_local_file=_getInputs2.sync_local_file,ref=_getInputs2.ref,sha=_getInputs2.sha,branch=_getInputs2.branch;if(options.path){_context2.next=6;break;}throw new Error("modifyPathContents: file directory parameter does not exist");case 6:fullPath=external_path_default().resolve(options.path);isExists=lib_default().existsSync(fullPath);(0,core.info)("\uD83D\uDC49 Modify Path (".concat(options.path,")"));(0,core.info)("\uD83D\uDC49 Context.ref: (".concat(github.context.ref,")"));body=(0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({owner:owner,repo:repo,path:options.path,message:message||"doc: ".concat(isExists?'modify':'create'," ").concat(options.path,"."),committer:{name:committer_name||'github-actions[bot]',email:committer_email||'github-actions[bot]@users.noreply.github.com'}},other),{},{content:Buffer.from(content).toString("base64")});if(!branch){_context2.next=22;break;}body.branch=branch;_context2.next=15;return octokit.rest.repos.getBranch({owner:owner,repo:repo,branch:branch});case 15:bh=_context2.sent;body.sha=sha||bh.data.commit.sha;(0,core.startGroup)("\uD83D\uDC49 Branch content: ".concat(bh.data.commit.commit.message," ").concat(bh.data.commit.commit.author));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(bh,null,2)));(0,core.endGroup)();_context2.next=23;break;case 22:if(sha){body.sha=sha;}case 23:if(!isExists){_context2.next=51;break;}_context2.next=26;return getReposPathContents(options.path);case 26:fileResult=_context2.sent;if(!(fileResult.status===200&&fileResult.data.sha)){_context2.next=51;break;}if(!branch){body.sha=fileResult.data.sha||sha;}fileContent=fileResult.data.content||'';oldFileContent=Buffer.from(fileContent,'base64').toString();REG=new RegExp("".concat(openDelimiter,"([\\s\\S]*?)").concat(closeDelimiter),'ig');reuslt=oldFileContent.replace(REG,"".concat(openDelimiter).concat(content).concat(closeDelimiter));match=oldFileContent.match(REG);(0,core.startGroup)("\uD83D\uDC49 Text old content: ".concat(match===null||match===void 0?void 0:match.length," ").concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(oldFileContent));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(match,null,2)));(0,core.endGroup)();(0,core.startGroup)("\uD83D\uDC49 Text new content: ".concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(fileResult.data,null,2)));(0,core.info)("\uD83D\uDC49 ".concat(reuslt));(0,core.endGroup)();(0,core.setOutput)('content',reuslt);if(!(oldFileContent==reuslt)){_context2.next=46;break;}(0,core.warning)("\uD83D\uDC49 Content has not changed!!!!!");return _context2.abrupt("return");case 46:new_content=Buffer.from(content).toString("base64");if(overwrite.toString()==='true'){body.content=new_content;}else{body.content=Buffer.from(reuslt).toString("base64");new_content=reuslt;}if(!(sync_local_file.toString()==='true'&&ref===github.context.ref)){_context2.next=51;break;}_context2.next=51;return lib_default().writeFile(fullPath,new_content);case 51:(0,core.startGroup)("modifyPathContents Body:");(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(body,null,2)));(0,core.endGroup)();return _context2.abrupt("return",octokit.request('PUT /repos/{owner}/{repo}/contents/{path}',(0,objectSpread2/* default */.Z)({},body)));case 55:case"end":return _context2.stop();}}},_callee2);}));return _modifyPathContents.apply(this,arguments);} + */ref:ref});case 3:result=_context.sent;return _context.abrupt("return",result);case 5:case"end":return _context.stop();}}},_callee);}));return _getReposPathContents.apply(this,arguments);}function modifyPathContents(){return _modifyPathContents.apply(this,arguments);}function _modifyPathContents(){_modifyPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee2(){var options,content,other,_getInputs2,owner,repo,openDelimiter,closeDelimiter,message,committer_name,committer_email,overwrite,sync_local_file,ref,sha,branch,fullPath,isExists,body,_bh$data$commit$commi,bh,fileResult,fileContent,oldFileContent,REG,reuslt,match,new_content,_args2=arguments;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:options=_args2.length>0&&_args2[0]!==undefined?_args2[0]:{};content=_args2.length>1?_args2[1]:undefined;other=Object.assign({},(_objectDestructuringEmpty(options),options));_getInputs2=getInputs(),owner=_getInputs2.owner,repo=_getInputs2.repo,openDelimiter=_getInputs2.openDelimiter,closeDelimiter=_getInputs2.closeDelimiter,message=_getInputs2.message,committer_name=_getInputs2.committer_name,committer_email=_getInputs2.committer_email,overwrite=_getInputs2.overwrite,sync_local_file=_getInputs2.sync_local_file,ref=_getInputs2.ref,sha=_getInputs2.sha,branch=_getInputs2.branch;if(options.path){_context2.next=6;break;}throw new Error("modifyPathContents: file directory parameter does not exist");case 6:fullPath=external_path_default().resolve(options.path);isExists=lib_default().existsSync(fullPath);(0,core.info)("\uD83D\uDC49 Modify Path (".concat(options.path,")"));(0,core.info)("\uD83D\uDC49 Context.ref: (".concat(github.context.ref,")"));(0,core.info)("\uD83D\uDC49 Context.sha: (".concat(github.context.sha,")"));body=(0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({owner:owner,repo:repo,path:options.path,message:message||"doc: ".concat(isExists?'modify':'create'," ").concat(options.path,"."),committer:{name:committer_name||'github-actions[bot]',email:committer_email||'github-actions[bot]@users.noreply.github.com'}},other),{},{content:Buffer.from(content).toString("base64")});if(!branch){_context2.next=23;break;}body.branch=branch;_context2.next=16;return octokit.rest.repos.getBranch({owner:owner,repo:repo,branch:branch});case 16:bh=_context2.sent;body.sha=sha||bh.data.commit.sha;(0,core.startGroup)("\uD83D\uDC49 Branch content: ".concat(bh.data.commit.commit.message," ").concat((_bh$data$commit$commi=bh.data.commit.commit.author)===null||_bh$data$commit$commi===void 0?void 0:_bh$data$commit$commi.name));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(bh,null,2)));(0,core.endGroup)();_context2.next=24;break;case 23:if(sha){body.sha=sha;}case 24:if(!isExists){_context2.next=52;break;}_context2.next=27;return getReposPathContents(options.path);case 27:fileResult=_context2.sent;if(!(fileResult.status===200&&fileResult.data.sha)){_context2.next=52;break;}if(!branch){body.sha=fileResult.data.sha||sha;}fileContent=fileResult.data.content||'';oldFileContent=Buffer.from(fileContent,'base64').toString();REG=new RegExp("".concat(openDelimiter,"([\\s\\S]*?)").concat(closeDelimiter),'ig');reuslt=oldFileContent.replace(REG,"".concat(openDelimiter).concat(content).concat(closeDelimiter));match=oldFileContent.match(REG);(0,core.startGroup)("\uD83D\uDC49 Text old content: ".concat(match===null||match===void 0?void 0:match.length," ").concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(oldFileContent));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(match,null,2)));(0,core.endGroup)();(0,core.startGroup)("\uD83D\uDC49 Text new content: ".concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(fileResult.data,null,2)));(0,core.info)("\uD83D\uDC49 ".concat(reuslt));(0,core.endGroup)();(0,core.setOutput)('content',reuslt);if(!(oldFileContent==reuslt)){_context2.next=47;break;}(0,core.warning)("\uD83D\uDC49 Content has not changed!!!!!");return _context2.abrupt("return");case 47:new_content=Buffer.from(content).toString("base64");if(overwrite.toString()==='true'){body.content=new_content;}else{body.content=Buffer.from(reuslt).toString("base64");new_content=reuslt;}if(!(sync_local_file.toString()==='true'&&ref===github.context.ref)){_context2.next=52;break;}_context2.next=52;return lib_default().writeFile(fullPath,new_content);case 52:(0,core.startGroup)("modifyPathContents Body:");(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(body,null,2)));(0,core.endGroup)();return _context2.abrupt("return",octokit.request('PUT /repos/{owner}/{repo}/contents/{path}',(0,objectSpread2/* default */.Z)({},body)));case 56:case"end":return _context2.stop();}}},_callee2);}));return _modifyPathContents.apply(this,arguments);} ;// CONCATENATED MODULE: ./node_modules/@uiw/formatter/esm/index.js /**! * @uiw/formatter v1.3.3 diff --git a/src/utils.ts b/src/utils.ts index b831fa0..422683c 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -60,6 +60,7 @@ export async function modifyPathContents(options: Partial = {}, co const isExists = FS.existsSync(fullPath) info(`👉 Modify Path (${options.path})`) info(`👉 Context.ref: (${context.ref})`); + info(`👉 Context.sha: (${context.sha})`); const body: FilePutQuery = { owner, repo, path: options.path, @@ -75,7 +76,7 @@ export async function modifyPathContents(options: Partial = {}, co body.branch = branch; const bh = await octokit.rest.repos.getBranch({ owner, repo, branch }) body.sha = sha || bh.data.commit.sha; - startGroup(`👉 Branch content: ${bh.data.commit.commit.message} ${bh.data.commit.commit.author}`); + startGroup(`👉 Branch content: ${bh.data.commit.commit.message} ${bh.data.commit.commit.author?.name}`); info(`👉 ${JSON.stringify(bh, null, 2)}`); endGroup(); } else if (sha) { From 5a423bb854d315eba3ae40deca9423458a936b60 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 29 Nov 2022 06:19:48 +0000 Subject: [PATCH 21/42] doc: modify README.md. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2acbfd3..41ad9b6 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Modify File Content Replace text content and submit content -Here is the example: update time 2022-11-29 06:09:37 +Here is the example: update time 2022-11-29 06:19:47 Here is the different delimiter example: different `GAMFC_TABEL` & `GAMFC_TABEL-END` (test) @@ -39,10 +39,10 @@ Here is the different delimiter example: different `GAMFC_TABE `README.md` file content ```markdown -update time 2022-11-29 06:09:37 +update time 2022-11-29 06:19:47 ``` -Replace the content between `2022-11-29 06:09:37`. +Replace the content between `2022-11-29 06:19:47`. ### format date From 245135fdb8aefd27fa85ddbba7aae8e59d56efa2 Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Tue, 29 Nov 2022 14:28:08 +0800 Subject: [PATCH 22/42] fix: input ref issue. --- dist/index.js | 4 ++-- src/utils.ts | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/dist/index.js b/dist/index.js index 52408af..bc806c4 100644 --- a/dist/index.js +++ b/dist/index.js @@ -14266,9 +14266,9 @@ var external_path_default = /*#__PURE__*/__webpack_require__.n(external_path_); // EXTERNAL MODULE: ./node_modules/@actions/github/lib/github.js var github = __webpack_require__(1374); ;// CONCATENATED MODULE: ./src/utils.ts -var myToken=(0,core.getInput)('token');var octokit=(0,github.getOctokit)(myToken);var getInputs=function getInputs(){var body=(0,core.getInput)('body')||'';var ref=(0,core.getInput)('ref')||github.context.ref;var branch=(0,core.getInput)('branch');var sha=(0,core.getInput)('sha');var overwrite=(0,core.getInput)('overwrite')||'false';var sync_local_file=(0,core.getInput)('sync_local_file')||'true';var filepath=(0,core.getInput)('path')||'';var message=(0,core.getInput)('message')||'';var committer_name=(0,core.getInput)('committer_name')||'';var committer_email=(0,core.getInput)('committer_email')||'';var openDelimiter=(0,core.getInput)('openDelimiter')||'';var closeDelimiter=(0,core.getInput)('closeDelimiter')||'';return (0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({},github.context.repo),{},{body:body,filepath:filepath,ref:ref,branch:branch,sha:sha,message:message,committer_name:committer_name,committer_email:committer_email,openDelimiter:openDelimiter,closeDelimiter:closeDelimiter,overwrite:overwrite,sync_local_file:sync_local_file});};function getReposPathContents(_x){return _getReposPathContents.apply(this,arguments);}function _getReposPathContents(){_getReposPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee(filePath){var _getInputs,owner,repo,ref,result;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:_getInputs=getInputs(),owner=_getInputs.owner,repo=_getInputs.repo,ref=_getInputs.ref;_context.next=3;return octokit.rest.repos.getContent({owner:owner,repo:repo,path:filePath,/** +var myToken=(0,core.getInput)('token');var octokit=(0,github.getOctokit)(myToken);var getInputs=function getInputs(){var body=(0,core.getInput)('body')||'';var ref=(0,core.getInput)('ref')||github.context.ref;var branch=(0,core.getInput)('branch');var sha=(0,core.getInput)('sha');var overwrite=(0,core.getInput)('overwrite')||'false';var sync_local_file=(0,core.getInput)('sync_local_file')||'true';var filepath=(0,core.getInput)('path')||'';var message=(0,core.getInput)('message')||'';var committer_name=(0,core.getInput)('committer_name')||'';var committer_email=(0,core.getInput)('committer_email')||'';var openDelimiter=(0,core.getInput)('openDelimiter')||'';var closeDelimiter=(0,core.getInput)('closeDelimiter')||'';return (0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({},github.context.repo),{},{body:body,filepath:filepath,ref:ref,branch:branch,sha:sha,message:message,committer_name:committer_name,committer_email:committer_email,openDelimiter:openDelimiter,closeDelimiter:closeDelimiter,overwrite:overwrite,sync_local_file:sync_local_file});};function getReposPathContents(_x){return _getReposPathContents.apply(this,arguments);}function _getReposPathContents(){_getReposPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee(filePath){var options,_getInputs,owner,repo,ref,result,_args=arguments;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:options=_args.length>1&&_args[1]!==undefined?_args[1]:{};_getInputs=getInputs(),owner=_getInputs.owner,repo=_getInputs.repo,ref=_getInputs.ref;_context.next=4;return octokit.rest.repos.getContent({owner:owner,repo:repo,path:filePath,/** * The name of the commit/branch/tag. Default: the repository’s default branch (usually `master`) - */ref:ref});case 3:result=_context.sent;return _context.abrupt("return",result);case 5:case"end":return _context.stop();}}},_callee);}));return _getReposPathContents.apply(this,arguments);}function modifyPathContents(){return _modifyPathContents.apply(this,arguments);}function _modifyPathContents(){_modifyPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee2(){var options,content,other,_getInputs2,owner,repo,openDelimiter,closeDelimiter,message,committer_name,committer_email,overwrite,sync_local_file,ref,sha,branch,fullPath,isExists,body,_bh$data$commit$commi,bh,fileResult,fileContent,oldFileContent,REG,reuslt,match,new_content,_args2=arguments;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:options=_args2.length>0&&_args2[0]!==undefined?_args2[0]:{};content=_args2.length>1?_args2[1]:undefined;other=Object.assign({},(_objectDestructuringEmpty(options),options));_getInputs2=getInputs(),owner=_getInputs2.owner,repo=_getInputs2.repo,openDelimiter=_getInputs2.openDelimiter,closeDelimiter=_getInputs2.closeDelimiter,message=_getInputs2.message,committer_name=_getInputs2.committer_name,committer_email=_getInputs2.committer_email,overwrite=_getInputs2.overwrite,sync_local_file=_getInputs2.sync_local_file,ref=_getInputs2.ref,sha=_getInputs2.sha,branch=_getInputs2.branch;if(options.path){_context2.next=6;break;}throw new Error("modifyPathContents: file directory parameter does not exist");case 6:fullPath=external_path_default().resolve(options.path);isExists=lib_default().existsSync(fullPath);(0,core.info)("\uD83D\uDC49 Modify Path (".concat(options.path,")"));(0,core.info)("\uD83D\uDC49 Context.ref: (".concat(github.context.ref,")"));(0,core.info)("\uD83D\uDC49 Context.sha: (".concat(github.context.sha,")"));body=(0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({owner:owner,repo:repo,path:options.path,message:message||"doc: ".concat(isExists?'modify':'create'," ").concat(options.path,"."),committer:{name:committer_name||'github-actions[bot]',email:committer_email||'github-actions[bot]@users.noreply.github.com'}},other),{},{content:Buffer.from(content).toString("base64")});if(!branch){_context2.next=23;break;}body.branch=branch;_context2.next=16;return octokit.rest.repos.getBranch({owner:owner,repo:repo,branch:branch});case 16:bh=_context2.sent;body.sha=sha||bh.data.commit.sha;(0,core.startGroup)("\uD83D\uDC49 Branch content: ".concat(bh.data.commit.commit.message," ").concat((_bh$data$commit$commi=bh.data.commit.commit.author)===null||_bh$data$commit$commi===void 0?void 0:_bh$data$commit$commi.name));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(bh,null,2)));(0,core.endGroup)();_context2.next=24;break;case 23:if(sha){body.sha=sha;}case 24:if(!isExists){_context2.next=52;break;}_context2.next=27;return getReposPathContents(options.path);case 27:fileResult=_context2.sent;if(!(fileResult.status===200&&fileResult.data.sha)){_context2.next=52;break;}if(!branch){body.sha=fileResult.data.sha||sha;}fileContent=fileResult.data.content||'';oldFileContent=Buffer.from(fileContent,'base64').toString();REG=new RegExp("".concat(openDelimiter,"([\\s\\S]*?)").concat(closeDelimiter),'ig');reuslt=oldFileContent.replace(REG,"".concat(openDelimiter).concat(content).concat(closeDelimiter));match=oldFileContent.match(REG);(0,core.startGroup)("\uD83D\uDC49 Text old content: ".concat(match===null||match===void 0?void 0:match.length," ").concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(oldFileContent));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(match,null,2)));(0,core.endGroup)();(0,core.startGroup)("\uD83D\uDC49 Text new content: ".concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(fileResult.data,null,2)));(0,core.info)("\uD83D\uDC49 ".concat(reuslt));(0,core.endGroup)();(0,core.setOutput)('content',reuslt);if(!(oldFileContent==reuslt)){_context2.next=47;break;}(0,core.warning)("\uD83D\uDC49 Content has not changed!!!!!");return _context2.abrupt("return");case 47:new_content=Buffer.from(content).toString("base64");if(overwrite.toString()==='true'){body.content=new_content;}else{body.content=Buffer.from(reuslt).toString("base64");new_content=reuslt;}if(!(sync_local_file.toString()==='true'&&ref===github.context.ref)){_context2.next=52;break;}_context2.next=52;return lib_default().writeFile(fullPath,new_content);case 52:(0,core.startGroup)("modifyPathContents Body:");(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(body,null,2)));(0,core.endGroup)();return _context2.abrupt("return",octokit.request('PUT /repos/{owner}/{repo}/contents/{path}',(0,objectSpread2/* default */.Z)({},body)));case 56:case"end":return _context2.stop();}}},_callee2);}));return _modifyPathContents.apply(this,arguments);} + */ref:options.ref||ref});case 4:result=_context.sent;return _context.abrupt("return",result);case 6:case"end":return _context.stop();}}},_callee);}));return _getReposPathContents.apply(this,arguments);}function modifyPathContents(){return _modifyPathContents.apply(this,arguments);}function _modifyPathContents(){_modifyPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee2(){var options,content,other,_getInputs2,owner,repo,openDelimiter,closeDelimiter,message,committer_name,committer_email,overwrite,sync_local_file,ref,sha,branch,fullPath,isExists,body,_bh$data$commit$commi,bh,fileResult,fileContent,oldFileContent,REG,reuslt,match,new_content,_args2=arguments;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:options=_args2.length>0&&_args2[0]!==undefined?_args2[0]:{};content=_args2.length>1?_args2[1]:undefined;other=Object.assign({},(_objectDestructuringEmpty(options),options));_getInputs2=getInputs(),owner=_getInputs2.owner,repo=_getInputs2.repo,openDelimiter=_getInputs2.openDelimiter,closeDelimiter=_getInputs2.closeDelimiter,message=_getInputs2.message,committer_name=_getInputs2.committer_name,committer_email=_getInputs2.committer_email,overwrite=_getInputs2.overwrite,sync_local_file=_getInputs2.sync_local_file,ref=_getInputs2.ref,sha=_getInputs2.sha,branch=_getInputs2.branch;if(options.path){_context2.next=6;break;}throw new Error("modifyPathContents: file directory parameter does not exist");case 6:fullPath=external_path_default().resolve(options.path);isExists=lib_default().existsSync(fullPath);(0,core.info)("\uD83D\uDC49 Modify Path (".concat(options.path,")"));(0,core.info)("\uD83D\uDC49 Context.ref: (".concat(github.context.ref,")"));(0,core.info)("\uD83D\uDC49 Context.sha: (".concat(github.context.sha,")"));body=(0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({owner:owner,repo:repo,path:options.path,message:message||"doc: ".concat(isExists?'modify':'create'," ").concat(options.path,"."),committer:{name:committer_name||'github-actions[bot]',email:committer_email||'github-actions[bot]@users.noreply.github.com'}},other),{},{content:Buffer.from(content).toString("base64")});if(!branch){_context2.next=23;break;}body.branch=branch;_context2.next=16;return octokit.rest.repos.getBranch({owner:owner,repo:repo,branch:branch});case 16:bh=_context2.sent;body.sha=sha||bh.data.commit.sha;(0,core.startGroup)("\uD83D\uDC49 Branch content: ".concat(bh.data.commit.commit.message," ").concat((_bh$data$commit$commi=bh.data.commit.commit.author)===null||_bh$data$commit$commi===void 0?void 0:_bh$data$commit$commi.name));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(bh,null,2)));(0,core.endGroup)();_context2.next=24;break;case 23:if(sha){body.sha=sha;}case 24:if(!isExists){_context2.next=53;break;}(0,core.info)("\uD83D\uDC49 body.sha: (".concat(body.sha,")"));_context2.next=28;return getReposPathContents(options.path,{ref:body.branch||body.sha});case 28:fileResult=_context2.sent;if(!(fileResult.status===200&&fileResult.data.sha)){_context2.next=53;break;}if(!branch){body.sha=fileResult.data.sha||sha;}fileContent=fileResult.data.content||'';oldFileContent=Buffer.from(fileContent,'base64').toString();REG=new RegExp("".concat(openDelimiter,"([\\s\\S]*?)").concat(closeDelimiter),'ig');reuslt=oldFileContent.replace(REG,"".concat(openDelimiter).concat(content).concat(closeDelimiter));match=oldFileContent.match(REG);(0,core.startGroup)("\uD83D\uDC49 Text old content: ".concat(match===null||match===void 0?void 0:match.length," ").concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(oldFileContent));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(match,null,2)));(0,core.endGroup)();(0,core.startGroup)("\uD83D\uDC49 Text new content: ".concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(fileResult.data,null,2)));(0,core.info)("\uD83D\uDC49 ".concat(reuslt));(0,core.endGroup)();(0,core.setOutput)('content',reuslt);if(!(oldFileContent==reuslt)){_context2.next=48;break;}(0,core.warning)("\uD83D\uDC49 Content has not changed!!!!!");return _context2.abrupt("return");case 48:new_content=Buffer.from(content).toString("base64");if(overwrite.toString()==='true'){body.content=new_content;}else{body.content=Buffer.from(reuslt).toString("base64");new_content=reuslt;}if(!(sync_local_file.toString()==='true'&&ref===github.context.ref)){_context2.next=53;break;}_context2.next=53;return lib_default().writeFile(fullPath,new_content);case 53:(0,core.startGroup)("modifyPathContents Body:");(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(body,null,2)));(0,core.endGroup)();return _context2.abrupt("return",octokit.request('PUT /repos/{owner}/{repo}/contents/{path}',(0,objectSpread2/* default */.Z)({},body)));case 57:case"end":return _context2.stop();}}},_callee2);}));return _modifyPathContents.apply(this,arguments);} ;// CONCATENATED MODULE: ./node_modules/@uiw/formatter/esm/index.js /**! * @uiw/formatter v1.3.3 diff --git a/src/utils.ts b/src/utils.ts index 422683c..823122c 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -37,7 +37,7 @@ export const getInputs = () => { } } -export async function getReposPathContents(filePath: string) { +export async function getReposPathContents(filePath: string, options: { ref?: string; } = {}) { const {owner, repo, ref} = getInputs() const result = await octokit.rest.repos.getContent({ owner, repo, @@ -45,7 +45,7 @@ export async function getReposPathContents(filePath: string) { /** * The name of the commit/branch/tag. Default: the repository’s default branch (usually `master`) */ - ref, + ref: options.ref || ref, }) return result } @@ -83,7 +83,8 @@ export async function modifyPathContents(options: Partial = {}, co body.sha = sha; } if (isExists) { - const fileResult = await getReposPathContents(options.path) + info(`👉 body.sha: (${body.sha})`); + const fileResult = await getReposPathContents(options.path, { ref: body.branch || body.sha }); if (fileResult.status === 200 && (fileResult.data as any).sha) { if (!branch) { body.sha = (fileResult.data as any).sha || sha; From f0aafd4230787222c5384ed93499ed63d23c36e3 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 29 Nov 2022 06:29:40 +0000 Subject: [PATCH 23/42] doc: modify README.md. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 41ad9b6..f7c9625 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Modify File Content Replace text content and submit content -Here is the example: update time 2022-11-29 06:19:47 +Here is the example: update time 2022-11-29 06:29:40 Here is the different delimiter example: different `GAMFC_TABEL` & `GAMFC_TABEL-END` (test) @@ -39,10 +39,10 @@ Here is the different delimiter example: different `GAMFC_TABE `README.md` file content ```markdown -update time 2022-11-29 06:19:47 +update time 2022-11-29 06:29:40 ``` -Replace the content between `2022-11-29 06:19:47`. +Replace the content between `2022-11-29 06:29:40`. ### format date From 406c4009eda218a2b5a1ebe65fc995c8642abe39 Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Tue, 29 Nov 2022 14:36:13 +0800 Subject: [PATCH 24/42] fix: fix branch issue. --- dist/index.js | 2 +- src/utils.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index bc806c4..008a43d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -14268,7 +14268,7 @@ var github = __webpack_require__(1374); ;// CONCATENATED MODULE: ./src/utils.ts var myToken=(0,core.getInput)('token');var octokit=(0,github.getOctokit)(myToken);var getInputs=function getInputs(){var body=(0,core.getInput)('body')||'';var ref=(0,core.getInput)('ref')||github.context.ref;var branch=(0,core.getInput)('branch');var sha=(0,core.getInput)('sha');var overwrite=(0,core.getInput)('overwrite')||'false';var sync_local_file=(0,core.getInput)('sync_local_file')||'true';var filepath=(0,core.getInput)('path')||'';var message=(0,core.getInput)('message')||'';var committer_name=(0,core.getInput)('committer_name')||'';var committer_email=(0,core.getInput)('committer_email')||'';var openDelimiter=(0,core.getInput)('openDelimiter')||'';var closeDelimiter=(0,core.getInput)('closeDelimiter')||'';return (0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({},github.context.repo),{},{body:body,filepath:filepath,ref:ref,branch:branch,sha:sha,message:message,committer_name:committer_name,committer_email:committer_email,openDelimiter:openDelimiter,closeDelimiter:closeDelimiter,overwrite:overwrite,sync_local_file:sync_local_file});};function getReposPathContents(_x){return _getReposPathContents.apply(this,arguments);}function _getReposPathContents(){_getReposPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee(filePath){var options,_getInputs,owner,repo,ref,result,_args=arguments;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:options=_args.length>1&&_args[1]!==undefined?_args[1]:{};_getInputs=getInputs(),owner=_getInputs.owner,repo=_getInputs.repo,ref=_getInputs.ref;_context.next=4;return octokit.rest.repos.getContent({owner:owner,repo:repo,path:filePath,/** * The name of the commit/branch/tag. Default: the repository’s default branch (usually `master`) - */ref:options.ref||ref});case 4:result=_context.sent;return _context.abrupt("return",result);case 6:case"end":return _context.stop();}}},_callee);}));return _getReposPathContents.apply(this,arguments);}function modifyPathContents(){return _modifyPathContents.apply(this,arguments);}function _modifyPathContents(){_modifyPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee2(){var options,content,other,_getInputs2,owner,repo,openDelimiter,closeDelimiter,message,committer_name,committer_email,overwrite,sync_local_file,ref,sha,branch,fullPath,isExists,body,_bh$data$commit$commi,bh,fileResult,fileContent,oldFileContent,REG,reuslt,match,new_content,_args2=arguments;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:options=_args2.length>0&&_args2[0]!==undefined?_args2[0]:{};content=_args2.length>1?_args2[1]:undefined;other=Object.assign({},(_objectDestructuringEmpty(options),options));_getInputs2=getInputs(),owner=_getInputs2.owner,repo=_getInputs2.repo,openDelimiter=_getInputs2.openDelimiter,closeDelimiter=_getInputs2.closeDelimiter,message=_getInputs2.message,committer_name=_getInputs2.committer_name,committer_email=_getInputs2.committer_email,overwrite=_getInputs2.overwrite,sync_local_file=_getInputs2.sync_local_file,ref=_getInputs2.ref,sha=_getInputs2.sha,branch=_getInputs2.branch;if(options.path){_context2.next=6;break;}throw new Error("modifyPathContents: file directory parameter does not exist");case 6:fullPath=external_path_default().resolve(options.path);isExists=lib_default().existsSync(fullPath);(0,core.info)("\uD83D\uDC49 Modify Path (".concat(options.path,")"));(0,core.info)("\uD83D\uDC49 Context.ref: (".concat(github.context.ref,")"));(0,core.info)("\uD83D\uDC49 Context.sha: (".concat(github.context.sha,")"));body=(0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({owner:owner,repo:repo,path:options.path,message:message||"doc: ".concat(isExists?'modify':'create'," ").concat(options.path,"."),committer:{name:committer_name||'github-actions[bot]',email:committer_email||'github-actions[bot]@users.noreply.github.com'}},other),{},{content:Buffer.from(content).toString("base64")});if(!branch){_context2.next=23;break;}body.branch=branch;_context2.next=16;return octokit.rest.repos.getBranch({owner:owner,repo:repo,branch:branch});case 16:bh=_context2.sent;body.sha=sha||bh.data.commit.sha;(0,core.startGroup)("\uD83D\uDC49 Branch content: ".concat(bh.data.commit.commit.message," ").concat((_bh$data$commit$commi=bh.data.commit.commit.author)===null||_bh$data$commit$commi===void 0?void 0:_bh$data$commit$commi.name));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(bh,null,2)));(0,core.endGroup)();_context2.next=24;break;case 23:if(sha){body.sha=sha;}case 24:if(!isExists){_context2.next=53;break;}(0,core.info)("\uD83D\uDC49 body.sha: (".concat(body.sha,")"));_context2.next=28;return getReposPathContents(options.path,{ref:body.branch||body.sha});case 28:fileResult=_context2.sent;if(!(fileResult.status===200&&fileResult.data.sha)){_context2.next=53;break;}if(!branch){body.sha=fileResult.data.sha||sha;}fileContent=fileResult.data.content||'';oldFileContent=Buffer.from(fileContent,'base64').toString();REG=new RegExp("".concat(openDelimiter,"([\\s\\S]*?)").concat(closeDelimiter),'ig');reuslt=oldFileContent.replace(REG,"".concat(openDelimiter).concat(content).concat(closeDelimiter));match=oldFileContent.match(REG);(0,core.startGroup)("\uD83D\uDC49 Text old content: ".concat(match===null||match===void 0?void 0:match.length," ").concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(oldFileContent));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(match,null,2)));(0,core.endGroup)();(0,core.startGroup)("\uD83D\uDC49 Text new content: ".concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(fileResult.data,null,2)));(0,core.info)("\uD83D\uDC49 ".concat(reuslt));(0,core.endGroup)();(0,core.setOutput)('content',reuslt);if(!(oldFileContent==reuslt)){_context2.next=48;break;}(0,core.warning)("\uD83D\uDC49 Content has not changed!!!!!");return _context2.abrupt("return");case 48:new_content=Buffer.from(content).toString("base64");if(overwrite.toString()==='true'){body.content=new_content;}else{body.content=Buffer.from(reuslt).toString("base64");new_content=reuslt;}if(!(sync_local_file.toString()==='true'&&ref===github.context.ref)){_context2.next=53;break;}_context2.next=53;return lib_default().writeFile(fullPath,new_content);case 53:(0,core.startGroup)("modifyPathContents Body:");(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(body,null,2)));(0,core.endGroup)();return _context2.abrupt("return",octokit.request('PUT /repos/{owner}/{repo}/contents/{path}',(0,objectSpread2/* default */.Z)({},body)));case 57:case"end":return _context2.stop();}}},_callee2);}));return _modifyPathContents.apply(this,arguments);} + */ref:options.ref||ref});case 4:result=_context.sent;return _context.abrupt("return",result);case 6:case"end":return _context.stop();}}},_callee);}));return _getReposPathContents.apply(this,arguments);}function modifyPathContents(){return _modifyPathContents.apply(this,arguments);}function _modifyPathContents(){_modifyPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee2(){var options,content,other,_getInputs2,owner,repo,openDelimiter,closeDelimiter,message,committer_name,committer_email,overwrite,sync_local_file,ref,sha,branch,fullPath,isExists,body,_bh$data$commit$commi,bh,fileResult,fileContent,oldFileContent,REG,reuslt,match,new_content,_args2=arguments;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:options=_args2.length>0&&_args2[0]!==undefined?_args2[0]:{};content=_args2.length>1?_args2[1]:undefined;other=Object.assign({},(_objectDestructuringEmpty(options),options));_getInputs2=getInputs(),owner=_getInputs2.owner,repo=_getInputs2.repo,openDelimiter=_getInputs2.openDelimiter,closeDelimiter=_getInputs2.closeDelimiter,message=_getInputs2.message,committer_name=_getInputs2.committer_name,committer_email=_getInputs2.committer_email,overwrite=_getInputs2.overwrite,sync_local_file=_getInputs2.sync_local_file,ref=_getInputs2.ref,sha=_getInputs2.sha,branch=_getInputs2.branch;if(options.path){_context2.next=6;break;}throw new Error("modifyPathContents: file directory parameter does not exist");case 6:fullPath=external_path_default().resolve(options.path);isExists=lib_default().existsSync(fullPath);(0,core.info)("\uD83D\uDC49 Modify Path (".concat(options.path,")"));(0,core.info)("\uD83D\uDC49 Context.ref: (".concat(github.context.ref,")"));(0,core.info)("\uD83D\uDC49 Context.sha: (".concat(github.context.sha,")"));body=(0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({owner:owner,repo:repo,path:options.path,message:message||"doc: ".concat(isExists?'modify':'create'," ").concat(options.path,"."),committer:{name:committer_name||'github-actions[bot]',email:committer_email||'github-actions[bot]@users.noreply.github.com'}},other),{},{content:Buffer.from(content).toString("base64")});if(!branch){_context2.next=23;break;}body.branch=branch;_context2.next=16;return octokit.rest.repos.getBranch({owner:owner,repo:repo,branch:branch});case 16:bh=_context2.sent;body.sha=bh.data.commit.sha;(0,core.startGroup)("\uD83D\uDC49 Branch content: ".concat(bh.data.commit.commit.message," ").concat((_bh$data$commit$commi=bh.data.commit.commit.author)===null||_bh$data$commit$commi===void 0?void 0:_bh$data$commit$commi.name));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(bh,null,2)));(0,core.endGroup)();_context2.next=24;break;case 23:if(sha){body.sha=sha;}case 24:if(!isExists){_context2.next=53;break;}(0,core.info)("\uD83D\uDC49 body.sha: (".concat(body.sha,")"));_context2.next=28;return getReposPathContents(options.path,{ref:body.branch||body.sha});case 28:fileResult=_context2.sent;if(!(fileResult.status===200&&fileResult.data.sha)){_context2.next=53;break;}if(!branch){body.sha=fileResult.data.sha||sha;}fileContent=fileResult.data.content||'';oldFileContent=Buffer.from(fileContent,'base64').toString();REG=new RegExp("".concat(openDelimiter,"([\\s\\S]*?)").concat(closeDelimiter),'ig');reuslt=oldFileContent.replace(REG,"".concat(openDelimiter).concat(content).concat(closeDelimiter));match=oldFileContent.match(REG);(0,core.startGroup)("\uD83D\uDC49 Text old content: ".concat(match===null||match===void 0?void 0:match.length," ").concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(oldFileContent));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(match,null,2)));(0,core.endGroup)();(0,core.startGroup)("\uD83D\uDC49 Text new content: ".concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(fileResult.data,null,2)));(0,core.info)("\uD83D\uDC49 ".concat(reuslt));(0,core.endGroup)();(0,core.setOutput)('content',reuslt);if(!(oldFileContent==reuslt)){_context2.next=48;break;}(0,core.warning)("\uD83D\uDC49 Content has not changed!!!!!");return _context2.abrupt("return");case 48:new_content=Buffer.from(content).toString("base64");if(overwrite.toString()==='true'){body.content=new_content;}else{body.content=Buffer.from(reuslt).toString("base64");new_content=reuslt;}if(!(sync_local_file.toString()==='true'&&ref===github.context.ref)){_context2.next=53;break;}_context2.next=53;return lib_default().writeFile(fullPath,new_content);case 53:(0,core.startGroup)("modifyPathContents Body:");(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(body,null,2)));(0,core.endGroup)();return _context2.abrupt("return",octokit.request('PUT /repos/{owner}/{repo}/contents/{path}',(0,objectSpread2/* default */.Z)({},body)));case 57:case"end":return _context2.stop();}}},_callee2);}));return _modifyPathContents.apply(this,arguments);} ;// CONCATENATED MODULE: ./node_modules/@uiw/formatter/esm/index.js /**! * @uiw/formatter v1.3.3 diff --git a/src/utils.ts b/src/utils.ts index 823122c..af50c64 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -75,7 +75,7 @@ export async function modifyPathContents(options: Partial = {}, co if (branch) { body.branch = branch; const bh = await octokit.rest.repos.getBranch({ owner, repo, branch }) - body.sha = sha || bh.data.commit.sha; + body.sha = bh.data.commit.sha; startGroup(`👉 Branch content: ${bh.data.commit.commit.message} ${bh.data.commit.commit.author?.name}`); info(`👉 ${JSON.stringify(bh, null, 2)}`); endGroup(); From e9d18baf459d543672b073454253bd3632b37021 Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Tue, 29 Nov 2022 14:53:52 +0800 Subject: [PATCH 25/42] chore: add log. --- dist/index.js | 2 +- src/utils.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 008a43d..86cb2f8 100644 --- a/dist/index.js +++ b/dist/index.js @@ -14268,7 +14268,7 @@ var github = __webpack_require__(1374); ;// CONCATENATED MODULE: ./src/utils.ts var myToken=(0,core.getInput)('token');var octokit=(0,github.getOctokit)(myToken);var getInputs=function getInputs(){var body=(0,core.getInput)('body')||'';var ref=(0,core.getInput)('ref')||github.context.ref;var branch=(0,core.getInput)('branch');var sha=(0,core.getInput)('sha');var overwrite=(0,core.getInput)('overwrite')||'false';var sync_local_file=(0,core.getInput)('sync_local_file')||'true';var filepath=(0,core.getInput)('path')||'';var message=(0,core.getInput)('message')||'';var committer_name=(0,core.getInput)('committer_name')||'';var committer_email=(0,core.getInput)('committer_email')||'';var openDelimiter=(0,core.getInput)('openDelimiter')||'';var closeDelimiter=(0,core.getInput)('closeDelimiter')||'';return (0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({},github.context.repo),{},{body:body,filepath:filepath,ref:ref,branch:branch,sha:sha,message:message,committer_name:committer_name,committer_email:committer_email,openDelimiter:openDelimiter,closeDelimiter:closeDelimiter,overwrite:overwrite,sync_local_file:sync_local_file});};function getReposPathContents(_x){return _getReposPathContents.apply(this,arguments);}function _getReposPathContents(){_getReposPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee(filePath){var options,_getInputs,owner,repo,ref,result,_args=arguments;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:options=_args.length>1&&_args[1]!==undefined?_args[1]:{};_getInputs=getInputs(),owner=_getInputs.owner,repo=_getInputs.repo,ref=_getInputs.ref;_context.next=4;return octokit.rest.repos.getContent({owner:owner,repo:repo,path:filePath,/** * The name of the commit/branch/tag. Default: the repository’s default branch (usually `master`) - */ref:options.ref||ref});case 4:result=_context.sent;return _context.abrupt("return",result);case 6:case"end":return _context.stop();}}},_callee);}));return _getReposPathContents.apply(this,arguments);}function modifyPathContents(){return _modifyPathContents.apply(this,arguments);}function _modifyPathContents(){_modifyPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee2(){var options,content,other,_getInputs2,owner,repo,openDelimiter,closeDelimiter,message,committer_name,committer_email,overwrite,sync_local_file,ref,sha,branch,fullPath,isExists,body,_bh$data$commit$commi,bh,fileResult,fileContent,oldFileContent,REG,reuslt,match,new_content,_args2=arguments;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:options=_args2.length>0&&_args2[0]!==undefined?_args2[0]:{};content=_args2.length>1?_args2[1]:undefined;other=Object.assign({},(_objectDestructuringEmpty(options),options));_getInputs2=getInputs(),owner=_getInputs2.owner,repo=_getInputs2.repo,openDelimiter=_getInputs2.openDelimiter,closeDelimiter=_getInputs2.closeDelimiter,message=_getInputs2.message,committer_name=_getInputs2.committer_name,committer_email=_getInputs2.committer_email,overwrite=_getInputs2.overwrite,sync_local_file=_getInputs2.sync_local_file,ref=_getInputs2.ref,sha=_getInputs2.sha,branch=_getInputs2.branch;if(options.path){_context2.next=6;break;}throw new Error("modifyPathContents: file directory parameter does not exist");case 6:fullPath=external_path_default().resolve(options.path);isExists=lib_default().existsSync(fullPath);(0,core.info)("\uD83D\uDC49 Modify Path (".concat(options.path,")"));(0,core.info)("\uD83D\uDC49 Context.ref: (".concat(github.context.ref,")"));(0,core.info)("\uD83D\uDC49 Context.sha: (".concat(github.context.sha,")"));body=(0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({owner:owner,repo:repo,path:options.path,message:message||"doc: ".concat(isExists?'modify':'create'," ").concat(options.path,"."),committer:{name:committer_name||'github-actions[bot]',email:committer_email||'github-actions[bot]@users.noreply.github.com'}},other),{},{content:Buffer.from(content).toString("base64")});if(!branch){_context2.next=23;break;}body.branch=branch;_context2.next=16;return octokit.rest.repos.getBranch({owner:owner,repo:repo,branch:branch});case 16:bh=_context2.sent;body.sha=bh.data.commit.sha;(0,core.startGroup)("\uD83D\uDC49 Branch content: ".concat(bh.data.commit.commit.message," ").concat((_bh$data$commit$commi=bh.data.commit.commit.author)===null||_bh$data$commit$commi===void 0?void 0:_bh$data$commit$commi.name));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(bh,null,2)));(0,core.endGroup)();_context2.next=24;break;case 23:if(sha){body.sha=sha;}case 24:if(!isExists){_context2.next=53;break;}(0,core.info)("\uD83D\uDC49 body.sha: (".concat(body.sha,")"));_context2.next=28;return getReposPathContents(options.path,{ref:body.branch||body.sha});case 28:fileResult=_context2.sent;if(!(fileResult.status===200&&fileResult.data.sha)){_context2.next=53;break;}if(!branch){body.sha=fileResult.data.sha||sha;}fileContent=fileResult.data.content||'';oldFileContent=Buffer.from(fileContent,'base64').toString();REG=new RegExp("".concat(openDelimiter,"([\\s\\S]*?)").concat(closeDelimiter),'ig');reuslt=oldFileContent.replace(REG,"".concat(openDelimiter).concat(content).concat(closeDelimiter));match=oldFileContent.match(REG);(0,core.startGroup)("\uD83D\uDC49 Text old content: ".concat(match===null||match===void 0?void 0:match.length," ").concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(oldFileContent));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(match,null,2)));(0,core.endGroup)();(0,core.startGroup)("\uD83D\uDC49 Text new content: ".concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(fileResult.data,null,2)));(0,core.info)("\uD83D\uDC49 ".concat(reuslt));(0,core.endGroup)();(0,core.setOutput)('content',reuslt);if(!(oldFileContent==reuslt)){_context2.next=48;break;}(0,core.warning)("\uD83D\uDC49 Content has not changed!!!!!");return _context2.abrupt("return");case 48:new_content=Buffer.from(content).toString("base64");if(overwrite.toString()==='true'){body.content=new_content;}else{body.content=Buffer.from(reuslt).toString("base64");new_content=reuslt;}if(!(sync_local_file.toString()==='true'&&ref===github.context.ref)){_context2.next=53;break;}_context2.next=53;return lib_default().writeFile(fullPath,new_content);case 53:(0,core.startGroup)("modifyPathContents Body:");(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(body,null,2)));(0,core.endGroup)();return _context2.abrupt("return",octokit.request('PUT /repos/{owner}/{repo}/contents/{path}',(0,objectSpread2/* default */.Z)({},body)));case 57:case"end":return _context2.stop();}}},_callee2);}));return _modifyPathContents.apply(this,arguments);} + */ref:options.ref||ref});case 4:result=_context.sent;return _context.abrupt("return",result);case 6:case"end":return _context.stop();}}},_callee);}));return _getReposPathContents.apply(this,arguments);}function modifyPathContents(){return _modifyPathContents.apply(this,arguments);}function _modifyPathContents(){_modifyPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee2(){var options,content,other,_getInputs2,owner,repo,openDelimiter,closeDelimiter,message,committer_name,committer_email,overwrite,sync_local_file,ref,sha,branch,fullPath,isExists,body,_bh$data$commit$commi,bh,fileResult,fileContent,oldFileContent,REG,reuslt,match,new_content,_args2=arguments;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:options=_args2.length>0&&_args2[0]!==undefined?_args2[0]:{};content=_args2.length>1?_args2[1]:undefined;other=Object.assign({},(_objectDestructuringEmpty(options),options));_getInputs2=getInputs(),owner=_getInputs2.owner,repo=_getInputs2.repo,openDelimiter=_getInputs2.openDelimiter,closeDelimiter=_getInputs2.closeDelimiter,message=_getInputs2.message,committer_name=_getInputs2.committer_name,committer_email=_getInputs2.committer_email,overwrite=_getInputs2.overwrite,sync_local_file=_getInputs2.sync_local_file,ref=_getInputs2.ref,sha=_getInputs2.sha,branch=_getInputs2.branch;if(options.path){_context2.next=6;break;}throw new Error("modifyPathContents: file directory parameter does not exist");case 6:fullPath=external_path_default().resolve(options.path);isExists=lib_default().existsSync(fullPath);(0,core.info)("\uD83D\uDC49 Modify Path (".concat(options.path,")"));(0,core.info)("\uD83D\uDC49 Context.ref: (".concat(github.context.ref,")"));(0,core.info)("\uD83D\uDC49 Context.sha: (".concat(github.context.sha,")"));body=(0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({owner:owner,repo:repo,path:options.path,message:message||"doc: ".concat(isExists?'modify':'create'," ").concat(options.path,"."),committer:{name:committer_name||'github-actions[bot]',email:committer_email||'github-actions[bot]@users.noreply.github.com'}},other),{},{content:Buffer.from(content).toString("base64")});if(!branch){_context2.next=24;break;}body.branch=branch;_context2.next=16;return octokit.rest.repos.getBranch({owner:owner,repo:repo,branch:branch});case 16:bh=_context2.sent;body.sha=bh.data.commit.sha;(0,core.startGroup)("\uD83D\uDC49 Branch content: ".concat(bh.data.commit.commit.message," ").concat((_bh$data$commit$commi=bh.data.commit.commit.author)===null||_bh$data$commit$commi===void 0?void 0:_bh$data$commit$commi.name));(0,core.info)("\uD83D\uDC49 body.sha: (".concat(body.sha,")"));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(bh,null,2)));(0,core.endGroup)();_context2.next=25;break;case 24:if(!branch&&sha){body.sha=sha;}case 25:if(!isExists){_context2.next=54;break;}(0,core.info)("\uD83D\uDC49 body.sha: (".concat(body.sha,")"));_context2.next=29;return getReposPathContents(options.path,{ref:body.branch||body.sha});case 29:fileResult=_context2.sent;if(!(fileResult.status===200&&fileResult.data.sha)){_context2.next=54;break;}if(!branch){body.sha=fileResult.data.sha||sha;}fileContent=fileResult.data.content||'';oldFileContent=Buffer.from(fileContent,'base64').toString();REG=new RegExp("".concat(openDelimiter,"([\\s\\S]*?)").concat(closeDelimiter),'ig');reuslt=oldFileContent.replace(REG,"".concat(openDelimiter).concat(content).concat(closeDelimiter));match=oldFileContent.match(REG);(0,core.startGroup)("\uD83D\uDC49 Text old content: ".concat(match===null||match===void 0?void 0:match.length," ").concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(oldFileContent));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(match,null,2)));(0,core.endGroup)();(0,core.startGroup)("\uD83D\uDC49 Text new content: ".concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(fileResult.data,null,2)));(0,core.info)("\uD83D\uDC49 ".concat(reuslt));(0,core.endGroup)();(0,core.setOutput)('content',reuslt);if(!(oldFileContent==reuslt)){_context2.next=49;break;}(0,core.warning)("\uD83D\uDC49 Content has not changed!!!!!");return _context2.abrupt("return");case 49:new_content=Buffer.from(content).toString("base64");if(overwrite.toString()==='true'){body.content=new_content;}else{body.content=Buffer.from(reuslt).toString("base64");new_content=reuslt;}if(!(sync_local_file.toString()==='true'&&ref===github.context.ref)){_context2.next=54;break;}_context2.next=54;return lib_default().writeFile(fullPath,new_content);case 54:(0,core.startGroup)("modifyPathContents Body:");(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(body,null,2)));(0,core.endGroup)();return _context2.abrupt("return",octokit.request('PUT /repos/{owner}/{repo}/contents/{path}',(0,objectSpread2/* default */.Z)({},body)));case 58:case"end":return _context2.stop();}}},_callee2);}));return _modifyPathContents.apply(this,arguments);} ;// CONCATENATED MODULE: ./node_modules/@uiw/formatter/esm/index.js /**! * @uiw/formatter v1.3.3 diff --git a/src/utils.ts b/src/utils.ts index af50c64..33bed8f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -77,9 +77,10 @@ export async function modifyPathContents(options: Partial = {}, co const bh = await octokit.rest.repos.getBranch({ owner, repo, branch }) body.sha = bh.data.commit.sha; startGroup(`👉 Branch content: ${bh.data.commit.commit.message} ${bh.data.commit.commit.author?.name}`); + info(`👉 body.sha: (${body.sha})`); info(`👉 ${JSON.stringify(bh, null, 2)}`); endGroup(); - } else if (sha) { + } else if (!branch && sha) { body.sha = sha; } if (isExists) { From ce6d8923dc39f92991ecf9e2e102661f00a98905 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 29 Nov 2022 06:57:07 +0000 Subject: [PATCH 26/42] doc: modify README.md. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f7c9625..99c9bf6 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Modify File Content Replace text content and submit content -Here is the example: update time 2022-11-29 06:29:40 +Here is the example: update time 2022-11-29 06:57:07 Here is the different delimiter example: different `GAMFC_TABEL` & `GAMFC_TABEL-END` (test) @@ -39,10 +39,10 @@ Here is the different delimiter example: different `GAMFC_TABE `README.md` file content ```markdown -update time 2022-11-29 06:29:40 +update time 2022-11-29 06:57:07 ``` -Replace the content between `2022-11-29 06:29:40`. +Replace the content between `2022-11-29 06:57:07`. ### format date From 1f3942f2896fa74adbce871fb4aed6d6b6cbdc3c Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Tue, 29 Nov 2022 15:09:48 +0800 Subject: [PATCH 27/42] fix: fix branch issue. --- dist/index.js | 2 +- src/utils.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 86cb2f8..92330a4 100644 --- a/dist/index.js +++ b/dist/index.js @@ -14268,7 +14268,7 @@ var github = __webpack_require__(1374); ;// CONCATENATED MODULE: ./src/utils.ts var myToken=(0,core.getInput)('token');var octokit=(0,github.getOctokit)(myToken);var getInputs=function getInputs(){var body=(0,core.getInput)('body')||'';var ref=(0,core.getInput)('ref')||github.context.ref;var branch=(0,core.getInput)('branch');var sha=(0,core.getInput)('sha');var overwrite=(0,core.getInput)('overwrite')||'false';var sync_local_file=(0,core.getInput)('sync_local_file')||'true';var filepath=(0,core.getInput)('path')||'';var message=(0,core.getInput)('message')||'';var committer_name=(0,core.getInput)('committer_name')||'';var committer_email=(0,core.getInput)('committer_email')||'';var openDelimiter=(0,core.getInput)('openDelimiter')||'';var closeDelimiter=(0,core.getInput)('closeDelimiter')||'';return (0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({},github.context.repo),{},{body:body,filepath:filepath,ref:ref,branch:branch,sha:sha,message:message,committer_name:committer_name,committer_email:committer_email,openDelimiter:openDelimiter,closeDelimiter:closeDelimiter,overwrite:overwrite,sync_local_file:sync_local_file});};function getReposPathContents(_x){return _getReposPathContents.apply(this,arguments);}function _getReposPathContents(){_getReposPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee(filePath){var options,_getInputs,owner,repo,ref,result,_args=arguments;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:options=_args.length>1&&_args[1]!==undefined?_args[1]:{};_getInputs=getInputs(),owner=_getInputs.owner,repo=_getInputs.repo,ref=_getInputs.ref;_context.next=4;return octokit.rest.repos.getContent({owner:owner,repo:repo,path:filePath,/** * The name of the commit/branch/tag. Default: the repository’s default branch (usually `master`) - */ref:options.ref||ref});case 4:result=_context.sent;return _context.abrupt("return",result);case 6:case"end":return _context.stop();}}},_callee);}));return _getReposPathContents.apply(this,arguments);}function modifyPathContents(){return _modifyPathContents.apply(this,arguments);}function _modifyPathContents(){_modifyPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee2(){var options,content,other,_getInputs2,owner,repo,openDelimiter,closeDelimiter,message,committer_name,committer_email,overwrite,sync_local_file,ref,sha,branch,fullPath,isExists,body,_bh$data$commit$commi,bh,fileResult,fileContent,oldFileContent,REG,reuslt,match,new_content,_args2=arguments;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:options=_args2.length>0&&_args2[0]!==undefined?_args2[0]:{};content=_args2.length>1?_args2[1]:undefined;other=Object.assign({},(_objectDestructuringEmpty(options),options));_getInputs2=getInputs(),owner=_getInputs2.owner,repo=_getInputs2.repo,openDelimiter=_getInputs2.openDelimiter,closeDelimiter=_getInputs2.closeDelimiter,message=_getInputs2.message,committer_name=_getInputs2.committer_name,committer_email=_getInputs2.committer_email,overwrite=_getInputs2.overwrite,sync_local_file=_getInputs2.sync_local_file,ref=_getInputs2.ref,sha=_getInputs2.sha,branch=_getInputs2.branch;if(options.path){_context2.next=6;break;}throw new Error("modifyPathContents: file directory parameter does not exist");case 6:fullPath=external_path_default().resolve(options.path);isExists=lib_default().existsSync(fullPath);(0,core.info)("\uD83D\uDC49 Modify Path (".concat(options.path,")"));(0,core.info)("\uD83D\uDC49 Context.ref: (".concat(github.context.ref,")"));(0,core.info)("\uD83D\uDC49 Context.sha: (".concat(github.context.sha,")"));body=(0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({owner:owner,repo:repo,path:options.path,message:message||"doc: ".concat(isExists?'modify':'create'," ").concat(options.path,"."),committer:{name:committer_name||'github-actions[bot]',email:committer_email||'github-actions[bot]@users.noreply.github.com'}},other),{},{content:Buffer.from(content).toString("base64")});if(!branch){_context2.next=24;break;}body.branch=branch;_context2.next=16;return octokit.rest.repos.getBranch({owner:owner,repo:repo,branch:branch});case 16:bh=_context2.sent;body.sha=bh.data.commit.sha;(0,core.startGroup)("\uD83D\uDC49 Branch content: ".concat(bh.data.commit.commit.message," ").concat((_bh$data$commit$commi=bh.data.commit.commit.author)===null||_bh$data$commit$commi===void 0?void 0:_bh$data$commit$commi.name));(0,core.info)("\uD83D\uDC49 body.sha: (".concat(body.sha,")"));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(bh,null,2)));(0,core.endGroup)();_context2.next=25;break;case 24:if(!branch&&sha){body.sha=sha;}case 25:if(!isExists){_context2.next=54;break;}(0,core.info)("\uD83D\uDC49 body.sha: (".concat(body.sha,")"));_context2.next=29;return getReposPathContents(options.path,{ref:body.branch||body.sha});case 29:fileResult=_context2.sent;if(!(fileResult.status===200&&fileResult.data.sha)){_context2.next=54;break;}if(!branch){body.sha=fileResult.data.sha||sha;}fileContent=fileResult.data.content||'';oldFileContent=Buffer.from(fileContent,'base64').toString();REG=new RegExp("".concat(openDelimiter,"([\\s\\S]*?)").concat(closeDelimiter),'ig');reuslt=oldFileContent.replace(REG,"".concat(openDelimiter).concat(content).concat(closeDelimiter));match=oldFileContent.match(REG);(0,core.startGroup)("\uD83D\uDC49 Text old content: ".concat(match===null||match===void 0?void 0:match.length," ").concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(oldFileContent));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(match,null,2)));(0,core.endGroup)();(0,core.startGroup)("\uD83D\uDC49 Text new content: ".concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(fileResult.data,null,2)));(0,core.info)("\uD83D\uDC49 ".concat(reuslt));(0,core.endGroup)();(0,core.setOutput)('content',reuslt);if(!(oldFileContent==reuslt)){_context2.next=49;break;}(0,core.warning)("\uD83D\uDC49 Content has not changed!!!!!");return _context2.abrupt("return");case 49:new_content=Buffer.from(content).toString("base64");if(overwrite.toString()==='true'){body.content=new_content;}else{body.content=Buffer.from(reuslt).toString("base64");new_content=reuslt;}if(!(sync_local_file.toString()==='true'&&ref===github.context.ref)){_context2.next=54;break;}_context2.next=54;return lib_default().writeFile(fullPath,new_content);case 54:(0,core.startGroup)("modifyPathContents Body:");(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(body,null,2)));(0,core.endGroup)();return _context2.abrupt("return",octokit.request('PUT /repos/{owner}/{repo}/contents/{path}',(0,objectSpread2/* default */.Z)({},body)));case 58:case"end":return _context2.stop();}}},_callee2);}));return _modifyPathContents.apply(this,arguments);} + */ref:options.ref||ref});case 4:result=_context.sent;return _context.abrupt("return",result);case 6:case"end":return _context.stop();}}},_callee);}));return _getReposPathContents.apply(this,arguments);}function modifyPathContents(){return _modifyPathContents.apply(this,arguments);}function _modifyPathContents(){_modifyPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee2(){var options,content,other,_getInputs2,owner,repo,openDelimiter,closeDelimiter,message,committer_name,committer_email,overwrite,sync_local_file,ref,sha,branch,fullPath,isExists,body,_bh$data$commit$commi,bh,fileResult,fileContent,oldFileContent,REG,reuslt,match,new_content,_args2=arguments;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:options=_args2.length>0&&_args2[0]!==undefined?_args2[0]:{};content=_args2.length>1?_args2[1]:undefined;other=Object.assign({},(_objectDestructuringEmpty(options),options));_getInputs2=getInputs(),owner=_getInputs2.owner,repo=_getInputs2.repo,openDelimiter=_getInputs2.openDelimiter,closeDelimiter=_getInputs2.closeDelimiter,message=_getInputs2.message,committer_name=_getInputs2.committer_name,committer_email=_getInputs2.committer_email,overwrite=_getInputs2.overwrite,sync_local_file=_getInputs2.sync_local_file,ref=_getInputs2.ref,sha=_getInputs2.sha,branch=_getInputs2.branch;if(options.path){_context2.next=6;break;}throw new Error("modifyPathContents: file directory parameter does not exist");case 6:fullPath=external_path_default().resolve(options.path);isExists=lib_default().existsSync(fullPath);(0,core.info)("\uD83D\uDC49 Modify Path (".concat(options.path,")"));(0,core.info)("\uD83D\uDC49 Context.ref: (".concat(github.context.ref,")"));(0,core.info)("\uD83D\uDC49 Context.sha: (".concat(github.context.sha,")"));body=(0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({owner:owner,repo:repo,path:options.path,message:message||"doc: ".concat(isExists?'modify':'create'," ").concat(options.path,"."),committer:{name:committer_name||'github-actions[bot]',email:committer_email||'github-actions[bot]@users.noreply.github.com'}},other),{},{content:Buffer.from(content).toString("base64")});if(!branch){_context2.next=24;break;}body.branch=branch;_context2.next=16;return octokit.rest.repos.getBranch({owner:owner,repo:repo,branch:branch});case 16:bh=_context2.sent;body.sha=branch||bh.data.commit.sha;(0,core.startGroup)("\uD83D\uDC49 Branch content: ".concat(bh.data.commit.commit.message," ").concat((_bh$data$commit$commi=bh.data.commit.commit.author)===null||_bh$data$commit$commi===void 0?void 0:_bh$data$commit$commi.name));(0,core.info)("\uD83D\uDC49 body.sha: (".concat(body.sha,")"));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(bh,null,2)));(0,core.endGroup)();_context2.next=25;break;case 24:if(!branch&&sha){body.sha=sha;}case 25:if(!isExists){_context2.next=54;break;}(0,core.info)("\uD83D\uDC49 body.sha: (".concat(body.sha,")"));_context2.next=29;return getReposPathContents(options.path,{ref:body.branch||body.sha});case 29:fileResult=_context2.sent;if(!(fileResult.status===200&&fileResult.data.sha)){_context2.next=54;break;}if(!branch){body.sha=fileResult.data.sha||sha;}fileContent=fileResult.data.content||'';oldFileContent=Buffer.from(fileContent,'base64').toString();REG=new RegExp("".concat(openDelimiter,"([\\s\\S]*?)").concat(closeDelimiter),'ig');reuslt=oldFileContent.replace(REG,"".concat(openDelimiter).concat(content).concat(closeDelimiter));match=oldFileContent.match(REG);(0,core.startGroup)("\uD83D\uDC49 Text old content: ".concat(match===null||match===void 0?void 0:match.length," ").concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(oldFileContent));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(match,null,2)));(0,core.endGroup)();(0,core.startGroup)("\uD83D\uDC49 Text new content: ".concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(fileResult.data,null,2)));(0,core.info)("\uD83D\uDC49 ".concat(reuslt));(0,core.endGroup)();(0,core.setOutput)('content',reuslt);if(!(oldFileContent==reuslt)){_context2.next=49;break;}(0,core.warning)("\uD83D\uDC49 Content has not changed!!!!!");return _context2.abrupt("return");case 49:new_content=Buffer.from(content).toString("base64");if(overwrite.toString()==='true'){body.content=new_content;}else{body.content=Buffer.from(reuslt).toString("base64");new_content=reuslt;}if(!(sync_local_file.toString()==='true'&&ref===github.context.ref)){_context2.next=54;break;}_context2.next=54;return lib_default().writeFile(fullPath,new_content);case 54:(0,core.startGroup)("modifyPathContents Body:");(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(body,null,2)));(0,core.endGroup)();return _context2.abrupt("return",octokit.request('PUT /repos/{owner}/{repo}/contents/{path}',(0,objectSpread2/* default */.Z)({},body)));case 58:case"end":return _context2.stop();}}},_callee2);}));return _modifyPathContents.apply(this,arguments);} ;// CONCATENATED MODULE: ./node_modules/@uiw/formatter/esm/index.js /**! * @uiw/formatter v1.3.3 diff --git a/src/utils.ts b/src/utils.ts index 33bed8f..bd99477 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -75,7 +75,7 @@ export async function modifyPathContents(options: Partial = {}, co if (branch) { body.branch = branch; const bh = await octokit.rest.repos.getBranch({ owner, repo, branch }) - body.sha = bh.data.commit.sha; + body.sha = branch || bh.data.commit.sha; startGroup(`👉 Branch content: ${bh.data.commit.commit.message} ${bh.data.commit.commit.author?.name}`); info(`👉 body.sha: (${body.sha})`); info(`👉 ${JSON.stringify(bh, null, 2)}`); From 76c4dcc6a7eb30dc6379c93ace78ad897582467b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 29 Nov 2022 07:11:15 +0000 Subject: [PATCH 28/42] doc: modify README.md. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 99c9bf6..4f96032 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Modify File Content Replace text content and submit content -Here is the example: update time 2022-11-29 06:57:07 +Here is the example: update time 2022-11-29 07:11:15 Here is the different delimiter example: different `GAMFC_TABEL` & `GAMFC_TABEL-END` (test) @@ -39,10 +39,10 @@ Here is the different delimiter example: different `GAMFC_TABE `README.md` file content ```markdown -update time 2022-11-29 06:57:07 +update time 2022-11-29 07:11:15 ``` -Replace the content between `2022-11-29 06:57:07`. +Replace the content between `2022-11-29 07:11:15`. ### format date From a13fd0f165850f7604f98a7f61a52ff7170abe5f Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Tue, 29 Nov 2022 15:17:02 +0800 Subject: [PATCH 29/42] chore: add log. --- dist/index.js | 2 +- src/utils.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/index.js b/dist/index.js index 92330a4..c4a2419 100644 --- a/dist/index.js +++ b/dist/index.js @@ -14268,7 +14268,7 @@ var github = __webpack_require__(1374); ;// CONCATENATED MODULE: ./src/utils.ts var myToken=(0,core.getInput)('token');var octokit=(0,github.getOctokit)(myToken);var getInputs=function getInputs(){var body=(0,core.getInput)('body')||'';var ref=(0,core.getInput)('ref')||github.context.ref;var branch=(0,core.getInput)('branch');var sha=(0,core.getInput)('sha');var overwrite=(0,core.getInput)('overwrite')||'false';var sync_local_file=(0,core.getInput)('sync_local_file')||'true';var filepath=(0,core.getInput)('path')||'';var message=(0,core.getInput)('message')||'';var committer_name=(0,core.getInput)('committer_name')||'';var committer_email=(0,core.getInput)('committer_email')||'';var openDelimiter=(0,core.getInput)('openDelimiter')||'';var closeDelimiter=(0,core.getInput)('closeDelimiter')||'';return (0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({},github.context.repo),{},{body:body,filepath:filepath,ref:ref,branch:branch,sha:sha,message:message,committer_name:committer_name,committer_email:committer_email,openDelimiter:openDelimiter,closeDelimiter:closeDelimiter,overwrite:overwrite,sync_local_file:sync_local_file});};function getReposPathContents(_x){return _getReposPathContents.apply(this,arguments);}function _getReposPathContents(){_getReposPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee(filePath){var options,_getInputs,owner,repo,ref,result,_args=arguments;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:options=_args.length>1&&_args[1]!==undefined?_args[1]:{};_getInputs=getInputs(),owner=_getInputs.owner,repo=_getInputs.repo,ref=_getInputs.ref;_context.next=4;return octokit.rest.repos.getContent({owner:owner,repo:repo,path:filePath,/** * The name of the commit/branch/tag. Default: the repository’s default branch (usually `master`) - */ref:options.ref||ref});case 4:result=_context.sent;return _context.abrupt("return",result);case 6:case"end":return _context.stop();}}},_callee);}));return _getReposPathContents.apply(this,arguments);}function modifyPathContents(){return _modifyPathContents.apply(this,arguments);}function _modifyPathContents(){_modifyPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee2(){var options,content,other,_getInputs2,owner,repo,openDelimiter,closeDelimiter,message,committer_name,committer_email,overwrite,sync_local_file,ref,sha,branch,fullPath,isExists,body,_bh$data$commit$commi,bh,fileResult,fileContent,oldFileContent,REG,reuslt,match,new_content,_args2=arguments;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:options=_args2.length>0&&_args2[0]!==undefined?_args2[0]:{};content=_args2.length>1?_args2[1]:undefined;other=Object.assign({},(_objectDestructuringEmpty(options),options));_getInputs2=getInputs(),owner=_getInputs2.owner,repo=_getInputs2.repo,openDelimiter=_getInputs2.openDelimiter,closeDelimiter=_getInputs2.closeDelimiter,message=_getInputs2.message,committer_name=_getInputs2.committer_name,committer_email=_getInputs2.committer_email,overwrite=_getInputs2.overwrite,sync_local_file=_getInputs2.sync_local_file,ref=_getInputs2.ref,sha=_getInputs2.sha,branch=_getInputs2.branch;if(options.path){_context2.next=6;break;}throw new Error("modifyPathContents: file directory parameter does not exist");case 6:fullPath=external_path_default().resolve(options.path);isExists=lib_default().existsSync(fullPath);(0,core.info)("\uD83D\uDC49 Modify Path (".concat(options.path,")"));(0,core.info)("\uD83D\uDC49 Context.ref: (".concat(github.context.ref,")"));(0,core.info)("\uD83D\uDC49 Context.sha: (".concat(github.context.sha,")"));body=(0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({owner:owner,repo:repo,path:options.path,message:message||"doc: ".concat(isExists?'modify':'create'," ").concat(options.path,"."),committer:{name:committer_name||'github-actions[bot]',email:committer_email||'github-actions[bot]@users.noreply.github.com'}},other),{},{content:Buffer.from(content).toString("base64")});if(!branch){_context2.next=24;break;}body.branch=branch;_context2.next=16;return octokit.rest.repos.getBranch({owner:owner,repo:repo,branch:branch});case 16:bh=_context2.sent;body.sha=branch||bh.data.commit.sha;(0,core.startGroup)("\uD83D\uDC49 Branch content: ".concat(bh.data.commit.commit.message," ").concat((_bh$data$commit$commi=bh.data.commit.commit.author)===null||_bh$data$commit$commi===void 0?void 0:_bh$data$commit$commi.name));(0,core.info)("\uD83D\uDC49 body.sha: (".concat(body.sha,")"));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(bh,null,2)));(0,core.endGroup)();_context2.next=25;break;case 24:if(!branch&&sha){body.sha=sha;}case 25:if(!isExists){_context2.next=54;break;}(0,core.info)("\uD83D\uDC49 body.sha: (".concat(body.sha,")"));_context2.next=29;return getReposPathContents(options.path,{ref:body.branch||body.sha});case 29:fileResult=_context2.sent;if(!(fileResult.status===200&&fileResult.data.sha)){_context2.next=54;break;}if(!branch){body.sha=fileResult.data.sha||sha;}fileContent=fileResult.data.content||'';oldFileContent=Buffer.from(fileContent,'base64').toString();REG=new RegExp("".concat(openDelimiter,"([\\s\\S]*?)").concat(closeDelimiter),'ig');reuslt=oldFileContent.replace(REG,"".concat(openDelimiter).concat(content).concat(closeDelimiter));match=oldFileContent.match(REG);(0,core.startGroup)("\uD83D\uDC49 Text old content: ".concat(match===null||match===void 0?void 0:match.length," ").concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(oldFileContent));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(match,null,2)));(0,core.endGroup)();(0,core.startGroup)("\uD83D\uDC49 Text new content: ".concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(fileResult.data,null,2)));(0,core.info)("\uD83D\uDC49 ".concat(reuslt));(0,core.endGroup)();(0,core.setOutput)('content',reuslt);if(!(oldFileContent==reuslt)){_context2.next=49;break;}(0,core.warning)("\uD83D\uDC49 Content has not changed!!!!!");return _context2.abrupt("return");case 49:new_content=Buffer.from(content).toString("base64");if(overwrite.toString()==='true'){body.content=new_content;}else{body.content=Buffer.from(reuslt).toString("base64");new_content=reuslt;}if(!(sync_local_file.toString()==='true'&&ref===github.context.ref)){_context2.next=54;break;}_context2.next=54;return lib_default().writeFile(fullPath,new_content);case 54:(0,core.startGroup)("modifyPathContents Body:");(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(body,null,2)));(0,core.endGroup)();return _context2.abrupt("return",octokit.request('PUT /repos/{owner}/{repo}/contents/{path}',(0,objectSpread2/* default */.Z)({},body)));case 58:case"end":return _context2.stop();}}},_callee2);}));return _modifyPathContents.apply(this,arguments);} + */ref:options.ref||ref});case 4:result=_context.sent;return _context.abrupt("return",result);case 6:case"end":return _context.stop();}}},_callee);}));return _getReposPathContents.apply(this,arguments);}function modifyPathContents(){return _modifyPathContents.apply(this,arguments);}function _modifyPathContents(){_modifyPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee2(){var options,content,other,_getInputs2,owner,repo,openDelimiter,closeDelimiter,message,committer_name,committer_email,overwrite,sync_local_file,ref,sha,branch,fullPath,isExists,body,_bh$data$commit$commi,bh,fileResult,fileContent,oldFileContent,REG,reuslt,match,new_content,_args2=arguments;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:options=_args2.length>0&&_args2[0]!==undefined?_args2[0]:{};content=_args2.length>1?_args2[1]:undefined;other=Object.assign({},(_objectDestructuringEmpty(options),options));_getInputs2=getInputs(),owner=_getInputs2.owner,repo=_getInputs2.repo,openDelimiter=_getInputs2.openDelimiter,closeDelimiter=_getInputs2.closeDelimiter,message=_getInputs2.message,committer_name=_getInputs2.committer_name,committer_email=_getInputs2.committer_email,overwrite=_getInputs2.overwrite,sync_local_file=_getInputs2.sync_local_file,ref=_getInputs2.ref,sha=_getInputs2.sha,branch=_getInputs2.branch;if(options.path){_context2.next=6;break;}throw new Error("modifyPathContents: file directory parameter does not exist");case 6:fullPath=external_path_default().resolve(options.path);isExists=lib_default().existsSync(fullPath);(0,core.info)("\uD83D\uDC49 Modify Path (".concat(options.path,")"));(0,core.info)("\uD83D\uDC49 Context.ref: (".concat(github.context.ref,")"));(0,core.info)("\uD83D\uDC49 Context.sha: (".concat(github.context.sha,")"));body=(0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({owner:owner,repo:repo,path:options.path,message:message||"doc: ".concat(isExists?'modify':'create'," ").concat(options.path,"."),committer:{name:committer_name||'github-actions[bot]',email:committer_email||'github-actions[bot]@users.noreply.github.com'}},other),{},{content:Buffer.from(content).toString("base64")});if(!branch){_context2.next=24;break;}body.branch=branch;_context2.next=16;return octokit.rest.repos.getBranch({owner:owner,repo:repo,branch:branch});case 16:bh=_context2.sent;body.sha=branch||bh.data.commit.sha;(0,core.startGroup)("\uD83D\uDC49 Branch content: ".concat(bh.data.commit.commit.message," ").concat((_bh$data$commit$commi=bh.data.commit.commit.author)===null||_bh$data$commit$commi===void 0?void 0:_bh$data$commit$commi.name));(0,core.info)("\uD83D\uDC49 body.sha: (".concat(branch,") (").concat(body.sha,")"));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(bh,null,2)));(0,core.endGroup)();_context2.next=25;break;case 24:if(!branch&&sha){body.sha=sha;}case 25:if(!isExists){_context2.next=54;break;}(0,core.info)("\uD83D\uDC49 body.sha: (".concat(branch,") (").concat(body.sha,")"));_context2.next=29;return getReposPathContents(options.path,{ref:body.branch||body.sha});case 29:fileResult=_context2.sent;if(!(fileResult.status===200&&fileResult.data.sha)){_context2.next=54;break;}if(!branch){body.sha=fileResult.data.sha||sha;}fileContent=fileResult.data.content||'';oldFileContent=Buffer.from(fileContent,'base64').toString();REG=new RegExp("".concat(openDelimiter,"([\\s\\S]*?)").concat(closeDelimiter),'ig');reuslt=oldFileContent.replace(REG,"".concat(openDelimiter).concat(content).concat(closeDelimiter));match=oldFileContent.match(REG);(0,core.startGroup)("\uD83D\uDC49 Text old content: ".concat(match===null||match===void 0?void 0:match.length," ").concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(oldFileContent));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(match,null,2)));(0,core.endGroup)();(0,core.startGroup)("\uD83D\uDC49 Text new content: ".concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(fileResult.data,null,2)));(0,core.info)("\uD83D\uDC49 ".concat(reuslt));(0,core.endGroup)();(0,core.setOutput)('content',reuslt);if(!(oldFileContent==reuslt)){_context2.next=49;break;}(0,core.warning)("\uD83D\uDC49 Content has not changed!!!!!");return _context2.abrupt("return");case 49:new_content=Buffer.from(content).toString("base64");if(overwrite.toString()==='true'){body.content=new_content;}else{body.content=Buffer.from(reuslt).toString("base64");new_content=reuslt;}if(!(sync_local_file.toString()==='true'&&ref===github.context.ref)){_context2.next=54;break;}_context2.next=54;return lib_default().writeFile(fullPath,new_content);case 54:(0,core.startGroup)("modifyPathContents Body:");(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(body,null,2)));(0,core.endGroup)();return _context2.abrupt("return",octokit.request('PUT /repos/{owner}/{repo}/contents/{path}',(0,objectSpread2/* default */.Z)({},body)));case 58:case"end":return _context2.stop();}}},_callee2);}));return _modifyPathContents.apply(this,arguments);} ;// CONCATENATED MODULE: ./node_modules/@uiw/formatter/esm/index.js /**! * @uiw/formatter v1.3.3 diff --git a/src/utils.ts b/src/utils.ts index bd99477..bdacaa8 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -77,14 +77,14 @@ export async function modifyPathContents(options: Partial = {}, co const bh = await octokit.rest.repos.getBranch({ owner, repo, branch }) body.sha = branch || bh.data.commit.sha; startGroup(`👉 Branch content: ${bh.data.commit.commit.message} ${bh.data.commit.commit.author?.name}`); - info(`👉 body.sha: (${body.sha})`); + info(`👉 body.sha: (${branch}) (${body.sha})`); info(`👉 ${JSON.stringify(bh, null, 2)}`); endGroup(); } else if (!branch && sha) { body.sha = sha; } if (isExists) { - info(`👉 body.sha: (${body.sha})`); + info(`👉 body.sha: (${branch}) (${body.sha})`); const fileResult = await getReposPathContents(options.path, { ref: body.branch || body.sha }); if (fileResult.status === 200 && (fileResult.data as any).sha) { if (!branch) { From 049c88e7a6fa3db1d1ae106797834d7915d940c4 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 29 Nov 2022 07:18:45 +0000 Subject: [PATCH 30/42] doc: modify README.md. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4f96032..b8a864f 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Modify File Content Replace text content and submit content -Here is the example: update time 2022-11-29 07:11:15 +Here is the example: update time 2022-11-29 07:18:44 Here is the different delimiter example: different `GAMFC_TABEL` & `GAMFC_TABEL-END` (test) @@ -39,10 +39,10 @@ Here is the different delimiter example: different `GAMFC_TABE `README.md` file content ```markdown -update time 2022-11-29 07:11:15 +update time 2022-11-29 07:18:44 ``` -Replace the content between `2022-11-29 07:11:15`. +Replace the content between `2022-11-29 07:18:44`. ### format date From 044d249c44551cc08c13b721c14ea7addcb116b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=BC=9F=E8=B0=83=E8=B0=83=E2=84=A2?= <398188662@qq.com> Date: Wed, 30 Nov 2022 00:04:46 +0800 Subject: [PATCH 31/42] fix: Fix branch input parameters. #2 (#5) --- .github/workflows/issue.yml | 36 +++++++++ README.md | 1 - action.yml | 4 - dist/index.js | 6 +- src/index.ts | 11 +-- src/utils.ts | 147 ++++++++++++++++++------------------ 6 files changed, 114 insertions(+), 91 deletions(-) create mode 100644 .github/workflows/issue.yml diff --git a/.github/workflows/issue.yml b/.github/workflows/issue.yml new file mode 100644 index 0000000..3c25b33 --- /dev/null +++ b/.github/workflows/issue.yml @@ -0,0 +1,36 @@ +name: fix issue +on: + push: + branches: + - issue + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 16 + + - run: npm install + - run: npm run build + - run: mkdir -p build + + - name: Modify gh-pages README.md + # uses: github-action-modify-file-content@main + uses: ./ + with: + path: README.md + branch: gh-pages + body: "{{date:YYYY-MM-DD HH:mm:ss}}" + + + - name: Overwrite test/overwrite.file.md + # uses: github-action-modify-file-content@main + uses: ./ + with: + path: test/overwrite.file.md + branch: issue + body: "{{date:YYYY-MM-DD HH:mm:ss}}" + overwrite: 'true' \ No newline at end of file diff --git a/README.md b/README.md index b8a864f..9bd30ef 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,6 @@ Here is the different delimiter example: different `GAMFC_TABE - `token` Your `GITHUB_TOKEN`. This is required. Why do we need `token`? Read more here: [About the GITHUB_TOKEN secret](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/authenticating-with-the-github_token#about-the-github_token-secret). Default: `${{ github.token }}` - `body` what needs to be replaced - `path` file to be replaced -- `sha` The blob SHA of the file being replaced - `branch` The person that committed the file. Default: the authenticated user - `ref` The name of the commit/branch/tag. Default: the repository’s default branch (usually `master`) - `overwrite` Overwrite the entire file content, by default `false` diff --git a/action.yml b/action.yml index 8de1ec9..b41a5fd 100644 --- a/action.yml +++ b/action.yml @@ -18,10 +18,6 @@ inputs: description: 'The name of the commit/branch/tag. Default: the repository’s default branch (usually `master`)' default: '' required: false - sha: - description: 'The blob SHA of the file being replaced.' - default: ${{ github.sha }} - required: false branch: description: 'The person that committed the file. Default: the authenticated user.' default: '' diff --git a/dist/index.js b/dist/index.js index c4a2419..cee5560 100644 --- a/dist/index.js +++ b/dist/index.js @@ -14266,9 +14266,7 @@ var external_path_default = /*#__PURE__*/__webpack_require__.n(external_path_); // EXTERNAL MODULE: ./node_modules/@actions/github/lib/github.js var github = __webpack_require__(1374); ;// CONCATENATED MODULE: ./src/utils.ts -var myToken=(0,core.getInput)('token');var octokit=(0,github.getOctokit)(myToken);var getInputs=function getInputs(){var body=(0,core.getInput)('body')||'';var ref=(0,core.getInput)('ref')||github.context.ref;var branch=(0,core.getInput)('branch');var sha=(0,core.getInput)('sha');var overwrite=(0,core.getInput)('overwrite')||'false';var sync_local_file=(0,core.getInput)('sync_local_file')||'true';var filepath=(0,core.getInput)('path')||'';var message=(0,core.getInput)('message')||'';var committer_name=(0,core.getInput)('committer_name')||'';var committer_email=(0,core.getInput)('committer_email')||'';var openDelimiter=(0,core.getInput)('openDelimiter')||'';var closeDelimiter=(0,core.getInput)('closeDelimiter')||'';return (0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({},github.context.repo),{},{body:body,filepath:filepath,ref:ref,branch:branch,sha:sha,message:message,committer_name:committer_name,committer_email:committer_email,openDelimiter:openDelimiter,closeDelimiter:closeDelimiter,overwrite:overwrite,sync_local_file:sync_local_file});};function getReposPathContents(_x){return _getReposPathContents.apply(this,arguments);}function _getReposPathContents(){_getReposPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee(filePath){var options,_getInputs,owner,repo,ref,result,_args=arguments;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:options=_args.length>1&&_args[1]!==undefined?_args[1]:{};_getInputs=getInputs(),owner=_getInputs.owner,repo=_getInputs.repo,ref=_getInputs.ref;_context.next=4;return octokit.rest.repos.getContent({owner:owner,repo:repo,path:filePath,/** - * The name of the commit/branch/tag. Default: the repository’s default branch (usually `master`) - */ref:options.ref||ref});case 4:result=_context.sent;return _context.abrupt("return",result);case 6:case"end":return _context.stop();}}},_callee);}));return _getReposPathContents.apply(this,arguments);}function modifyPathContents(){return _modifyPathContents.apply(this,arguments);}function _modifyPathContents(){_modifyPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee2(){var options,content,other,_getInputs2,owner,repo,openDelimiter,closeDelimiter,message,committer_name,committer_email,overwrite,sync_local_file,ref,sha,branch,fullPath,isExists,body,_bh$data$commit$commi,bh,fileResult,fileContent,oldFileContent,REG,reuslt,match,new_content,_args2=arguments;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:options=_args2.length>0&&_args2[0]!==undefined?_args2[0]:{};content=_args2.length>1?_args2[1]:undefined;other=Object.assign({},(_objectDestructuringEmpty(options),options));_getInputs2=getInputs(),owner=_getInputs2.owner,repo=_getInputs2.repo,openDelimiter=_getInputs2.openDelimiter,closeDelimiter=_getInputs2.closeDelimiter,message=_getInputs2.message,committer_name=_getInputs2.committer_name,committer_email=_getInputs2.committer_email,overwrite=_getInputs2.overwrite,sync_local_file=_getInputs2.sync_local_file,ref=_getInputs2.ref,sha=_getInputs2.sha,branch=_getInputs2.branch;if(options.path){_context2.next=6;break;}throw new Error("modifyPathContents: file directory parameter does not exist");case 6:fullPath=external_path_default().resolve(options.path);isExists=lib_default().existsSync(fullPath);(0,core.info)("\uD83D\uDC49 Modify Path (".concat(options.path,")"));(0,core.info)("\uD83D\uDC49 Context.ref: (".concat(github.context.ref,")"));(0,core.info)("\uD83D\uDC49 Context.sha: (".concat(github.context.sha,")"));body=(0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({owner:owner,repo:repo,path:options.path,message:message||"doc: ".concat(isExists?'modify':'create'," ").concat(options.path,"."),committer:{name:committer_name||'github-actions[bot]',email:committer_email||'github-actions[bot]@users.noreply.github.com'}},other),{},{content:Buffer.from(content).toString("base64")});if(!branch){_context2.next=24;break;}body.branch=branch;_context2.next=16;return octokit.rest.repos.getBranch({owner:owner,repo:repo,branch:branch});case 16:bh=_context2.sent;body.sha=branch||bh.data.commit.sha;(0,core.startGroup)("\uD83D\uDC49 Branch content: ".concat(bh.data.commit.commit.message," ").concat((_bh$data$commit$commi=bh.data.commit.commit.author)===null||_bh$data$commit$commi===void 0?void 0:_bh$data$commit$commi.name));(0,core.info)("\uD83D\uDC49 body.sha: (".concat(branch,") (").concat(body.sha,")"));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(bh,null,2)));(0,core.endGroup)();_context2.next=25;break;case 24:if(!branch&&sha){body.sha=sha;}case 25:if(!isExists){_context2.next=54;break;}(0,core.info)("\uD83D\uDC49 body.sha: (".concat(branch,") (").concat(body.sha,")"));_context2.next=29;return getReposPathContents(options.path,{ref:body.branch||body.sha});case 29:fileResult=_context2.sent;if(!(fileResult.status===200&&fileResult.data.sha)){_context2.next=54;break;}if(!branch){body.sha=fileResult.data.sha||sha;}fileContent=fileResult.data.content||'';oldFileContent=Buffer.from(fileContent,'base64').toString();REG=new RegExp("".concat(openDelimiter,"([\\s\\S]*?)").concat(closeDelimiter),'ig');reuslt=oldFileContent.replace(REG,"".concat(openDelimiter).concat(content).concat(closeDelimiter));match=oldFileContent.match(REG);(0,core.startGroup)("\uD83D\uDC49 Text old content: ".concat(match===null||match===void 0?void 0:match.length," ").concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(oldFileContent));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(match,null,2)));(0,core.endGroup)();(0,core.startGroup)("\uD83D\uDC49 Text new content: ".concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(fileResult.data,null,2)));(0,core.info)("\uD83D\uDC49 ".concat(reuslt));(0,core.endGroup)();(0,core.setOutput)('content',reuslt);if(!(oldFileContent==reuslt)){_context2.next=49;break;}(0,core.warning)("\uD83D\uDC49 Content has not changed!!!!!");return _context2.abrupt("return");case 49:new_content=Buffer.from(content).toString("base64");if(overwrite.toString()==='true'){body.content=new_content;}else{body.content=Buffer.from(reuslt).toString("base64");new_content=reuslt;}if(!(sync_local_file.toString()==='true'&&ref===github.context.ref)){_context2.next=54;break;}_context2.next=54;return lib_default().writeFile(fullPath,new_content);case 54:(0,core.startGroup)("modifyPathContents Body:");(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(body,null,2)));(0,core.endGroup)();return _context2.abrupt("return",octokit.request('PUT /repos/{owner}/{repo}/contents/{path}',(0,objectSpread2/* default */.Z)({},body)));case 58:case"end":return _context2.stop();}}},_callee2);}));return _modifyPathContents.apply(this,arguments);} +var myToken=(0,core.getInput)('token');var octokit=(0,github.getOctokit)(myToken);var getInputs=function getInputs(){var body=(0,core.getInput)('body')||'';var ref=(0,core.getInput)('ref')||github.context.ref;var branch=(0,core.getInput)('branch');var sha=(0,core.getInput)('sha');var overwrite=(0,core.getInput)('overwrite')||'false';var sync_local_file=(0,core.getInput)('sync_local_file')||'true';var filepath=(0,core.getInput)('path')||'';var message=(0,core.getInput)('message')||'';var committer_name=(0,core.getInput)('committer_name')||'';var committer_email=(0,core.getInput)('committer_email')||'';var openDelimiter=(0,core.getInput)('openDelimiter')||'';var closeDelimiter=(0,core.getInput)('closeDelimiter')||'';return (0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({},github.context.repo),{},{body:body,filepath:filepath,ref:ref,branch:branch,sha:sha,message:message,committer_name:committer_name,committer_email:committer_email,openDelimiter:openDelimiter,closeDelimiter:closeDelimiter,overwrite:overwrite,sync_local_file:sync_local_file});};function getBranch(){return _getBranch.apply(this,arguments);}function _getBranch(){_getBranch=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee(){var _getInputs,branch,_yield$octokit$rest$r,data;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:_getInputs=getInputs(),branch=_getInputs.branch;if(!(branch!==null)){_context.next=3;break;}return _context.abrupt("return",Promise.resolve(branch));case 3:_context.next=5;return octokit.rest.repos.get(github.context.repo);case 5:_yield$octokit$rest$r=_context.sent;data=_yield$octokit$rest$r.data;return _context.abrupt("return",data.default_branch);case 8:case"end":return _context.stop();}}},_callee);}));return _getBranch.apply(this,arguments);}function getFileContents(_x){return _getFileContents.apply(this,arguments);}function _getFileContents(){_getFileContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee2(branch){var _getInputs2,owner,repo,filepath,committer_name,committer_email,data;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:_getInputs2=getInputs(),owner=_getInputs2.owner,repo=_getInputs2.repo,filepath=_getInputs2.filepath,committer_name=_getInputs2.committer_name,committer_email=_getInputs2.committer_email;_context2.next=3;return octokit.rest.repos.getContent({owner:owner,repo:repo,ref:branch,path:filepath});case 3:data=_context2.sent;return _context2.abrupt("return",data);case 5:case"end":return _context2.stop();}}},_callee2);}));return _getFileContents.apply(this,arguments);}function modifyPathContents(){return _modifyPathContents.apply(this,arguments);}function _modifyPathContents(){_modifyPathContents=(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee3(){var options,content,other,_getInputs3,owner,repo,openDelimiter,closeDelimiter,message,committer_name,committer_email,overwrite,sync_local_file,ref,sha,branch,fullPath,new_content,body,currentFile,_result$data$content,_result$data$content2,_result$data$content3,fileContent,oldFileContent,REG,reuslt,match,isExists,result,_args3=arguments;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee3$(_context3){while(1){switch(_context3.prev=_context3.next){case 0:options=_args3.length>0&&_args3[0]!==undefined?_args3[0]:{};content=_args3.length>1?_args3[1]:undefined;other=Object.assign({},(_objectDestructuringEmpty(options),options));_getInputs3=getInputs(),owner=_getInputs3.owner,repo=_getInputs3.repo,openDelimiter=_getInputs3.openDelimiter,closeDelimiter=_getInputs3.closeDelimiter,message=_getInputs3.message,committer_name=_getInputs3.committer_name,committer_email=_getInputs3.committer_email,overwrite=_getInputs3.overwrite,sync_local_file=_getInputs3.sync_local_file,ref=_getInputs3.ref,sha=_getInputs3.sha;_context3.next=6;return getBranch();case 6:branch=_context3.sent;if(options.path){_context3.next=9;break;}throw new Error("modifyPathContents: file directory parameter does not exist");case 9:fullPath=external_path_default().resolve(options.path);(0,core.info)("\uD83D\uDC49 Modify Path (".concat(options.path,")"));(0,core.info)("\uD83D\uDC49 Context.ref: (".concat(github.context.ref,")"));(0,core.info)("\uD83D\uDC49 Context.sha: (".concat(github.context.sha,")"));(0,core.info)("\uD83D\uDC49 branch: (".concat(branch,")"));new_content=Buffer.from(content).toString("base64");body=(0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({owner:owner,repo:repo,path:options.path,message:message||"doc: update ".concat(options.path,"."),committer:{name:committer_name||'github-actions[bot]',email:committer_email||'github-actions[bot]@users.noreply.github.com'}},other),{},{content:new_content});_context3.next=18;return getFileContents(branch);case 18:currentFile=_context3.sent;if(!(currentFile.status===200)){_context3.next=58;break;}fileContent=currentFile.data.content||'';oldFileContent=Buffer.from(fileContent,'base64').toString();REG=new RegExp("".concat(openDelimiter,"([\\s\\S]*?)").concat(closeDelimiter),'ig');reuslt=oldFileContent.replace(REG,"".concat(openDelimiter).concat(content).concat(closeDelimiter));match=oldFileContent.match(REG);(0,core.startGroup)("\uD83D\uDC49 Current File content: ".concat(match===null||match===void 0?void 0:match.length," ").concat(options.path));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(match,null,2)));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(currentFile.data,null,2)));(0,core.endGroup)();if(overwrite.toString()==='true'){body.content=new_content;reuslt=new_content;}else{body.content=Buffer.from(reuslt).toString("base64");new_content=reuslt;}(0,core.setOutput)('content',reuslt);(0,core.startGroup)("\uD83D\uDC49 Text OLD content:");(0,core.info)("\uD83D\uDC49 ".concat(oldFileContent));(0,core.endGroup)();(0,core.startGroup)("\uD83D\uDC49 Text NEW content:");(0,core.info)("\uD83D\uDC49 ".concat(reuslt));(0,core.endGroup)();if(!(oldFileContent==reuslt)){_context3.next=40;break;}(0,core.warning)("\uD83D\uDC49 Content has not changed!!!!!");return _context3.abrupt("return");case 40:body=(0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({},body),currentFile.data),{},{branch:branch,sha:currentFile.data.sha});isExists=lib_default().existsSync(fullPath);if(!(isExists&&sync_local_file.toString()==='true'&&ref===github.context.ref)){_context3.next=45;break;}_context3.next=45;return lib_default().writeFile(fullPath,new_content);case 45:(0,core.startGroup)("modifyPathContents Body:");(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(body,null,2)));(0,core.endGroup)();_context3.next=50;return octokit.request('PUT /repos/{owner}/{repo}/contents/{path}',(0,objectSpread2/* default */.Z)((0,objectSpread2/* default */.Z)({},body),{},{sha:currentFile.data.sha}));case 50:result=_context3.sent;(0,core.startGroup)("file result:");(0,core.info)("\uD83D\uDC49 ".concat((_result$data$content=result.data.content)===null||_result$data$content===void 0?void 0:_result$data$content.path));(0,core.info)("\uD83D\uDC49 ".concat((_result$data$content2=result.data.content)===null||_result$data$content2===void 0?void 0:_result$data$content2.size));(0,core.info)("\uD83D\uDC49 ".concat((_result$data$content3=result.data.content)===null||_result$data$content3===void 0?void 0:_result$data$content3.sha));(0,core.endGroup)();_context3.next=62;break;case 58:(0,core.startGroup)("result error:");(0,core.info)("\uD83D\uDC49 ".concat(currentFile.status));(0,core.info)("\uD83D\uDC49 ".concat(JSON.stringify(currentFile.data,null,2)));(0,core.endGroup)();case 62:case"end":return _context3.stop();}}},_callee3);}));return _modifyPathContents.apply(this,arguments);} ;// CONCATENATED MODULE: ./node_modules/@uiw/formatter/esm/index.js /**! * @uiw/formatter v1.3.3 @@ -14314,7 +14312,7 @@ formatter.utc = function (str, date) { }; ;// CONCATENATED MODULE: ./src/index.ts -var REGEXP=/\{\{date:?(.*?)\}\}/ig;(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee(){var _result$data$content,_result$data$content2,_result$data$content3,body,filepath,_result,result;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:_context.prev=0;body=(0,core.getInput)('body')||'';filepath=(0,core.getInput)('path')||'';if(body){_context.next=6;break;}(0,core.warning)("\uD83D\uDC49 \"body\" input value does not exist.");return _context.abrupt("return");case 6:if(filepath){_context.next=9;break;}(0,core.warning)("\uD83D\uDC49 \"path\" input value does not exist.");return _context.abrupt("return");case 9:if(REGEXP.test(body)){_result=body.replace(REGEXP,function(match,str2){var format=match.replace(REGEXP,'$1');var str=formatter(format||'YYYY/MM/DD HH:mm:ss',new Date());return str;});if(_result){body=_result;}}(0,core.info)("\uD83D\uDC49 Body Content: ".concat(body));_context.next=13;return modifyPathContents({path:filepath},body);case 13:result=_context.sent;if(result){_context.next=16;break;}return _context.abrupt("return");case 16:(0,core.startGroup)("file result:");(0,core.info)("\uD83D\uDC49 ".concat((_result$data$content=result.data.content)===null||_result$data$content===void 0?void 0:_result$data$content.path));(0,core.info)("\uD83D\uDC49 ".concat((_result$data$content2=result.data.content)===null||_result$data$content2===void 0?void 0:_result$data$content2.size));(0,core.info)("\uD83D\uDC49 ".concat((_result$data$content3=result.data.content)===null||_result$data$content3===void 0?void 0:_result$data$content3.sha));(0,core.endGroup)();_context.next=26;break;case 23:_context.prev=23;_context.t0=_context["catch"](0);if(_context.t0 instanceof Error){(0,core.setFailed)(_context.t0.message);}case 26:case"end":return _context.stop();}}},_callee,null,[[0,23]]);}))(); +var REGEXP=/\{\{date:?(.*?)\}\}/ig;(0,asyncToGenerator/* default */.Z)(/*#__PURE__*/(0,regeneratorRuntime/* default */.Z)().mark(function _callee(){var body,filepath,result;return (0,regeneratorRuntime/* default */.Z)().wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:_context.prev=0;body=(0,core.getInput)('body')||'';filepath=(0,core.getInput)('path')||'';if(body){_context.next=6;break;}(0,core.warning)("\uD83D\uDC49 \"body\" input value does not exist.");return _context.abrupt("return");case 6:if(filepath){_context.next=9;break;}(0,core.warning)("\uD83D\uDC49 \"path\" input value does not exist.");return _context.abrupt("return");case 9:if(REGEXP.test(body)){result=body.replace(REGEXP,function(match,str2){var format=match.replace(REGEXP,'$1');var str=formatter(format||'YYYY/MM/DD HH:mm:ss',new Date());return str;});if(result){body=result;}}(0,core.info)("\uD83D\uDC49 Body Content: ".concat(body));_context.next=13;return modifyPathContents({path:filepath},body);case 13:_context.next=18;break;case 15:_context.prev=15;_context.t0=_context["catch"](0);if(_context.t0 instanceof Error){(0,core.setFailed)(_context.t0.message);}case 18:case"end":return _context.stop();}}},_callee,null,[[0,15]]);}))(); })(); module.exports = __webpack_exports__; diff --git a/src/index.ts b/src/index.ts index 3e8c140..2e4b7de 100644 --- a/src/index.ts +++ b/src/index.ts @@ -29,16 +29,7 @@ const REGEXP = /\{\{date:?(.*?)\}\}/ig } info(`👉 Body Content: ${body}`) - const result = await modifyPathContents({ path: filepath }, body); - if (!result) { - return - } - - startGroup(`file result:`) - info(`👉 ${result.data.content?.path}`) - info(`👉 ${result.data.content?.size}`) - info(`👉 ${result.data.content?.sha}`) - endGroup() + await modifyPathContents({ path: filepath }, body); } catch (error) { if (error instanceof Error) { setFailed(error.message); diff --git a/src/utils.ts b/src/utils.ts index bdacaa8..d09a026 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -2,10 +2,10 @@ import FS from 'fs-extra'; import path from 'path'; import { context, getOctokit } from '@actions/github'; import { getInput, setOutput, startGroup, info, endGroup, warning } from '@actions/core'; -import { paths, components, } from '@octokit/openapi-types'; -import { OctokitResponse } from '@octokit/types'; +import { paths } from '@octokit/openapi-types'; export type FilePutQuery = paths['/repos/{owner}/{repo}/contents/{path}']['put']['requestBody']['content']['application/json'] & paths['/repos/{owner}/{repo}/contents/{path}']['put']['parameters']['path']; +export type FilePutResult = paths['/repos/{owner}/{repo}/contents/{path}']['get']['responses']['200']['content']['application/json'] export const myToken = getInput('token'); export const octokit = getOctokit(myToken); @@ -37,96 +37,99 @@ export const getInputs = () => { } } -export async function getReposPathContents(filePath: string, options: { ref?: string; } = {}) { - const {owner, repo, ref} = getInputs() - const result = await octokit.rest.repos.getContent({ - owner, repo, - path: filePath, - /** - * The name of the commit/branch/tag. Default: the repository’s default branch (usually `master`) - */ - ref: options.ref || ref, +async function getBranch(): Promise { + const { branch } = getInputs() + if (branch !== null) { + return Promise.resolve(branch); + } + const { data } = await octokit.rest.repos.get(context.repo); + return data.default_branch; +} + +async function getFileContents(branch: string) { + const {owner, repo, filepath, committer_name, committer_email} = getInputs() + const data = await octokit.rest.repos.getContent({ + owner, repo, ref: branch, path: filepath }) - return result + return data; } export async function modifyPathContents(options: Partial = {}, content: string) { const { ...other} = options; - const { owner, repo, openDelimiter, closeDelimiter, message, committer_name, committer_email, overwrite, sync_local_file, ref, sha, branch} = getInputs(); + const { owner, repo, openDelimiter, closeDelimiter, message, committer_name, committer_email, overwrite, sync_local_file, ref, sha} = getInputs(); + const branch = await getBranch(); if (!options.path) { throw new Error(`modifyPathContents: file directory parameter does not exist`) } const fullPath = path.resolve(options.path); - const isExists = FS.existsSync(fullPath) info(`👉 Modify Path (${options.path})`) info(`👉 Context.ref: (${context.ref})`); info(`👉 Context.sha: (${context.sha})`); - const body: FilePutQuery = { + info(`👉 branch: (${branch})`); + + let new_content = Buffer.from(content).toString("base64") + let body: FilePutQuery = { owner, repo, path: options.path, - message: message || `doc: ${isExists ? 'modify' : 'create'} ${options.path}.`, + message: message || `doc: update ${options.path}.`, committer: { name: committer_name || 'github-actions[bot]', email: committer_email || 'github-actions[bot]@users.noreply.github.com' }, ...other, - content: Buffer.from(content).toString("base64"), + content: new_content, } - if (branch) { - body.branch = branch; - const bh = await octokit.rest.repos.getBranch({ owner, repo, branch }) - body.sha = branch || bh.data.commit.sha; - startGroup(`👉 Branch content: ${bh.data.commit.commit.message} ${bh.data.commit.commit.author?.name}`); - info(`👉 body.sha: (${branch}) (${body.sha})`); - info(`👉 ${JSON.stringify(bh, null, 2)}`); + + const currentFile = await getFileContents(branch); + if (currentFile.status === 200) { + const fileContent: string = (currentFile.data as any).content || ''; + const oldFileContent = Buffer.from(fileContent, 'base64').toString(); + const REG = new RegExp(`${openDelimiter}([\\s\\S]*?)${closeDelimiter}`, 'ig') + let reuslt = oldFileContent.replace(REG, `${openDelimiter}${content}${closeDelimiter}`); + const match = oldFileContent.match(REG); + startGroup(`👉 Current File content: ${match?.length} ${options.path}`); + info(`👉 ${JSON.stringify(match, null, 2)}`); + info(`👉 ${JSON.stringify(currentFile.data, null, 2)}`); endGroup(); - } else if (!branch && sha) { - body.sha = sha; - } - if (isExists) { - info(`👉 body.sha: (${branch}) (${body.sha})`); - const fileResult = await getReposPathContents(options.path, { ref: body.branch || body.sha }); - if (fileResult.status === 200 && (fileResult.data as any).sha) { - if (!branch) { - body.sha = (fileResult.data as any).sha || sha; - } - const fileContent: string = (fileResult.data as any).content || ''; - const oldFileContent = Buffer.from(fileContent, 'base64').toString(); - const REG = new RegExp(`${openDelimiter}([\\s\\S]*?)${closeDelimiter}`, 'ig') - const reuslt = oldFileContent.replace(REG, `${openDelimiter}${content}${closeDelimiter}`); - const match = oldFileContent.match(REG); - startGroup(`👉 Text old content: ${match?.length} ${options.path}`); - info(`👉 ${oldFileContent}`); - info(`👉 ${JSON.stringify(match, null, 2)}`); - endGroup(); - startGroup(`👉 Text new content: ${options.path}`); - info(`👉 ${JSON.stringify(fileResult.data, null, 2)}`); - info(`👉 ${reuslt}`); - endGroup(); - setOutput('content', reuslt); - if (oldFileContent == reuslt) { - warning(`👉 Content has not changed!!!!!`) - return; - } - let new_content = Buffer.from(content).toString("base64") - if (overwrite.toString() === 'true') { - body.content = new_content; - } else { - body.content = Buffer.from(reuslt).toString("base64"); - new_content = reuslt; - } - if (sync_local_file.toString() === 'true' && ref === context.ref) { - await FS.writeFile(fullPath, new_content); - } + if (overwrite.toString() === 'true') { + body.content = new_content; + reuslt = new_content; + } else { + body.content = Buffer.from(reuslt).toString("base64"); + new_content = reuslt; } + setOutput('content', reuslt); + startGroup(`👉 Text OLD content:`); + info(`👉 ${oldFileContent}`); + endGroup(); + startGroup(`👉 Text NEW content:`); + info(`👉 ${reuslt}`); + endGroup(); + if (oldFileContent == reuslt) { + warning(`👉 Content has not changed!!!!!`) + return; + } + body = { ...body, ...currentFile.data, branch, sha: (currentFile.data as any).sha } + const isExists = FS.existsSync(fullPath) + if (isExists && sync_local_file.toString() === 'true' && ref === context.ref) { + await FS.writeFile(fullPath, new_content); + } + startGroup(`modifyPathContents Body:`) + info(`👉 ${JSON.stringify(body, null, 2)}`) + endGroup() + const result = await octokit.request('PUT /repos/{owner}/{repo}/contents/{path}', { + ...body, + sha: (currentFile.data as any).sha + }); + startGroup(`file result:`) + info(`👉 ${result.data.content?.path}`) + info(`👉 ${result.data.content?.size}`) + info(`👉 ${result.data.content?.sha}`) + endGroup() + } else { + startGroup(`result error:`) + info(`👉 ${currentFile.status}`) + info(`👉 ${JSON.stringify(currentFile.data, null, 2)}`) + endGroup() } - startGroup(`modifyPathContents Body:`) - info(`👉 ${JSON.stringify(body, null, 2)}`) - endGroup() - return octokit.request('PUT /repos/{owner}/{repo}/contents/{path}', { - ...body, - }); -} - -export type IssuesData = components["schemas"]["issue"][]; -export type Response = OctokitResponse +} \ No newline at end of file From 8a51d6523fe26e9d2d5ec89a2d10936bfd28442f Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Wed, 30 Nov 2022 00:11:17 +0800 Subject: [PATCH 32/42] fix: fix branch issue. --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index b41a5fd..4496ae8 100644 --- a/action.yml +++ b/action.yml @@ -20,7 +20,7 @@ inputs: required: false branch: description: 'The person that committed the file. Default: the authenticated user.' - default: '' + default: ${{ steps.default.outputs.default_branch }} required: false message: description: 'The commit message.' From d76985b25ab30731724d9537b6a23f8807a4b617 Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Wed, 30 Nov 2022 00:15:44 +0800 Subject: [PATCH 33/42] fix: fix branch issue. --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 4496ae8..153e85c 100644 --- a/action.yml +++ b/action.yml @@ -20,7 +20,7 @@ inputs: required: false branch: description: 'The person that committed the file. Default: the authenticated user.' - default: ${{ steps.default.outputs.default_branch }} + default: ${{ github.ref_name }} required: false message: description: 'The commit message.' From 697acd155abe7da17a085398e0fbc300bbe9038c Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 29 Nov 2022 16:17:04 +0000 Subject: [PATCH 34/42] doc: update test/overwrite.file.md. From dee32f17e87338be66f531e86ca55f60b7be0783 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 29 Nov 2022 16:17:05 +0000 Subject: [PATCH 35/42] doc: update README.md. From a7d8fe43eaea46ba42ee4212f4932153ec26e1ba Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Wed, 30 Nov 2022 00:20:23 +0800 Subject: [PATCH 36/42] chore: update workflows config. --- .github/workflows/ci.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dac554d..282d8c4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -69,6 +69,13 @@ jobs: TEST: 2022-11-29 01:44:16 EOF + - name: Deploy + uses: peaceiris/actions-gh-pages@v3 + with: + commit_message: ${{steps.tag_version.outputs.tag}} ${{ github.event.head_commit.message }} + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./build + - name: Modify gh-pages README.md # uses: github-action-modify-file-content@main uses: ./ @@ -77,13 +84,6 @@ jobs: branch: gh-pages body: "{{date:YYYY-MM-DD HH:mm:ss}}" - - name: Deploy - uses: peaceiris/actions-gh-pages@v3 - with: - commit_message: ${{steps.tag_version.outputs.tag}} ${{ github.event.head_commit.message }} - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./build - - name: Generate Changelog id: changelog uses: jaywcjlove/changelog-generator@main From 3a16f54cffb3e893fe00ca6228ed70f5f28d34b4 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 29 Nov 2022 16:22:13 +0000 Subject: [PATCH 37/42] doc: update test/overwrite.file.md. From 77ef22494742710d7410bd59d5d31f5ce05f93e0 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 29 Nov 2022 16:22:14 +0000 Subject: [PATCH 38/42] doc: update README.md. From 88f6fd97ed3fb2b7ec6b7aacee02e6fa25e502cd Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Wed, 30 Nov 2022 00:29:48 +0800 Subject: [PATCH 39/42] chore: update workflows config. --- .github/workflows/ci.yml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 282d8c4..b930349 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,6 +25,15 @@ jobs: body: "{{date:YYYY-MM-DD HH:mm:ss}}" overwrite: 'true' + - name: Modify test test/overwrite.file.md + # uses: github-action-modify-file-content@main + uses: ./ + with: + branch: test + path: test/overwrite.file.md + body: "{{date:YYYY-MM-DD HH:mm:ss}}" + overwrite: 'true' + - name: Modify README.md # uses: github-action-modify-file-content@main uses: ./ @@ -76,14 +85,6 @@ jobs: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./build - - name: Modify gh-pages README.md - # uses: github-action-modify-file-content@main - uses: ./ - with: - path: README.md - branch: gh-pages - body: "{{date:YYYY-MM-DD HH:mm:ss}}" - - name: Generate Changelog id: changelog uses: jaywcjlove/changelog-generator@main From d122e22edd8649209ee6fa42dd2f94ecf4fac71f Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 29 Nov 2022 16:31:21 +0000 Subject: [PATCH 40/42] doc: update test/overwrite.file.md. From 58e4b5581d8e3b61025c4e8b09888ae516a256aa Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 29 Nov 2022 16:31:23 +0000 Subject: [PATCH 41/42] doc: update README.md. From 0b7c967d5620ed43eb537e208dbef6863ce2930f Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Wed, 30 Nov 2022 00:34:24 +0800 Subject: [PATCH 42/42] released v1.4.1 #2 --- README.md | 14 +++++++++++++- package.json | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9bd30ef..30e5db9 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Here is the different delimiter example: different `GAMFC_TABE - `token` Your `GITHUB_TOKEN`. This is required. Why do we need `token`? Read more here: [About the GITHUB_TOKEN secret](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/authenticating-with-the-github_token#about-the-github_token-secret). Default: `${{ github.token }}` - `body` what needs to be replaced - `path` file to be replaced -- `branch` The person that committed the file. Default: the authenticated user +- `branch` The person that committed the file. Default: `${{ github.ref_name }}` - `ref` The name of the commit/branch/tag. Default: the repository’s default branch (usually `master`) - `overwrite` Overwrite the entire file content, by default `false` - `sync_local_file` Sync local file content, by default `true` @@ -64,6 +64,18 @@ Replace the content between `2022-11-29 07:18:44`. overwrite: 'true' ``` +### specify branch changes + +```yml +- name: Modify test test/overwrite.file.md + uses: github-action-modify-file-content@main + with: + branch: test + path: test/overwrite.file.md + body: "{{date:YYYY-MM-DD HH:mm:ss}}" + overwrite: 'true' +``` + ## See Also - [Github Release Changelog Generator](https://github.com/jaywcjlove/changelog-generator) A GitHub Action that compares the commit differences between two branches diff --git a/package.json b/package.json index 1d01688..a2091f8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "github-action-modify-file-content", - "version": "1.4.0", + "version": "1.4.1", "description": "Replace text content and submit content", "homepage": "https://github.com/jaywcjlove/github-action-modify-file-content#readme", "main": "dist/index.js",