diff --git a/dist/blog-post-workflow.js b/dist/blog-post-workflow.js index 999ed87..0d1fce6 100644 --- a/dist/blog-post-workflow.js +++ b/dist/blog-post-workflow.js @@ -126,12 +126,10 @@ var r=require("./retry_operation");exports.operation=function(t){var e=exports.t module.exports=require("./lib/retry"); },{"./lib/retry":"Wk2y"}],"gnqO":[function(require,module,exports) { "use strict";var r=require("err-code"),e=require("retry"),t=Object.prototype.hasOwnProperty;function n(r){return r&&"EPROMISERETRY"===r.code&&t.call(r,"retried")}function o(t,o){var i,u;return"object"==typeof t&&"function"==typeof o&&(i=o,o=t,t=i),u=e.operation(o),new Promise(function(e,o){u.attempt(function(i){Promise.resolve().then(function(){return t(function(e){throw n(e)&&(e=e.retried),r(new Error("Retrying"),"EPROMISERETRY",{retried:e})},i)}).then(e,function(r){n(r)&&(r=r.retried,u.retry(r||new Error))||o(r)})})})}module.exports=o; -},{"err-code":"JPoj","retry":"NFGJ"}],"EQNY":[function(require,module,exports) { -const{execute:t}=require("util"),e=async(e,i,o,a,r)=>new Promise(async(n,c)=>{try{const{outputData:p}=await t("git",["--no-pager","log","-1","--format=%ct"],{encoding:"utf8",stdio:["pipe","pipe","pipe"]}),m=new Date(1e3*parseInt(p,10));Math.round((new Date-m)/864e5)>r?(await t("git",["config","--global","user.email",o]),await t("git",["remote","set-url","origin",`https://${e}@github.com/${process.env.GITHUB_REPOSITORY}.git`]),await t("git",["config","--global","user.name",i]),await t("git",["commit","--allow-empty","-m",`"${a}"`]),n("Dummy commit created to keep the repository active...")):n("Nothing to do...")}catch(g){c(g.toString())}});module.exports={KeepAliveWorkflow:e}; -},{}],"FOZT":[function(require,module,exports) { +},{"err-code":"JPoj","retry":"NFGJ"}],"FOZT":[function(require,module,exports) { function e(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function t(t){for(var r=1;rnew Promise((o,c)=>{let a="";const s=t({},i);s.stdio||Object.assign(s,{stdio:["inherit","inherit","inherit"]});const u=r(e,n,s);u.stdout&&u.stdout.on("data",function(e){a+=e.toString()}),u.on("close",e=>0!==e?c({code:e,outputData:a}):o({code:e,outputData:a})),u.on("error",()=>c({code:1,outputData:a}))}),c=(e,t)=>{const n=i.getInput("comment_tag_name"),r=n?`\x3c!-- ${n}:`:"\x3c!-- BLOG-POST-LIST:",o="true"===i.getInput("tag_post_pre_newline"),c=e.indexOf(`${r}START`),a=e.indexOf("--\x3e",c),s=e.indexOf(`${r}END`,a);return-1!==c&&-1!==a&&-1!==s||(i.error(`Cannot find the comment tag on the readme:\n${r}START --\x3e\n${r}END --\x3e`),process.exit(1)),[e.slice(0,a+"--\x3e".length),o?"\n":"",t,o?"\n":"",e.slice(s)].join("")},a=(e,t)=>{const n=e.trim(),r=[...n].slice(0,t).join("");return r===n?n:r.trim()+"..."},s=async(e,t)=>{const n=i.getInput("committer_username"),r=i.getInput("committer_email"),c=i.getInput("commit_message");await o("git",["config","--global","user.email",r]),e&&await o("git",["remote","set-url","origin",`https://${e}@github.com/${process.env.GITHUB_REPOSITORY}.git`]),await o("git",["config","--global","user.name",n]),await o("git",["add",...t]),await o("git",["commit","-m",c]),await o("git",["push"]),i.info("Readme updated successfully in the upstream repository")},u=(e,t)=>{const n=e.split("/");return 3===n.length?(Object.assign(t,{[n[0]]:n[1]}),n[0]):e},m=(e,t)=>{const n="$"+t+"(";if(e.indexOf(n)>-1){const t=e.indexOf(n)+n.length,r=e.indexOf(")",t);return-1===r?null:e.slice(t,r).split(",").map(e=>e.trim())}return null};module.exports={updateAndParseCompoundParams:u,commitReadme:s,truncateString:a,buildReadme:c,exec:o,getParameterisedTemplate:m}; },{"@actions/core":"FTVr"}],"KSDV":[function(require,module,exports) { const{updateAndParseCompoundParams:e}=require("./utils"),t=require("@actions/core"),o={stackoverflow:"Comment by $author",stackexchange:"Comment by $author"},a=t.getInput("filter_comments").trim().split(",").map(t=>(t=t.trim()).startsWith("stackoverflow")||t.startsWith("stackexchange")?e(t,o):t),i=e=>!(-1!==a.indexOf("medium")&&e.link&&e.link.includes("medium.com")&&void 0===e.categories),r=e=>!(-1!==a.indexOf("stackoverflow")&&e.link&&e.link.includes("stackoverflow.com")&&e.title.startsWith(o.stackoverflow.replace(/\$author/g,e.author))),s=e=>!(-1!==a.indexOf("stackexchange")&&e.link&&e.link.includes("stackexchange.com")&&e.title.startsWith(o.stackexchange.replace(/\$author/g,e.author)));module.exports={ignoreMediumComments:i,ignoreStackOverflowComments:r,ignoreStackExchangeComments:s}; },{"./utils":"FOZT","@actions/core":"FTVr"}],"MHPq":[function(require,module,exports) { -function ownKeys(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,o)}return r}function _objectSpread(e){for(var t=1;te.trim()),GITHUB_TOKEN=core.getInput("gh_token"),CUSTOM_TAGS={},ENABLE_KEEPALIVE="true"===core.getInput("enable_keepalive"),retryConfig={retries:Number.parseInt(core.getInput("retry_count")),factor:1,minTimeout:1e3*Number.parseInt(core.getInput("retry_wait_time"))};core.setSecret(GITHUB_TOKEN),core.getInput("custom_tags").trim().split(",").forEach(e=>{e=e.trim(),updateAndParseCompoundParams(e,CUSTOM_TAGS)});const promiseArray=[],runnerNameArray=[];let postsArray=[],jobFailFlag=!1;const feedObjString=core.getInput("feed_list").trim();let feedList=feedObjString.split(",").map(e=>e.trim());0===feedList.length&&(core.error("Please double check the value of feed_list"),process.exit(1));const feedNames=core.getInput("feed_names").trim(),feedNamesList=feedNames.split(",").map(e=>e.trim()),customTagArgs=Object.keys(CUSTOM_TAGS).map(e=>[CUSTOM_TAGS[e],e]);let parser=new Parser({headers:{"User-Agent":userAgent,Accept:acceptHeader},customFields:{item:[...customTagArgs]}});feedList.forEach(siteUrl=>{runnerNameArray.push(siteUrl),promiseArray.push(new Promise((resolve,reject)=>{promiseRetry((e,t)=>(t>1&&core.info(`Previous try for ${siteUrl} failed, retrying: ${t-1}`),parser.parseURL(siteUrl).catch(e)),retryConfig).then(data=>{if(data.items){const responsePosts=data.items,posts=responsePosts.filter(ignoreMediumComments).filter(ignoreStackOverflowComments).filter(ignoreStackExchangeComments).map(item=>{ENABLE_SORT&&!item.pubDate&&reject("Cannot read response->item->pubDate"),item.title||reject("Cannot read response->item->title"),item.link||reject("Cannot read response->item->link");let customTags={};Object.keys(CUSTOM_TAGS).forEach(e=>{item[e]&&Object.assign(customTags,{[e]:item[e]})});let post=_objectSpread({title:item.title.trim(),url:item.link.trim(),description:item.content?item.content:""},customTags);if(ENABLE_SORT&&(post.date=new Date(item.pubDate.trim())),ITEM_EXEC)try{eval(ITEM_EXEC)}catch(e){core.error("Failure in executing `item_exec` parameter"),core.error(e),process.exit(1)}if(TITLE_MAX_LENGTH&&post&&post.title&&(post.title=truncateString(post.title,TITLE_MAX_LENGTH)),DESCRIPTION_MAX_LENGTH&&post&&post.description){const e=post.description.trim();post.description=truncateString(e,DESCRIPTION_MAX_LENGTH)}return post});resolve(posts)}else reject("Cannot read response->item")},e=>{reject(e)})}))}),Promise.allSettled(promiseArray).then(e=>{e.forEach((e,t)=>{"fulfilled"===e.status?(core.info(runnerNameArray[t]+" runner succeeded. Post count: "+e.value.length),void 0!==typeof feedNamesList[t]&&feedNamesList[t]&&(e.value=e.value.map(e=>(e.feedName=feedNamesList[t],e))),postsArray.push(...e.value)):(jobFailFlag=!0,core.error(runnerNameArray[t]+" runner failed, please verify the configuration. Error:"),core.error(e.reason))})}).finally(async()=>{if(postsArray=postsArray.filter(e=>null!==e),ENABLE_SORT&&postsArray.sort(function(e,t){return t.date-e.date}),(postsArray=postsArray.slice(0,TOTAL_POST_COUNT)).length>0)try{process.env.TEST_MODE||(await exec("git",["config","pull.rebase","true"],{stdio:["pipe","pipe","pipe"]}),await exec("git",["pull"],{stdio:["pipe","pipe","pipe"]}));const t=core.getInput("template"),r=getParameterisedTemplate(t,"randomEmoji"),o=getParameterisedTemplate(t,"emojiKey"),s=postsArray.reduce((e,s,i)=>{if("default"===t)return e+`\n- [${s.title}](${s.url})`+(i+1===postsArray.length?"\n":"");{const a=dateFormat(s.date,core.getInput("date_format"));let n=t.replace(/\$title\b/g,s.title).replace(/\$url\b/g,s.url).replace(/\$description\b/g,s.description).replace(/\$date\b/g,a).replace(/\$counter\b/g,(i+1).toString()).replace(/\$feedName\b/g,s.feedName?s.feedName:"").replace(/\$newline/g,"\n");if(Object.keys(CUSTOM_TAGS).forEach(e=>{const t=s[e]?s[e]:"";n=n.replace(new RegExp("\\$"+e+"\\b","g"),t)}),r){const e=(process.env.GITHUB_REPOSITORY&&!process.env.TEST_MODE?process.env.GITHUB_REPOSITORY:"example")+i,t=r[rand.create(e).range(r.length)];n=n.replace(/\$randomEmoji\((\S)*\)/g,t)}return o&&(n=n.replace(/\$emojiKey\((\S)*\)/g,o[i%o.length])),e+n}},"");"false"!==core.getInput("output_only")&&(core.info("outputOnly mode: set `results` variable. Readme not committed."),core.setOutput("results",postsArray),process.exit(jobFailFlag?1:0));let i=0;if(README_FILE_PATH_LIST.forEach(e=>{const t=fs.readFileSync(e,"utf8"),r=buildReadme(t,s);r!==t&&(core.info("Writing to "+e),fs.writeFileSync(e,r),i+=1)}),i>0)process.env.TEST_MODE||await commitReadme(GITHUB_TOKEN,README_FILE_PATH_LIST).then(()=>{process.exit(jobFailFlag?1:0)});else{if(!process.env.TEST_MODE&&ENABLE_KEEPALIVE){core.info("Doing dummy commit to keep workflow active, see: https://git.io/Jtm4V");const e=core.getInput("committer_username"),t=core.getInput("committer_email"),r=await keepaliveWorkflow.KeepAliveWorkflow(GITHUB_TOKEN,e,t,"dummy commit to keep the repository active, see https://git.io/Jtm4V",50);core.info(r)}else core.info("No change detected, skipping");process.exit(jobFailFlag?1:0)}}catch(e){core.error(e),process.exit(1)}else core.info("0 blog posts fetched"),process.exit(jobFailFlag?1:0)}); -},{"rss-parser":"BF6Y","@actions/core":"FTVr","dateformat":"FWyg","random-seed":"KFkI","promise-retry":"gnqO","keepalive-workflow":"EQNY","./utils":"FOZT","./filters":"KSDV"}]},{},["MHPq"], null) \ No newline at end of file +function ownKeys(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,o)}return r}function _objectSpread(e){for(var t=1;te.trim()),GITHUB_TOKEN=core.getInput("gh_token"),CUSTOM_TAGS={},ENABLE_KEEPALIVE="true"===core.getInput("enable_keepalive"),retryConfig={retries:Number.parseInt(core.getInput("retry_count")),factor:1,minTimeout:1e3*Number.parseInt(core.getInput("retry_wait_time"))};core.setSecret(GITHUB_TOKEN),core.getInput("custom_tags").trim().split(",").forEach(e=>{e=e.trim(),updateAndParseCompoundParams(e,CUSTOM_TAGS)});const promiseArray=[],runnerNameArray=[];let postsArray=[],jobFailFlag=!1;const feedObjString=core.getInput("feed_list").trim();let feedList=feedObjString.split(",").map(e=>e.trim());0===feedList.length&&(core.error("Please double check the value of feed_list"),process.exit(1));const feedNames=core.getInput("feed_names").trim(),feedNamesList=feedNames.split(",").map(e=>e.trim()),customTagArgs=Object.keys(CUSTOM_TAGS).map(e=>[CUSTOM_TAGS[e],e]);let parser=new Parser({headers:{"User-Agent":userAgent,Accept:acceptHeader},customFields:{item:[...customTagArgs]}});feedList.forEach(siteUrl=>{runnerNameArray.push(siteUrl),promiseArray.push(new Promise((resolve,reject)=>{promiseRetry((e,t)=>(t>1&&core.info(`Previous try for ${siteUrl} failed, retrying: ${t-1}`),parser.parseURL(siteUrl).catch(e)),retryConfig).then(data=>{if(data.items){const responsePosts=data.items,posts=responsePosts.filter(ignoreMediumComments).filter(ignoreStackOverflowComments).filter(ignoreStackExchangeComments).map(item=>{ENABLE_SORT&&!item.pubDate&&reject("Cannot read response->item->pubDate"),item.title||reject("Cannot read response->item->title"),item.link||reject("Cannot read response->item->link");let customTags={};Object.keys(CUSTOM_TAGS).forEach(e=>{item[e]&&Object.assign(customTags,{[e]:item[e]})});let post=_objectSpread({title:item.title.trim(),url:item.link.trim(),description:item.content?item.content:""},customTags);if(ENABLE_SORT&&(post.date=new Date(item.pubDate.trim())),ITEM_EXEC)try{eval(ITEM_EXEC)}catch(e){core.error("Failure in executing `item_exec` parameter"),core.error(e),process.exit(1)}if(TITLE_MAX_LENGTH&&post&&post.title&&(post.title=truncateString(post.title,TITLE_MAX_LENGTH)),DESCRIPTION_MAX_LENGTH&&post&&post.description){const e=post.description.trim();post.description=truncateString(e,DESCRIPTION_MAX_LENGTH)}return post});resolve(posts)}else reject("Cannot read response->item")},e=>{reject(e)})}))}),Promise.allSettled(promiseArray).then(e=>{e.forEach((e,t)=>{"fulfilled"===e.status?(core.info(runnerNameArray[t]+" runner succeeded. Post count: "+e.value.length),void 0!==typeof feedNamesList[t]&&feedNamesList[t]&&(e.value=e.value.map(e=>(e.feedName=feedNamesList[t],e))),postsArray.push(...e.value)):(jobFailFlag=!0,core.error(runnerNameArray[t]+" runner failed, please verify the configuration. Error:"),core.error(e.reason))})}).finally(async()=>{if(postsArray=postsArray.filter(e=>null!==e),ENABLE_SORT&&postsArray.sort(function(e,t){return t.date-e.date}),(postsArray=postsArray.slice(0,TOTAL_POST_COUNT)).length>0)try{process.env.TEST_MODE||(await exec("git",["config","pull.rebase","true"],{stdio:["pipe","pipe","pipe"]}),await exec("git",["pull"],{stdio:["pipe","pipe","pipe"]}));const t=core.getInput("template"),r=getParameterisedTemplate(t,"randomEmoji"),o=getParameterisedTemplate(t,"emojiKey"),s=postsArray.reduce((e,s,a)=>{if("default"===t)return e+`\n- [${s.title}](${s.url})`+(a+1===postsArray.length?"\n":"");{const i=dateFormat(s.date,core.getInput("date_format"));let n=t.replace(/\$title\b/g,s.title).replace(/\$url\b/g,s.url).replace(/\$description\b/g,s.description).replace(/\$date\b/g,i).replace(/\$counter\b/g,(a+1).toString()).replace(/\$feedName\b/g,s.feedName?s.feedName:"").replace(/\$newline/g,"\n");if(Object.keys(CUSTOM_TAGS).forEach(e=>{const t=s[e]?s[e]:"";n=n.replace(new RegExp("\\$"+e+"\\b","g"),t)}),r){const e=(process.env.GITHUB_REPOSITORY&&!process.env.TEST_MODE?process.env.GITHUB_REPOSITORY:"example")+a,t=r[rand.create(e).range(r.length)];n=n.replace(/\$randomEmoji\((\S)*\)/g,t)}return o&&(n=n.replace(/\$emojiKey\((\S)*\)/g,o[a%o.length])),e+n}},"");"false"!==core.getInput("output_only")&&(core.info("outputOnly mode: set `results` variable. Readme not committed."),core.setOutput("results",postsArray),process.exit(jobFailFlag?1:0));let a=0;if(README_FILE_PATH_LIST.forEach(e=>{const t=fs.readFileSync(e,"utf8"),r=buildReadme(t,s);r!==t&&(core.info("Writing to "+e),fs.writeFileSync(e,r),a+=1)}),a>0)process.env.TEST_MODE||await commitReadme(GITHUB_TOKEN,README_FILE_PATH_LIST).then(()=>{process.exit(jobFailFlag?1:0)});else{const{outputData:e}=await exec("git",["--no-pager","log","-1","--format=%ct"],{encoding:"utf8",stdio:["pipe","pipe","pipe"]}),t=new Date(1e3*parseInt(e,10));Math.round((new Date-t)/864e5)>50&&!process.env.TEST_MODE&&ENABLE_KEEPALIVE?(core.info("Doing dummy commit to keep workflow active, see: https://git.io/Jtm4V"),await commitReadme(GITHUB_TOKEN,README_FILE_PATH_LIST,!0).then(()=>{process.exit(jobFailFlag?1:0)}),process.exit(0)):(core.info("No change detected, skipping"),process.exit(jobFailFlag?1:0))}}catch(e){core.error(e),process.exit(1)}else core.info("0 blog posts fetched"),process.exit(jobFailFlag?1:0)}); +},{"rss-parser":"BF6Y","@actions/core":"FTVr","dateformat":"FWyg","random-seed":"KFkI","promise-retry":"gnqO","./utils":"FOZT","./filters":"KSDV"}]},{},["MHPq"], null) \ No newline at end of file diff --git a/package.json b/package.json index 6612fc7..eb8cf3c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "blog-post-workflow", - "version": "1.5.9", + "version": "1.6.0", "description": "Allows you to show your latest blog posts on your github profile or project readme", "main": "blog-post-workflow.js", "scripts": {