@yukiakai/actions-git 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var H=Object.create;var y=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var B=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var M=(o,e)=>{for(var t in e)y(o,t,{get:e[t],enumerable:!0})},A=(o,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of V(e))!q.call(o,r)&&r!==t&&y(o,r,{get:()=>e[r],enumerable:!(i=Q(e,r))||i.enumerable});return o};var p=(o,e,t)=>(t=o!=null?H(B(o)):{},A(e||!o||!o.__esModule?y(t,"default",{value:o,enumerable:!0}):t,o)),X=o=>A(y({},"__esModule",{value:!0}),o);var le={};M(le,{GitClient:()=>G});module.exports=X(le);var x=p(require("os"),1),$=p(require("events"),1),I=p(require("child_process"),1),F=p(require("path"),1);var h=p(require("path"),1);var v=p(require("fs"),1),f=p(require("path"),1),T=function(o,e,t,i){function r(s){return s instanceof t?s:new t(function(n){n(s)})}return new(t||(t=Promise))(function(s,n){function a(c){try{l(i.next(c))}catch(d){n(d)}}function u(c){try{l(i.throw(c))}catch(d){n(d)}}function l(c){c.done?s(c.value):r(c.value).then(a,u)}l((i=i.apply(o,e||[])).next())})},{chmod:Y,copyFile:z,lstat:K,mkdir:Z,open:de,readdir:k,rename:J,rm:ee,rmdir:ue,stat:g,symlink:te,unlink:ie}=v.promises,m=process.platform==="win32";var he=v.constants.O_RDONLY;function C(o){return T(this,void 0,void 0,function*(){try{yield g(o)}catch(e){if(e.code==="ENOENT")return!1;throw e}return!0})}function E(o){if(o=re(o),!o)throw new Error('isRooted() parameter "p" cannot be empty');return m?o.startsWith("\\")||/^[A-Z]:/i.test(o):o.startsWith("/")}function S(o,e){return T(this,void 0,void 0,function*(){let t;try{t=yield g(o)}catch(r){r.code!=="ENOENT"&&console.log(`Unexpected error attempting to determine if executable file exists '${o}': ${r}`)}if(t&&t.isFile()){if(m){let r=f.extname(o).toUpperCase();if(e.some(s=>s.toUpperCase()===r))return o}else if(R(t))return o}let i=o;for(let r of e){o=i+r,t=void 0;try{t=yield g(o)}catch(s){s.code!=="ENOENT"&&console.log(`Unexpected error attempting to determine if executable file exists '${o}': ${s}`)}if(t&&t.isFile()){if(m){try{let s=f.dirname(o),n=f.basename(o).toUpperCase();for(let a of yield k(s))if(n===a.toUpperCase()){o=f.join(s,a);break}}catch(s){console.log(`Unexpected error attempting to determine the actual case of the file '${o}': ${s}`)}return o}else if(R(t))return o}}return""})}function re(o){return o=o||"",m?(o=o.replace(/\//g,"\\"),o.replace(/\\\\+/g,"\\")):o.replace(/\/\/+/g,"/")}function R(o){return(o.mode&1)>0||(o.mode&8)>0&&process.getgid!==void 0&&o.gid===process.getgid()||(o.mode&64)>0&&process.getuid!==void 0&&o.uid===process.getuid()}var D=function(o,e,t,i){function r(s){return s instanceof t?s:new t(function(n){n(s)})}return new(t||(t=Promise))(function(s,n){function a(c){try{l(i.next(c))}catch(d){n(d)}}function u(c){try{l(i.throw(c))}catch(d){n(d)}}function l(c){c.done?s(c.value):r(c.value).then(a,u)}l((i=i.apply(o,e||[])).next())})};function O(o,e){return D(this,void 0,void 0,function*(){if(!o)throw new Error("parameter 'tool' is required");if(e){let i=yield O(o,!1);if(!i)throw m?new Error(`Unable to locate executable file: ${o}. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also verify the file has a valid extension for an executable file.`):new Error(`Unable to locate executable file: ${o}. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.`);return i}let t=yield oe(o);return t&&t.length>0?t[0]:""})}function oe(o){return D(this,void 0,void 0,function*(){if(!o)throw new Error("parameter 'tool' is required");let e=[];if(m&&process.env.PATHEXT)for(let r of process.env.PATHEXT.split(h.delimiter))r&&e.push(r);if(E(o)){let r=yield S(o,e);return r?[r]:[]}if(o.includes(h.sep))return[];let t=[];if(process.env.PATH)for(let r of process.env.PATH.split(h.delimiter))r&&t.push(r);let i=[];for(let r of t){let s=yield S(h.join(r,o),e);s&&i.push(s)}return i})}var W=require("timers"),N=function(o,e,t,i){function r(s){return s instanceof t?s:new t(function(n){n(s)})}return new(t||(t=Promise))(function(s,n){function a(c){try{l(i.next(c))}catch(d){n(d)}}function u(c){try{l(i.throw(c))}catch(d){n(d)}}function l(c){c.done?s(c.value):r(c.value).then(a,u)}l((i=i.apply(o,e||[])).next())})},b=process.platform==="win32",_=class extends $.EventEmitter{constructor(e,t,i){if(super(),!e)throw new Error("Parameter 'toolPath' cannot be null or empty.");this.toolPath=e,this.args=t||[],this.options=i||{}}_debug(e){this.options.listeners&&this.options.listeners.debug&&this.options.listeners.debug(e)}_getCommandString(e,t){let i=this._getSpawnFileName(),r=this._getSpawnArgs(e),s=t?"":"[command]";if(b)if(this._isCmdFile()){s+=i;for(let n of r)s+=` ${n}`}else if(e.windowsVerbatimArguments){s+=`"${i}"`;for(let n of r)s+=` ${n}`}else{s+=this._windowsQuoteCmdArg(i);for(let n of r)s+=` ${this._windowsQuoteCmdArg(n)}`}else{s+=i;for(let n of r)s+=` ${n}`}return s}_processLineBuffer(e,t,i){try{let r=t+e.toString(),s=r.indexOf(x.EOL);for(;s>-1;){let n=r.substring(0,s);i(n),r=r.substring(s+x.EOL.length),s=r.indexOf(x.EOL)}return r}catch(r){return this._debug(`error processing line. Failed with error ${r}`),""}}_getSpawnFileName(){return b&&this._isCmdFile()?process.env.COMSPEC||"cmd.exe":this.toolPath}_getSpawnArgs(e){if(b&&this._isCmdFile()){let t=`/D /S /C "${this._windowsQuoteCmdArg(this.toolPath)}`;for(let i of this.args)t+=" ",t+=e.windowsVerbatimArguments?i:this._windowsQuoteCmdArg(i);return t+='"',[t]}return this.args}_endsWith(e,t){return e.endsWith(t)}_isCmdFile(){let e=this.toolPath.toUpperCase();return this._endsWith(e,".CMD")||this._endsWith(e,".BAT")}_windowsQuoteCmdArg(e){if(!this._isCmdFile())return this._uvQuoteCmdArg(e);if(!e)return'""';let t=[" "," ","&","(",")","[","]","{","}","^","=",";","!","'","+",",","`","~","|","<",">",'"'],i=!1;for(let n of e)if(t.some(a=>a===n)){i=!0;break}if(!i)return e;let r='"',s=!0;for(let n=e.length;n>0;n--)r+=e[n-1],s&&e[n-1]==="\\"?r+="\\":e[n-1]==='"'?(s=!0,r+='"'):s=!1;return r+='"',r.split("").reverse().join("")}_uvQuoteCmdArg(e){if(!e)return'""';if(!e.includes(" ")&&!e.includes(" ")&&!e.includes('"'))return e;if(!e.includes('"')&&!e.includes("\\"))return`"${e}"`;let t='"',i=!0;for(let r=e.length;r>0;r--)t+=e[r-1],i&&e[r-1]==="\\"?t+="\\":e[r-1]==='"'?(i=!0,t+="\\"):i=!1;return t+='"',t.split("").reverse().join("")}_cloneExecOptions(e){e=e||{};let t={cwd:e.cwd||process.cwd(),env:e.env||process.env,silent:e.silent||!1,windowsVerbatimArguments:e.windowsVerbatimArguments||!1,failOnStdErr:e.failOnStdErr||!1,ignoreReturnCode:e.ignoreReturnCode||!1,delay:e.delay||1e4};return t.outStream=e.outStream||process.stdout,t.errStream=e.errStream||process.stderr,t}_getSpawnOptions(e,t){e=e||{};let i={};return i.cwd=e.cwd,i.env=e.env,i.windowsVerbatimArguments=e.windowsVerbatimArguments||this._isCmdFile(),e.windowsVerbatimArguments&&(i.argv0=`"${t}"`),i}exec(){return N(this,void 0,void 0,function*(){return!E(this.toolPath)&&(this.toolPath.includes("/")||b&&this.toolPath.includes("\\"))&&(this.toolPath=F.resolve(process.cwd(),this.options.cwd||process.cwd(),this.toolPath)),this.toolPath=yield O(this.toolPath,!0),new Promise((e,t)=>N(this,void 0,void 0,function*(){this._debug(`exec tool: ${this.toolPath}`),this._debug("arguments:");for(let l of this.args)this._debug(` ${l}`);let i=this._cloneExecOptions(this.options);!i.silent&&i.outStream&&i.outStream.write(this._getCommandString(i)+x.EOL);let r=new U(i,this.toolPath);if(r.on("debug",l=>{this._debug(l)}),this.options.cwd&&!(yield C(this.options.cwd)))return t(new Error(`The cwd: ${this.options.cwd} does not exist!`));let s=this._getSpawnFileName(),n=I.spawn(s,this._getSpawnArgs(i),this._getSpawnOptions(this.options,s)),a="";n.stdout&&n.stdout.on("data",l=>{this.options.listeners&&this.options.listeners.stdout&&this.options.listeners.stdout(l),!i.silent&&i.outStream&&i.outStream.write(l),a=this._processLineBuffer(l,a,c=>{this.options.listeners&&this.options.listeners.stdline&&this.options.listeners.stdline(c)})});let u="";if(n.stderr&&n.stderr.on("data",l=>{r.processStderr=!0,this.options.listeners&&this.options.listeners.stderr&&this.options.listeners.stderr(l),!i.silent&&i.errStream&&i.outStream&&(i.failOnStdErr?i.errStream:i.outStream).write(l),u=this._processLineBuffer(l,u,c=>{this.options.listeners&&this.options.listeners.errline&&this.options.listeners.errline(c)})}),n.on("error",l=>{r.processError=l.message,r.processExited=!0,r.processClosed=!0,r.CheckComplete()}),n.on("exit",l=>{r.processExitCode=l,r.processExited=!0,this._debug(`Exit code ${l} received from tool '${this.toolPath}'`),r.CheckComplete()}),n.on("close",l=>{r.processExitCode=l,r.processExited=!0,r.processClosed=!0,this._debug(`STDIO streams have closed for tool '${this.toolPath}'`),r.CheckComplete()}),r.on("done",(l,c)=>{a.length>0&&this.emit("stdline",a),u.length>0&&this.emit("errline",u),n.removeAllListeners(),l?t(l):e(c)}),this.options.input){if(!n.stdin)throw new Error("child process missing stdin");n.stdin.end(this.options.input)}}))})}};function L(o){let e=[],t=!1,i=!1,r="";function s(n){i&&n!=='"'&&(r+="\\"),r+=n,i=!1}for(let n=0;n<o.length;n++){let a=o.charAt(n);if(a==='"'){i?s(a):t=!t;continue}if(a==="\\"&&i){s(a);continue}if(a==="\\"&&t){i=!0;continue}if(a===" "&&!t){r.length>0&&(e.push(r),r="");continue}s(a)}return r.length>0&&e.push(r.trim()),e}var U=class o extends $.EventEmitter{constructor(e,t){if(super(),this.processClosed=!1,this.processError="",this.processExitCode=0,this.processExited=!1,this.processStderr=!1,this.delay=1e4,this.done=!1,this.timeout=null,!t)throw new Error("toolPath must not be empty");this.options=e,this.toolPath=t,e.delay&&(this.delay=e.delay)}CheckComplete(){this.done||(this.processClosed?this._setResult():this.processExited&&(this.timeout=(0,W.setTimeout)(o.HandleTimeout,this.delay,this)))}_debug(e){this.emit("debug",e)}_setResult(){let e;this.processExited&&(this.processError?e=new Error(`There was an error when attempting to execute the process '${this.toolPath}'. This may indicate the process failed to start. Error: ${this.processError}`):this.processExitCode!==0&&!this.options.ignoreReturnCode?e=new Error(`The process '${this.toolPath}' failed with exit code ${this.processExitCode}`):this.processStderr&&this.options.failOnStdErr&&(e=new Error(`The process '${this.toolPath}' failed because one or more lines were written to the STDERR stream`))),this.timeout&&(clearTimeout(this.timeout),this.timeout=null),this.done=!0,this.emit("done",e,this.processExitCode)}static HandleTimeout(e){if(!e.done){if(!e.processClosed&&e.processExited){let t=`The STDIO streams did not close within ${e.delay/1e3} seconds of the exit event from process '${e.toolPath}'. This may indicate a child process inherited the STDIO streams and has not yet exited.`;e._debug(t)}e._setResult()}}};var ce=function(o,e,t,i){function r(s){return s instanceof t?s:new t(function(n){n(s)})}return new(t||(t=Promise))(function(s,n){function a(c){try{l(i.next(c))}catch(d){n(d)}}function u(c){try{l(i.throw(c))}catch(d){n(d)}}function l(c){c.done?s(c.value):r(c.value).then(a,u)}l((i=i.apply(o,e||[])).next())})};function j(o,e,t){return ce(this,void 0,void 0,function*(){let i=L(o);if(i.length===0)throw new Error("Parameter 'commandLine' cannot be null or empty.");let r=i[0];return e=i.slice(1).concat(e||[]),new _(r,e,t).exec()})}var G=class{constructor(e){this.options=e}get repoUrl(){let{repo:e,token:t}=this.options;return`https://x-access-token:${t}@github.com/${e}.git`}async execGitRaw(e,t){return{exitCode:await j("git",e,t)}}async execGit(e,t){return await this.execGitRaw(e,{cwd:this.options.cwd,...t})}async execGitInspectable(e,t){return await this.execGit(e,{...t,ignoreReturnCode:!0})}async clone(){let{branch:e,cwd:t}=this.options;(await this.execGitRaw(["clone","--depth=1","--branch",e,this.repoUrl,t],{ignoreReturnCode:!0})).exitCode!==0&&await this.execGitRaw(["clone",this.repoUrl,t])}async wipe(e){await this.execGit(["rm","-r","-f","--ignore-unmatch",...e]),await this.execGit(["clean","-fdx"])}async setup(){await this.execGit(["config","user.name","github-actions[bot]"]),await this.execGit(["config","user.email","github-actions[bot]@users.noreply.github.com"])}async checkout(){let{branch:e}=this.options;await this.branchExists(e)?await this.execGit(["checkout",e]):(await this.execGit(["checkout","--orphan",e]),await this.wipe(["."]))}async pullRebase(){let{branch:e}=this.options;await this.execGit(["pull","--rebase","origin",e])}async commit(e){await this.execGit(["commit","-m",e])}async add(e){await this.execGit(["add",...e])}async push(){let{branch:e}=this.options;await this.execGit(["push","origin",e])}async hasChanges(){let e=await this.execGitInspectable(["diff","--cached","--quiet"]);if(e.exitCode===0)return!1;if(e.exitCode===1)return!0;throw new Error(`git diff failed with exit code ${e.exitCode}`)}async branchExists(e){let t=await this.execGitInspectable(["ls-remote","--exit-code","--heads","origin",e]);if(t.exitCode===0)return!0;if(t.exitCode===2)return!1;throw new Error(`Failed to check remote branch "${e}" (exit code ${t.exitCode})`)}};0&&(module.exports={GitClient});
|
|
1
|
+
"use strict";var n=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var u=(i,t)=>{for(var e in t)n(i,e,{get:t[e],enumerable:!0})},l=(i,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of h(t))!x.call(i,s)&&s!==e&&n(i,s,{get:()=>t[s],enumerable:!(o=p(t,s))||o.enumerable});return i};var w=i=>l(n({},"__esModule",{value:!0}),i);var d={};u(d,{GitClient:()=>r});module.exports=w(d);var a=require("@actions/exec"),r=class{constructor(t){this.options=t}get repoUrl(){let{repo:t,token:e}=this.options;return`https://x-access-token:${e}@github.com/${t}.git`}async execGitRaw(t,e){return{exitCode:await(0,a.exec)("git",t,e)}}async execGit(t,e){return await this.execGitRaw(t,{cwd:this.options.cwd,...e})}async execGitInspectable(t,e){return await this.execGit(t,{...e,ignoreReturnCode:!0})}async clone(){let{branch:t,cwd:e}=this.options;(await this.execGitRaw(["clone","--depth=1","--branch",t,this.repoUrl,e],{ignoreReturnCode:!0})).exitCode!==0&&await this.execGitRaw(["clone",this.repoUrl,e])}async wipe(t){await this.execGit(["rm","-r","-f","--ignore-unmatch",...t]),await this.execGit(["clean","-fdx","--",...t])}async setup(){await this.execGit(["config","user.name","github-actions[bot]"]),await this.execGit(["config","user.email","github-actions[bot]@users.noreply.github.com"])}async checkout(){let{branch:t}=this.options;await this.branchExists(t)?await this.execGit(["checkout",t]):(await this.execGit(["checkout","--orphan",t]),await this.wipe(["."]))}async pullRebase(){let{branch:t}=this.options;await this.execGit(["pull","--rebase","origin",t])}async commit(t){await this.execGit(["commit","-m",t])}async add(t){await this.execGit(["add",...t])}async push(){let{branch:t}=this.options;await this.execGit(["push","origin",t])}async hasChanges(){let t=await this.execGitInspectable(["diff","--cached","--quiet"]);if(t.exitCode===0)return!1;if(t.exitCode===1)return!0;throw new Error(`git diff failed with exit code ${t.exitCode}`)}async branchExists(t){let e=await this.execGitInspectable(["ls-remote","--exit-code","--heads","origin",t]);if(e.exitCode===0)return!0;if(e.exitCode===2)return!1;throw new Error(`Failed to check remote branch "${t}" (exit code ${e.exitCode})`)}};0&&(module.exports={GitClient});
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as x from"os";import*as U from"events";import*as P from"child_process";import*as D from"path";import*as h from"path";import*as g from"fs";import*as f from"path";var G=function(o,e,t,i){function r(s){return s instanceof t?s:new t(function(n){n(s)})}return new(t||(t=Promise))(function(s,n){function a(c){try{l(i.next(c))}catch(d){n(d)}}function u(c){try{l(i.throw(c))}catch(d){n(d)}}function l(c){c.done?s(c.value):r(c.value).then(a,u)}l((i=i.apply(o,e||[])).next())})},{chmod:W,copyFile:L,lstat:j,mkdir:H,open:J,readdir:A,rename:Q,rm:V,rmdir:ee,stat:y,symlink:B,unlink:q}=g.promises,p=process.platform==="win32";var te=g.constants.O_RDONLY;function _(o){return G(this,void 0,void 0,function*(){try{yield y(o)}catch(e){if(e.code==="ENOENT")return!1;throw e}return!0})}function v(o){if(o=M(o),!o)throw new Error('isRooted() parameter "p" cannot be empty');return p?o.startsWith("\\")||/^[A-Z]:/i.test(o):o.startsWith("/")}function C(o,e){return G(this,void 0,void 0,function*(){let t;try{t=yield y(o)}catch(r){r.code!=="ENOENT"&&console.log(`Unexpected error attempting to determine if executable file exists '${o}': ${r}`)}if(t&&t.isFile()){if(p){let r=f.extname(o).toUpperCase();if(e.some(s=>s.toUpperCase()===r))return o}else if($(t))return o}let i=o;for(let r of e){o=i+r,t=void 0;try{t=yield y(o)}catch(s){s.code!=="ENOENT"&&console.log(`Unexpected error attempting to determine if executable file exists '${o}': ${s}`)}if(t&&t.isFile()){if(p){try{let s=f.dirname(o),n=f.basename(o).toUpperCase();for(let a of yield A(s))if(n===a.toUpperCase()){o=f.join(s,a);break}}catch(s){console.log(`Unexpected error attempting to determine the actual case of the file '${o}': ${s}`)}return o}else if($(t))return o}}return""})}function M(o){return o=o||"",p?(o=o.replace(/\//g,"\\"),o.replace(/\\\\+/g,"\\")):o.replace(/\/\/+/g,"/")}function $(o){return(o.mode&1)>0||(o.mode&8)>0&&process.getgid!==void 0&&o.gid===process.getgid()||(o.mode&64)>0&&process.getuid!==void 0&&o.uid===process.getuid()}var T=function(o,e,t,i){function r(s){return s instanceof t?s:new t(function(n){n(s)})}return new(t||(t=Promise))(function(s,n){function a(c){try{l(i.next(c))}catch(d){n(d)}}function u(c){try{l(i.throw(c))}catch(d){n(d)}}function l(c){c.done?s(c.value):r(c.value).then(a,u)}l((i=i.apply(o,e||[])).next())})};function S(o,e){return T(this,void 0,void 0,function*(){if(!o)throw new Error("parameter 'tool' is required");if(e){let i=yield S(o,!1);if(!i)throw p?new Error(`Unable to locate executable file: ${o}. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also verify the file has a valid extension for an executable file.`):new Error(`Unable to locate executable file: ${o}. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.`);return i}let t=yield X(o);return t&&t.length>0?t[0]:""})}function X(o){return T(this,void 0,void 0,function*(){if(!o)throw new Error("parameter 'tool' is required");let e=[];if(p&&process.env.PATHEXT)for(let r of process.env.PATHEXT.split(h.delimiter))r&&e.push(r);if(v(o)){let r=yield C(o,e);return r?[r]:[]}if(o.includes(h.sep))return[];let t=[];if(process.env.PATH)for(let r of process.env.PATH.split(h.delimiter))r&&t.push(r);let i=[];for(let r of t){let s=yield C(h.join(r,o),e);s&&i.push(s)}return i})}import{setTimeout as z}from"timers";var k=function(o,e,t,i){function r(s){return s instanceof t?s:new t(function(n){n(s)})}return new(t||(t=Promise))(function(s,n){function a(c){try{l(i.next(c))}catch(d){n(d)}}function u(c){try{l(i.throw(c))}catch(d){n(d)}}function l(c){c.done?s(c.value):r(c.value).then(a,u)}l((i=i.apply(o,e||[])).next())})},E=process.platform==="win32",b=class extends U.EventEmitter{constructor(e,t,i){if(super(),!e)throw new Error("Parameter 'toolPath' cannot be null or empty.");this.toolPath=e,this.args=t||[],this.options=i||{}}_debug(e){this.options.listeners&&this.options.listeners.debug&&this.options.listeners.debug(e)}_getCommandString(e,t){let i=this._getSpawnFileName(),r=this._getSpawnArgs(e),s=t?"":"[command]";if(E)if(this._isCmdFile()){s+=i;for(let n of r)s+=` ${n}`}else if(e.windowsVerbatimArguments){s+=`"${i}"`;for(let n of r)s+=` ${n}`}else{s+=this._windowsQuoteCmdArg(i);for(let n of r)s+=` ${this._windowsQuoteCmdArg(n)}`}else{s+=i;for(let n of r)s+=` ${n}`}return s}_processLineBuffer(e,t,i){try{let r=t+e.toString(),s=r.indexOf(x.EOL);for(;s>-1;){let n=r.substring(0,s);i(n),r=r.substring(s+x.EOL.length),s=r.indexOf(x.EOL)}return r}catch(r){return this._debug(`error processing line. Failed with error ${r}`),""}}_getSpawnFileName(){return E&&this._isCmdFile()?process.env.COMSPEC||"cmd.exe":this.toolPath}_getSpawnArgs(e){if(E&&this._isCmdFile()){let t=`/D /S /C "${this._windowsQuoteCmdArg(this.toolPath)}`;for(let i of this.args)t+=" ",t+=e.windowsVerbatimArguments?i:this._windowsQuoteCmdArg(i);return t+='"',[t]}return this.args}_endsWith(e,t){return e.endsWith(t)}_isCmdFile(){let e=this.toolPath.toUpperCase();return this._endsWith(e,".CMD")||this._endsWith(e,".BAT")}_windowsQuoteCmdArg(e){if(!this._isCmdFile())return this._uvQuoteCmdArg(e);if(!e)return'""';let t=[" "," ","&","(",")","[","]","{","}","^","=",";","!","'","+",",","`","~","|","<",">",'"'],i=!1;for(let n of e)if(t.some(a=>a===n)){i=!0;break}if(!i)return e;let r='"',s=!0;for(let n=e.length;n>0;n--)r+=e[n-1],s&&e[n-1]==="\\"?r+="\\":e[n-1]==='"'?(s=!0,r+='"'):s=!1;return r+='"',r.split("").reverse().join("")}_uvQuoteCmdArg(e){if(!e)return'""';if(!e.includes(" ")&&!e.includes(" ")&&!e.includes('"'))return e;if(!e.includes('"')&&!e.includes("\\"))return`"${e}"`;let t='"',i=!0;for(let r=e.length;r>0;r--)t+=e[r-1],i&&e[r-1]==="\\"?t+="\\":e[r-1]==='"'?(i=!0,t+="\\"):i=!1;return t+='"',t.split("").reverse().join("")}_cloneExecOptions(e){e=e||{};let t={cwd:e.cwd||process.cwd(),env:e.env||process.env,silent:e.silent||!1,windowsVerbatimArguments:e.windowsVerbatimArguments||!1,failOnStdErr:e.failOnStdErr||!1,ignoreReturnCode:e.ignoreReturnCode||!1,delay:e.delay||1e4};return t.outStream=e.outStream||process.stdout,t.errStream=e.errStream||process.stderr,t}_getSpawnOptions(e,t){e=e||{};let i={};return i.cwd=e.cwd,i.env=e.env,i.windowsVerbatimArguments=e.windowsVerbatimArguments||this._isCmdFile(),e.windowsVerbatimArguments&&(i.argv0=`"${t}"`),i}exec(){return k(this,void 0,void 0,function*(){return!v(this.toolPath)&&(this.toolPath.includes("/")||E&&this.toolPath.includes("\\"))&&(this.toolPath=D.resolve(process.cwd(),this.options.cwd||process.cwd(),this.toolPath)),this.toolPath=yield S(this.toolPath,!0),new Promise((e,t)=>k(this,void 0,void 0,function*(){this._debug(`exec tool: ${this.toolPath}`),this._debug("arguments:");for(let l of this.args)this._debug(` ${l}`);let i=this._cloneExecOptions(this.options);!i.silent&&i.outStream&&i.outStream.write(this._getCommandString(i)+x.EOL);let r=new O(i,this.toolPath);if(r.on("debug",l=>{this._debug(l)}),this.options.cwd&&!(yield _(this.options.cwd)))return t(new Error(`The cwd: ${this.options.cwd} does not exist!`));let s=this._getSpawnFileName(),n=P.spawn(s,this._getSpawnArgs(i),this._getSpawnOptions(this.options,s)),a="";n.stdout&&n.stdout.on("data",l=>{this.options.listeners&&this.options.listeners.stdout&&this.options.listeners.stdout(l),!i.silent&&i.outStream&&i.outStream.write(l),a=this._processLineBuffer(l,a,c=>{this.options.listeners&&this.options.listeners.stdline&&this.options.listeners.stdline(c)})});let u="";if(n.stderr&&n.stderr.on("data",l=>{r.processStderr=!0,this.options.listeners&&this.options.listeners.stderr&&this.options.listeners.stderr(l),!i.silent&&i.errStream&&i.outStream&&(i.failOnStdErr?i.errStream:i.outStream).write(l),u=this._processLineBuffer(l,u,c=>{this.options.listeners&&this.options.listeners.errline&&this.options.listeners.errline(c)})}),n.on("error",l=>{r.processError=l.message,r.processExited=!0,r.processClosed=!0,r.CheckComplete()}),n.on("exit",l=>{r.processExitCode=l,r.processExited=!0,this._debug(`Exit code ${l} received from tool '${this.toolPath}'`),r.CheckComplete()}),n.on("close",l=>{r.processExitCode=l,r.processExited=!0,r.processClosed=!0,this._debug(`STDIO streams have closed for tool '${this.toolPath}'`),r.CheckComplete()}),r.on("done",(l,c)=>{a.length>0&&this.emit("stdline",a),u.length>0&&this.emit("errline",u),n.removeAllListeners(),l?t(l):e(c)}),this.options.input){if(!n.stdin)throw new Error("child process missing stdin");n.stdin.end(this.options.input)}}))})}};function N(o){let e=[],t=!1,i=!1,r="";function s(n){i&&n!=='"'&&(r+="\\"),r+=n,i=!1}for(let n=0;n<o.length;n++){let a=o.charAt(n);if(a==='"'){i?s(a):t=!t;continue}if(a==="\\"&&i){s(a);continue}if(a==="\\"&&t){i=!0;continue}if(a===" "&&!t){r.length>0&&(e.push(r),r="");continue}s(a)}return r.length>0&&e.push(r.trim()),e}var O=class o extends U.EventEmitter{constructor(e,t){if(super(),this.processClosed=!1,this.processError="",this.processExitCode=0,this.processExited=!1,this.processStderr=!1,this.delay=1e4,this.done=!1,this.timeout=null,!t)throw new Error("toolPath must not be empty");this.options=e,this.toolPath=t,e.delay&&(this.delay=e.delay)}CheckComplete(){this.done||(this.processClosed?this._setResult():this.processExited&&(this.timeout=z(o.HandleTimeout,this.delay,this)))}_debug(e){this.emit("debug",e)}_setResult(){let e;this.processExited&&(this.processError?e=new Error(`There was an error when attempting to execute the process '${this.toolPath}'. This may indicate the process failed to start. Error: ${this.processError}`):this.processExitCode!==0&&!this.options.ignoreReturnCode?e=new Error(`The process '${this.toolPath}' failed with exit code ${this.processExitCode}`):this.processStderr&&this.options.failOnStdErr&&(e=new Error(`The process '${this.toolPath}' failed because one or more lines were written to the STDERR stream`))),this.timeout&&(clearTimeout(this.timeout),this.timeout=null),this.done=!0,this.emit("done",e,this.processExitCode)}static HandleTimeout(e){if(!e.done){if(!e.processClosed&&e.processExited){let t=`The STDIO streams did not close within ${e.delay/1e3} seconds of the exit event from process '${e.toolPath}'. This may indicate a child process inherited the STDIO streams and has not yet exited.`;e._debug(t)}e._setResult()}}};var Z=function(o,e,t,i){function r(s){return s instanceof t?s:new t(function(n){n(s)})}return new(t||(t=Promise))(function(s,n){function a(c){try{l(i.next(c))}catch(d){n(d)}}function u(c){try{l(i.throw(c))}catch(d){n(d)}}function l(c){c.done?s(c.value):r(c.value).then(a,u)}l((i=i.apply(o,e||[])).next())})};function I(o,e,t){return Z(this,void 0,void 0,function*(){let i=N(o);if(i.length===0)throw new Error("Parameter 'commandLine' cannot be null or empty.");let r=i[0];return e=i.slice(1).concat(e||[]),new b(r,e,t).exec()})}var F=class{constructor(e){this.options=e}get repoUrl(){let{repo:e,token:t}=this.options;return`https://x-access-token:${t}@github.com/${e}.git`}async execGitRaw(e,t){return{exitCode:await I("git",e,t)}}async execGit(e,t){return await this.execGitRaw(e,{cwd:this.options.cwd,...t})}async execGitInspectable(e,t){return await this.execGit(e,{...t,ignoreReturnCode:!0})}async clone(){let{branch:e,cwd:t}=this.options;(await this.execGitRaw(["clone","--depth=1","--branch",e,this.repoUrl,t],{ignoreReturnCode:!0})).exitCode!==0&&await this.execGitRaw(["clone",this.repoUrl,t])}async wipe(e){await this.execGit(["rm","-r","-f","--ignore-unmatch",...e]),await this.execGit(["clean","-fdx"])}async setup(){await this.execGit(["config","user.name","github-actions[bot]"]),await this.execGit(["config","user.email","github-actions[bot]@users.noreply.github.com"])}async checkout(){let{branch:e}=this.options;await this.branchExists(e)?await this.execGit(["checkout",e]):(await this.execGit(["checkout","--orphan",e]),await this.wipe(["."]))}async pullRebase(){let{branch:e}=this.options;await this.execGit(["pull","--rebase","origin",e])}async commit(e){await this.execGit(["commit","-m",e])}async add(e){await this.execGit(["add",...e])}async push(){let{branch:e}=this.options;await this.execGit(["push","origin",e])}async hasChanges(){let e=await this.execGitInspectable(["diff","--cached","--quiet"]);if(e.exitCode===0)return!1;if(e.exitCode===1)return!0;throw new Error(`git diff failed with exit code ${e.exitCode}`)}async branchExists(e){let t=await this.execGitInspectable(["ls-remote","--exit-code","--heads","origin",e]);if(t.exitCode===0)return!0;if(t.exitCode===2)return!1;throw new Error(`Failed to check remote branch "${e}" (exit code ${t.exitCode})`)}};export{F as GitClient};
|
|
1
|
+
import{exec as r}from"@actions/exec";var i=class{constructor(t){this.options=t}get repoUrl(){let{repo:t,token:e}=this.options;return`https://x-access-token:${e}@github.com/${t}.git`}async execGitRaw(t,e){return{exitCode:await r("git",t,e)}}async execGit(t,e){return await this.execGitRaw(t,{cwd:this.options.cwd,...e})}async execGitInspectable(t,e){return await this.execGit(t,{...e,ignoreReturnCode:!0})}async clone(){let{branch:t,cwd:e}=this.options;(await this.execGitRaw(["clone","--depth=1","--branch",t,this.repoUrl,e],{ignoreReturnCode:!0})).exitCode!==0&&await this.execGitRaw(["clone",this.repoUrl,e])}async wipe(t){await this.execGit(["rm","-r","-f","--ignore-unmatch",...t]),await this.execGit(["clean","-fdx","--",...t])}async setup(){await this.execGit(["config","user.name","github-actions[bot]"]),await this.execGit(["config","user.email","github-actions[bot]@users.noreply.github.com"])}async checkout(){let{branch:t}=this.options;await this.branchExists(t)?await this.execGit(["checkout",t]):(await this.execGit(["checkout","--orphan",t]),await this.wipe(["."]))}async pullRebase(){let{branch:t}=this.options;await this.execGit(["pull","--rebase","origin",t])}async commit(t){await this.execGit(["commit","-m",t])}async add(t){await this.execGit(["add",...t])}async push(){let{branch:t}=this.options;await this.execGit(["push","origin",t])}async hasChanges(){let t=await this.execGitInspectable(["diff","--cached","--quiet"]);if(t.exitCode===0)return!1;if(t.exitCode===1)return!0;throw new Error(`git diff failed with exit code ${t.exitCode}`)}async branchExists(t){let e=await this.execGitInspectable(["ls-remote","--exit-code","--heads","origin",t]);if(e.exitCode===0)return!0;if(e.exitCode===2)return!1;throw new Error(`Failed to check remote branch "${t}" (exit code ${e.exitCode})`)}};export{i as GitClient};
|