UNPKG

github-badge-action

Version:

Create a badge using GitHub Actions inputs & outputs, and save it into a file

3 lines (2 loc) 1.14 kB
var t=require("@actions/core"),e=require("gradient-badge"),a=require("fs");function n(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var i=/*#__PURE__*/n(e),s=/*#__PURE__*/n(a);const o={label:"label",labelColor:"label-color",status:"status",gradient:"color",style:"style",icon:"icon",iconWidth:"icon-width",scale:"scale",path:"path"},r={status:({status:t})=>`${t}`,icon:({icon:t})=>t?.length?t:null,gradient:({gradient:t})=>t.split(",").map(t=>t.trim(" "))};exports.createBadgeFromInputs=({inputMap:e=o,inputFixes:a=r,outputName:n="badge"}={})=>{try{const o=Object.entries(e).reduce((e,[a,n])=>({...e,[a]:t.getInput(n)}),{});t.debug("Received inputs:",o);for(const[t,e]of Object.entries(a))o[t]=e(o);t.info("Generate badge using the given inputs and defaults:",o);const{path:r,...u}=o,l=i.default(u);n?.length&&(t.info("Write data to action's output 'badge'..."),t.setOutput(n,l)),r?.length&&(t.info(`Write data to file ${r}...`),s.default.writeFileSync(r,l),t.info("Data saved succesfully."))}catch(e){t.error(e),t.setFailed(e.message)}},exports.defaultInputFixes=r,exports.defaultInputMap=o; //# sourceMappingURL=index.js.map