diff --git a/.github/workflows/versioning.yml b/.github/workflows/versioning.yml new file mode 100644 index 00000000..aa076789 --- /dev/null +++ b/.github/workflows/versioning.yml @@ -0,0 +1,43 @@ +######################### +######################### +## Version GitHub Tags ## +######################### +######################### + +# +# Documentation: +# https://help.github.com/en/articles/workflow-syntax-for-github-actions +# + +########################## +# Name of the action job # +########################## +name: Keep GitHub tag versions up-to-date + +##################################################### +# Run the job when a release is published or edited # +##################################################### +on: + release: + types: [ published, edited ] + +################# +# Start the job # +################# +jobs: + actions-tagger: + runs-on: windows-latest + steps: + ############################# + # Check out the latest code # + ############################# + - uses: actions/checkout@v2.3.4 + + ###################### + # Run the tag action # + ###################### + - uses: Actions-R-Us/actions-tagger@v2.0.1 + with: + publish_latest_tag: true + env: + GITHUB_TOKEN: "${{secrets.GITHUB_TOKEN}}" diff --git a/dist/index.js b/dist/index.js index a928c37c..2f0d5915 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1 +1 @@ -module.exports=(()=>{"use strict";var __webpack_modules__={932:(module,__unused_webpack_exports,__nccwpck_require__)=>{const core=__nccwpck_require__(186);const path=__nccwpck_require__(622);const http=__nccwpck_require__(211);const fs=__nccwpck_require__(747);const config=__nccwpck_require__(570);const{notBlankOrElse:notBlankOrElse}=__nccwpck_require__(608);async function createSnapshot(e,t,n,r){try{const o=path.join(t,`${n}.${r}`);console.log(`\n Generating screenshot with parameters: url=${e}, file=${o}\n `);if(!fs.existsSync(t)){fs.mkdirSync(t)}const s=fs.createWriteStream(o);await http.get(e,e=>{e.pipe(s)});return o}catch(e){console.error(e)}}async function run(){const e=core.getInput("url");const t=notBlankOrElse(core.getInput("width"),config.width);const n=notBlankOrElse(core.getInput("height"),config.height);const r=notBlankOrElse(core.getInput("fullPage"),config.fullPage);const o=notBlankOrElse(core.getInput("encoding"),config.encoding);const s=notBlankOrElse(core.getInput("name"),config.name);const i=notBlankOrElse(core.getInput("path"),config.path);const a=notBlankOrElse(core.getInput("type"),config.type);const c=`${config.url}?url=${e}&width=${t}&height=${n}&fullPage=${r}&encoding=${o}&type=${a}`;const u=await createSnapshot(c,i,s,a);core.setOutput("image",u)}module.exports=run;if(require.main===require.cache[eval("__filename")]){run()}},351:function(e,t,n){var r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var n in e)if(Object.hasOwnProperty.call(e,n))t[n]=e[n];t["default"]=e;return t};Object.defineProperty(t,"__esModule",{value:true});const o=r(n(87));const s=n(278);function issueCommand(e,t,n){const r=new Command(e,t,n);process.stdout.write(r.toString()+o.EOL)}t.issueCommand=issueCommand;function issue(e,t=""){issueCommand(e,{},t)}t.issue=issue;const i="::";class Command{constructor(e,t,n){if(!e){e="missing.command"}this.command=e;this.properties=t;this.message=n}toString(){let e=i+this.command;if(this.properties&&Object.keys(this.properties).length>0){e+=" ";let t=true;for(const n in this.properties){if(this.properties.hasOwnProperty(n)){const r=this.properties[n];if(r){if(t){t=false}else{e+=","}e+=`${n}=${escapeProperty(r)}`}}}}e+=`${i}${escapeData(this.message)}`;return e}}function escapeData(e){return s.toCommandValue(e).replace(/%/g,"%25").replace(/\r/g,"%0D").replace(/\n/g,"%0A")}function escapeProperty(e){return s.toCommandValue(e).replace(/%/g,"%25").replace(/\r/g,"%0D").replace(/\n/g,"%0A").replace(/:/g,"%3A").replace(/,/g,"%2C")}},186:function(e,t,n){var r=this&&this.__awaiter||function(e,t,n,r){function adopt(e){return e instanceof n?e:new n(function(t){t(e)})}return new(n||(n=Promise))(function(n,o){function fulfilled(e){try{step(r.next(e))}catch(e){o(e)}}function rejected(e){try{step(r["throw"](e))}catch(e){o(e)}}function step(e){e.done?n(e.value):adopt(e.value).then(fulfilled,rejected)}step((r=r.apply(e,t||[])).next())})};var o=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var n in e)if(Object.hasOwnProperty.call(e,n))t[n]=e[n];t["default"]=e;return t};Object.defineProperty(t,"__esModule",{value:true});const s=n(351);const i=n(717);const a=n(278);const c=o(n(87));const u=o(n(622));var p;(function(e){e[e["Success"]=0]="Success";e[e["Failure"]=1]="Failure"})(p=t.ExitCode||(t.ExitCode={}));function exportVariable(e,t){const n=a.toCommandValue(t);process.env[e]=n;const r=process.env["GITHUB_ENV"]||"";if(r){const t="_GitHubActionsFileCommandDelimeter_";const r=`${e}<<${t}${c.EOL}${n}${c.EOL}${t}`;i.issueCommand("ENV",r)}else{s.issueCommand("set-env",{name:e},n)}}t.exportVariable=exportVariable;function setSecret(e){s.issueCommand("add-mask",{},e)}t.setSecret=setSecret;function addPath(e){const t=process.env["GITHUB_PATH"]||"";if(t){i.issueCommand("PATH",e)}else{s.issueCommand("add-path",{},e)}process.env["PATH"]=`${e}${u.delimiter}${process.env["PATH"]}`}t.addPath=addPath;function getInput(e,t){const n=process.env[`INPUT_${e.replace(/ /g,"_").toUpperCase()}`]||"";if(t&&t.required&&!n){throw new Error(`Input required and not supplied: ${e}`)}return n.trim()}t.getInput=getInput;function setOutput(e,t){s.issueCommand("set-output",{name:e},t)}t.setOutput=setOutput;function setCommandEcho(e){s.issue("echo",e?"on":"off")}t.setCommandEcho=setCommandEcho;function setFailed(e){process.exitCode=p.Failure;error(e)}t.setFailed=setFailed;function isDebug(){return process.env["RUNNER_DEBUG"]==="1"}t.isDebug=isDebug;function debug(e){s.issueCommand("debug",{},e)}t.debug=debug;function error(e){s.issue("error",e instanceof Error?e.toString():e)}t.error=error;function warning(e){s.issue("warning",e instanceof Error?e.toString():e)}t.warning=warning;function info(e){process.stdout.write(e+c.EOL)}t.info=info;function startGroup(e){s.issue("group",e)}t.startGroup=startGroup;function endGroup(){s.issue("endgroup")}t.endGroup=endGroup;function group(e,t){return r(this,void 0,void 0,function*(){startGroup(e);let n;try{n=yield t()}finally{endGroup()}return n})}t.group=group;function saveState(e,t){s.issueCommand("save-state",{name:e},t)}t.saveState=saveState;function getState(e){return process.env[`STATE_${e}`]||""}t.getState=getState},717:function(e,t,n){var r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var n in e)if(Object.hasOwnProperty.call(e,n))t[n]=e[n];t["default"]=e;return t};Object.defineProperty(t,"__esModule",{value:true});const o=r(n(747));const s=r(n(87));const i=n(278);function issueCommand(e,t){const n=process.env[`GITHUB_${e}`];if(!n){throw new Error(`Unable to find environment variable for file command ${e}`)}if(!o.existsSync(n)){throw new Error(`Missing file at path: ${n}`)}o.appendFileSync(n,`${i.toCommandValue(t)}${s.EOL}`,{encoding:"utf8"})}t.issueCommand=issueCommand},278:(e,t)=>{Object.defineProperty(t,"__esModule",{value:true});function toCommandValue(e){if(e===null||e===undefined){return""}else if(typeof e==="string"||e instanceof String){return e}return JSON.stringify(e)}t.toCommandValue=toCommandValue},570:e=>{const t={url:"https://styled-screenshots.vercel.app/api",name:"screenshot",path:"images",type:"png",encoding:"binary",fullPage:false,width:1024,height:768};e.exports=t},608:e=>{const t=(e,t)=>{return{shotSize:{width:e,height:t},windowSize:{width:e,height:t}}};const n=e=>{return e&&e.length>0};const r=e=>{return!e||/^\s*$/.test(e)};const o=(e,t)=>{return r(e)?t:e};const s=e=>{return`(${i(e)})`};const i=e=>{let t="";for(const n in e){if(Object.prototype.hasOwnProperty.call(e,n)){t+=`${n} => ${typeof e[n]==="object"?`[${i(e[n])}]`:`${+e[n]},`}`}}return t};e.exports={createOptions:t,toString:s,isNonEmptyString:n,isBlankString:r,notBlankOrElse:o}},747:e=>{e.exports=require("fs")},211:e=>{e.exports=require("https")},87:e=>{e.exports=require("os")},622:e=>{e.exports=require("path")}};var __webpack_module_cache__={};function __nccwpck_require__(e){if(__webpack_module_cache__[e]){return __webpack_module_cache__[e].exports}var t=__webpack_module_cache__[e]={exports:{}};var n=true;try{__webpack_modules__[e].call(t.exports,t,t.exports,__nccwpck_require__);n=false}finally{if(n)delete __webpack_module_cache__[e]}return t.exports}__nccwpck_require__.ab=__dirname+"/";return __nccwpck_require__(932)})(); \ No newline at end of file +module.exports=(()=>{"use strict";var __webpack_modules__={932:(module,__unused_webpack_exports,__nccwpck_require__)=>{const core=__nccwpck_require__(186);const path=__nccwpck_require__(622);const http=__nccwpck_require__(211);const fs=__nccwpck_require__(747);const config=__nccwpck_require__(570);const{notBlankOrElse:notBlankOrElse}=__nccwpck_require__(608);async function createSnapshot(e,t,n,r){const o=path.join(t,`${n}.${r}`);console.log(`\n Generating screenshot with parameters: url=${e}, file=${o}\n `);if(!fs.existsSync(t)){fs.mkdirSync(t)}const s=fs.createWriteStream(o);await http.get(e,e=>{e.pipe(s)});return o}async function run(){const e=core.getInput("url",{required:true});const t=notBlankOrElse(core.getInput("width"),config.width);const n=notBlankOrElse(core.getInput("height"),config.height);const r=notBlankOrElse(core.getInput("fullPage"),config.fullPage);const o=notBlankOrElse(core.getInput("encoding"),config.encoding);const s=notBlankOrElse(core.getInput("name"),config.name);const i=notBlankOrElse(core.getInput("path"),config.path);const a=notBlankOrElse(core.getInput("type"),config.type);const c=`${config.url}?url=${e}&width=${t}&height=${n}&fullPage=${r}&encoding=${o}&type=${a}`;try{const e=await createSnapshot(c,i,s,a);core.info(`Storing screenshot image by path: ${e}`);core.setOutput("image",e)}catch(e){core.setFailed(`Cannot create screenshot image by path: ${i}/${s}, message: ${e.message}`)}}module.exports=run;if(require.main===require.cache[eval("__filename")]){run()}},351:function(e,t,n){var r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var n in e)if(Object.hasOwnProperty.call(e,n))t[n]=e[n];t["default"]=e;return t};Object.defineProperty(t,"__esModule",{value:true});const o=r(n(87));const s=n(278);function issueCommand(e,t,n){const r=new Command(e,t,n);process.stdout.write(r.toString()+o.EOL)}t.issueCommand=issueCommand;function issue(e,t=""){issueCommand(e,{},t)}t.issue=issue;const i="::";class Command{constructor(e,t,n){if(!e){e="missing.command"}this.command=e;this.properties=t;this.message=n}toString(){let e=i+this.command;if(this.properties&&Object.keys(this.properties).length>0){e+=" ";let t=true;for(const n in this.properties){if(this.properties.hasOwnProperty(n)){const r=this.properties[n];if(r){if(t){t=false}else{e+=","}e+=`${n}=${escapeProperty(r)}`}}}}e+=`${i}${escapeData(this.message)}`;return e}}function escapeData(e){return s.toCommandValue(e).replace(/%/g,"%25").replace(/\r/g,"%0D").replace(/\n/g,"%0A")}function escapeProperty(e){return s.toCommandValue(e).replace(/%/g,"%25").replace(/\r/g,"%0D").replace(/\n/g,"%0A").replace(/:/g,"%3A").replace(/,/g,"%2C")}},186:function(e,t,n){var r=this&&this.__awaiter||function(e,t,n,r){function adopt(e){return e instanceof n?e:new n(function(t){t(e)})}return new(n||(n=Promise))(function(n,o){function fulfilled(e){try{step(r.next(e))}catch(e){o(e)}}function rejected(e){try{step(r["throw"](e))}catch(e){o(e)}}function step(e){e.done?n(e.value):adopt(e.value).then(fulfilled,rejected)}step((r=r.apply(e,t||[])).next())})};var o=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var n in e)if(Object.hasOwnProperty.call(e,n))t[n]=e[n];t["default"]=e;return t};Object.defineProperty(t,"__esModule",{value:true});const s=n(351);const i=n(717);const a=n(278);const c=o(n(87));const u=o(n(622));var p;(function(e){e[e["Success"]=0]="Success";e[e["Failure"]=1]="Failure"})(p=t.ExitCode||(t.ExitCode={}));function exportVariable(e,t){const n=a.toCommandValue(t);process.env[e]=n;const r=process.env["GITHUB_ENV"]||"";if(r){const t="_GitHubActionsFileCommandDelimeter_";const r=`${e}<<${t}${c.EOL}${n}${c.EOL}${t}`;i.issueCommand("ENV",r)}else{s.issueCommand("set-env",{name:e},n)}}t.exportVariable=exportVariable;function setSecret(e){s.issueCommand("add-mask",{},e)}t.setSecret=setSecret;function addPath(e){const t=process.env["GITHUB_PATH"]||"";if(t){i.issueCommand("PATH",e)}else{s.issueCommand("add-path",{},e)}process.env["PATH"]=`${e}${u.delimiter}${process.env["PATH"]}`}t.addPath=addPath;function getInput(e,t){const n=process.env[`INPUT_${e.replace(/ /g,"_").toUpperCase()}`]||"";if(t&&t.required&&!n){throw new Error(`Input required and not supplied: ${e}`)}return n.trim()}t.getInput=getInput;function setOutput(e,t){s.issueCommand("set-output",{name:e},t)}t.setOutput=setOutput;function setCommandEcho(e){s.issue("echo",e?"on":"off")}t.setCommandEcho=setCommandEcho;function setFailed(e){process.exitCode=p.Failure;error(e)}t.setFailed=setFailed;function isDebug(){return process.env["RUNNER_DEBUG"]==="1"}t.isDebug=isDebug;function debug(e){s.issueCommand("debug",{},e)}t.debug=debug;function error(e){s.issue("error",e instanceof Error?e.toString():e)}t.error=error;function warning(e){s.issue("warning",e instanceof Error?e.toString():e)}t.warning=warning;function info(e){process.stdout.write(e+c.EOL)}t.info=info;function startGroup(e){s.issue("group",e)}t.startGroup=startGroup;function endGroup(){s.issue("endgroup")}t.endGroup=endGroup;function group(e,t){return r(this,void 0,void 0,function*(){startGroup(e);let n;try{n=yield t()}finally{endGroup()}return n})}t.group=group;function saveState(e,t){s.issueCommand("save-state",{name:e},t)}t.saveState=saveState;function getState(e){return process.env[`STATE_${e}`]||""}t.getState=getState},717:function(e,t,n){var r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var n in e)if(Object.hasOwnProperty.call(e,n))t[n]=e[n];t["default"]=e;return t};Object.defineProperty(t,"__esModule",{value:true});const o=r(n(747));const s=r(n(87));const i=n(278);function issueCommand(e,t){const n=process.env[`GITHUB_${e}`];if(!n){throw new Error(`Unable to find environment variable for file command ${e}`)}if(!o.existsSync(n)){throw new Error(`Missing file at path: ${n}`)}o.appendFileSync(n,`${i.toCommandValue(t)}${s.EOL}`,{encoding:"utf8"})}t.issueCommand=issueCommand},278:(e,t)=>{Object.defineProperty(t,"__esModule",{value:true});function toCommandValue(e){if(e===null||e===undefined){return""}else if(typeof e==="string"||e instanceof String){return e}return JSON.stringify(e)}t.toCommandValue=toCommandValue},570:e=>{const t={url:"https://styled-screenshots.vercel.app/api",name:"screenshot",path:"images",type:"png",encoding:"binary",fullPage:false,width:1024,height:768};e.exports=t},608:e=>{const t=(e,t)=>{return{shotSize:{width:e,height:t},windowSize:{width:e,height:t}}};const n=e=>{return e&&e.length>0};const r=e=>{return!e||/^\s*$/.test(e)};const o=(e,t)=>{return r(e)?t:e};const s=e=>{return`(${i(e)})`};const i=e=>{let t="";for(const n in e){if(Object.prototype.hasOwnProperty.call(e,n)){t+=`${n} => ${typeof e[n]==="object"?`[${i(e[n])}]`:`${+e[n]},`}`}}return t};e.exports={createOptions:t,toString:s,isNonEmptyString:n,isBlankString:r,notBlankOrElse:o}},747:e=>{e.exports=require("fs")},211:e=>{e.exports=require("https")},87:e=>{e.exports=require("os")},622:e=>{e.exports=require("path")}};var __webpack_module_cache__={};function __nccwpck_require__(e){if(__webpack_module_cache__[e]){return __webpack_module_cache__[e].exports}var t=__webpack_module_cache__[e]={exports:{}};var n=true;try{__webpack_modules__[e].call(t.exports,t,t.exports,__nccwpck_require__);n=false}finally{if(n)delete __webpack_module_cache__[e]}return t.exports}__nccwpck_require__.ab=__dirname+"/";return __nccwpck_require__(932)})(); \ No newline at end of file diff --git a/index.js b/index.js index f173de45..6fb74be7 100644 --- a/index.js +++ b/index.js @@ -9,29 +9,25 @@ const config = require('./src/config'); const { notBlankOrElse } = require('./src/utils'); async function createSnapshot(url, filePath, fileName, fileExtension) { - try { - const imagePath = path.join(filePath, `${fileName}.${fileExtension}`); - console.log(` + const imagePath = path.join(filePath, `${fileName}.${fileExtension}`); + console.log(` Generating screenshot with parameters: url=${url}, file=${imagePath} `); - if (!fs.existsSync(filePath)) { - fs.mkdirSync(filePath); - } + if (!fs.existsSync(filePath)) { + fs.mkdirSync(filePath); + } - const image = fs.createWriteStream(imagePath); - await http.get(url, resp => { - resp.pipe(image); - }); + const image = fs.createWriteStream(imagePath); + await http.get(url, resp => { + resp.pipe(image); + }); - return imagePath; - } catch (e) { - console.error(e); - } + return imagePath; } async function run() { - const url = core.getInput('url'); + const url = core.getInput('url', { required: true }); const width = notBlankOrElse(core.getInput('width'), config.width); const height = notBlankOrElse(core.getInput('height'), config.height); const fullPage = notBlankOrElse(core.getInput('fullPage'), config.fullPage); @@ -43,9 +39,13 @@ async function run() { const target = `${config.url}?url=${url}&width=${width}&height=${height}&fullPage=${fullPage}&encoding=${encoding}&type=${fileExtension}`; - const imagePath = await createSnapshot(target, filePath, fileName, fileExtension); - - core.setOutput('image', imagePath); + try { + const imagePath = await createSnapshot(target, filePath, fileName, fileExtension); + core.info(`Storing screenshot image by path: ${imagePath}`); + core.setOutput('image', imagePath); + } catch (e) { + core.setFailed(`Cannot create screenshot image by path: ${filePath}/${fileName}, message: ${e.message}`); + } } module.exports = run;