From 8e3acd84f2249a7450c0635e227c180d0ca734cd Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Thu, 29 Dec 2022 15:46:56 +0100 Subject: [PATCH 01/46] start e2e --- .github/workflows/example.yml | 34 ++++++++++++++++++++++++++++++++++ .gitignore | 1 + 2 files changed, 35 insertions(+) create mode 100644 .github/workflows/example.yml diff --git a/.github/workflows/example.yml b/.github/workflows/example.yml new file mode 100644 index 0000000..be40520 --- /dev/null +++ b/.github/workflows/example.yml @@ -0,0 +1,34 @@ +name: e2e Test + +on: + push: + branches: + - main + +env: + TEST_PROJECT: ./test_project + + +jobs: + host: + + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [ ubuntu-latest ] + + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Create ssh keys + run: | + ssh-keygen -m PEM -t rsa -b 4096 + shell: bash + - name: Create project file + run: | + mkdir $TEST_PROJECT && cd $TEST_PROJECT + touch index.html + date +"%Y-%m-%d %H:%M:%S,%3N" >> index.html + cat index.html + shell: bash diff --git a/.gitignore b/.gitignore index dea9f6a..08910a6 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ node_modules/ # IDE .idea +.vscode From b1a31cce807a2d220dfb533fbcb589739429959c Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Thu, 29 Dec 2022 15:47:33 +0100 Subject: [PATCH 02/46] test on current branch --- .github/workflows/example.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/example.yml b/.github/workflows/example.yml index be40520..1f38892 100644 --- a/.github/workflows/example.yml +++ b/.github/workflows/example.yml @@ -3,7 +3,7 @@ name: e2e Test on: push: branches: - - main + - add-test env: TEST_PROJECT: ./test_project @@ -13,7 +13,7 @@ jobs: host: runs-on: ${{ matrix.os }} - + strategy: matrix: os: [ ubuntu-latest ] From cc49ab6239fc1a1308a3d64634816eb1099d5847 Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Thu, 29 Dec 2022 15:50:00 +0100 Subject: [PATCH 03/46] typo fix --- .github/workflows/example.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/example.yml b/.github/workflows/example.yml index 1f38892..e45d917 100644 --- a/.github/workflows/example.yml +++ b/.github/workflows/example.yml @@ -3,7 +3,7 @@ name: e2e Test on: push: branches: - - add-test + - add-tests env: TEST_PROJECT: ./test_project From 5f8d616f952eb705c21031ea1b137876503c011b Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Thu, 29 Dec 2022 15:51:02 +0100 Subject: [PATCH 04/46] fix branch name --- .github/workflows/example.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/example.yml b/.github/workflows/example.yml index e45d917..e90e988 100644 --- a/.github/workflows/example.yml +++ b/.github/workflows/example.yml @@ -3,7 +3,7 @@ name: e2e Test on: push: branches: - - add-tests + - feature/add-tests env: TEST_PROJECT: ./test_project From 416e17545e45a50cdaa57ecf40f37bf7d612d11c Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Thu, 29 Dec 2022 15:55:39 +0100 Subject: [PATCH 05/46] silent ssh-keygen --- .github/workflows/example.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/example.yml b/.github/workflows/example.yml index e90e988..16301b0 100644 --- a/.github/workflows/example.yml +++ b/.github/workflows/example.yml @@ -23,7 +23,7 @@ jobs: uses: actions/checkout@v3 - name: Create ssh keys run: | - ssh-keygen -m PEM -t rsa -b 4096 + ssh-keygen -m PEM -t rsa -b 4096 -q -f "$HOME/.ssh/id_rsa" -N "" shell: bash - name: Create project file run: | From 2fdbdb60e6303931d6c9faed1dd49eea1e225172 Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Thu, 29 Dec 2022 16:01:41 +0100 Subject: [PATCH 06/46] get host info --- .github/workflows/example.yml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/example.yml b/.github/workflows/example.yml index 16301b0..62678e3 100644 --- a/.github/workflows/example.yml +++ b/.github/workflows/example.yml @@ -7,6 +7,13 @@ on: env: TEST_PROJECT: ./test_project + EXAMPLE_REMOTE_HOST: + REMOTE_USER: + REMOTE_PORT: + ARGS: + SOURCE: + TARGET: + EXCLUDE: '' jobs: @@ -21,9 +28,14 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 - - name: Create ssh keys + - name: Get Host info run: | - ssh-keygen -m PEM -t rsa -b 4096 -q -f "$HOME/.ssh/id_rsa" -N "" + ls -l + ip addr show + whoami + - name: 1. Create ssh keys + run: | + ssh-keygen -m PEM -t rsa -b 4096 -f "$HOME/.ssh/id_rsa" -N "" shell: bash - name: Create project file run: | From a9382b67a2f81058872f8c4f0c969af4ffa4ef66 Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Thu, 29 Dec 2022 23:14:51 +0100 Subject: [PATCH 07/46] e2e docker --- .github/workflows/e2e.yml | 72 +++++++++++++++++++++++++++++++++++ .github/workflows/example.yml | 46 ---------------------- test/.dockerignore | 5 +++ test/Dockerfile | 11 ++++++ 4 files changed, 88 insertions(+), 46 deletions(-) create mode 100644 .github/workflows/e2e.yml delete mode 100644 .github/workflows/example.yml create mode 100644 test/.dockerignore create mode 100644 test/Dockerfile diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml new file mode 100644 index 0000000..94bf786 --- /dev/null +++ b/.github/workflows/e2e.yml @@ -0,0 +1,72 @@ +name: e2e Test + +on: + push: + branches: + - feature/add-tests + +env: + TEST_PROJECT: ./test_project + TEST_HOST_DOCKER: ./test + TEST_USER: kaja + REMOTE_USER: '' + REMOTE_PORT: '' + ARGS: '' + SOURCE: '' + TARGET: '' + EXCLUDE: '' + +jobs: + e2e: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: 1. Create ssh keys + run: | + ssh-keygen -m PEM -t rsa -b 4096 -f "$HOME/.ssh/id_rsa" -N "" + EXAMPLE_SSH_PRIVATE_KEY=$(cat $HOME/.ssh/id_rsa) + echo "EXAMPLE_SSH_PRIVATE_KEY=$EXAMPLE_SSH_PRIVATE_KEY" >> $GITHUB_ENV + ssh-add "$HOME/.ssh/id_rsa" + ssh-add -l + + - name: Build Host Server Image + working-directory: $TEST_HOST_DOCKER + run: | + docker build \ + -t ssh-host-image . \ + --build-arg ssh_pub_key="$(cat $HOME/.ssh/id_rsa.pub)" \ + --build-arg ssh_user=$TEST_USER \ + + - name: Start Host Server Container + working-directory: $TEST_HOST_DOCKER + run: | + docker run --name ssh-host-container -d ssh-host-image + + - name: Get IP of Host Server + run: | + docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ssh-host-container > ip.txt + cat ip.txt + EXAMPLE_REMOTE_HOST=$(cat ip.txt) + echo "EXAMPLE_REMOTE_HOST=$EXAMPLE_REMOTE_HOST" >> $GITHUB_ENV + + - name: Create project file + run: | + mkdir $TEST_PROJECT && cd $TEST_PROJECT + touch index.html + date +"%Y-%m-%d %H:%M:%S,%3N" >> index.html + cat index.html + + - name: e2e Test ssh-deploy action + uses: easingthemes/ssh-deploy@main + env: + SSH_PRIVATE_KEY: $EXAMPLE_SSH_PRIVATE_KEY + ARGS: "-rltgoDzvO" + SOURCE: "dist/" + REMOTE_HOST: $EXAMPLE_REMOTE_HOST + REMOTE_USER: $TEST_USER + TARGET: "/var/www/html/" + EXCLUDE: "/dist/, /node_modules/" + diff --git a/.github/workflows/example.yml b/.github/workflows/example.yml deleted file mode 100644 index 62678e3..0000000 --- a/.github/workflows/example.yml +++ /dev/null @@ -1,46 +0,0 @@ -name: e2e Test - -on: - push: - branches: - - feature/add-tests - -env: - TEST_PROJECT: ./test_project - EXAMPLE_REMOTE_HOST: - REMOTE_USER: - REMOTE_PORT: - ARGS: - SOURCE: - TARGET: - EXCLUDE: '' - - -jobs: - host: - - runs-on: ${{ matrix.os }} - - strategy: - matrix: - os: [ ubuntu-latest ] - - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Get Host info - run: | - ls -l - ip addr show - whoami - - name: 1. Create ssh keys - run: | - ssh-keygen -m PEM -t rsa -b 4096 -f "$HOME/.ssh/id_rsa" -N "" - shell: bash - - name: Create project file - run: | - mkdir $TEST_PROJECT && cd $TEST_PROJECT - touch index.html - date +"%Y-%m-%d %H:%M:%S,%3N" >> index.html - cat index.html - shell: bash diff --git a/test/.dockerignore b/test/.dockerignore new file mode 100644 index 0000000..a612c4f --- /dev/null +++ b/test/.dockerignore @@ -0,0 +1,5 @@ +/node_modules +.gitignore +.gitattributes +LICENSE +README.md \ No newline at end of file diff --git a/test/Dockerfile b/test/Dockerfile new file mode 100644 index 0000000..babab6a --- /dev/null +++ b/test/Dockerfile @@ -0,0 +1,11 @@ +FROM nginx +# Set args to get from Gtihub Action +ARG ssh_pub_key +ARG ssh_user +# Add a user to the container +RUN adduser -D $ssh_user +USER $ssh_user +# Add the ssh public key to the container +RUN mkdir -p $HOME/.ssh +RUN echo "$ssh_pub_key" > $HOME/.ssh/authorized_keys +RUN chmod 700 $HOME/.ssh From a3412294d1af2e8f5e12798b5163eb0262982f5a Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Thu, 29 Dec 2022 23:28:40 +0100 Subject: [PATCH 08/46] remove unused envs --- .github/workflows/e2e.yml | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 94bf786..d0e0bbf 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -9,12 +9,6 @@ env: TEST_PROJECT: ./test_project TEST_HOST_DOCKER: ./test TEST_USER: kaja - REMOTE_USER: '' - REMOTE_PORT: '' - ARGS: '' - SOURCE: '' - TARGET: '' - EXCLUDE: '' jobs: e2e: @@ -28,7 +22,7 @@ jobs: run: | ssh-keygen -m PEM -t rsa -b 4096 -f "$HOME/.ssh/id_rsa" -N "" EXAMPLE_SSH_PRIVATE_KEY=$(cat $HOME/.ssh/id_rsa) - echo "EXAMPLE_SSH_PRIVATE_KEY=$EXAMPLE_SSH_PRIVATE_KEY" >> $GITHUB_ENV + echo "EXAMPLE_SSH_PRIVATE_KEY=$EXAMPLE_SSH_PRIVATE_KEY<> $GITHUB_ENV ssh-add "$HOME/.ssh/id_rsa" ssh-add -l @@ -58,7 +52,7 @@ jobs: touch index.html date +"%Y-%m-%d %H:%M:%S,%3N" >> index.html cat index.html - + - name: e2e Test ssh-deploy action uses: easingthemes/ssh-deploy@main env: From d334a45df7431b7509fa1ce5e4a1591fd8736d45 Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Fri, 30 Dec 2022 10:29:20 +0100 Subject: [PATCH 09/46] fix paths --- .github/workflows/e2e.yml | 29 ++++++++++++++++++----------- test/Dockerfile | 2 +- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index d0e0bbf..0aa67c1 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -6,7 +6,6 @@ on: - feature/add-tests env: - TEST_PROJECT: ./test_project TEST_HOST_DOCKER: ./test TEST_USER: kaja @@ -18,16 +17,23 @@ jobs: - name: Checkout uses: actions/checkout@v3 + - name: Clean up old test files + run: | + docker stop ssh-host-container || true && docker rm ssh-host-container || true + - name: 1. Create ssh keys run: | + echo $HOME + ls -la $HOME ssh-keygen -m PEM -t rsa -b 4096 -f "$HOME/.ssh/id_rsa" -N "" - EXAMPLE_SSH_PRIVATE_KEY=$(cat $HOME/.ssh/id_rsa) - echo "EXAMPLE_SSH_PRIVATE_KEY=$EXAMPLE_SSH_PRIVATE_KEY<> $GITHUB_ENV - ssh-add "$HOME/.ssh/id_rsa" - ssh-add -l + # ssh-add "$HOME/.ssh/id_rsa" + # ssh-add -l + echo "EXAMPLE_SSH_PRIVATE_KEY<> $GITHUB_ENV + cat $HOME/.ssh/id_rsa >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV - name: Build Host Server Image - working-directory: $TEST_HOST_DOCKER + working-directory: ${{ env.TEST_HOST_DOCKER }} run: | docker build \ -t ssh-host-image . \ @@ -35,7 +41,7 @@ jobs: --build-arg ssh_user=$TEST_USER \ - name: Start Host Server Container - working-directory: $TEST_HOST_DOCKER + working-directory: ${{ env.TEST_HOST_DOCKER }} run: | docker run --name ssh-host-container -d ssh-host-image @@ -48,7 +54,8 @@ jobs: - name: Create project file run: | - mkdir $TEST_PROJECT && cd $TEST_PROJECT + mkdir test_project + cd test_project touch index.html date +"%Y-%m-%d %H:%M:%S,%3N" >> index.html cat index.html @@ -56,10 +63,10 @@ jobs: - name: e2e Test ssh-deploy action uses: easingthemes/ssh-deploy@main env: - SSH_PRIVATE_KEY: $EXAMPLE_SSH_PRIVATE_KEY + SSH_PRIVATE_KEY: env.EXAMPLE_SSH_PRIVATE_KEY ARGS: "-rltgoDzvO" - SOURCE: "dist/" - REMOTE_HOST: $EXAMPLE_REMOTE_HOST + SOURCE: "test_project/" + REMOTE_HOST: env.EXAMPLE_REMOTE_HOST REMOTE_USER: $TEST_USER TARGET: "/var/www/html/" EXCLUDE: "/dist/, /node_modules/" diff --git a/test/Dockerfile b/test/Dockerfile index babab6a..23ca795 100644 --- a/test/Dockerfile +++ b/test/Dockerfile @@ -3,7 +3,7 @@ FROM nginx ARG ssh_pub_key ARG ssh_user # Add a user to the container -RUN adduser -D $ssh_user +RUN adduser --disabled-password $ssh_user USER $ssh_user # Add the ssh public key to the container RUN mkdir -p $HOME/.ssh From f7c067b07e56eeb667396f4eb7bd0ec839de4874 Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Fri, 30 Dec 2022 11:21:24 +0100 Subject: [PATCH 10/46] fix env --- .github/workflows/e2e.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 0aa67c1..797bd4e 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -38,7 +38,7 @@ jobs: docker build \ -t ssh-host-image . \ --build-arg ssh_pub_key="$(cat $HOME/.ssh/id_rsa.pub)" \ - --build-arg ssh_user=$TEST_USER \ + --build-arg ssh_user="${{ env.TEST_USER }}" \ - name: Start Host Server Container working-directory: ${{ env.TEST_HOST_DOCKER }} @@ -67,7 +67,7 @@ jobs: ARGS: "-rltgoDzvO" SOURCE: "test_project/" REMOTE_HOST: env.EXAMPLE_REMOTE_HOST - REMOTE_USER: $TEST_USER + REMOTE_USER: env.TEST_USER TARGET: "/var/www/html/" EXCLUDE: "/dist/, /node_modules/" From 692d3fee7dad975b502c1e15e693627d910e889b Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Fri, 30 Dec 2022 14:29:31 +0100 Subject: [PATCH 11/46] start nginx for testing --- .github/workflows/e2e.yml | 39 +-- dist/index.js | 525 +++++++++++++++++++++++++++++++++++++- package-lock.json | 313 ++++++++++++----------- package.json | 14 +- src/rsyncCli.js | 3 +- test/Dockerfile | 12 +- 6 files changed, 733 insertions(+), 173 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 797bd4e..ded30f7 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -38,19 +38,13 @@ jobs: docker build \ -t ssh-host-image . \ --build-arg ssh_pub_key="$(cat $HOME/.ssh/id_rsa.pub)" \ - --build-arg ssh_user="${{ env.TEST_USER }}" \ - - - name: Start Host Server Container - working-directory: ${{ env.TEST_HOST_DOCKER }} - run: | - docker run --name ssh-host-container -d ssh-host-image - - - name: Get IP of Host Server - run: | - docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ssh-host-container > ip.txt - cat ip.txt - EXAMPLE_REMOTE_HOST=$(cat ip.txt) - echo "EXAMPLE_REMOTE_HOST=$EXAMPLE_REMOTE_HOST" >> $GITHUB_ENV + --build-arg ssh_user="${{ env.TEST_USER }}" + docker run -d --name=ssh-host-container ssh-host-image + docker exec ssh-host-container sh -c "hostname --ip-address" > ip.txt + echo "EXAMPLE_REMOTE_HOST<> $GITHUB_ENV + cat ip.txt >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV + shell: bash - name: Create project file run: | @@ -60,14 +54,25 @@ jobs: date +"%Y-%m-%d %H:%M:%S,%3N" >> index.html cat index.html - - name: e2e Test ssh-deploy action + # - name: e2e Test local ssh-deploy action + # run: node ./dist/index.js + # env: + # SSH_PRIVATE_KEY: $EXAMPLE_SSH_PRIVATE_KEY + # ARGS: "-rltgoDzvO" + # SOURCE: "test_project/" + # REMOTE_HOST: $EXAMPLE_REMOTE_HOST + # REMOTE_USER: $TEST_USER + # TARGET: "/var/www/html/" + # EXCLUDE: "/dist/, /node_modules/" + + - name: e2e Test published ssh-deploy action uses: easingthemes/ssh-deploy@main env: - SSH_PRIVATE_KEY: env.EXAMPLE_SSH_PRIVATE_KEY + SSH_PRIVATE_KEY: $EXAMPLE_SSH_PRIVATE_KEY ARGS: "-rltgoDzvO" SOURCE: "test_project/" - REMOTE_HOST: env.EXAMPLE_REMOTE_HOST - REMOTE_USER: env.TEST_USER + REMOTE_HOST: $EXAMPLE_REMOTE_HOST + REMOTE_USER: $TEST_USER TARGET: "/var/www/html/" EXCLUDE: "/dist/, /node_modules/" diff --git a/dist/index.js b/dist/index.js index f95c0a3..2c5655a 100755 --- a/dist/index.js +++ b/dist/index.js @@ -1,2 +1,525 @@ #!/usr/bin/env node -(()=>{var e={569:(e,r,t)=>{e.exports=t(325)},325:(e,r,t)=>{"use strict";var n=t(81).exec;var s=t(81).execSync;var o=t(147);var c=t(17);var i=o.access;var a=o.accessSync;var u=o.constants||o;var l=process.platform=="win32";var fileNotExists=function(e,r){i(e,u.F_OK,(function(e){r(!e)}))};var fileNotExistsSync=function(e){try{a(e,u.F_OK);return false}catch(e){return true}};var localExecutable=function(e,r){i(e,u.F_OK|u.X_OK,(function(e){r(null,!e)}))};var localExecutableSync=function(e){try{a(e,u.F_OK|u.X_OK);return true}catch(e){return false}};var commandExistsUnix=function(e,r,t){fileNotExists(e,(function(s){if(!s){var o=n("command -v "+r+" 2>/dev/null"+" && { echo >&1 "+r+"; exit 0; }",(function(e,r,n){t(null,!!r)}));return}localExecutable(e,t)}))};var commandExistsWindows=function(e,r,t){if(!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(e)){t(null,false);return}var s=n("where "+r,(function(e){if(e!==null){t(null,false)}else{t(null,true)}}))};var commandExistsUnixSync=function(e,r){if(fileNotExistsSync(e)){try{var t=s("command -v "+r+" 2>/dev/null"+" && { echo >&1 "+r+"; exit 0; }");return!!t}catch(e){return false}}return localExecutableSync(e)};var commandExistsWindowsSync=function(e,r,t){if(!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(e)){return false}try{var n=s("where "+r,{stdio:[]});return!!n}catch(e){return false}};var cleanInput=function(e){if(/[^A-Za-z0-9_\/:=-]/.test(e)){e="'"+e.replace(/'/g,"'\\''")+"'";e=e.replace(/^(?:'')+/g,"").replace(/\\'''/g,"\\'")}return e};if(l){cleanInput=function(e){var r=/[\\]/.test(e);if(r){var t='"'+c.dirname(e)+'"';var n='"'+c.basename(e)+'"';return t+":"+n}return'"'+e+'"'}}e.exports=function commandExists(e,r){var t=cleanInput(e);if(!r&&typeof Promise!=="undefined"){return new Promise((function(r,t){commandExists(e,(function(n,s){if(s){r(e)}else{t(n)}}))}))}if(l){commandExistsWindows(e,t,r)}else{commandExistsUnix(e,t,r)}};e.exports.sync=function(e){var r=cleanInput(e);if(l){return commandExistsWindowsSync(e,r)}else{return commandExistsUnixSync(e,r)}}},748:(e,r,t)=>{const{exec:n,execSync:s}=t(81);const o={run:runCommand,runSync:runSync};function runCommand(e,r){return n(e,function(){return function(e,t,n){if(!r)return;r(e,t,n)}}(r))}function runSync(e){try{return{data:s(e).toString(),err:null,stderr:null}}catch(e){return{data:null,err:e.stderr.toString(),stderr:e.stderr.toString()}}}e.exports=o},898:(e,r,t)=>{"use strict";var n=t(81).spawn;var s=t(837);var escapeSpaces=function(e){if(typeof e==="string"){return e.replace(/\b\s/g,"\\ ")}else{return e}};var escapeSpacesInOptions=function(e){["src","dest","include","exclude","excludeFirst"].forEach((function(r){var t=e[r];if(typeof t==="string"){e[r]=escapeSpaces(t)}else if(Array.isArray(t)===true){e[r]=t.map(escapeSpaces)}}));return e};e.exports=function(e,r){e=e||{};e=s._extend({},e);e=escapeSpacesInOptions(e);var t=e.platform||process.platform;var o=t==="win32";if(typeof e.src==="undefined"){throw new Error("'src' directory is missing from options")}if(typeof e.dest==="undefined"){throw new Error("'dest' directory is missing from options")}var c=e.dest;if(typeof e.host!=="undefined"){c=e.host+":"+e.dest}if(!Array.isArray(e.src)){e.src=[e.src]}var i=[].concat(e.src);i.push(c);var a=(e.args||[]).find((function(e){return e.match(/--chmod=/)}));if(o&&!a){i.push("--chmod=ugo=rwX")}if(typeof e.host!=="undefined"||e.ssh){i.push("--rsh");var u="ssh";if(typeof e.port!=="undefined"){u+=" -p "+e.port}if(typeof e.privateKey!=="undefined"){u+=" -i "+e.privateKey}if(typeof e.sshCmdArgs!=="undefined"){u+=" "+e.sshCmdArgs.join(" ")}i.push(u)}if(e.recursive===true){i.push("--recursive")}if(e.times===true){i.push("--times")}if(e.syncDest===true||e.deleteAll===true){i.push("--delete");i.push("--delete-excluded")}if(e.syncDestIgnoreExcl===true||e.delete===true){i.push("--delete")}if(e.dryRun===true){i.push("--dry-run");i.push("--verbose")}if(typeof e.excludeFirst!=="undefined"&&s.isArray(e.excludeFirst)){e.excludeFirst.forEach((function(e,r){i.push("--exclude="+e)}))}if(typeof e.include!=="undefined"&&s.isArray(e.include)){e.include.forEach((function(e,r){i.push("--include="+e)}))}if(typeof e.exclude!=="undefined"&&s.isArray(e.exclude)){e.exclude.forEach((function(e,r){i.push("--exclude="+e)}))}switch(e.compareMode){case"sizeOnly":i.push("--size-only");break;case"checksum":i.push("--checksum");break}if(typeof e.args!=="undefined"&&s.isArray(e.args)){i=[...new Set([...i,...e.args])]}i=[...new Set(i)];var noop=function(){};var l=e.onStdout||noop;var d=e.onStderr||noop;var f="rsync ";i.forEach((function(e){if(e.substr(0,4)==="ssh "){e='"'+e+'"'}f+=e+" "}));f=f.trim();if(e.noExec){r(null,null,null,f);return}try{var p="";var y="";var v;if(o){v=n("cmd.exe",["/s","/c",'"'+f+'"'],{windowsVerbatimArguments:true,stdio:[process.stdin,"pipe","pipe"]})}else{v=n("/bin/sh",["-c",f])}v.stdout.on("data",(function(e){l(e);p+=e}));v.stderr.on("data",(function(e){d(e);y+=e}));v.on("exit",(function(e){var t=null;if(e!==0){t=new Error("rsync exited with code "+e);t.code=e}r(t,p,y,f)}))}catch(e){r(e,null,null,f)}}},505:(e,r,t)=>{const{existsSync:n,mkdirSync:s,writeFileSync:o}=t(147);const{GITHUB_WORKSPACE:c}=process.env;const validateDir=e=>{if(!n(e)){console.log(`[SSH] Creating ${e} dir in `,c);s(e);console.log("✅ [SSH] dir created.")}else{console.log(`[SSH] ${e} dir exist`)}};const validateFile=e=>{if(!n(e)){console.log(`[SSH] Creating ${e} file in `,c);try{o(e,"",{encoding:"utf8",mode:384});console.log("✅ [SSH] file created.")}catch(r){console.error("⚠️ [SSH] writeFileSync error",e,r.message);process.abort()}}else{console.log(`[SSH] ${e} file exist`)}};e.exports={validateDir:validateDir,validateFile:validateFile}},229:e=>{const r=["REMOTE_HOST","REMOTE_USER","REMOTE_PORT","SSH_PRIVATE_KEY","DEPLOY_KEY_NAME","SOURCE","TARGET","ARGS","EXCLUDE"];const t={GITHUB_WORKSPACE:process.env.GITHUB_WORKSPACE};r.forEach((e=>{t[e]=process.env[e]||process.env[`INPUT_${e}`]}));e.exports=t},447:(e,r,t)=>{const{sync:n}=t(569);const{get:s}=t(748);const validateRsync=(e=(()=>{}))=>{const r=n("rsync");if(!r){s("sudo apt-get --no-install-recommends install rsync",((r,t,n)=>{if(r){console.log("⚠️ [CLI] Rsync installation failed. Aborting ... ",r.message);process.abort()}else{console.log("✅ [CLI] Rsync installed. \n",t,n);e()}}))}else{e()}};const validateInputs=e=>{const r=Object.keys(e);const t=r.filter((r=>{const t=e[r];if(!t){console.error(`⚠️ [INPUTS] ${r} is mandatory`)}return t}));if(t.length!==r.length){console.error("⚠️ [INPUTS] Inputs not valid, aborting ...");process.abort()}};e.exports={validateRsync:validateRsync,validateInputs:validateInputs}},822:(e,r,t)=>{const{writeFileSync:n}=t(147);const{join:s}=t(17);const{validateDir:o,validateFile:c}=t(505);const{HOME:i}=process.env;const addSshKey=(e,r)=>{const t=s(i||__dirname,".ssh");const a=s(t,r);o(t);c(`${t}/known_hosts`);try{n(a,e,{encoding:"utf8",mode:384})}catch(e){console.error("⚠️ writeFileSync error",a,e.message);process.abort()}console.log("✅ Ssh key added to `.ssh` dir ",a);return a};e.exports={addSshKey:addSshKey}},81:e=>{"use strict";e.exports=require("child_process")},147:e=>{"use strict";e.exports=require("fs")},17:e=>{"use strict";e.exports=require("path")},837:e=>{"use strict";e.exports=require("util")}};var r={};function __nccwpck_require__(t){var n=r[t];if(n!==undefined){return n.exports}var s=r[t]={exports:{}};var o=true;try{e[t](s,s.exports,__nccwpck_require__);o=false}finally{if(o)delete r[t]}return s.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var t={};(()=>{const e=__nccwpck_require__(898);const{validateRsync:r,validateInputs:t}=__nccwpck_require__(447);const{addSshKey:n}=__nccwpck_require__(822);const{REMOTE_HOST:s,REMOTE_USER:o,REMOTE_PORT:c,SSH_PRIVATE_KEY:i,DEPLOY_KEY_NAME:a,SOURCE:u,TARGET:l,ARGS:d,EXCLUDE:f,GITHUB_WORKSPACE:p}=__nccwpck_require__(229);const y={ssh:true,sshCmdArgs:["-o StrictHostKeyChecking=no"],recursive:true};console.log("[general] GITHUB_WORKSPACE: ",p);const v=(()=>{const rsync=({privateKey:r,port:t,src:n,dest:s,args:o,exclude:c})=>{console.log(`[Rsync] Starting Rsync Action: ${n} to ${s}`);if(c)console.log(`[Rsync] exluding folders ${c}`);try{e({src:n,dest:s,args:o,privateKey:r,port:t,excludeFirst:c,...y},((e,r,t,n)=>{if(e){console.error("⚠️ [Rsync] error: ",e.message);console.log("⚠️ [Rsync] stderr: ",t);console.log("⚠️ [Rsync] stdout: ",r);console.log("⚠️ [Rsync] cmd: ",n);process.abort()}else{console.log("✅ [Rsync] finished.",r)}}))}catch(e){console.error("⚠️ [Rsync] command error: ",e.message,e.stack);process.abort()}};const init=({src:e,dest:t,args:s,host:o="localhost",port:c,username:i,privateKeyContent:u,exclude:l=[]})=>{r((()=>{const r=n(u,a||"deploy_key");const d=`${i}@${o}:${t}`;rsync({privateKey:r,port:c,src:e,dest:d,args:s,exclude:l})}))};return{init:init}})();const run=()=>{t({SSH_PRIVATE_KEY:i,REMOTE_HOST:s,REMOTE_USER:o});v.init({src:`${p}/${u||""}`,dest:l||`/home/${o}/`,args:d?[d]:["-rltgoDzvO"],host:s,port:c||"22",username:o,privateKeyContent:i,exclude:(f||"").split(",").map((e=>e.trim()))})};run()})();module.exports=t})(); \ No newline at end of file +(() => { + var e = { + 569: (e, r, t) => { + e.exports = t(325); + }, + 325: (e, r, t) => { + "use strict"; + var n = t(81).exec; + var s = t(81).execSync; + var o = t(147); + var c = t(17); + var i = o.access; + var a = o.accessSync; + var u = o.constants || o; + var l = process.platform == "win32"; + var fileNotExists = function (e, r) { + i(e, u.F_OK, function (e) { + r(!e); + }); + }; + var fileNotExistsSync = function (e) { + try { + a(e, u.F_OK); + return false; + } catch (e) { + return true; + } + }; + var localExecutable = function (e, r) { + i(e, u.F_OK | u.X_OK, function (e) { + r(null, !e); + }); + }; + var localExecutableSync = function (e) { + try { + a(e, u.F_OK | u.X_OK); + return true; + } catch (e) { + return false; + } + }; + var commandExistsUnix = function (e, r, t) { + fileNotExists(e, function (s) { + if (!s) { + var o = n("command -v " + r + " 2>/dev/null" + " && { echo >&1 " + r + "; exit 0; }", function (e, r, n) { + t(null, !!r); + }); + return; + } + localExecutable(e, t); + }); + }; + var commandExistsWindows = function (e, r, t) { + if (!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(e)) { + t(null, false); + return; + } + var s = n("where " + r, function (e) { + if (e !== null) { + t(null, false); + } else { + t(null, true); + } + }); + }; + var commandExistsUnixSync = function (e, r) { + if (fileNotExistsSync(e)) { + try { + var t = s("command -v " + r + " 2>/dev/null" + " && { echo >&1 " + r + "; exit 0; }"); + return !!t; + } catch (e) { + return false; + } + } + return localExecutableSync(e); + }; + var commandExistsWindowsSync = function (e, r, t) { + if (!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(e)) { + return false; + } + try { + var n = s("where " + r, { stdio: [] }); + return !!n; + } catch (e) { + return false; + } + }; + var cleanInput = function (e) { + if (/[^A-Za-z0-9_\/:=-]/.test(e)) { + e = "'" + e.replace(/'/g, "'\\''") + "'"; + e = e.replace(/^(?:'')+/g, "").replace(/\\'''/g, "\\'"); + } + return e; + }; + if (l) { + cleanInput = function (e) { + var r = /[\\]/.test(e); + if (r) { + var t = '"' + c.dirname(e) + '"'; + var n = '"' + c.basename(e) + '"'; + return t + ":" + n; + } + return '"' + e + '"'; + }; + } + e.exports = function commandExists(e, r) { + var t = cleanInput(e); + if (!r && typeof Promise !== "undefined") { + return new Promise(function (r, t) { + commandExists(e, function (n, s) { + if (s) { + r(e); + } else { + t(n); + } + }); + }); + } + if (l) { + commandExistsWindows(e, t, r); + } else { + commandExistsUnix(e, t, r); + } + }; + e.exports.sync = function (e) { + var r = cleanInput(e); + if (l) { + return commandExistsWindowsSync(e, r); + } else { + return commandExistsUnixSync(e, r); + } + }; + }, + 748: (e, r, t) => { + const { exec: n, execSync: s } = t(81); + const o = { run: runCommand, runSync: runSync }; + function runCommand(e, r) { + return n( + e, + (function () { + return function (e, t, n) { + if (!r) return; + r(e, t, n); + }; + })(r) + ); + } + function runSync(e) { + try { + return { data: s(e).toString(), err: null, stderr: null }; + } catch (e) { + return { data: null, err: e.stderr.toString(), stderr: e.stderr.toString() }; + } + } + e.exports = o; + }, + 898: (e, r, t) => { + "use strict"; + var n = t(81).spawn; + var s = t(837); + var escapeSpaces = function (e) { + if (typeof e === "string") { + return e.replace(/\b\s/g, "\\ "); + } else { + return e; + } + }; + var escapeSpacesInOptions = function (e) { + ["src", "dest", "include", "exclude", "excludeFirst"].forEach(function (r) { + var t = e[r]; + if (typeof t === "string") { + e[r] = escapeSpaces(t); + } else if (Array.isArray(t) === true) { + e[r] = t.map(escapeSpaces); + } + }); + return e; + }; + e.exports = function (e, r) { + e = e || {}; + e = s._extend({}, e); + e = escapeSpacesInOptions(e); + var t = e.platform || process.platform; + var o = t === "win32"; + if (typeof e.src === "undefined") { + throw new Error("'src' directory is missing from options"); + } + if (typeof e.dest === "undefined") { + throw new Error("'dest' directory is missing from options"); + } + var c = e.dest; + if (typeof e.host !== "undefined") { + c = e.host + ":" + e.dest; + } + if (!Array.isArray(e.src)) { + e.src = [e.src]; + } + var i = [].concat(e.src); + i.push(c); + var a = (e.args || []).find(function (e) { + return e.match(/--chmod=/); + }); + if (o && !a) { + i.push("--chmod=ugo=rwX"); + } + if (typeof e.host !== "undefined" || e.ssh) { + i.push("--rsh"); + var u = "ssh"; + if (typeof e.port !== "undefined") { + u += " -p " + e.port; + } + if (typeof e.privateKey !== "undefined") { + u += " -i " + e.privateKey; + } + if (typeof e.sshCmdArgs !== "undefined") { + u += " " + e.sshCmdArgs.join(" "); + } + i.push(u); + } + if (e.recursive === true) { + i.push("--recursive"); + } + if (e.times === true) { + i.push("--times"); + } + if (e.syncDest === true || e.deleteAll === true) { + i.push("--delete"); + i.push("--delete-excluded"); + } + if (e.syncDestIgnoreExcl === true || e.delete === true) { + i.push("--delete"); + } + if (e.dryRun === true) { + i.push("--dry-run"); + i.push("--verbose"); + } + if (typeof e.excludeFirst !== "undefined" && s.isArray(e.excludeFirst)) { + e.excludeFirst.forEach(function (e, r) { + i.push("--exclude=" + e); + }); + } + if (typeof e.include !== "undefined" && s.isArray(e.include)) { + e.include.forEach(function (e, r) { + i.push("--include=" + e); + }); + } + if (typeof e.exclude !== "undefined" && s.isArray(e.exclude)) { + e.exclude.forEach(function (e, r) { + i.push("--exclude=" + e); + }); + } + switch (e.compareMode) { + case "sizeOnly": + i.push("--size-only"); + break; + case "checksum": + i.push("--checksum"); + break; + } + if (typeof e.args !== "undefined" && s.isArray(e.args)) { + i = [...new Set([...i, ...e.args])]; + } + i = [...new Set(i)]; + var noop = function () {}; + var l = e.onStdout || noop; + var d = e.onStderr || noop; + var f = "rsync "; + i.forEach(function (e) { + if (e.substr(0, 4) === "ssh ") { + e = '"' + e + '"'; + } + f += e + " "; + }); + f = f.trim(); + if (e.noExec) { + r(null, null, null, f); + return; + } + try { + var p = ""; + var y = ""; + var v; + if (o) { + v = n("cmd.exe", ["/s", "/c", '"' + f + '"'], { + windowsVerbatimArguments: true, + stdio: [process.stdin, "pipe", "pipe"], + }); + } else { + v = n("/bin/sh", ["-c", f]); + } + v.stdout.on("data", function (e) { + l(e); + p += e; + }); + v.stderr.on("data", function (e) { + d(e); + y += e; + }); + v.on("exit", function (e) { + var t = null; + if (e !== 0) { + t = new Error("rsync exited with code " + e); + t.code = e; + } + r(t, p, y, f); + }); + } catch (e) { + r(e, null, null, f); + } + }; + }, + 505: (e, r, t) => { + const { existsSync: n, mkdirSync: s, writeFileSync: o } = t(147); + const { GITHUB_WORKSPACE: c } = process.env; + const validateDir = (e) => { + if (!n(e)) { + console.log(`[SSH] Creating ${e} dir in `, c); + s(e); + console.log("✅ [SSH] dir created."); + } else { + console.log(`[SSH] ${e} dir exist`); + } + }; + const validateFile = (e) => { + if (!n(e)) { + console.log(`[SSH] Creating ${e} file in `, c); + try { + o(e, "", { encoding: "utf8", mode: 384 }); + console.log("✅ [SSH] file created."); + } catch (r) { + console.error("⚠️ [SSH] writeFileSync error", e, r.message); + process.abort(); + } + } else { + console.log(`[SSH] ${e} file exist`); + } + }; + e.exports = { validateDir: validateDir, validateFile: validateFile }; + }, + 229: (e) => { + const r = [ + "REMOTE_HOST", + "REMOTE_USER", + "REMOTE_PORT", + "SSH_PRIVATE_KEY", + "DEPLOY_KEY_NAME", + "SOURCE", + "TARGET", + "ARGS", + "EXCLUDE", + ]; + const t = { GITHUB_WORKSPACE: process.env.GITHUB_WORKSPACE }; + r.forEach((e) => { + t[e] = process.env[e] || process.env[`INPUT_${e}`]; + }); + e.exports = t; + }, + 447: (e, r, t) => { + const { sync: n } = t(569); + const { get: s } = t(748); + const validateRsync = (e = () => {}) => { + const r = n("rsync"); + console.log('⚠️ [CLI] Rsync doesn\'t exists. Start installation with "apt-get" \n'); + console.log("nodeCmd: ", s); + if (!r) { + s("sudo apt-get --no-install-recommends install rsync", (r, t, n) => { + if (r) { + console.log("⚠️ [CLI] Rsync installation failed. Aborting ... ", r.message); + process.abort(); + } else { + console.log("✅ [CLI] Rsync installed. \n", t, n); + e(); + } + }); + } else { + e(); + } + }; + const validateInputs = (e) => { + const r = Object.keys(e); + const t = r.filter((r) => { + const t = e[r]; + if (!t) { + console.error(`⚠️ [INPUTS] ${r} is mandatory`); + } + return t; + }); + if (t.length !== r.length) { + console.error("⚠️ [INPUTS] Inputs not valid, aborting ..."); + process.abort(); + } + }; + e.exports = { validateRsync: validateRsync, validateInputs: validateInputs }; + }, + 822: (e, r, t) => { + const { writeFileSync: n } = t(147); + const { join: s } = t(17); + const { validateDir: o, validateFile: c } = t(505); + const { HOME: i } = process.env; + const addSshKey = (e, r) => { + const t = s(i || __dirname, ".ssh"); + const a = s(t, r); + o(t); + c(`${t}/known_hosts`); + try { + n(a, e, { encoding: "utf8", mode: 384 }); + } catch (e) { + console.error("⚠️ writeFileSync error", a, e.message); + process.abort(); + } + console.log("✅ Ssh key added to `.ssh` dir ", a); + return a; + }; + e.exports = { addSshKey: addSshKey }; + }, + 81: (e) => { + "use strict"; + e.exports = require("child_process"); + }, + 147: (e) => { + "use strict"; + e.exports = require("fs"); + }, + 17: (e) => { + "use strict"; + e.exports = require("path"); + }, + 837: (e) => { + "use strict"; + e.exports = require("util"); + }, + }; + var r = {}; + function __nccwpck_require__(t) { + var n = r[t]; + if (n !== undefined) { + return n.exports; + } + var s = (r[t] = { exports: {} }); + var o = true; + try { + e[t](s, s.exports, __nccwpck_require__); + o = false; + } finally { + if (o) delete r[t]; + } + return s.exports; + } + if (typeof __nccwpck_require__ !== "undefined") __nccwpck_require__.ab = __dirname + "/"; + var t = {}; + (() => { + const e = __nccwpck_require__(898); + const { validateRsync: r, validateInputs: t } = __nccwpck_require__(447); + const { addSshKey: n } = __nccwpck_require__(822); + const { + REMOTE_HOST: s, + REMOTE_USER: o, + REMOTE_PORT: c, + SSH_PRIVATE_KEY: i, + DEPLOY_KEY_NAME: a, + SOURCE: u, + TARGET: l, + ARGS: d, + EXCLUDE: f, + GITHUB_WORKSPACE: p, + } = __nccwpck_require__(229); + const y = { ssh: true, sshCmdArgs: ["-o StrictHostKeyChecking=no"], recursive: true }; + console.log("[general] GITHUB_WORKSPACE: ", p); + const v = (() => { + const rsync = ({ privateKey: r, port: t, src: n, dest: s, args: o, exclude: c }) => { + console.log(`[Rsync] Starting Rsync Action: ${n} to ${s}`); + if (c) console.log(`[Rsync] exluding folders ${c}`); + try { + e({ src: n, dest: s, args: o, privateKey: r, port: t, excludeFirst: c, ...y }, (e, r, t, n) => { + if (e) { + console.error("⚠️ [Rsync] error: ", e.message); + console.log("⚠️ [Rsync] stderr: ", t); + console.log("⚠️ [Rsync] stdout: ", r); + console.log("⚠️ [Rsync] cmd: ", n); + process.abort(); + } else { + console.log("✅ [Rsync] finished.", r); + } + }); + } catch (e) { + console.error("⚠️ [Rsync] command error: ", e.message, e.stack); + process.abort(); + } + }; + const init = ({ + src: e, + dest: t, + args: s, + host: o = "localhost", + port: c, + username: i, + privateKeyContent: u, + exclude: l = [], + }) => { + r(() => { + const r = n(u, a || "deploy_key"); + const d = `${i}@${o}:${t}`; + rsync({ privateKey: r, port: c, src: e, dest: d, args: s, exclude: l }); + }); + }; + return { init: init }; + })(); + const run = () => { + t({ SSH_PRIVATE_KEY: i, REMOTE_HOST: s, REMOTE_USER: o }); + v.init({ + src: `${p}/${u || ""}`, + dest: l || `/home/${o}/`, + args: d ? [d] : ["-rltgoDzvO"], + host: s, + port: c || "22", + username: o, + privateKeyContent: i, + exclude: (f || "").split(",").map((e) => e.trim()), + }); + }; + run(); + })(); + module.exports = t; +})(); diff --git a/package-lock.json b/package-lock.json index 15c3618..49c75b1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@draganfilipovic/ssh-deploy", - "version": "2.2.11", + "version": "3.0.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@draganfilipovic/ssh-deploy", - "version": "2.2.11", + "version": "3.0.1", "license": "MIT", "dependencies": { "command-exists": "^1.2.9", @@ -14,22 +14,22 @@ "rsyncwrapper": "^3.0.1" }, "devDependencies": { - "@vercel/ncc": "^0.34.0", - "eslint": "^8.26.0", + "@vercel/ncc": "^0.36.0", + "eslint": "^8.30.0", "eslint-config-airbnb-base": "^15.0.0", "eslint-plugin-import": "^2.26.0" } }, "node_modules/@eslint/eslintrc": { - "version": "1.3.3", - "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.3.3.tgz", - "integrity": "sha512-uj3pT6Mg+3t39fvLrj8iuCIJ38zKO9FpGtJ4BBJebJhEwjoT+KLVNCcHT5QC9NGRIEi7fZ0ZR8YRb884auB4Lg==", + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.4.0.tgz", + "integrity": "sha512-7yfvXy6MWLgWSFsLhz5yH3iQ52St8cdUY6FoGieKkRDVxuxmrNuUetIuu6cmjNWwniUHiWXjxCr5tTXDrbYS5A==", "dev": true, "dependencies": { "ajv": "^6.12.4", "debug": "^4.3.2", "espree": "^9.4.0", - "globals": "^13.15.0", + "globals": "^13.19.0", "ignore": "^5.2.0", "import-fresh": "^3.2.1", "js-yaml": "^4.1.0", @@ -44,14 +44,14 @@ } }, "node_modules/@humanwhocodes/config-array": { - "version": "0.11.6", - "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.6.tgz", - "integrity": "sha512-jJr+hPTJYKyDILJfhNSHsjiwXYf26Flsz8DvNndOsHs5pwSnpGUEy8yzF0JYhCEvTDdV2vuOK5tt8BVhwO5/hg==", + "version": "0.11.8", + "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.8.tgz", + "integrity": "sha512-UybHIJzJnR5Qc/MsD9Kr+RpO2h+/P1GhOwdiLPXK5TWk5sgTdu88bTD9UP+CKbPPh5Rni1u0GjAdYQLemG8g+g==", "dev": true, "dependencies": { "@humanwhocodes/object-schema": "^1.2.1", "debug": "^4.1.1", - "minimatch": "^3.0.4" + "minimatch": "^3.0.5" }, "engines": { "node": ">=10.10.0" @@ -118,9 +118,9 @@ "dev": true }, "node_modules/@vercel/ncc": { - "version": "0.34.0", - "resolved": "https://registry.npmjs.org/@vercel/ncc/-/ncc-0.34.0.tgz", - "integrity": "sha512-G9h5ZLBJ/V57Ou9vz5hI8pda/YQX5HQszCs3AmIus3XzsmRn/0Ptic5otD3xVST8QLKk7AMk7AqpsyQGN7MZ9A==", + "version": "0.36.0", + "resolved": "https://registry.npmjs.org/@vercel/ncc/-/ncc-0.36.0.tgz", + "integrity": "sha512-/ZTUJ/ZkRt694k7KJNimgmHjtQcRuVwsST2Z6XfYveQIuBbHR+EqkTc1jfgPkQmMyk/vtpxo3nVxe8CNuau86A==", "dev": true, "bin": { "ncc": "dist/ncc/cli.js" @@ -194,15 +194,15 @@ "dev": true }, "node_modules/array-includes": { - "version": "3.1.5", - "resolved": "https://registry.npmjs.org/array-includes/-/array-includes-3.1.5.tgz", - "integrity": "sha512-iSDYZMMyTPkiFasVqfuAQnWAYcvO/SeBSCGKePoEthjp4LEMTe4uLc7b025o4jAZpHhihh8xPo99TNWUWWkGDQ==", + "version": "3.1.6", + "resolved": "https://registry.npmjs.org/array-includes/-/array-includes-3.1.6.tgz", + "integrity": "sha512-sgTbLvL6cNnw24FnbaDyjmvddQ2ML8arZsgaJhoABMoplz/4QRhtrYS+alr1BUM1Bwp6dhx8vVCBSLG+StwOFw==", "dev": true, "dependencies": { "call-bind": "^1.0.2", "define-properties": "^1.1.4", - "es-abstract": "^1.19.5", - "get-intrinsic": "^1.1.1", + "es-abstract": "^1.20.4", + "get-intrinsic": "^1.1.3", "is-string": "^1.0.7" }, "engines": { @@ -213,14 +213,14 @@ } }, "node_modules/array.prototype.flat": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/array.prototype.flat/-/array.prototype.flat-1.3.0.tgz", - "integrity": "sha512-12IUEkHsAhA4DY5s0FPgNXIdc8VRSqD9Zp78a5au9abH/SOBrsp082JOWFNTjkMozh8mqcdiKuaLGhPeYztxSw==", + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/array.prototype.flat/-/array.prototype.flat-1.3.1.tgz", + "integrity": "sha512-roTU0KWIOmJ4DRLmwKd19Otg0/mT3qPNt0Qb3GWW8iObuZXxrjB/pzn0R3hqpRSWg4HCwqx+0vwOnWnvlOyeIA==", "dev": true, "dependencies": { "call-bind": "^1.0.2", - "define-properties": "^1.1.3", - "es-abstract": "^1.19.2", + "define-properties": "^1.1.4", + "es-abstract": "^1.20.4", "es-shim-unscopables": "^1.0.0" }, "engines": { @@ -385,9 +385,9 @@ } }, "node_modules/es-abstract": { - "version": "1.20.4", - "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.20.4.tgz", - "integrity": "sha512-0UtvRN79eMe2L+UNEF1BwRe364sj/DXhQ/k5FmivgoSdpM90b8Jc0mDzKMGo7QS0BVbOP/bTwBKNnDc9rNzaPA==", + "version": "1.20.5", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.20.5.tgz", + "integrity": "sha512-7h8MM2EQhsCA7pU/Nv78qOXFpD8Rhqd12gYiSJVkrH9+e8VuA8JlPJK/hQjjlLv6pJvx/z1iRFKzYb0XT/RuAQ==", "dev": true, "dependencies": { "call-bind": "^1.0.2", @@ -396,6 +396,7 @@ "function.prototype.name": "^1.1.5", "get-intrinsic": "^1.1.3", "get-symbol-description": "^1.0.0", + "gopd": "^1.0.1", "has": "^1.0.3", "has-property-descriptors": "^1.0.0", "has-symbols": "^1.0.3", @@ -411,8 +412,8 @@ "object.assign": "^4.1.4", "regexp.prototype.flags": "^1.4.3", "safe-regex-test": "^1.0.0", - "string.prototype.trimend": "^1.0.5", - "string.prototype.trimstart": "^1.0.5", + "string.prototype.trimend": "^1.0.6", + "string.prototype.trimstart": "^1.0.6", "unbox-primitive": "^1.0.2" }, "engines": { @@ -461,13 +462,13 @@ } }, "node_modules/eslint": { - "version": "8.26.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.26.0.tgz", - "integrity": "sha512-kzJkpaw1Bfwheq4VXUezFriD1GxszX6dUekM7Z3aC2o4hju+tsR/XyTC3RcoSD7jmy9VkPU3+N6YjVU2e96Oyg==", + "version": "8.30.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.30.0.tgz", + "integrity": "sha512-MGADB39QqYuzEGov+F/qb18r4i7DohCDOfatHaxI2iGlPuC65bwG2gxgO+7DkyL38dRFaRH7RaRAgU6JKL9rMQ==", "dev": true, "dependencies": { - "@eslint/eslintrc": "^1.3.3", - "@humanwhocodes/config-array": "^0.11.6", + "@eslint/eslintrc": "^1.4.0", + "@humanwhocodes/config-array": "^0.11.8", "@humanwhocodes/module-importer": "^1.0.1", "@nodelib/fs.walk": "^1.2.8", "ajv": "^6.10.0", @@ -486,7 +487,7 @@ "file-entry-cache": "^6.0.1", "find-up": "^5.0.0", "glob-parent": "^6.0.2", - "globals": "^13.15.0", + "globals": "^13.19.0", "grapheme-splitter": "^1.0.4", "ignore": "^5.2.0", "import-fresh": "^3.0.0", @@ -684,9 +685,9 @@ } }, "node_modules/espree": { - "version": "9.4.0", - "resolved": "https://registry.npmjs.org/espree/-/espree-9.4.0.tgz", - "integrity": "sha512-DQmnRpLj7f6TgN/NYb0MTzJXL+vJF9h3pHy4JhCIs3zwcgez8xmGg3sXHcEO97BrmO2OSvCwMdfdlyl+E9KjOw==", + "version": "9.4.1", + "resolved": "https://registry.npmjs.org/espree/-/espree-9.4.1.tgz", + "integrity": "sha512-XwctdmTO6SIvCzd9810yyNzIrOrqNYV9Koizx4C/mRhf9uq0o4yHoCEU/670pOxOL/MSraektvSAji79kX90Vg==", "dev": true, "dependencies": { "acorn": "^8.8.0", @@ -761,9 +762,9 @@ "dev": true }, "node_modules/fastq": { - "version": "1.13.0", - "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.13.0.tgz", - "integrity": "sha512-YpkpUnK8od0o1hmeSc7UUs/eB/vIPWJYjKck2QKIzAf71Vm1AAQ3EbuZB3g2JIy+pg+ERD0vqI79KyZiB2e2Nw==", + "version": "1.14.0", + "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.14.0.tgz", + "integrity": "sha512-eR2D+V9/ExcbF9ls441yIuN6TI2ED1Y2ZcA5BmMtJsOkWOFRJQ0Jt0g1UwqXJJVAb+V+umH5Dfr8oh4EVP7VVg==", "dev": true, "dependencies": { "reusify": "^1.0.4" @@ -918,9 +919,9 @@ } }, "node_modules/globals": { - "version": "13.17.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-13.17.0.tgz", - "integrity": "sha512-1C+6nQRb1GwGMKm2dH/E7enFAMxGTmGI7/dEdhy/DNelv85w9B72t3uc5frtMNXIbzrarJJ/lTCjcaZwbLJmyw==", + "version": "13.19.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-13.19.0.tgz", + "integrity": "sha512-dkQ957uSRWHw7CFXLUtUHQI3g3aWApYhfNR2O6jn/907riyTYKVBmxYVROkBcY614FSSeSJh7Xm7SrUWCxvJMQ==", "dev": true, "dependencies": { "type-fest": "^0.20.2" @@ -932,6 +933,18 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/gopd": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", + "integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==", + "dev": true, + "dependencies": { + "get-intrinsic": "^1.1.3" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/grapheme-splitter": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/grapheme-splitter/-/grapheme-splitter-1.0.4.tgz", @@ -1008,9 +1021,9 @@ } }, "node_modules/ignore": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.0.tgz", - "integrity": "sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ==", + "version": "5.2.4", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.4.tgz", + "integrity": "sha512-MAb38BcSbH0eHNBxn7ql2NH/kX33OkB3lZ1BNdh7ENeRChHTYsTvWrMubiIAMNS2llXEEgZ1MUOBtXChP3kaFQ==", "dev": true, "engines": { "node": ">= 4" @@ -1058,12 +1071,12 @@ "dev": true }, "node_modules/internal-slot": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/internal-slot/-/internal-slot-1.0.3.tgz", - "integrity": "sha512-O0DB1JC/sPyZl7cIo78n5dR7eUSwwpYPiXRhTzNxZVAMUuB8vlnRFyLxdrVToks6XPLVnFfbzaVd5WLjhgg+vA==", + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/internal-slot/-/internal-slot-1.0.4.tgz", + "integrity": "sha512-tA8URYccNzMo94s5MQZgH8NB/XTa6HsOo0MLfXTKKEnHVVdegzaQoFZ7Jp44bdvLvY2waT5dc+j5ICEswhi7UQ==", "dev": true, "dependencies": { - "get-intrinsic": "^1.1.0", + "get-intrinsic": "^1.1.3", "has": "^1.0.3", "side-channel": "^1.0.4" }, @@ -1272,10 +1285,14 @@ "dev": true }, "node_modules/js-sdsl": { - "version": "4.1.5", - "resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.1.5.tgz", - "integrity": "sha512-08bOAKweV2NUC1wqTtf3qZlnpOX/R2DU9ikpjOHs0H+ibQv3zpncVQg6um4uYtRtrwIX8M4Nh3ytK4HGlYAq7Q==", - "dev": true + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.2.0.tgz", + "integrity": "sha512-dyBIzQBDkCqCu+0upx25Y2jGdbTGxE9fshMsCdK0ViOongpV+n5tXRcZY9v7CaVQ79AGS9KA1KHtojxiM7aXSQ==", + "dev": true, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/js-sdsl" + } }, "node_modules/js-yaml": { "version": "4.1.0", @@ -1425,28 +1442,28 @@ } }, "node_modules/object.entries": { - "version": "1.1.5", - "resolved": "https://registry.npmjs.org/object.entries/-/object.entries-1.1.5.tgz", - "integrity": "sha512-TyxmjUoZggd4OrrU1W66FMDG6CuqJxsFvymeyXI51+vQLN67zYfZseptRge703kKQdo4uccgAKebXFcRCzk4+g==", + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/object.entries/-/object.entries-1.1.6.tgz", + "integrity": "sha512-leTPzo4Zvg3pmbQ3rDK69Rl8GQvIqMWubrkxONG9/ojtFE2rD9fjMKfSI5BxW3osRH1m6VdzmqK8oAY9aT4x5w==", "dev": true, "dependencies": { "call-bind": "^1.0.2", - "define-properties": "^1.1.3", - "es-abstract": "^1.19.1" + "define-properties": "^1.1.4", + "es-abstract": "^1.20.4" }, "engines": { "node": ">= 0.4" } }, "node_modules/object.values": { - "version": "1.1.5", - "resolved": "https://registry.npmjs.org/object.values/-/object.values-1.1.5.tgz", - "integrity": "sha512-QUZRW0ilQ3PnPpbNtgdNV1PDbEqLIiSFB3l+EnGtBQ/8SUTLj1PZwtQHABZtLgwpJZTSZhuGLOGk57Drx2IvYg==", + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/object.values/-/object.values-1.1.6.tgz", + "integrity": "sha512-FVVTkD1vENCsAcwNs9k6jea2uHC/X0+JcjG8YA60FN5CMaJmG95wT9jek/xX9nornqGRrBkKtzuAu2wuHpKqvw==", "dev": true, "dependencies": { "call-bind": "^1.0.2", - "define-properties": "^1.1.3", - "es-abstract": "^1.19.1" + "define-properties": "^1.1.4", + "es-abstract": "^1.20.4" }, "engines": { "node": ">= 0.4" @@ -1764,28 +1781,28 @@ } }, "node_modules/string.prototype.trimend": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/string.prototype.trimend/-/string.prototype.trimend-1.0.5.tgz", - "integrity": "sha512-I7RGvmjV4pJ7O3kdf+LXFpVfdNOxtCW/2C8f6jNiW4+PQchwxkCDzlk1/7p+Wl4bqFIZeF47qAHXLuHHWKAxog==", + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/string.prototype.trimend/-/string.prototype.trimend-1.0.6.tgz", + "integrity": "sha512-JySq+4mrPf9EsDBEDYMOb/lM7XQLulwg5R/m1r0PXEFqrV0qHvl58sdTilSXtKOflCsK2E8jxf+GKC0T07RWwQ==", "dev": true, "dependencies": { "call-bind": "^1.0.2", "define-properties": "^1.1.4", - "es-abstract": "^1.19.5" + "es-abstract": "^1.20.4" }, "funding": { "url": "https://github.com/sponsors/ljharb" } }, "node_modules/string.prototype.trimstart": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/string.prototype.trimstart/-/string.prototype.trimstart-1.0.5.tgz", - "integrity": "sha512-THx16TJCGlsN0o6dl2o6ncWUsdgnLRSA23rRE5pyGBw/mLr3Ej/R2LaqCtgP8VNMGZsvMWnf9ooZPyY2bHvUFg==", + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/string.prototype.trimstart/-/string.prototype.trimstart-1.0.6.tgz", + "integrity": "sha512-omqjMDaY92pbn5HOX7f9IccLA+U1tA9GvtU4JrodiXFfYB7jPzzHpRzpglLAjtUV6bB557zwClJezTqnAiYnQA==", "dev": true, "dependencies": { "call-bind": "^1.0.2", "define-properties": "^1.1.4", - "es-abstract": "^1.19.5" + "es-abstract": "^1.20.4" }, "funding": { "url": "https://github.com/sponsors/ljharb" @@ -1975,15 +1992,15 @@ }, "dependencies": { "@eslint/eslintrc": { - "version": "1.3.3", - "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.3.3.tgz", - "integrity": "sha512-uj3pT6Mg+3t39fvLrj8iuCIJ38zKO9FpGtJ4BBJebJhEwjoT+KLVNCcHT5QC9NGRIEi7fZ0ZR8YRb884auB4Lg==", + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.4.0.tgz", + "integrity": "sha512-7yfvXy6MWLgWSFsLhz5yH3iQ52St8cdUY6FoGieKkRDVxuxmrNuUetIuu6cmjNWwniUHiWXjxCr5tTXDrbYS5A==", "dev": true, "requires": { "ajv": "^6.12.4", "debug": "^4.3.2", "espree": "^9.4.0", - "globals": "^13.15.0", + "globals": "^13.19.0", "ignore": "^5.2.0", "import-fresh": "^3.2.1", "js-yaml": "^4.1.0", @@ -1992,14 +2009,14 @@ } }, "@humanwhocodes/config-array": { - "version": "0.11.6", - "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.6.tgz", - "integrity": "sha512-jJr+hPTJYKyDILJfhNSHsjiwXYf26Flsz8DvNndOsHs5pwSnpGUEy8yzF0JYhCEvTDdV2vuOK5tt8BVhwO5/hg==", + "version": "0.11.8", + "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.8.tgz", + "integrity": "sha512-UybHIJzJnR5Qc/MsD9Kr+RpO2h+/P1GhOwdiLPXK5TWk5sgTdu88bTD9UP+CKbPPh5Rni1u0GjAdYQLemG8g+g==", "dev": true, "requires": { "@humanwhocodes/object-schema": "^1.2.1", "debug": "^4.1.1", - "minimatch": "^3.0.4" + "minimatch": "^3.0.5" } }, "@humanwhocodes/module-importer": { @@ -2047,9 +2064,9 @@ "dev": true }, "@vercel/ncc": { - "version": "0.34.0", - "resolved": "https://registry.npmjs.org/@vercel/ncc/-/ncc-0.34.0.tgz", - "integrity": "sha512-G9h5ZLBJ/V57Ou9vz5hI8pda/YQX5HQszCs3AmIus3XzsmRn/0Ptic5otD3xVST8QLKk7AMk7AqpsyQGN7MZ9A==", + "version": "0.36.0", + "resolved": "https://registry.npmjs.org/@vercel/ncc/-/ncc-0.36.0.tgz", + "integrity": "sha512-/ZTUJ/ZkRt694k7KJNimgmHjtQcRuVwsST2Z6XfYveQIuBbHR+EqkTc1jfgPkQmMyk/vtpxo3nVxe8CNuau86A==", "dev": true }, "acorn": { @@ -2099,27 +2116,27 @@ "dev": true }, "array-includes": { - "version": "3.1.5", - "resolved": "https://registry.npmjs.org/array-includes/-/array-includes-3.1.5.tgz", - "integrity": "sha512-iSDYZMMyTPkiFasVqfuAQnWAYcvO/SeBSCGKePoEthjp4LEMTe4uLc7b025o4jAZpHhihh8xPo99TNWUWWkGDQ==", + "version": "3.1.6", + "resolved": "https://registry.npmjs.org/array-includes/-/array-includes-3.1.6.tgz", + "integrity": "sha512-sgTbLvL6cNnw24FnbaDyjmvddQ2ML8arZsgaJhoABMoplz/4QRhtrYS+alr1BUM1Bwp6dhx8vVCBSLG+StwOFw==", "dev": true, "requires": { "call-bind": "^1.0.2", "define-properties": "^1.1.4", - "es-abstract": "^1.19.5", - "get-intrinsic": "^1.1.1", + "es-abstract": "^1.20.4", + "get-intrinsic": "^1.1.3", "is-string": "^1.0.7" } }, "array.prototype.flat": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/array.prototype.flat/-/array.prototype.flat-1.3.0.tgz", - "integrity": "sha512-12IUEkHsAhA4DY5s0FPgNXIdc8VRSqD9Zp78a5au9abH/SOBrsp082JOWFNTjkMozh8mqcdiKuaLGhPeYztxSw==", + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/array.prototype.flat/-/array.prototype.flat-1.3.1.tgz", + "integrity": "sha512-roTU0KWIOmJ4DRLmwKd19Otg0/mT3qPNt0Qb3GWW8iObuZXxrjB/pzn0R3hqpRSWg4HCwqx+0vwOnWnvlOyeIA==", "dev": true, "requires": { "call-bind": "^1.0.2", - "define-properties": "^1.1.3", - "es-abstract": "^1.19.2", + "define-properties": "^1.1.4", + "es-abstract": "^1.20.4", "es-shim-unscopables": "^1.0.0" } }, @@ -2243,9 +2260,9 @@ } }, "es-abstract": { - "version": "1.20.4", - "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.20.4.tgz", - "integrity": "sha512-0UtvRN79eMe2L+UNEF1BwRe364sj/DXhQ/k5FmivgoSdpM90b8Jc0mDzKMGo7QS0BVbOP/bTwBKNnDc9rNzaPA==", + "version": "1.20.5", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.20.5.tgz", + "integrity": "sha512-7h8MM2EQhsCA7pU/Nv78qOXFpD8Rhqd12gYiSJVkrH9+e8VuA8JlPJK/hQjjlLv6pJvx/z1iRFKzYb0XT/RuAQ==", "dev": true, "requires": { "call-bind": "^1.0.2", @@ -2254,6 +2271,7 @@ "function.prototype.name": "^1.1.5", "get-intrinsic": "^1.1.3", "get-symbol-description": "^1.0.0", + "gopd": "^1.0.1", "has": "^1.0.3", "has-property-descriptors": "^1.0.0", "has-symbols": "^1.0.3", @@ -2269,8 +2287,8 @@ "object.assign": "^4.1.4", "regexp.prototype.flags": "^1.4.3", "safe-regex-test": "^1.0.0", - "string.prototype.trimend": "^1.0.5", - "string.prototype.trimstart": "^1.0.5", + "string.prototype.trimend": "^1.0.6", + "string.prototype.trimstart": "^1.0.6", "unbox-primitive": "^1.0.2" } }, @@ -2301,13 +2319,13 @@ "dev": true }, "eslint": { - "version": "8.26.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.26.0.tgz", - "integrity": "sha512-kzJkpaw1Bfwheq4VXUezFriD1GxszX6dUekM7Z3aC2o4hju+tsR/XyTC3RcoSD7jmy9VkPU3+N6YjVU2e96Oyg==", + "version": "8.30.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.30.0.tgz", + "integrity": "sha512-MGADB39QqYuzEGov+F/qb18r4i7DohCDOfatHaxI2iGlPuC65bwG2gxgO+7DkyL38dRFaRH7RaRAgU6JKL9rMQ==", "dev": true, "requires": { - "@eslint/eslintrc": "^1.3.3", - "@humanwhocodes/config-array": "^0.11.6", + "@eslint/eslintrc": "^1.4.0", + "@humanwhocodes/config-array": "^0.11.8", "@humanwhocodes/module-importer": "^1.0.1", "@nodelib/fs.walk": "^1.2.8", "ajv": "^6.10.0", @@ -2326,7 +2344,7 @@ "file-entry-cache": "^6.0.1", "find-up": "^5.0.0", "glob-parent": "^6.0.2", - "globals": "^13.15.0", + "globals": "^13.19.0", "grapheme-splitter": "^1.0.4", "ignore": "^5.2.0", "import-fresh": "^3.0.0", @@ -2481,9 +2499,9 @@ "dev": true }, "espree": { - "version": "9.4.0", - "resolved": "https://registry.npmjs.org/espree/-/espree-9.4.0.tgz", - "integrity": "sha512-DQmnRpLj7f6TgN/NYb0MTzJXL+vJF9h3pHy4JhCIs3zwcgez8xmGg3sXHcEO97BrmO2OSvCwMdfdlyl+E9KjOw==", + "version": "9.4.1", + "resolved": "https://registry.npmjs.org/espree/-/espree-9.4.1.tgz", + "integrity": "sha512-XwctdmTO6SIvCzd9810yyNzIrOrqNYV9Koizx4C/mRhf9uq0o4yHoCEU/670pOxOL/MSraektvSAji79kX90Vg==", "dev": true, "requires": { "acorn": "^8.8.0", @@ -2540,9 +2558,9 @@ "dev": true }, "fastq": { - "version": "1.13.0", - "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.13.0.tgz", - "integrity": "sha512-YpkpUnK8od0o1hmeSc7UUs/eB/vIPWJYjKck2QKIzAf71Vm1AAQ3EbuZB3g2JIy+pg+ERD0vqI79KyZiB2e2Nw==", + "version": "1.14.0", + "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.14.0.tgz", + "integrity": "sha512-eR2D+V9/ExcbF9ls441yIuN6TI2ED1Y2ZcA5BmMtJsOkWOFRJQ0Jt0g1UwqXJJVAb+V+umH5Dfr8oh4EVP7VVg==", "dev": true, "requires": { "reusify": "^1.0.4" @@ -2658,14 +2676,23 @@ } }, "globals": { - "version": "13.17.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-13.17.0.tgz", - "integrity": "sha512-1C+6nQRb1GwGMKm2dH/E7enFAMxGTmGI7/dEdhy/DNelv85w9B72t3uc5frtMNXIbzrarJJ/lTCjcaZwbLJmyw==", + "version": "13.19.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-13.19.0.tgz", + "integrity": "sha512-dkQ957uSRWHw7CFXLUtUHQI3g3aWApYhfNR2O6jn/907riyTYKVBmxYVROkBcY614FSSeSJh7Xm7SrUWCxvJMQ==", "dev": true, "requires": { "type-fest": "^0.20.2" } }, + "gopd": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", + "integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==", + "dev": true, + "requires": { + "get-intrinsic": "^1.1.3" + } + }, "grapheme-splitter": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/grapheme-splitter/-/grapheme-splitter-1.0.4.tgz", @@ -2718,9 +2745,9 @@ } }, "ignore": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.0.tgz", - "integrity": "sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ==", + "version": "5.2.4", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.4.tgz", + "integrity": "sha512-MAb38BcSbH0eHNBxn7ql2NH/kX33OkB3lZ1BNdh7ENeRChHTYsTvWrMubiIAMNS2llXEEgZ1MUOBtXChP3kaFQ==", "dev": true }, "import-fresh": { @@ -2756,12 +2783,12 @@ "dev": true }, "internal-slot": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/internal-slot/-/internal-slot-1.0.3.tgz", - "integrity": "sha512-O0DB1JC/sPyZl7cIo78n5dR7eUSwwpYPiXRhTzNxZVAMUuB8vlnRFyLxdrVToks6XPLVnFfbzaVd5WLjhgg+vA==", + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/internal-slot/-/internal-slot-1.0.4.tgz", + "integrity": "sha512-tA8URYccNzMo94s5MQZgH8NB/XTa6HsOo0MLfXTKKEnHVVdegzaQoFZ7Jp44bdvLvY2waT5dc+j5ICEswhi7UQ==", "dev": true, "requires": { - "get-intrinsic": "^1.1.0", + "get-intrinsic": "^1.1.3", "has": "^1.0.3", "side-channel": "^1.0.4" } @@ -2898,9 +2925,9 @@ "dev": true }, "js-sdsl": { - "version": "4.1.5", - "resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.1.5.tgz", - "integrity": "sha512-08bOAKweV2NUC1wqTtf3qZlnpOX/R2DU9ikpjOHs0H+ibQv3zpncVQg6um4uYtRtrwIX8M4Nh3ytK4HGlYAq7Q==", + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.2.0.tgz", + "integrity": "sha512-dyBIzQBDkCqCu+0upx25Y2jGdbTGxE9fshMsCdK0ViOongpV+n5tXRcZY9v7CaVQ79AGS9KA1KHtojxiM7aXSQ==", "dev": true }, "js-yaml": { @@ -3015,25 +3042,25 @@ } }, "object.entries": { - "version": "1.1.5", - "resolved": "https://registry.npmjs.org/object.entries/-/object.entries-1.1.5.tgz", - "integrity": "sha512-TyxmjUoZggd4OrrU1W66FMDG6CuqJxsFvymeyXI51+vQLN67zYfZseptRge703kKQdo4uccgAKebXFcRCzk4+g==", + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/object.entries/-/object.entries-1.1.6.tgz", + "integrity": "sha512-leTPzo4Zvg3pmbQ3rDK69Rl8GQvIqMWubrkxONG9/ojtFE2rD9fjMKfSI5BxW3osRH1m6VdzmqK8oAY9aT4x5w==", "dev": true, "requires": { "call-bind": "^1.0.2", - "define-properties": "^1.1.3", - "es-abstract": "^1.19.1" + "define-properties": "^1.1.4", + "es-abstract": "^1.20.4" } }, "object.values": { - "version": "1.1.5", - "resolved": "https://registry.npmjs.org/object.values/-/object.values-1.1.5.tgz", - "integrity": "sha512-QUZRW0ilQ3PnPpbNtgdNV1PDbEqLIiSFB3l+EnGtBQ/8SUTLj1PZwtQHABZtLgwpJZTSZhuGLOGk57Drx2IvYg==", + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/object.values/-/object.values-1.1.6.tgz", + "integrity": "sha512-FVVTkD1vENCsAcwNs9k6jea2uHC/X0+JcjG8YA60FN5CMaJmG95wT9jek/xX9nornqGRrBkKtzuAu2wuHpKqvw==", "dev": true, "requires": { "call-bind": "^1.0.2", - "define-properties": "^1.1.3", - "es-abstract": "^1.19.1" + "define-properties": "^1.1.4", + "es-abstract": "^1.20.4" } }, "once": { @@ -3235,25 +3262,25 @@ } }, "string.prototype.trimend": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/string.prototype.trimend/-/string.prototype.trimend-1.0.5.tgz", - "integrity": "sha512-I7RGvmjV4pJ7O3kdf+LXFpVfdNOxtCW/2C8f6jNiW4+PQchwxkCDzlk1/7p+Wl4bqFIZeF47qAHXLuHHWKAxog==", + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/string.prototype.trimend/-/string.prototype.trimend-1.0.6.tgz", + "integrity": "sha512-JySq+4mrPf9EsDBEDYMOb/lM7XQLulwg5R/m1r0PXEFqrV0qHvl58sdTilSXtKOflCsK2E8jxf+GKC0T07RWwQ==", "dev": true, "requires": { "call-bind": "^1.0.2", "define-properties": "^1.1.4", - "es-abstract": "^1.19.5" + "es-abstract": "^1.20.4" } }, "string.prototype.trimstart": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/string.prototype.trimstart/-/string.prototype.trimstart-1.0.5.tgz", - "integrity": "sha512-THx16TJCGlsN0o6dl2o6ncWUsdgnLRSA23rRE5pyGBw/mLr3Ej/R2LaqCtgP8VNMGZsvMWnf9ooZPyY2bHvUFg==", + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/string.prototype.trimstart/-/string.prototype.trimstart-1.0.6.tgz", + "integrity": "sha512-omqjMDaY92pbn5HOX7f9IccLA+U1tA9GvtU4JrodiXFfYB7jPzzHpRzpglLAjtUV6bB557zwClJezTqnAiYnQA==", "dev": true, "requires": { "call-bind": "^1.0.2", "define-properties": "^1.1.4", - "es-abstract": "^1.19.5" + "es-abstract": "^1.20.4" } }, "strip-ansi": { diff --git a/package.json b/package.json index 9476bc2..f6a6a16 100644 --- a/package.json +++ b/package.json @@ -9,11 +9,6 @@ "./README.md", "LICENSE" ], - "dependencies": { - "command-exists": "^1.2.9", - "node-cmd": "^5.0.0", - "rsyncwrapper": "^3.0.1" - }, "scripts": { "build": "npm run lint && ncc build ./src/index.js -o dist -m", "lint": "eslint ./src/index.js", @@ -34,9 +29,14 @@ "url": "https://github.com/easingthemes/ssh-deploy/issues" }, "homepage": "https://github.com/easingthemes/ssh-deploy#readme", + "dependencies": { + "command-exists": "^1.2.9", + "node-cmd": "^5.0.0", + "rsyncwrapper": "^3.0.1" + }, "devDependencies": { - "@vercel/ncc": "^0.34.0", - "eslint": "^8.26.0", + "@vercel/ncc": "^0.36.0", + "eslint": "^8.30.0", "eslint-config-airbnb-base": "^15.0.0", "eslint-plugin-import": "^2.26.0" } diff --git a/src/rsyncCli.js b/src/rsyncCli.js index a78bbb3..9a5b6a4 100644 --- a/src/rsyncCli.js +++ b/src/rsyncCli.js @@ -3,7 +3,8 @@ const { get: nodeCmd } = require('node-cmd'); const validateRsync = (callback = () => {}) => { const rsyncCli = commandExists('rsync'); - + console.log('⚠️ [CLI] Rsync doesn\'t exists. Start installation with "apt-get" \n'); + console.log('nodeCmd: ', nodeCmd); if (!rsyncCli) { nodeCmd( 'sudo apt-get --no-install-recommends install rsync', diff --git a/test/Dockerfile b/test/Dockerfile index 23ca795..f580c95 100644 --- a/test/Dockerfile +++ b/test/Dockerfile @@ -4,8 +4,12 @@ ARG ssh_pub_key ARG ssh_user # Add a user to the container RUN adduser --disabled-password $ssh_user -USER $ssh_user +# USER $ssh_user # Add the ssh public key to the container -RUN mkdir -p $HOME/.ssh -RUN echo "$ssh_pub_key" > $HOME/.ssh/authorized_keys -RUN chmod 700 $HOME/.ssh +RUN mkdir -p /home/$ssh_user/.ssh +RUN echo "$ssh_pub_key" > /home/$ssh_user/.ssh/authorized_keys +RUN chmod 700 /home/$ssh_user/.ssh +# Start server +EXPOSE 80 +STOPSIGNAL SIGTERM +CMD ["nginx", "-g", "daemon off;"] From c7bd38757d88aefb77fb14bf5565ff0f6e0079e0 Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Fri, 30 Dec 2022 15:23:23 +0100 Subject: [PATCH 12/46] replace nodeCMD with exec --- .github/workflows/e2e.yml | 37 +- dist/index.js | 525 +----------------- package-lock.json | 14 - package.json | 1 - src/rsyncCli.js | 31 +- .../workflows => tmp}/codeql-analysis.yml | 0 {.github/workflows => tmp}/manual-release.yml | 0 {.github/workflows => tmp}/release.yml | 0 8 files changed, 36 insertions(+), 572 deletions(-) rename {.github/workflows => tmp}/codeql-analysis.yml (100%) rename {.github/workflows => tmp}/manual-release.yml (100%) rename {.github/workflows => tmp}/release.yml (100%) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index ded30f7..5ee0d19 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -1,9 +1,11 @@ name: e2e Test on: - push: - branches: - - feature/add-tests + workflow_run: + workflows: ["Build"] + branches: [ main ] + types: + - completed env: TEST_HOST_DOCKER: ./test @@ -54,19 +56,11 @@ jobs: date +"%Y-%m-%d %H:%M:%S,%3N" >> index.html cat index.html - # - name: e2e Test local ssh-deploy action - # run: node ./dist/index.js - # env: - # SSH_PRIVATE_KEY: $EXAMPLE_SSH_PRIVATE_KEY - # ARGS: "-rltgoDzvO" - # SOURCE: "test_project/" - # REMOTE_HOST: $EXAMPLE_REMOTE_HOST - # REMOTE_USER: $TEST_USER - # TARGET: "/var/www/html/" - # EXCLUDE: "/dist/, /node_modules/" - - - name: e2e Test published ssh-deploy action - uses: easingthemes/ssh-deploy@main + - name: e2e Test local ssh-deploy action + run: | + npm ci + npm run build + node ./src/index.js env: SSH_PRIVATE_KEY: $EXAMPLE_SSH_PRIVATE_KEY ARGS: "-rltgoDzvO" @@ -76,3 +70,14 @@ jobs: TARGET: "/var/www/html/" EXCLUDE: "/dist/, /node_modules/" + # - name: e2e Test published ssh-deploy action + # uses: easingthemes/ssh-deploy@main + # env: + # SSH_PRIVATE_KEY: $EXAMPLE_SSH_PRIVATE_KEY + # ARGS: "-rltgoDzvO" + # SOURCE: "test_project/" + # REMOTE_HOST: $EXAMPLE_REMOTE_HOST + # REMOTE_USER: $TEST_USER + # TARGET: "/var/www/html/" + # EXCLUDE: "/dist/, /node_modules/" + diff --git a/dist/index.js b/dist/index.js index 2c5655a..656d915 100755 --- a/dist/index.js +++ b/dist/index.js @@ -1,525 +1,2 @@ #!/usr/bin/env node -(() => { - var e = { - 569: (e, r, t) => { - e.exports = t(325); - }, - 325: (e, r, t) => { - "use strict"; - var n = t(81).exec; - var s = t(81).execSync; - var o = t(147); - var c = t(17); - var i = o.access; - var a = o.accessSync; - var u = o.constants || o; - var l = process.platform == "win32"; - var fileNotExists = function (e, r) { - i(e, u.F_OK, function (e) { - r(!e); - }); - }; - var fileNotExistsSync = function (e) { - try { - a(e, u.F_OK); - return false; - } catch (e) { - return true; - } - }; - var localExecutable = function (e, r) { - i(e, u.F_OK | u.X_OK, function (e) { - r(null, !e); - }); - }; - var localExecutableSync = function (e) { - try { - a(e, u.F_OK | u.X_OK); - return true; - } catch (e) { - return false; - } - }; - var commandExistsUnix = function (e, r, t) { - fileNotExists(e, function (s) { - if (!s) { - var o = n("command -v " + r + " 2>/dev/null" + " && { echo >&1 " + r + "; exit 0; }", function (e, r, n) { - t(null, !!r); - }); - return; - } - localExecutable(e, t); - }); - }; - var commandExistsWindows = function (e, r, t) { - if (!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(e)) { - t(null, false); - return; - } - var s = n("where " + r, function (e) { - if (e !== null) { - t(null, false); - } else { - t(null, true); - } - }); - }; - var commandExistsUnixSync = function (e, r) { - if (fileNotExistsSync(e)) { - try { - var t = s("command -v " + r + " 2>/dev/null" + " && { echo >&1 " + r + "; exit 0; }"); - return !!t; - } catch (e) { - return false; - } - } - return localExecutableSync(e); - }; - var commandExistsWindowsSync = function (e, r, t) { - if (!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(e)) { - return false; - } - try { - var n = s("where " + r, { stdio: [] }); - return !!n; - } catch (e) { - return false; - } - }; - var cleanInput = function (e) { - if (/[^A-Za-z0-9_\/:=-]/.test(e)) { - e = "'" + e.replace(/'/g, "'\\''") + "'"; - e = e.replace(/^(?:'')+/g, "").replace(/\\'''/g, "\\'"); - } - return e; - }; - if (l) { - cleanInput = function (e) { - var r = /[\\]/.test(e); - if (r) { - var t = '"' + c.dirname(e) + '"'; - var n = '"' + c.basename(e) + '"'; - return t + ":" + n; - } - return '"' + e + '"'; - }; - } - e.exports = function commandExists(e, r) { - var t = cleanInput(e); - if (!r && typeof Promise !== "undefined") { - return new Promise(function (r, t) { - commandExists(e, function (n, s) { - if (s) { - r(e); - } else { - t(n); - } - }); - }); - } - if (l) { - commandExistsWindows(e, t, r); - } else { - commandExistsUnix(e, t, r); - } - }; - e.exports.sync = function (e) { - var r = cleanInput(e); - if (l) { - return commandExistsWindowsSync(e, r); - } else { - return commandExistsUnixSync(e, r); - } - }; - }, - 748: (e, r, t) => { - const { exec: n, execSync: s } = t(81); - const o = { run: runCommand, runSync: runSync }; - function runCommand(e, r) { - return n( - e, - (function () { - return function (e, t, n) { - if (!r) return; - r(e, t, n); - }; - })(r) - ); - } - function runSync(e) { - try { - return { data: s(e).toString(), err: null, stderr: null }; - } catch (e) { - return { data: null, err: e.stderr.toString(), stderr: e.stderr.toString() }; - } - } - e.exports = o; - }, - 898: (e, r, t) => { - "use strict"; - var n = t(81).spawn; - var s = t(837); - var escapeSpaces = function (e) { - if (typeof e === "string") { - return e.replace(/\b\s/g, "\\ "); - } else { - return e; - } - }; - var escapeSpacesInOptions = function (e) { - ["src", "dest", "include", "exclude", "excludeFirst"].forEach(function (r) { - var t = e[r]; - if (typeof t === "string") { - e[r] = escapeSpaces(t); - } else if (Array.isArray(t) === true) { - e[r] = t.map(escapeSpaces); - } - }); - return e; - }; - e.exports = function (e, r) { - e = e || {}; - e = s._extend({}, e); - e = escapeSpacesInOptions(e); - var t = e.platform || process.platform; - var o = t === "win32"; - if (typeof e.src === "undefined") { - throw new Error("'src' directory is missing from options"); - } - if (typeof e.dest === "undefined") { - throw new Error("'dest' directory is missing from options"); - } - var c = e.dest; - if (typeof e.host !== "undefined") { - c = e.host + ":" + e.dest; - } - if (!Array.isArray(e.src)) { - e.src = [e.src]; - } - var i = [].concat(e.src); - i.push(c); - var a = (e.args || []).find(function (e) { - return e.match(/--chmod=/); - }); - if (o && !a) { - i.push("--chmod=ugo=rwX"); - } - if (typeof e.host !== "undefined" || e.ssh) { - i.push("--rsh"); - var u = "ssh"; - if (typeof e.port !== "undefined") { - u += " -p " + e.port; - } - if (typeof e.privateKey !== "undefined") { - u += " -i " + e.privateKey; - } - if (typeof e.sshCmdArgs !== "undefined") { - u += " " + e.sshCmdArgs.join(" "); - } - i.push(u); - } - if (e.recursive === true) { - i.push("--recursive"); - } - if (e.times === true) { - i.push("--times"); - } - if (e.syncDest === true || e.deleteAll === true) { - i.push("--delete"); - i.push("--delete-excluded"); - } - if (e.syncDestIgnoreExcl === true || e.delete === true) { - i.push("--delete"); - } - if (e.dryRun === true) { - i.push("--dry-run"); - i.push("--verbose"); - } - if (typeof e.excludeFirst !== "undefined" && s.isArray(e.excludeFirst)) { - e.excludeFirst.forEach(function (e, r) { - i.push("--exclude=" + e); - }); - } - if (typeof e.include !== "undefined" && s.isArray(e.include)) { - e.include.forEach(function (e, r) { - i.push("--include=" + e); - }); - } - if (typeof e.exclude !== "undefined" && s.isArray(e.exclude)) { - e.exclude.forEach(function (e, r) { - i.push("--exclude=" + e); - }); - } - switch (e.compareMode) { - case "sizeOnly": - i.push("--size-only"); - break; - case "checksum": - i.push("--checksum"); - break; - } - if (typeof e.args !== "undefined" && s.isArray(e.args)) { - i = [...new Set([...i, ...e.args])]; - } - i = [...new Set(i)]; - var noop = function () {}; - var l = e.onStdout || noop; - var d = e.onStderr || noop; - var f = "rsync "; - i.forEach(function (e) { - if (e.substr(0, 4) === "ssh ") { - e = '"' + e + '"'; - } - f += e + " "; - }); - f = f.trim(); - if (e.noExec) { - r(null, null, null, f); - return; - } - try { - var p = ""; - var y = ""; - var v; - if (o) { - v = n("cmd.exe", ["/s", "/c", '"' + f + '"'], { - windowsVerbatimArguments: true, - stdio: [process.stdin, "pipe", "pipe"], - }); - } else { - v = n("/bin/sh", ["-c", f]); - } - v.stdout.on("data", function (e) { - l(e); - p += e; - }); - v.stderr.on("data", function (e) { - d(e); - y += e; - }); - v.on("exit", function (e) { - var t = null; - if (e !== 0) { - t = new Error("rsync exited with code " + e); - t.code = e; - } - r(t, p, y, f); - }); - } catch (e) { - r(e, null, null, f); - } - }; - }, - 505: (e, r, t) => { - const { existsSync: n, mkdirSync: s, writeFileSync: o } = t(147); - const { GITHUB_WORKSPACE: c } = process.env; - const validateDir = (e) => { - if (!n(e)) { - console.log(`[SSH] Creating ${e} dir in `, c); - s(e); - console.log("✅ [SSH] dir created."); - } else { - console.log(`[SSH] ${e} dir exist`); - } - }; - const validateFile = (e) => { - if (!n(e)) { - console.log(`[SSH] Creating ${e} file in `, c); - try { - o(e, "", { encoding: "utf8", mode: 384 }); - console.log("✅ [SSH] file created."); - } catch (r) { - console.error("⚠️ [SSH] writeFileSync error", e, r.message); - process.abort(); - } - } else { - console.log(`[SSH] ${e} file exist`); - } - }; - e.exports = { validateDir: validateDir, validateFile: validateFile }; - }, - 229: (e) => { - const r = [ - "REMOTE_HOST", - "REMOTE_USER", - "REMOTE_PORT", - "SSH_PRIVATE_KEY", - "DEPLOY_KEY_NAME", - "SOURCE", - "TARGET", - "ARGS", - "EXCLUDE", - ]; - const t = { GITHUB_WORKSPACE: process.env.GITHUB_WORKSPACE }; - r.forEach((e) => { - t[e] = process.env[e] || process.env[`INPUT_${e}`]; - }); - e.exports = t; - }, - 447: (e, r, t) => { - const { sync: n } = t(569); - const { get: s } = t(748); - const validateRsync = (e = () => {}) => { - const r = n("rsync"); - console.log('⚠️ [CLI] Rsync doesn\'t exists. Start installation with "apt-get" \n'); - console.log("nodeCmd: ", s); - if (!r) { - s("sudo apt-get --no-install-recommends install rsync", (r, t, n) => { - if (r) { - console.log("⚠️ [CLI] Rsync installation failed. Aborting ... ", r.message); - process.abort(); - } else { - console.log("✅ [CLI] Rsync installed. \n", t, n); - e(); - } - }); - } else { - e(); - } - }; - const validateInputs = (e) => { - const r = Object.keys(e); - const t = r.filter((r) => { - const t = e[r]; - if (!t) { - console.error(`⚠️ [INPUTS] ${r} is mandatory`); - } - return t; - }); - if (t.length !== r.length) { - console.error("⚠️ [INPUTS] Inputs not valid, aborting ..."); - process.abort(); - } - }; - e.exports = { validateRsync: validateRsync, validateInputs: validateInputs }; - }, - 822: (e, r, t) => { - const { writeFileSync: n } = t(147); - const { join: s } = t(17); - const { validateDir: o, validateFile: c } = t(505); - const { HOME: i } = process.env; - const addSshKey = (e, r) => { - const t = s(i || __dirname, ".ssh"); - const a = s(t, r); - o(t); - c(`${t}/known_hosts`); - try { - n(a, e, { encoding: "utf8", mode: 384 }); - } catch (e) { - console.error("⚠️ writeFileSync error", a, e.message); - process.abort(); - } - console.log("✅ Ssh key added to `.ssh` dir ", a); - return a; - }; - e.exports = { addSshKey: addSshKey }; - }, - 81: (e) => { - "use strict"; - e.exports = require("child_process"); - }, - 147: (e) => { - "use strict"; - e.exports = require("fs"); - }, - 17: (e) => { - "use strict"; - e.exports = require("path"); - }, - 837: (e) => { - "use strict"; - e.exports = require("util"); - }, - }; - var r = {}; - function __nccwpck_require__(t) { - var n = r[t]; - if (n !== undefined) { - return n.exports; - } - var s = (r[t] = { exports: {} }); - var o = true; - try { - e[t](s, s.exports, __nccwpck_require__); - o = false; - } finally { - if (o) delete r[t]; - } - return s.exports; - } - if (typeof __nccwpck_require__ !== "undefined") __nccwpck_require__.ab = __dirname + "/"; - var t = {}; - (() => { - const e = __nccwpck_require__(898); - const { validateRsync: r, validateInputs: t } = __nccwpck_require__(447); - const { addSshKey: n } = __nccwpck_require__(822); - const { - REMOTE_HOST: s, - REMOTE_USER: o, - REMOTE_PORT: c, - SSH_PRIVATE_KEY: i, - DEPLOY_KEY_NAME: a, - SOURCE: u, - TARGET: l, - ARGS: d, - EXCLUDE: f, - GITHUB_WORKSPACE: p, - } = __nccwpck_require__(229); - const y = { ssh: true, sshCmdArgs: ["-o StrictHostKeyChecking=no"], recursive: true }; - console.log("[general] GITHUB_WORKSPACE: ", p); - const v = (() => { - const rsync = ({ privateKey: r, port: t, src: n, dest: s, args: o, exclude: c }) => { - console.log(`[Rsync] Starting Rsync Action: ${n} to ${s}`); - if (c) console.log(`[Rsync] exluding folders ${c}`); - try { - e({ src: n, dest: s, args: o, privateKey: r, port: t, excludeFirst: c, ...y }, (e, r, t, n) => { - if (e) { - console.error("⚠️ [Rsync] error: ", e.message); - console.log("⚠️ [Rsync] stderr: ", t); - console.log("⚠️ [Rsync] stdout: ", r); - console.log("⚠️ [Rsync] cmd: ", n); - process.abort(); - } else { - console.log("✅ [Rsync] finished.", r); - } - }); - } catch (e) { - console.error("⚠️ [Rsync] command error: ", e.message, e.stack); - process.abort(); - } - }; - const init = ({ - src: e, - dest: t, - args: s, - host: o = "localhost", - port: c, - username: i, - privateKeyContent: u, - exclude: l = [], - }) => { - r(() => { - const r = n(u, a || "deploy_key"); - const d = `${i}@${o}:${t}`; - rsync({ privateKey: r, port: c, src: e, dest: d, args: s, exclude: l }); - }); - }; - return { init: init }; - })(); - const run = () => { - t({ SSH_PRIVATE_KEY: i, REMOTE_HOST: s, REMOTE_USER: o }); - v.init({ - src: `${p}/${u || ""}`, - dest: l || `/home/${o}/`, - args: d ? [d] : ["-rltgoDzvO"], - host: s, - port: c || "22", - username: o, - privateKeyContent: i, - exclude: (f || "").split(",").map((e) => e.trim()), - }); - }; - run(); - })(); - module.exports = t; -})(); +(()=>{var e={569:(e,r,t)=>{e.exports=t(325)},325:(e,r,t)=>{"use strict";var n=t(81).exec;var s=t(81).execSync;var o=t(147);var c=t(17);var i=o.access;var a=o.accessSync;var u=o.constants||o;var l=process.platform=="win32";var fileNotExists=function(e,r){i(e,u.F_OK,(function(e){r(!e)}))};var fileNotExistsSync=function(e){try{a(e,u.F_OK);return false}catch(e){return true}};var localExecutable=function(e,r){i(e,u.F_OK|u.X_OK,(function(e){r(null,!e)}))};var localExecutableSync=function(e){try{a(e,u.F_OK|u.X_OK);return true}catch(e){return false}};var commandExistsUnix=function(e,r,t){fileNotExists(e,(function(s){if(!s){var o=n("command -v "+r+" 2>/dev/null"+" && { echo >&1 "+r+"; exit 0; }",(function(e,r,n){t(null,!!r)}));return}localExecutable(e,t)}))};var commandExistsWindows=function(e,r,t){if(!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(e)){t(null,false);return}var s=n("where "+r,(function(e){if(e!==null){t(null,false)}else{t(null,true)}}))};var commandExistsUnixSync=function(e,r){if(fileNotExistsSync(e)){try{var t=s("command -v "+r+" 2>/dev/null"+" && { echo >&1 "+r+"; exit 0; }");return!!t}catch(e){return false}}return localExecutableSync(e)};var commandExistsWindowsSync=function(e,r,t){if(!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(e)){return false}try{var n=s("where "+r,{stdio:[]});return!!n}catch(e){return false}};var cleanInput=function(e){if(/[^A-Za-z0-9_\/:=-]/.test(e)){e="'"+e.replace(/'/g,"'\\''")+"'";e=e.replace(/^(?:'')+/g,"").replace(/\\'''/g,"\\'")}return e};if(l){cleanInput=function(e){var r=/[\\]/.test(e);if(r){var t='"'+c.dirname(e)+'"';var n='"'+c.basename(e)+'"';return t+":"+n}return'"'+e+'"'}}e.exports=function commandExists(e,r){var t=cleanInput(e);if(!r&&typeof Promise!=="undefined"){return new Promise((function(r,t){commandExists(e,(function(n,s){if(s){r(e)}else{t(n)}}))}))}if(l){commandExistsWindows(e,t,r)}else{commandExistsUnix(e,t,r)}};e.exports.sync=function(e){var r=cleanInput(e);if(l){return commandExistsWindowsSync(e,r)}else{return commandExistsUnixSync(e,r)}}},748:(e,r,t)=>{const{exec:n,execSync:s}=t(81);const o={run:runCommand,runSync:runSync};function runCommand(e,r){return n(e,function(){return function(e,t,n){if(!r)return;r(e,t,n)}}(r))}function runSync(e){try{return{data:s(e).toString(),err:null,stderr:null}}catch(e){return{data:null,err:e.stderr.toString(),stderr:e.stderr.toString()}}}e.exports=o},898:(e,r,t)=>{"use strict";var n=t(81).spawn;var s=t(837);var escapeSpaces=function(e){if(typeof e==="string"){return e.replace(/\b\s/g,"\\ ")}else{return e}};var escapeSpacesInOptions=function(e){["src","dest","include","exclude","excludeFirst"].forEach((function(r){var t=e[r];if(typeof t==="string"){e[r]=escapeSpaces(t)}else if(Array.isArray(t)===true){e[r]=t.map(escapeSpaces)}}));return e};e.exports=function(e,r){e=e||{};e=s._extend({},e);e=escapeSpacesInOptions(e);var t=e.platform||process.platform;var o=t==="win32";if(typeof e.src==="undefined"){throw new Error("'src' directory is missing from options")}if(typeof e.dest==="undefined"){throw new Error("'dest' directory is missing from options")}var c=e.dest;if(typeof e.host!=="undefined"){c=e.host+":"+e.dest}if(!Array.isArray(e.src)){e.src=[e.src]}var i=[].concat(e.src);i.push(c);var a=(e.args||[]).find((function(e){return e.match(/--chmod=/)}));if(o&&!a){i.push("--chmod=ugo=rwX")}if(typeof e.host!=="undefined"||e.ssh){i.push("--rsh");var u="ssh";if(typeof e.port!=="undefined"){u+=" -p "+e.port}if(typeof e.privateKey!=="undefined"){u+=" -i "+e.privateKey}if(typeof e.sshCmdArgs!=="undefined"){u+=" "+e.sshCmdArgs.join(" ")}i.push(u)}if(e.recursive===true){i.push("--recursive")}if(e.times===true){i.push("--times")}if(e.syncDest===true||e.deleteAll===true){i.push("--delete");i.push("--delete-excluded")}if(e.syncDestIgnoreExcl===true||e.delete===true){i.push("--delete")}if(e.dryRun===true){i.push("--dry-run");i.push("--verbose")}if(typeof e.excludeFirst!=="undefined"&&s.isArray(e.excludeFirst)){e.excludeFirst.forEach((function(e,r){i.push("--exclude="+e)}))}if(typeof e.include!=="undefined"&&s.isArray(e.include)){e.include.forEach((function(e,r){i.push("--include="+e)}))}if(typeof e.exclude!=="undefined"&&s.isArray(e.exclude)){e.exclude.forEach((function(e,r){i.push("--exclude="+e)}))}switch(e.compareMode){case"sizeOnly":i.push("--size-only");break;case"checksum":i.push("--checksum");break}if(typeof e.args!=="undefined"&&s.isArray(e.args)){i=[...new Set([...i,...e.args])]}i=[...new Set(i)];var noop=function(){};var l=e.onStdout||noop;var d=e.onStderr||noop;var f="rsync ";i.forEach((function(e){if(e.substr(0,4)==="ssh "){e='"'+e+'"'}f+=e+" "}));f=f.trim();if(e.noExec){r(null,null,null,f);return}try{var p="";var y="";var v;if(o){v=n("cmd.exe",["/s","/c",'"'+f+'"'],{windowsVerbatimArguments:true,stdio:[process.stdin,"pipe","pipe"]})}else{v=n("/bin/sh",["-c",f])}v.stdout.on("data",(function(e){l(e);p+=e}));v.stderr.on("data",(function(e){d(e);y+=e}));v.on("exit",(function(e){var t=null;if(e!==0){t=new Error("rsync exited with code "+e);t.code=e}r(t,p,y,f)}))}catch(e){r(e,null,null,f)}}},505:(e,r,t)=>{const{existsSync:n,mkdirSync:s,writeFileSync:o}=t(147);const{GITHUB_WORKSPACE:c}=process.env;const validateDir=e=>{if(!n(e)){console.log(`[SSH] Creating ${e} dir in `,c);s(e);console.log("✅ [SSH] dir created.")}else{console.log(`[SSH] ${e} dir exist`)}};const validateFile=e=>{if(!n(e)){console.log(`[SSH] Creating ${e} file in `,c);try{o(e,"",{encoding:"utf8",mode:384});console.log("✅ [SSH] file created.")}catch(r){console.error("⚠️ [SSH] writeFileSync error",e,r.message);process.abort()}}else{console.log(`[SSH] ${e} file exist`)}};e.exports={validateDir:validateDir,validateFile:validateFile}},229:e=>{const r=["REMOTE_HOST","REMOTE_USER","REMOTE_PORT","SSH_PRIVATE_KEY","DEPLOY_KEY_NAME","SOURCE","TARGET","ARGS","EXCLUDE"];const t={GITHUB_WORKSPACE:process.env.GITHUB_WORKSPACE};r.forEach((e=>{t[e]=process.env[e]||process.env[`INPUT_${e}`]}));e.exports=t},447:(e,r,t)=>{const{sync:n}=t(569);const{get:s}=t(748);const validateRsync=(e=(()=>{}))=>{const r=n("rsync");console.log('⚠️ [CLI] Rsync doesn\'t exists. Start installation with "apt-get" \n');console.log("nodeCmd: ",s);if(!r){s("sudo apt-get --no-install-recommends install rsync",((r,t,n)=>{if(r){console.log("⚠️ [CLI] Rsync installation failed. Aborting ... ",r.message);process.abort()}else{console.log("✅ [CLI] Rsync installed. \n",t,n);e()}}))}else{e()}};const validateInputs=e=>{const r=Object.keys(e);const t=r.filter((r=>{const t=e[r];if(!t){console.error(`⚠️ [INPUTS] ${r} is mandatory`)}return t}));if(t.length!==r.length){console.error("⚠️ [INPUTS] Inputs not valid, aborting ...");process.abort()}};e.exports={validateRsync:validateRsync,validateInputs:validateInputs}},822:(e,r,t)=>{const{writeFileSync:n}=t(147);const{join:s}=t(17);const{validateDir:o,validateFile:c}=t(505);const{HOME:i}=process.env;const addSshKey=(e,r)=>{const t=s(i||__dirname,".ssh");const a=s(t,r);o(t);c(`${t}/known_hosts`);try{n(a,e,{encoding:"utf8",mode:384})}catch(e){console.error("⚠️ writeFileSync error",a,e.message);process.abort()}console.log("✅ Ssh key added to `.ssh` dir ",a);return a};e.exports={addSshKey:addSshKey}},81:e=>{"use strict";e.exports=require("child_process")},147:e=>{"use strict";e.exports=require("fs")},17:e=>{"use strict";e.exports=require("path")},837:e=>{"use strict";e.exports=require("util")}};var r={};function __nccwpck_require__(t){var n=r[t];if(n!==undefined){return n.exports}var s=r[t]={exports:{}};var o=true;try{e[t](s,s.exports,__nccwpck_require__);o=false}finally{if(o)delete r[t]}return s.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var t={};(()=>{const e=__nccwpck_require__(898);const{validateRsync:r,validateInputs:t}=__nccwpck_require__(447);const{addSshKey:n}=__nccwpck_require__(822);const{REMOTE_HOST:s,REMOTE_USER:o,REMOTE_PORT:c,SSH_PRIVATE_KEY:i,DEPLOY_KEY_NAME:a,SOURCE:u,TARGET:l,ARGS:d,EXCLUDE:f,GITHUB_WORKSPACE:p}=__nccwpck_require__(229);const y={ssh:true,sshCmdArgs:["-o StrictHostKeyChecking=no"],recursive:true};console.log("[general] GITHUB_WORKSPACE: ",p);const v=(()=>{const rsync=({privateKey:r,port:t,src:n,dest:s,args:o,exclude:c})=>{console.log(`[Rsync] Starting Rsync Action: ${n} to ${s}`);if(c)console.log(`[Rsync] exluding folders ${c}`);try{e({src:n,dest:s,args:o,privateKey:r,port:t,excludeFirst:c,...y},((e,r,t,n)=>{if(e){console.error("⚠️ [Rsync] error: ",e.message);console.log("⚠️ [Rsync] stderr: ",t);console.log("⚠️ [Rsync] stdout: ",r);console.log("⚠️ [Rsync] cmd: ",n);process.abort()}else{console.log("✅ [Rsync] finished.",r)}}))}catch(e){console.error("⚠️ [Rsync] command error: ",e.message,e.stack);process.abort()}};const init=({src:e,dest:t,args:s,host:o="localhost",port:c,username:i,privateKeyContent:u,exclude:l=[]})=>{r((()=>{const r=n(u,a||"deploy_key");const d=`${i}@${o}:${t}`;rsync({privateKey:r,port:c,src:e,dest:d,args:s,exclude:l})}))};return{init:init}})();const run=()=>{t({SSH_PRIVATE_KEY:i,REMOTE_HOST:s,REMOTE_USER:o});v.init({src:`${p}/${u||""}`,dest:l||`/home/${o}/`,args:d?[d]:["-rltgoDzvO"],host:s,port:c||"22",username:o,privateKeyContent:i,exclude:(f||"").split(",").map((e=>e.trim()))})};run()})();module.exports=t})(); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 49c75b1..4026c44 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,6 @@ "license": "MIT", "dependencies": { "command-exists": "^1.2.9", - "node-cmd": "^5.0.0", "rsyncwrapper": "^3.0.1" }, "devDependencies": { @@ -1397,14 +1396,6 @@ "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==", "dev": true }, - "node_modules/node-cmd": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/node-cmd/-/node-cmd-5.0.0.tgz", - "integrity": "sha512-4sQTJmsS5uZKAPz/Df9fnIbmvOySfGdW+UreH4X5NcAOOpKjaE+K5wf4ehNBbZVPo0vQ36RkRnhhsXXJAT+Syw==", - "engines": { - "node": ">=6.4.0" - } - }, "node_modules/object-inspect": { "version": "1.12.2", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.2.tgz", @@ -3012,11 +3003,6 @@ "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==", "dev": true }, - "node-cmd": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/node-cmd/-/node-cmd-5.0.0.tgz", - "integrity": "sha512-4sQTJmsS5uZKAPz/Df9fnIbmvOySfGdW+UreH4X5NcAOOpKjaE+K5wf4ehNBbZVPo0vQ36RkRnhhsXXJAT+Syw==" - }, "object-inspect": { "version": "1.12.2", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.2.tgz", diff --git a/package.json b/package.json index f6a6a16..41d082c 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,6 @@ "homepage": "https://github.com/easingthemes/ssh-deploy#readme", "dependencies": { "command-exists": "^1.2.9", - "node-cmd": "^5.0.0", "rsyncwrapper": "^3.0.1" }, "devDependencies": { diff --git a/src/rsyncCli.js b/src/rsyncCli.js index 9a5b6a4..b29beea 100644 --- a/src/rsyncCli.js +++ b/src/rsyncCli.js @@ -1,23 +1,20 @@ -const { sync: commandExists } = require('command-exists'); -const { get: nodeCmd } = require('node-cmd'); +const { sync: commandExists } = require("command-exists"); +const { exec, execSync } = require("child_process"); const validateRsync = (callback = () => {}) => { - const rsyncCli = commandExists('rsync'); + const rsyncCli = commandExists("rsync"); console.log('⚠️ [CLI] Rsync doesn\'t exists. Start installation with "apt-get" \n'); - console.log('nodeCmd: ', nodeCmd); if (!rsyncCli) { - nodeCmd( - 'sudo apt-get --no-install-recommends install rsync', - (err, data, stderr) => { - if (err) { - console.log('⚠️ [CLI] Rsync installation failed. Aborting ... ', err.message); - process.abort(); - } else { - console.log('✅ [CLI] Rsync installed. \n', data, stderr); - callback(); - } + execSync("sudo apt-get update"); + exec("sudo apt-get --no-install-recommends install rsync", (err, data, stderr) => { + if (err) { + console.log("⚠️ [CLI] Rsync installation failed. Aborting ... ", err.message); + process.abort(); + } else { + console.log("✅ [CLI] Rsync installed. \n", data, stderr); + callback(); } - ); + }); } else { callback(); } @@ -36,12 +33,12 @@ const validateInputs = (inputs) => { }); if (validInputs.length !== inputKeys.length) { - console.error('⚠️ [INPUTS] Inputs not valid, aborting ...'); + console.error("⚠️ [INPUTS] Inputs not valid, aborting ..."); process.abort(); } }; module.exports = { validateRsync, - validateInputs + validateInputs, }; diff --git a/.github/workflows/codeql-analysis.yml b/tmp/codeql-analysis.yml similarity index 100% rename from .github/workflows/codeql-analysis.yml rename to tmp/codeql-analysis.yml diff --git a/.github/workflows/manual-release.yml b/tmp/manual-release.yml similarity index 100% rename from .github/workflows/manual-release.yml rename to tmp/manual-release.yml diff --git a/.github/workflows/release.yml b/tmp/release.yml similarity index 100% rename from .github/workflows/release.yml rename to tmp/release.yml From 6662bf770e33d7e9b8d363c25536e418af4349cc Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Fri, 30 Dec 2022 15:25:45 +0100 Subject: [PATCH 13/46] run on main branch --- .github/workflows/e2e.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 5ee0d19..8b44e2e 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -1,11 +1,8 @@ name: e2e Test on: - workflow_run: - workflows: ["Build"] - branches: [ main ] - types: - - completed + push: + branches: [ 'main' ] env: TEST_HOST_DOCKER: ./test From 25ffb03f81476ffeada3c4e07da89b1f459f4591 Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Fri, 30 Dec 2022 15:26:24 +0100 Subject: [PATCH 14/46] run on current branch --- .github/workflows/e2e.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 8b44e2e..27631e4 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -2,7 +2,7 @@ name: e2e Test on: push: - branches: [ 'main' ] + branches: [ 'feature/add-tests' ] env: TEST_HOST_DOCKER: ./test From 8073f2b34cbfc9864e1a2b00a8a47dea9ab08519 Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Fri, 30 Dec 2022 15:36:34 +0100 Subject: [PATCH 15/46] test env vars --- .github/workflows/e2e.yml | 2 +- src/test.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/test.js diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 27631e4..056544d 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -57,7 +57,7 @@ jobs: run: | npm ci npm run build - node ./src/index.js + node ./src/test.js env: SSH_PRIVATE_KEY: $EXAMPLE_SSH_PRIVATE_KEY ARGS: "-rltgoDzvO" diff --git a/src/test.js b/src/test.js new file mode 100644 index 0000000..4e1dbd1 --- /dev/null +++ b/src/test.js @@ -0,0 +1,9 @@ +const { + REMOTE_HOST, REMOTE_USER, + REMOTE_PORT, SSH_PRIVATE_KEY, DEPLOY_KEY_NAME, + SOURCE, TARGET, ARGS, EXCLUDE, + GITHUB_WORKSPACE +} = require('./inputs'); + +// eslint-disable-next-line max-len +console.log(REMOTE_HOST, REMOTE_USER, REMOTE_PORT, SSH_PRIVATE_KEY, DEPLOY_KEY_NAME, SOURCE, TARGET, ARGS, EXCLUDE, GITHUB_WORKSPACE); From 2f8e6000d2244c03f595a519509bc645f339522f Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Fri, 30 Dec 2022 15:40:28 +0100 Subject: [PATCH 16/46] env vars test --- .github/workflows/e2e.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 056544d..dfa535e 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -63,7 +63,7 @@ jobs: ARGS: "-rltgoDzvO" SOURCE: "test_project/" REMOTE_HOST: $EXAMPLE_REMOTE_HOST - REMOTE_USER: $TEST_USER + REMOTE_USER: ${{ TEST_USER }} TARGET: "/var/www/html/" EXCLUDE: "/dist/, /node_modules/" From 68642e11e3eac7480cb40d0f3971e012f71dd1ea Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Fri, 30 Dec 2022 15:44:09 +0100 Subject: [PATCH 17/46] env --- .github/workflows/e2e.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index dfa535e..5f1ac37 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -63,7 +63,7 @@ jobs: ARGS: "-rltgoDzvO" SOURCE: "test_project/" REMOTE_HOST: $EXAMPLE_REMOTE_HOST - REMOTE_USER: ${{ TEST_USER }} + REMOTE_USER: ${{ env.TEST_USER }} TARGET: "/var/www/html/" EXCLUDE: "/dist/, /node_modules/" From a3ddddcc151062ada4e0707483d4fe62f181eaf5 Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Fri, 30 Dec 2022 15:44:38 +0100 Subject: [PATCH 18/46] env --- .github/workflows/e2e.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 5f1ac37..b53b3a7 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -59,10 +59,10 @@ jobs: npm run build node ./src/test.js env: - SSH_PRIVATE_KEY: $EXAMPLE_SSH_PRIVATE_KEY + SSH_PRIVATE_KEY: "$EXAMPLE_SSH_PRIVATE_KEY" ARGS: "-rltgoDzvO" SOURCE: "test_project/" - REMOTE_HOST: $EXAMPLE_REMOTE_HOST + REMOTE_HOST: "$EXAMPLE_REMOTE_HOST" REMOTE_USER: ${{ env.TEST_USER }} TARGET: "/var/www/html/" EXCLUDE: "/dist/, /node_modules/" From e577b525ca3ec7769ae9e9c9b53a9e010d880cbe Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Fri, 30 Dec 2022 15:46:37 +0100 Subject: [PATCH 19/46] env2 --- .github/workflows/e2e.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index b53b3a7..15481cf 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -59,10 +59,10 @@ jobs: npm run build node ./src/test.js env: - SSH_PRIVATE_KEY: "$EXAMPLE_SSH_PRIVATE_KEY" + SSH_PRIVATE_KEY: ${{ env.EXAMPLE_SSH_PRIVATE_KEY }} ARGS: "-rltgoDzvO" SOURCE: "test_project/" - REMOTE_HOST: "$EXAMPLE_REMOTE_HOST" + REMOTE_HOST: ${{ env.EXAMPLE_REMOTE_HOST }} REMOTE_USER: ${{ env.TEST_USER }} TARGET: "/var/www/html/" EXCLUDE: "/dist/, /node_modules/" From f67f2211cb4af635e5eb76eed56015d234fc728e Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Fri, 30 Dec 2022 15:48:53 +0100 Subject: [PATCH 20/46] env3 --- .github/workflows/e2e.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 15481cf..a70d408 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -57,7 +57,7 @@ jobs: run: | npm ci npm run build - node ./src/test.js + node ./src/index.js env: SSH_PRIVATE_KEY: ${{ env.EXAMPLE_SSH_PRIVATE_KEY }} ARGS: "-rltgoDzvO" @@ -67,14 +67,14 @@ jobs: TARGET: "/var/www/html/" EXCLUDE: "/dist/, /node_modules/" - # - name: e2e Test published ssh-deploy action - # uses: easingthemes/ssh-deploy@main - # env: - # SSH_PRIVATE_KEY: $EXAMPLE_SSH_PRIVATE_KEY - # ARGS: "-rltgoDzvO" - # SOURCE: "test_project/" - # REMOTE_HOST: $EXAMPLE_REMOTE_HOST - # REMOTE_USER: $TEST_USER - # TARGET: "/var/www/html/" - # EXCLUDE: "/dist/, /node_modules/" + - name: e2e Test published ssh-deploy action + uses: easingthemes/ssh-deploy@main + env: + SSH_PRIVATE_KEY: ${{ env.EXAMPLE_SSH_PRIVATE_KEY }} + ARGS: "-rltgoDzvO" + SOURCE: "test_project/" + REMOTE_HOST: ${{ env.EXAMPLE_REMOTE_HOST }} + REMOTE_USER: ${{ env.TEST_USER }} + TARGET: "/var/www/html/" + EXCLUDE: "/dist/, /node_modules/" From 4d8753359e02f9a2887af44c3c15d5db055c0214 Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Fri, 30 Dec 2022 15:59:05 +0100 Subject: [PATCH 21/46] test ssh --- .github/workflows/e2e.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index a70d408..660afa6 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -53,11 +53,18 @@ jobs: date +"%Y-%m-%d %H:%M:%S,%3N" >> index.html cat index.html + - name: e2e Test ssh + run: | + ssh ${{ env.REMOTE_USER }}@${{ env.REMOTE_HOST }} + env: + REMOTE_HOST: ${{ env.EXAMPLE_REMOTE_HOST }} + REMOTE_USER: ${{ env.TEST_USER }} + - name: e2e Test local ssh-deploy action run: | npm ci npm run build - node ./src/index.js + node ./src/index.js || true env: SSH_PRIVATE_KEY: ${{ env.EXAMPLE_SSH_PRIVATE_KEY }} ARGS: "-rltgoDzvO" From 0f6376161f26186da1beeee12322cf4c8c663f22 Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Fri, 30 Dec 2022 16:01:47 +0100 Subject: [PATCH 22/46] add key --- .github/workflows/e2e.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 660afa6..5bf6056 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -25,8 +25,8 @@ jobs: echo $HOME ls -la $HOME ssh-keygen -m PEM -t rsa -b 4096 -f "$HOME/.ssh/id_rsa" -N "" - # ssh-add "$HOME/.ssh/id_rsa" - # ssh-add -l + ssh-add "$HOME/.ssh/id_rsa" + ssh-add -l echo "EXAMPLE_SSH_PRIVATE_KEY<> $GITHUB_ENV cat $HOME/.ssh/id_rsa >> $GITHUB_ENV echo "EOF" >> $GITHUB_ENV From fd8e654d7e57dca4265c7ff171e634319db182aa Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Fri, 30 Dec 2022 16:04:25 +0100 Subject: [PATCH 23/46] eval `ssh-agent -s` --- .github/workflows/e2e.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 5bf6056..1ba2f19 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -25,6 +25,7 @@ jobs: echo $HOME ls -la $HOME ssh-keygen -m PEM -t rsa -b 4096 -f "$HOME/.ssh/id_rsa" -N "" + eval `ssh-agent -s` ssh-add "$HOME/.ssh/id_rsa" ssh-add -l echo "EXAMPLE_SSH_PRIVATE_KEY<> $GITHUB_ENV From aeee708bee955b334c6ea09586924f8ba071fa01 Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Sat, 31 Dec 2022 02:43:17 +0100 Subject: [PATCH 24/46] test --- .github/workflows/e2e.yml | 73 +++++++++++++++++++++++++-------------- dist/index.js | 2 +- src/inputs.js | 3 ++ src/test.js | 11 ++---- test/Dockerfile | 42 +++++++++++++++------- test/entrypoint.sh | 3 ++ 6 files changed, 85 insertions(+), 49 deletions(-) create mode 100644 test/entrypoint.sh diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 1ba2f19..4430677 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -5,8 +5,9 @@ on: branches: [ 'feature/add-tests' ] env: + GLOBAL_WORKFLOW_ENV: __some value for GLOBAL_WORKFLOW_ENV__ TEST_HOST_DOCKER: ./test - TEST_USER: kaja + TEST_USER: test jobs: e2e: @@ -16,6 +17,25 @@ jobs: - name: Checkout uses: actions/checkout@v3 + # - name: Set ENV var + # run: | + # echo "CUSTOM_VAR=IT WORKS" >> $GITHUB_ENV + + # - name: Use ENV var via `env` block + # run: | + # echo $CUSTOM_VAR # OK + # echo ${{ env.CUSTOM_VAR }} # OK + # echo $USE_CUSTOM_VAR # NOT OK, prints '' + # echo ${{ env.USE_CUSTOM_VAR }} # NOT OK, prints '' + # echo $USE_CUSTOM_VAR_2 # NOT OK, prints '$CUSTOM_VAR' + # echo ${{ env.USE_CUSTOM_VAR_2 }} # OK + # echo $USE_CUSTOM_VAR_3 # NOT OK, prints '$GLOBAL_WORKFLOW_ENV' + # echo ${{ env.USE_CUSTOM_VAR_3 }} # OK + # env: + # USE_CUSTOM_VAR: ${{ env.CUSTOM_VAR }} + # USE_CUSTOM_VAR_2: $CUSTOM_VAR + # USE_CUSTOM_VAR_3: $GLOBAL_WORKFLOW_ENV + - name: Clean up old test files run: | docker stop ssh-host-container || true && docker rm ssh-host-container || true @@ -37,9 +57,9 @@ jobs: run: | docker build \ -t ssh-host-image . \ - --build-arg ssh_pub_key="$(cat $HOME/.ssh/id_rsa.pub)" \ + --build-arg SSH_PUB_KEY="$(cat $HOME/.ssh/id_rsa.pub)" \ --build-arg ssh_user="${{ env.TEST_USER }}" - docker run -d --name=ssh-host-container ssh-host-image + docker run -d -p 8822:22 --name=ssh-host-container ssh-host-image docker exec ssh-host-container sh -c "hostname --ip-address" > ip.txt echo "EXAMPLE_REMOTE_HOST<> $GITHUB_ENV cat ip.txt >> $GITHUB_ENV @@ -54,35 +74,36 @@ jobs: date +"%Y-%m-%d %H:%M:%S,%3N" >> index.html cat index.html - - name: e2e Test ssh - run: | - ssh ${{ env.REMOTE_USER }}@${{ env.REMOTE_HOST }} - env: - REMOTE_HOST: ${{ env.EXAMPLE_REMOTE_HOST }} - REMOTE_USER: ${{ env.TEST_USER }} + # - name: e2e Test local ssh-deploy action + # run: | + # echo "${{ env.REMOTE_HOST }} -- $EXAMPLE_REMOTE_HOST -- ${{ env.EXAMPLE_REMOTE_HOST }}" + # npm ci + # npm run build + # node ./src/test.js || true + # env: + # SSH_PRIVATE_KEY: $EXAMPLE_SSH_PRIVATE_KEY + # ARGS: "-rltgoDzvO" + # SOURCE: "test_project/" + # REMOTE_HOST: $EXAMPLE_REMOTE_HOST + # REMOTE_USER: ${{ env.TEST_USER }} + # TARGET: "/var/www/html/" + # EXCLUDE: "/dist/, /node_modules/" - - name: e2e Test local ssh-deploy action - run: | - npm ci - npm run build - node ./src/index.js || true - env: - SSH_PRIVATE_KEY: ${{ env.EXAMPLE_SSH_PRIVATE_KEY }} - ARGS: "-rltgoDzvO" - SOURCE: "test_project/" - REMOTE_HOST: ${{ env.EXAMPLE_REMOTE_HOST }} - REMOTE_USER: ${{ env.TEST_USER }} - TARGET: "/var/www/html/" - EXCLUDE: "/dist/, /node_modules/" + # - name: e2e Test ssh + # run: | + # echo "$SSH_REMOTE_USER@$SSH_REMOTE_HOST" + # ssh -p 8822 $SSH_REMOTE_USER@$SSH_REMOTE_HOST 'exit' + # env: + # SSH_REMOTE_HOST: ${{ env.EXAMPLE_REMOTE_HOST }} + # SSH_REMOTE_USER: ${{ env.TEST_USER }} - name: e2e Test published ssh-deploy action uses: easingthemes/ssh-deploy@main - env: - SSH_PRIVATE_KEY: ${{ env.EXAMPLE_SSH_PRIVATE_KEY }} + with: + SSH_PRIVATE_KEY: $EXAMPLE_SSH_PRIVATE_KEY ARGS: "-rltgoDzvO" SOURCE: "test_project/" - REMOTE_HOST: ${{ env.EXAMPLE_REMOTE_HOST }} + REMOTE_HOST: $EXAMPLE_REMOTE_HOST REMOTE_USER: ${{ env.TEST_USER }} TARGET: "/var/www/html/" EXCLUDE: "/dist/, /node_modules/" - diff --git a/dist/index.js b/dist/index.js index 656d915..f2597bb 100755 --- a/dist/index.js +++ b/dist/index.js @@ -1,2 +1,2 @@ #!/usr/bin/env node -(()=>{var e={569:(e,r,t)=>{e.exports=t(325)},325:(e,r,t)=>{"use strict";var n=t(81).exec;var s=t(81).execSync;var o=t(147);var c=t(17);var i=o.access;var a=o.accessSync;var u=o.constants||o;var l=process.platform=="win32";var fileNotExists=function(e,r){i(e,u.F_OK,(function(e){r(!e)}))};var fileNotExistsSync=function(e){try{a(e,u.F_OK);return false}catch(e){return true}};var localExecutable=function(e,r){i(e,u.F_OK|u.X_OK,(function(e){r(null,!e)}))};var localExecutableSync=function(e){try{a(e,u.F_OK|u.X_OK);return true}catch(e){return false}};var commandExistsUnix=function(e,r,t){fileNotExists(e,(function(s){if(!s){var o=n("command -v "+r+" 2>/dev/null"+" && { echo >&1 "+r+"; exit 0; }",(function(e,r,n){t(null,!!r)}));return}localExecutable(e,t)}))};var commandExistsWindows=function(e,r,t){if(!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(e)){t(null,false);return}var s=n("where "+r,(function(e){if(e!==null){t(null,false)}else{t(null,true)}}))};var commandExistsUnixSync=function(e,r){if(fileNotExistsSync(e)){try{var t=s("command -v "+r+" 2>/dev/null"+" && { echo >&1 "+r+"; exit 0; }");return!!t}catch(e){return false}}return localExecutableSync(e)};var commandExistsWindowsSync=function(e,r,t){if(!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(e)){return false}try{var n=s("where "+r,{stdio:[]});return!!n}catch(e){return false}};var cleanInput=function(e){if(/[^A-Za-z0-9_\/:=-]/.test(e)){e="'"+e.replace(/'/g,"'\\''")+"'";e=e.replace(/^(?:'')+/g,"").replace(/\\'''/g,"\\'")}return e};if(l){cleanInput=function(e){var r=/[\\]/.test(e);if(r){var t='"'+c.dirname(e)+'"';var n='"'+c.basename(e)+'"';return t+":"+n}return'"'+e+'"'}}e.exports=function commandExists(e,r){var t=cleanInput(e);if(!r&&typeof Promise!=="undefined"){return new Promise((function(r,t){commandExists(e,(function(n,s){if(s){r(e)}else{t(n)}}))}))}if(l){commandExistsWindows(e,t,r)}else{commandExistsUnix(e,t,r)}};e.exports.sync=function(e){var r=cleanInput(e);if(l){return commandExistsWindowsSync(e,r)}else{return commandExistsUnixSync(e,r)}}},748:(e,r,t)=>{const{exec:n,execSync:s}=t(81);const o={run:runCommand,runSync:runSync};function runCommand(e,r){return n(e,function(){return function(e,t,n){if(!r)return;r(e,t,n)}}(r))}function runSync(e){try{return{data:s(e).toString(),err:null,stderr:null}}catch(e){return{data:null,err:e.stderr.toString(),stderr:e.stderr.toString()}}}e.exports=o},898:(e,r,t)=>{"use strict";var n=t(81).spawn;var s=t(837);var escapeSpaces=function(e){if(typeof e==="string"){return e.replace(/\b\s/g,"\\ ")}else{return e}};var escapeSpacesInOptions=function(e){["src","dest","include","exclude","excludeFirst"].forEach((function(r){var t=e[r];if(typeof t==="string"){e[r]=escapeSpaces(t)}else if(Array.isArray(t)===true){e[r]=t.map(escapeSpaces)}}));return e};e.exports=function(e,r){e=e||{};e=s._extend({},e);e=escapeSpacesInOptions(e);var t=e.platform||process.platform;var o=t==="win32";if(typeof e.src==="undefined"){throw new Error("'src' directory is missing from options")}if(typeof e.dest==="undefined"){throw new Error("'dest' directory is missing from options")}var c=e.dest;if(typeof e.host!=="undefined"){c=e.host+":"+e.dest}if(!Array.isArray(e.src)){e.src=[e.src]}var i=[].concat(e.src);i.push(c);var a=(e.args||[]).find((function(e){return e.match(/--chmod=/)}));if(o&&!a){i.push("--chmod=ugo=rwX")}if(typeof e.host!=="undefined"||e.ssh){i.push("--rsh");var u="ssh";if(typeof e.port!=="undefined"){u+=" -p "+e.port}if(typeof e.privateKey!=="undefined"){u+=" -i "+e.privateKey}if(typeof e.sshCmdArgs!=="undefined"){u+=" "+e.sshCmdArgs.join(" ")}i.push(u)}if(e.recursive===true){i.push("--recursive")}if(e.times===true){i.push("--times")}if(e.syncDest===true||e.deleteAll===true){i.push("--delete");i.push("--delete-excluded")}if(e.syncDestIgnoreExcl===true||e.delete===true){i.push("--delete")}if(e.dryRun===true){i.push("--dry-run");i.push("--verbose")}if(typeof e.excludeFirst!=="undefined"&&s.isArray(e.excludeFirst)){e.excludeFirst.forEach((function(e,r){i.push("--exclude="+e)}))}if(typeof e.include!=="undefined"&&s.isArray(e.include)){e.include.forEach((function(e,r){i.push("--include="+e)}))}if(typeof e.exclude!=="undefined"&&s.isArray(e.exclude)){e.exclude.forEach((function(e,r){i.push("--exclude="+e)}))}switch(e.compareMode){case"sizeOnly":i.push("--size-only");break;case"checksum":i.push("--checksum");break}if(typeof e.args!=="undefined"&&s.isArray(e.args)){i=[...new Set([...i,...e.args])]}i=[...new Set(i)];var noop=function(){};var l=e.onStdout||noop;var d=e.onStderr||noop;var f="rsync ";i.forEach((function(e){if(e.substr(0,4)==="ssh "){e='"'+e+'"'}f+=e+" "}));f=f.trim();if(e.noExec){r(null,null,null,f);return}try{var p="";var y="";var v;if(o){v=n("cmd.exe",["/s","/c",'"'+f+'"'],{windowsVerbatimArguments:true,stdio:[process.stdin,"pipe","pipe"]})}else{v=n("/bin/sh",["-c",f])}v.stdout.on("data",(function(e){l(e);p+=e}));v.stderr.on("data",(function(e){d(e);y+=e}));v.on("exit",(function(e){var t=null;if(e!==0){t=new Error("rsync exited with code "+e);t.code=e}r(t,p,y,f)}))}catch(e){r(e,null,null,f)}}},505:(e,r,t)=>{const{existsSync:n,mkdirSync:s,writeFileSync:o}=t(147);const{GITHUB_WORKSPACE:c}=process.env;const validateDir=e=>{if(!n(e)){console.log(`[SSH] Creating ${e} dir in `,c);s(e);console.log("✅ [SSH] dir created.")}else{console.log(`[SSH] ${e} dir exist`)}};const validateFile=e=>{if(!n(e)){console.log(`[SSH] Creating ${e} file in `,c);try{o(e,"",{encoding:"utf8",mode:384});console.log("✅ [SSH] file created.")}catch(r){console.error("⚠️ [SSH] writeFileSync error",e,r.message);process.abort()}}else{console.log(`[SSH] ${e} file exist`)}};e.exports={validateDir:validateDir,validateFile:validateFile}},229:e=>{const r=["REMOTE_HOST","REMOTE_USER","REMOTE_PORT","SSH_PRIVATE_KEY","DEPLOY_KEY_NAME","SOURCE","TARGET","ARGS","EXCLUDE"];const t={GITHUB_WORKSPACE:process.env.GITHUB_WORKSPACE};r.forEach((e=>{t[e]=process.env[e]||process.env[`INPUT_${e}`]}));e.exports=t},447:(e,r,t)=>{const{sync:n}=t(569);const{get:s}=t(748);const validateRsync=(e=(()=>{}))=>{const r=n("rsync");console.log('⚠️ [CLI] Rsync doesn\'t exists. Start installation with "apt-get" \n');console.log("nodeCmd: ",s);if(!r){s("sudo apt-get --no-install-recommends install rsync",((r,t,n)=>{if(r){console.log("⚠️ [CLI] Rsync installation failed. Aborting ... ",r.message);process.abort()}else{console.log("✅ [CLI] Rsync installed. \n",t,n);e()}}))}else{e()}};const validateInputs=e=>{const r=Object.keys(e);const t=r.filter((r=>{const t=e[r];if(!t){console.error(`⚠️ [INPUTS] ${r} is mandatory`)}return t}));if(t.length!==r.length){console.error("⚠️ [INPUTS] Inputs not valid, aborting ...");process.abort()}};e.exports={validateRsync:validateRsync,validateInputs:validateInputs}},822:(e,r,t)=>{const{writeFileSync:n}=t(147);const{join:s}=t(17);const{validateDir:o,validateFile:c}=t(505);const{HOME:i}=process.env;const addSshKey=(e,r)=>{const t=s(i||__dirname,".ssh");const a=s(t,r);o(t);c(`${t}/known_hosts`);try{n(a,e,{encoding:"utf8",mode:384})}catch(e){console.error("⚠️ writeFileSync error",a,e.message);process.abort()}console.log("✅ Ssh key added to `.ssh` dir ",a);return a};e.exports={addSshKey:addSshKey}},81:e=>{"use strict";e.exports=require("child_process")},147:e=>{"use strict";e.exports=require("fs")},17:e=>{"use strict";e.exports=require("path")},837:e=>{"use strict";e.exports=require("util")}};var r={};function __nccwpck_require__(t){var n=r[t];if(n!==undefined){return n.exports}var s=r[t]={exports:{}};var o=true;try{e[t](s,s.exports,__nccwpck_require__);o=false}finally{if(o)delete r[t]}return s.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var t={};(()=>{const e=__nccwpck_require__(898);const{validateRsync:r,validateInputs:t}=__nccwpck_require__(447);const{addSshKey:n}=__nccwpck_require__(822);const{REMOTE_HOST:s,REMOTE_USER:o,REMOTE_PORT:c,SSH_PRIVATE_KEY:i,DEPLOY_KEY_NAME:a,SOURCE:u,TARGET:l,ARGS:d,EXCLUDE:f,GITHUB_WORKSPACE:p}=__nccwpck_require__(229);const y={ssh:true,sshCmdArgs:["-o StrictHostKeyChecking=no"],recursive:true};console.log("[general] GITHUB_WORKSPACE: ",p);const v=(()=>{const rsync=({privateKey:r,port:t,src:n,dest:s,args:o,exclude:c})=>{console.log(`[Rsync] Starting Rsync Action: ${n} to ${s}`);if(c)console.log(`[Rsync] exluding folders ${c}`);try{e({src:n,dest:s,args:o,privateKey:r,port:t,excludeFirst:c,...y},((e,r,t,n)=>{if(e){console.error("⚠️ [Rsync] error: ",e.message);console.log("⚠️ [Rsync] stderr: ",t);console.log("⚠️ [Rsync] stdout: ",r);console.log("⚠️ [Rsync] cmd: ",n);process.abort()}else{console.log("✅ [Rsync] finished.",r)}}))}catch(e){console.error("⚠️ [Rsync] command error: ",e.message,e.stack);process.abort()}};const init=({src:e,dest:t,args:s,host:o="localhost",port:c,username:i,privateKeyContent:u,exclude:l=[]})=>{r((()=>{const r=n(u,a||"deploy_key");const d=`${i}@${o}:${t}`;rsync({privateKey:r,port:c,src:e,dest:d,args:s,exclude:l})}))};return{init:init}})();const run=()=>{t({SSH_PRIVATE_KEY:i,REMOTE_HOST:s,REMOTE_USER:o});v.init({src:`${p}/${u||""}`,dest:l||`/home/${o}/`,args:d?[d]:["-rltgoDzvO"],host:s,port:c||"22",username:o,privateKeyContent:i,exclude:(f||"").split(",").map((e=>e.trim()))})};run()})();module.exports=t})(); \ No newline at end of file +(()=>{var e={569:(e,r,s)=>{e.exports=s(325)},325:(e,r,s)=>{"use strict";var t=s(81).exec;var n=s(81).execSync;var o=s(147);var c=s(17);var i=o.access;var a=o.accessSync;var u=o.constants||o;var l=process.platform=="win32";var fileNotExists=function(e,r){i(e,u.F_OK,(function(e){r(!e)}))};var fileNotExistsSync=function(e){try{a(e,u.F_OK);return false}catch(e){return true}};var localExecutable=function(e,r){i(e,u.F_OK|u.X_OK,(function(e){r(null,!e)}))};var localExecutableSync=function(e){try{a(e,u.F_OK|u.X_OK);return true}catch(e){return false}};var commandExistsUnix=function(e,r,s){fileNotExists(e,(function(n){if(!n){var o=t("command -v "+r+" 2>/dev/null"+" && { echo >&1 "+r+"; exit 0; }",(function(e,r,t){s(null,!!r)}));return}localExecutable(e,s)}))};var commandExistsWindows=function(e,r,s){if(!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(e)){s(null,false);return}var n=t("where "+r,(function(e){if(e!==null){s(null,false)}else{s(null,true)}}))};var commandExistsUnixSync=function(e,r){if(fileNotExistsSync(e)){try{var s=n("command -v "+r+" 2>/dev/null"+" && { echo >&1 "+r+"; exit 0; }");return!!s}catch(e){return false}}return localExecutableSync(e)};var commandExistsWindowsSync=function(e,r,s){if(!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(e)){return false}try{var t=n("where "+r,{stdio:[]});return!!t}catch(e){return false}};var cleanInput=function(e){if(/[^A-Za-z0-9_\/:=-]/.test(e)){e="'"+e.replace(/'/g,"'\\''")+"'";e=e.replace(/^(?:'')+/g,"").replace(/\\'''/g,"\\'")}return e};if(l){cleanInput=function(e){var r=/[\\]/.test(e);if(r){var s='"'+c.dirname(e)+'"';var t='"'+c.basename(e)+'"';return s+":"+t}return'"'+e+'"'}}e.exports=function commandExists(e,r){var s=cleanInput(e);if(!r&&typeof Promise!=="undefined"){return new Promise((function(r,s){commandExists(e,(function(t,n){if(n){r(e)}else{s(t)}}))}))}if(l){commandExistsWindows(e,s,r)}else{commandExistsUnix(e,s,r)}};e.exports.sync=function(e){var r=cleanInput(e);if(l){return commandExistsWindowsSync(e,r)}else{return commandExistsUnixSync(e,r)}}},898:(e,r,s)=>{"use strict";var t=s(81).spawn;var n=s(837);var escapeSpaces=function(e){if(typeof e==="string"){return e.replace(/\b\s/g,"\\ ")}else{return e}};var escapeSpacesInOptions=function(e){["src","dest","include","exclude","excludeFirst"].forEach((function(r){var s=e[r];if(typeof s==="string"){e[r]=escapeSpaces(s)}else if(Array.isArray(s)===true){e[r]=s.map(escapeSpaces)}}));return e};e.exports=function(e,r){e=e||{};e=n._extend({},e);e=escapeSpacesInOptions(e);var s=e.platform||process.platform;var o=s==="win32";if(typeof e.src==="undefined"){throw new Error("'src' directory is missing from options")}if(typeof e.dest==="undefined"){throw new Error("'dest' directory is missing from options")}var c=e.dest;if(typeof e.host!=="undefined"){c=e.host+":"+e.dest}if(!Array.isArray(e.src)){e.src=[e.src]}var i=[].concat(e.src);i.push(c);var a=(e.args||[]).find((function(e){return e.match(/--chmod=/)}));if(o&&!a){i.push("--chmod=ugo=rwX")}if(typeof e.host!=="undefined"||e.ssh){i.push("--rsh");var u="ssh";if(typeof e.port!=="undefined"){u+=" -p "+e.port}if(typeof e.privateKey!=="undefined"){u+=" -i "+e.privateKey}if(typeof e.sshCmdArgs!=="undefined"){u+=" "+e.sshCmdArgs.join(" ")}i.push(u)}if(e.recursive===true){i.push("--recursive")}if(e.times===true){i.push("--times")}if(e.syncDest===true||e.deleteAll===true){i.push("--delete");i.push("--delete-excluded")}if(e.syncDestIgnoreExcl===true||e.delete===true){i.push("--delete")}if(e.dryRun===true){i.push("--dry-run");i.push("--verbose")}if(typeof e.excludeFirst!=="undefined"&&n.isArray(e.excludeFirst)){e.excludeFirst.forEach((function(e,r){i.push("--exclude="+e)}))}if(typeof e.include!=="undefined"&&n.isArray(e.include)){e.include.forEach((function(e,r){i.push("--include="+e)}))}if(typeof e.exclude!=="undefined"&&n.isArray(e.exclude)){e.exclude.forEach((function(e,r){i.push("--exclude="+e)}))}switch(e.compareMode){case"sizeOnly":i.push("--size-only");break;case"checksum":i.push("--checksum");break}if(typeof e.args!=="undefined"&&n.isArray(e.args)){i=[...new Set([...i,...e.args])]}i=[...new Set(i)];var noop=function(){};var l=e.onStdout||noop;var d=e.onStderr||noop;var f="rsync ";i.forEach((function(e){if(e.substr(0,4)==="ssh "){e='"'+e+'"'}f+=e+" "}));f=f.trim();if(e.noExec){r(null,null,null,f);return}try{var p="";var y="";var v;if(o){v=t("cmd.exe",["/s","/c",'"'+f+'"'],{windowsVerbatimArguments:true,stdio:[process.stdin,"pipe","pipe"]})}else{v=t("/bin/sh",["-c",f])}v.stdout.on("data",(function(e){l(e);p+=e}));v.stderr.on("data",(function(e){d(e);y+=e}));v.on("exit",(function(e){var s=null;if(e!==0){s=new Error("rsync exited with code "+e);s.code=e}r(s,p,y,f)}))}catch(e){r(e,null,null,f)}}},505:(e,r,s)=>{const{existsSync:t,mkdirSync:n,writeFileSync:o}=s(147);const{GITHUB_WORKSPACE:c}=process.env;const validateDir=e=>{if(!t(e)){console.log(`[SSH] Creating ${e} dir in `,c);n(e);console.log("✅ [SSH] dir created.")}else{console.log(`[SSH] ${e} dir exist`)}};const validateFile=e=>{if(!t(e)){console.log(`[SSH] Creating ${e} file in `,c);try{o(e,"",{encoding:"utf8",mode:384});console.log("✅ [SSH] file created.")}catch(r){console.error("⚠️ [SSH] writeFileSync error",e,r.message);process.abort()}}else{console.log(`[SSH] ${e} file exist`)}};e.exports={validateDir:validateDir,validateFile:validateFile}},229:e=>{const r=["REMOTE_HOST","REMOTE_USER","REMOTE_PORT","SSH_PRIVATE_KEY","DEPLOY_KEY_NAME","SOURCE","TARGET","ARGS","EXCLUDE"];const s={GITHUB_WORKSPACE:process.env.GITHUB_WORKSPACE};r.forEach((e=>{s[e]=process.env[e]||process.env[`INPUT_${e}`]}));e.exports=s},447:(e,r,s)=>{const{sync:t}=s(569);const{exec:n,execSync:o}=s(81);const validateRsync=(e=(()=>{}))=>{const r=t("rsync");console.log('⚠️ [CLI] Rsync doesn\'t exists. Start installation with "apt-get" \n');if(!r){o("sudo apt-get update");n("sudo apt-get --no-install-recommends install rsync",((r,s,t)=>{if(r){console.log("⚠️ [CLI] Rsync installation failed. Aborting ... ",r.message);process.abort()}else{console.log("✅ [CLI] Rsync installed. \n",s,t);e()}}))}else{e()}};const validateInputs=e=>{const r=Object.keys(e);const s=r.filter((r=>{const s=e[r];if(!s){console.error(`⚠️ [INPUTS] ${r} is mandatory`)}return s}));if(s.length!==r.length){console.error("⚠️ [INPUTS] Inputs not valid, aborting ...");process.abort()}};e.exports={validateRsync:validateRsync,validateInputs:validateInputs}},822:(e,r,s)=>{const{writeFileSync:t}=s(147);const{join:n}=s(17);const{validateDir:o,validateFile:c}=s(505);const{HOME:i}=process.env;const addSshKey=(e,r)=>{const s=n(i||__dirname,".ssh");const a=n(s,r);o(s);c(`${s}/known_hosts`);try{t(a,e,{encoding:"utf8",mode:384})}catch(e){console.error("⚠️ writeFileSync error",a,e.message);process.abort()}console.log("✅ Ssh key added to `.ssh` dir ",a);return a};e.exports={addSshKey:addSshKey}},81:e=>{"use strict";e.exports=require("child_process")},147:e=>{"use strict";e.exports=require("fs")},17:e=>{"use strict";e.exports=require("path")},837:e=>{"use strict";e.exports=require("util")}};var r={};function __nccwpck_require__(s){var t=r[s];if(t!==undefined){return t.exports}var n=r[s]={exports:{}};var o=true;try{e[s](n,n.exports,__nccwpck_require__);o=false}finally{if(o)delete r[s]}return n.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var s={};(()=>{const e=__nccwpck_require__(898);const{validateRsync:r,validateInputs:s}=__nccwpck_require__(447);const{addSshKey:t}=__nccwpck_require__(822);const{REMOTE_HOST:n,REMOTE_USER:o,REMOTE_PORT:c,SSH_PRIVATE_KEY:i,DEPLOY_KEY_NAME:a,SOURCE:u,TARGET:l,ARGS:d,EXCLUDE:f,GITHUB_WORKSPACE:p}=__nccwpck_require__(229);const y={ssh:true,sshCmdArgs:["-o StrictHostKeyChecking=no"],recursive:true};console.log("[general] GITHUB_WORKSPACE: ",p);const v=(()=>{const rsync=({privateKey:r,port:s,src:t,dest:n,args:o,exclude:c})=>{console.log(`[Rsync] Starting Rsync Action: ${t} to ${n}`);if(c)console.log(`[Rsync] exluding folders ${c}`);try{e({src:t,dest:n,args:o,privateKey:r,port:s,excludeFirst:c,...y},((e,r,s,t)=>{if(e){console.error("⚠️ [Rsync] error: ",e.message);console.log("⚠️ [Rsync] stderr: ",s);console.log("⚠️ [Rsync] stdout: ",r);console.log("⚠️ [Rsync] cmd: ",t);process.abort()}else{console.log("✅ [Rsync] finished.",r)}}))}catch(e){console.error("⚠️ [Rsync] command error: ",e.message,e.stack);process.abort()}};const init=({src:e,dest:s,args:n,host:o="localhost",port:c,username:i,privateKeyContent:u,exclude:l=[]})=>{r((()=>{const r=t(u,a||"deploy_key");const d=`${i}@${o}:${s}`;rsync({privateKey:r,port:c,src:e,dest:d,args:n,exclude:l})}))};return{init:init}})();const run=()=>{s({SSH_PRIVATE_KEY:i,REMOTE_HOST:n,REMOTE_USER:o});v.init({src:`${p}/${u||""}`,dest:l||`/home/${o}/`,args:d?[d]:["-rltgoDzvO"],host:n,port:c||"22",username:o,privateKeyContent:i,exclude:(f||"").split(",").map((e=>e.trim()))})};run()})();module.exports=s})(); \ No newline at end of file diff --git a/src/inputs.js b/src/inputs.js index a0fe7b8..54188fe 100644 --- a/src/inputs.js +++ b/src/inputs.js @@ -4,6 +4,9 @@ const inputs = { GITHUB_WORKSPACE: process.env.GITHUB_WORKSPACE }; // Get inputs from ENV or WITH workflow settings +console.log('EXAMPLE_REMOTE_HOST: ', process.env.EXAMPLE_REMOTE_HOST); +console.log('REMOTE_HOST: ', process.env.REMOTE_HOST); + inputNames.forEach((input) => { inputs[input] = process.env[input] || process.env[`INPUT_${input}`]; }); diff --git a/src/test.js b/src/test.js index 4e1dbd1..51b221a 100644 --- a/src/test.js +++ b/src/test.js @@ -1,9 +1,2 @@ -const { - REMOTE_HOST, REMOTE_USER, - REMOTE_PORT, SSH_PRIVATE_KEY, DEPLOY_KEY_NAME, - SOURCE, TARGET, ARGS, EXCLUDE, - GITHUB_WORKSPACE -} = require('./inputs'); - -// eslint-disable-next-line max-len -console.log(REMOTE_HOST, REMOTE_USER, REMOTE_PORT, SSH_PRIVATE_KEY, DEPLOY_KEY_NAME, SOURCE, TARGET, ARGS, EXCLUDE, GITHUB_WORKSPACE); +console.log('EXAMPLE_REMOTE_HOST: ', process.env.EXAMPLE_REMOTE_HOST); +console.log('REMOTE_HOST: ', process.env.REMOTE_HOST); diff --git a/test/Dockerfile b/test/Dockerfile index f580c95..e9a9df4 100644 --- a/test/Dockerfile +++ b/test/Dockerfile @@ -1,15 +1,31 @@ FROM nginx -# Set args to get from Gtihub Action -ARG ssh_pub_key -ARG ssh_user -# Add a user to the container -RUN adduser --disabled-password $ssh_user -# USER $ssh_user -# Add the ssh public key to the container -RUN mkdir -p /home/$ssh_user/.ssh -RUN echo "$ssh_pub_key" > /home/$ssh_user/.ssh/authorized_keys -RUN chmod 700 /home/$ssh_user/.ssh -# Start server -EXPOSE 80 -STOPSIGNAL SIGTERM + +ARG SSH_PUB_KEY + +RUN apt update + +RUN apt install openssh-server sudo -y + +RUN useradd -rm -d /home/test -s /bin/bash -g root -G sudo -u 1000 test + +RUN usermod -aG sudo test + +RUN echo "PubkeyAuthentication yes" >> /etc/ssh/sshd_config.d/pub.conf +RUN echo "AuthorizedKeysFile .ssh/authorized_keys" >> /etc/ssh/sshd_config.d/pub.conf + +RUN mkdir -p /home/test/.ssh +RUN echo "$SSH_PUB_KEY" > /home/test/.ssh/authorized_keys +RUN chmod 700 /home/test/.ssh +RUN chown -R test /home/test/.ssh + +RUN service ssh start + +RUN echo 'test:test' | chpasswd + +EXPOSE 22 + +ADD entrypoint.sh /docker-entrypoint.d/entrypoint.sh +RUN chmod +x /docker-entrypoint.d/entrypoint.sh + + CMD ["nginx", "-g", "daemon off;"] diff --git a/test/entrypoint.sh b/test/entrypoint.sh new file mode 100644 index 0000000..20684ec --- /dev/null +++ b/test/entrypoint.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +/usr/sbin/sshd -D From 152ee9d6b24bc7e9465bc936cbe4f6f29669117d Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Sat, 31 Dec 2022 02:43:57 +0100 Subject: [PATCH 25/46] test --- .github/workflows/e2e.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 4430677..3e7c65f 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -98,7 +98,7 @@ jobs: # SSH_REMOTE_USER: ${{ env.TEST_USER }} - name: e2e Test published ssh-deploy action - uses: easingthemes/ssh-deploy@main + uses: easingthemes/ssh-deploy@feature/add-tests with: SSH_PRIVATE_KEY: $EXAMPLE_SSH_PRIVATE_KEY ARGS: "-rltgoDzvO" From d85914e1f952ab565234f6091b0f022e0cc02ff5 Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Sat, 31 Dec 2022 03:15:04 +0100 Subject: [PATCH 26/46] test --- .github/workflows/e2e.yml | 62 +++++++++------------------------------ src/test.js | 1 + 2 files changed, 15 insertions(+), 48 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 3e7c65f..9e25db2 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -5,7 +5,6 @@ on: branches: [ 'feature/add-tests' ] env: - GLOBAL_WORKFLOW_ENV: __some value for GLOBAL_WORKFLOW_ENV__ TEST_HOST_DOCKER: ./test TEST_USER: test @@ -17,30 +16,15 @@ jobs: - name: Checkout uses: actions/checkout@v3 - # - name: Set ENV var - # run: | - # echo "CUSTOM_VAR=IT WORKS" >> $GITHUB_ENV - - # - name: Use ENV var via `env` block - # run: | - # echo $CUSTOM_VAR # OK - # echo ${{ env.CUSTOM_VAR }} # OK - # echo $USE_CUSTOM_VAR # NOT OK, prints '' - # echo ${{ env.USE_CUSTOM_VAR }} # NOT OK, prints '' - # echo $USE_CUSTOM_VAR_2 # NOT OK, prints '$CUSTOM_VAR' - # echo ${{ env.USE_CUSTOM_VAR_2 }} # OK - # echo $USE_CUSTOM_VAR_3 # NOT OK, prints '$GLOBAL_WORKFLOW_ENV' - # echo ${{ env.USE_CUSTOM_VAR_3 }} # OK - # env: - # USE_CUSTOM_VAR: ${{ env.CUSTOM_VAR }} - # USE_CUSTOM_VAR_2: $CUSTOM_VAR - # USE_CUSTOM_VAR_3: $GLOBAL_WORKFLOW_ENV + - name: Set ENV var + run: | + echo "CUSTOM_VAR=IT WORKS" >> $GITHUB_ENV - name: Clean up old test files run: | docker stop ssh-host-container || true && docker rm ssh-host-container || true - - name: 1. Create ssh keys + - name: Create ssh keys run: | echo $HOME ls -la $HOME @@ -48,7 +32,7 @@ jobs: eval `ssh-agent -s` ssh-add "$HOME/.ssh/id_rsa" ssh-add -l - echo "EXAMPLE_SSH_PRIVATE_KEY<> $GITHUB_ENV + echo "SSH_PRIVATE_KEY<> $GITHUB_ENV cat $HOME/.ssh/id_rsa >> $GITHUB_ENV echo "EOF" >> $GITHUB_ENV @@ -61,7 +45,7 @@ jobs: --build-arg ssh_user="${{ env.TEST_USER }}" docker run -d -p 8822:22 --name=ssh-host-container ssh-host-image docker exec ssh-host-container sh -c "hostname --ip-address" > ip.txt - echo "EXAMPLE_REMOTE_HOST<> $GITHUB_ENV + echo "REMOTE_HOST<> $GITHUB_ENV cat ip.txt >> $GITHUB_ENV echo "EOF" >> $GITHUB_ENV shell: bash @@ -74,36 +58,18 @@ jobs: date +"%Y-%m-%d %H:%M:%S,%3N" >> index.html cat index.html - # - name: e2e Test local ssh-deploy action - # run: | - # echo "${{ env.REMOTE_HOST }} -- $EXAMPLE_REMOTE_HOST -- ${{ env.EXAMPLE_REMOTE_HOST }}" - # npm ci - # npm run build - # node ./src/test.js || true - # env: - # SSH_PRIVATE_KEY: $EXAMPLE_SSH_PRIVATE_KEY - # ARGS: "-rltgoDzvO" - # SOURCE: "test_project/" - # REMOTE_HOST: $EXAMPLE_REMOTE_HOST - # REMOTE_USER: ${{ env.TEST_USER }} - # TARGET: "/var/www/html/" - # EXCLUDE: "/dist/, /node_modules/" - - # - name: e2e Test ssh - # run: | - # echo "$SSH_REMOTE_USER@$SSH_REMOTE_HOST" - # ssh -p 8822 $SSH_REMOTE_USER@$SSH_REMOTE_HOST 'exit' - # env: - # SSH_REMOTE_HOST: ${{ env.EXAMPLE_REMOTE_HOST }} - # SSH_REMOTE_USER: ${{ env.TEST_USER }} + - name: e2e Test ssh + run: | + echo "$REMOTE_HOST@$REMOTE_HOST" + ssh -p 8822 $SSH_REMOTE_USER@$SSH_REMOTE_HOST 'exit' - name: e2e Test published ssh-deploy action uses: easingthemes/ssh-deploy@feature/add-tests - with: - SSH_PRIVATE_KEY: $EXAMPLE_SSH_PRIVATE_KEY + env: + # SSH_PRIVATE_KEY: $SSH_PRIVATE_KEY + # REMOTE_HOST: $REMOTE_HOST + REMOTE_USER: ${{ env.TEST_USER }} ARGS: "-rltgoDzvO" SOURCE: "test_project/" - REMOTE_HOST: $EXAMPLE_REMOTE_HOST - REMOTE_USER: ${{ env.TEST_USER }} TARGET: "/var/www/html/" EXCLUDE: "/dist/, /node_modules/" diff --git a/src/test.js b/src/test.js index 51b221a..e583525 100644 --- a/src/test.js +++ b/src/test.js @@ -1,2 +1,3 @@ console.log('EXAMPLE_REMOTE_HOST: ', process.env.EXAMPLE_REMOTE_HOST); console.log('REMOTE_HOST: ', process.env.REMOTE_HOST); +console.log('REMOTE_USER: ', process.env.REMOTE_USER); From a52870b4871f35ba527f87f83b11d77e4aab6f4e Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Sat, 31 Dec 2022 03:16:48 +0100 Subject: [PATCH 27/46] test --- .github/workflows/e2e.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 9e25db2..e387766 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -60,8 +60,8 @@ jobs: - name: e2e Test ssh run: | - echo "$REMOTE_HOST@$REMOTE_HOST" - ssh -p 8822 $SSH_REMOTE_USER@$SSH_REMOTE_HOST 'exit' + echo "$TEST_USER@$REMOTE_HOST" + ssh -p 8822 $TEST_USER@$REMOTE_HOST 'exit' - name: e2e Test published ssh-deploy action uses: easingthemes/ssh-deploy@feature/add-tests From 4efe6b6c406beb3429fc0a839d9c785401d12512 Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Sat, 31 Dec 2022 09:48:17 +0100 Subject: [PATCH 28/46] print vars --- .github/workflows/e2e.yml | 10 +++------- src/index.js | 3 +++ src/inputs.js | 3 --- src/test.js | 12 +++++++++++- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index e387766..6849069 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -16,10 +16,6 @@ jobs: - name: Checkout uses: actions/checkout@v3 - - name: Set ENV var - run: | - echo "CUSTOM_VAR=IT WORKS" >> $GITHUB_ENV - - name: Clean up old test files run: | docker stop ssh-host-container || true && docker rm ssh-host-container || true @@ -61,13 +57,13 @@ jobs: - name: e2e Test ssh run: | echo "$TEST_USER@$REMOTE_HOST" - ssh -p 8822 $TEST_USER@$REMOTE_HOST 'exit' + # ssh -p 8822 $TEST_USER@$REMOTE_HOST 'exit' - name: e2e Test published ssh-deploy action uses: easingthemes/ssh-deploy@feature/add-tests env: - # SSH_PRIVATE_KEY: $SSH_PRIVATE_KEY - # REMOTE_HOST: $REMOTE_HOST + # SSH_PRIVATE_KEY: $EXAMPLE_SSH_PRIVATE_KEY + # REMOTE_HOST: $EXAMPLE_REMOTE_HOST1 REMOTE_USER: ${{ env.TEST_USER }} ARGS: "-rltgoDzvO" SOURCE: "test_project/" diff --git a/src/index.js b/src/index.js index 123fcb4..cbdcfbe 100644 --- a/src/index.js +++ b/src/index.js @@ -18,6 +18,9 @@ const defaultOptions = { }; console.log('[general] GITHUB_WORKSPACE: ', GITHUB_WORKSPACE); +console.log('REMOTE_HOST: ', process.env.REMOTE_HOST); +console.log('REMOTE_USER: ', process.env.REMOTE_USER); +console.log('SSH_PRIVATE_KEY: ', process.env.SSH_PRIVATE_KEY); const sshDeploy = (() => { const rsync = ({ privateKey, port, src, dest, args, exclude }) => { diff --git a/src/inputs.js b/src/inputs.js index 54188fe..9b7638e 100644 --- a/src/inputs.js +++ b/src/inputs.js @@ -3,9 +3,6 @@ const inputNames = ['REMOTE_HOST', 'REMOTE_USER', 'REMOTE_PORT', 'SSH_PRIVATE_KE const inputs = { GITHUB_WORKSPACE: process.env.GITHUB_WORKSPACE }; -// Get inputs from ENV or WITH workflow settings -console.log('EXAMPLE_REMOTE_HOST: ', process.env.EXAMPLE_REMOTE_HOST); -console.log('REMOTE_HOST: ', process.env.REMOTE_HOST); inputNames.forEach((input) => { inputs[input] = process.env[input] || process.env[`INPUT_${input}`]; diff --git a/src/test.js b/src/test.js index e583525..75ab1c1 100644 --- a/src/test.js +++ b/src/test.js @@ -1,3 +1,13 @@ +console.log('||||||||||||||||||||||||||||||||||||||'); console.log('EXAMPLE_REMOTE_HOST: ', process.env.EXAMPLE_REMOTE_HOST); -console.log('REMOTE_HOST: ', process.env.REMOTE_HOST); +console.log('EXAMPLE_REMOTE_USER: ', process.env.EXAMPLE_REMOTE_USER); +console.log('EXAMPLE_SSH_PRIVATE_KEY: ', process.env.EXAMPLE_SSH_PRIVATE_KEY); +console.log('||||||||||||||||||||||||||||||||||||||'); +console.log('EXAMPLE_REMOTE_HOST1: ', process.env.EXAMPLE_REMOTE_HOST1); +console.log('EXAMPLE_REMOTE_USER1: ', process.env.EXAMPLE_REMOTE_USER1); +console.log('EXAMPLE_SSH_PRIVATE_KEY1: ', process.env.EXAMPLE_SSH_PRIVATE_KEY1); +console.log('||||||||||||||||||||||||||||||||||||||'); console.log('REMOTE_USER: ', process.env.REMOTE_USER); +console.log('REMOTE_HOST: ', process.env.REMOTE_HOST); +console.log('SSH_PRIVATE_KEY: ', process.env.SSH_PRIVATE_KEY); +console.log('||||||||||||||||||||||||||||||||||||||'); From 5404854e811e1df4687082f738ad9e6542c7fb05 Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Sat, 31 Dec 2022 09:53:43 +0100 Subject: [PATCH 29/46] envz --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index cbdcfbe..6cf3a0a 100644 --- a/src/index.js +++ b/src/index.js @@ -17,7 +17,7 @@ const defaultOptions = { recursive: true }; -console.log('[general] GITHUB_WORKSPACE: ', GITHUB_WORKSPACE); +console.log('GITHUB_WORKSPACE: ', GITHUB_WORKSPACE); console.log('REMOTE_HOST: ', process.env.REMOTE_HOST); console.log('REMOTE_USER: ', process.env.REMOTE_USER); console.log('SSH_PRIVATE_KEY: ', process.env.SSH_PRIVATE_KEY); From 11f58724d7e1f1b5d56caad6528bcfa634cfbe4c Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Sat, 31 Dec 2022 09:54:38 +0100 Subject: [PATCH 30/46] Build Action --- dist/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/index.js b/dist/index.js index f2597bb..dcf2afc 100755 --- a/dist/index.js +++ b/dist/index.js @@ -1,2 +1,2 @@ #!/usr/bin/env node -(()=>{var e={569:(e,r,s)=>{e.exports=s(325)},325:(e,r,s)=>{"use strict";var t=s(81).exec;var n=s(81).execSync;var o=s(147);var c=s(17);var i=o.access;var a=o.accessSync;var u=o.constants||o;var l=process.platform=="win32";var fileNotExists=function(e,r){i(e,u.F_OK,(function(e){r(!e)}))};var fileNotExistsSync=function(e){try{a(e,u.F_OK);return false}catch(e){return true}};var localExecutable=function(e,r){i(e,u.F_OK|u.X_OK,(function(e){r(null,!e)}))};var localExecutableSync=function(e){try{a(e,u.F_OK|u.X_OK);return true}catch(e){return false}};var commandExistsUnix=function(e,r,s){fileNotExists(e,(function(n){if(!n){var o=t("command -v "+r+" 2>/dev/null"+" && { echo >&1 "+r+"; exit 0; }",(function(e,r,t){s(null,!!r)}));return}localExecutable(e,s)}))};var commandExistsWindows=function(e,r,s){if(!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(e)){s(null,false);return}var n=t("where "+r,(function(e){if(e!==null){s(null,false)}else{s(null,true)}}))};var commandExistsUnixSync=function(e,r){if(fileNotExistsSync(e)){try{var s=n("command -v "+r+" 2>/dev/null"+" && { echo >&1 "+r+"; exit 0; }");return!!s}catch(e){return false}}return localExecutableSync(e)};var commandExistsWindowsSync=function(e,r,s){if(!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(e)){return false}try{var t=n("where "+r,{stdio:[]});return!!t}catch(e){return false}};var cleanInput=function(e){if(/[^A-Za-z0-9_\/:=-]/.test(e)){e="'"+e.replace(/'/g,"'\\''")+"'";e=e.replace(/^(?:'')+/g,"").replace(/\\'''/g,"\\'")}return e};if(l){cleanInput=function(e){var r=/[\\]/.test(e);if(r){var s='"'+c.dirname(e)+'"';var t='"'+c.basename(e)+'"';return s+":"+t}return'"'+e+'"'}}e.exports=function commandExists(e,r){var s=cleanInput(e);if(!r&&typeof Promise!=="undefined"){return new Promise((function(r,s){commandExists(e,(function(t,n){if(n){r(e)}else{s(t)}}))}))}if(l){commandExistsWindows(e,s,r)}else{commandExistsUnix(e,s,r)}};e.exports.sync=function(e){var r=cleanInput(e);if(l){return commandExistsWindowsSync(e,r)}else{return commandExistsUnixSync(e,r)}}},898:(e,r,s)=>{"use strict";var t=s(81).spawn;var n=s(837);var escapeSpaces=function(e){if(typeof e==="string"){return e.replace(/\b\s/g,"\\ ")}else{return e}};var escapeSpacesInOptions=function(e){["src","dest","include","exclude","excludeFirst"].forEach((function(r){var s=e[r];if(typeof s==="string"){e[r]=escapeSpaces(s)}else if(Array.isArray(s)===true){e[r]=s.map(escapeSpaces)}}));return e};e.exports=function(e,r){e=e||{};e=n._extend({},e);e=escapeSpacesInOptions(e);var s=e.platform||process.platform;var o=s==="win32";if(typeof e.src==="undefined"){throw new Error("'src' directory is missing from options")}if(typeof e.dest==="undefined"){throw new Error("'dest' directory is missing from options")}var c=e.dest;if(typeof e.host!=="undefined"){c=e.host+":"+e.dest}if(!Array.isArray(e.src)){e.src=[e.src]}var i=[].concat(e.src);i.push(c);var a=(e.args||[]).find((function(e){return e.match(/--chmod=/)}));if(o&&!a){i.push("--chmod=ugo=rwX")}if(typeof e.host!=="undefined"||e.ssh){i.push("--rsh");var u="ssh";if(typeof e.port!=="undefined"){u+=" -p "+e.port}if(typeof e.privateKey!=="undefined"){u+=" -i "+e.privateKey}if(typeof e.sshCmdArgs!=="undefined"){u+=" "+e.sshCmdArgs.join(" ")}i.push(u)}if(e.recursive===true){i.push("--recursive")}if(e.times===true){i.push("--times")}if(e.syncDest===true||e.deleteAll===true){i.push("--delete");i.push("--delete-excluded")}if(e.syncDestIgnoreExcl===true||e.delete===true){i.push("--delete")}if(e.dryRun===true){i.push("--dry-run");i.push("--verbose")}if(typeof e.excludeFirst!=="undefined"&&n.isArray(e.excludeFirst)){e.excludeFirst.forEach((function(e,r){i.push("--exclude="+e)}))}if(typeof e.include!=="undefined"&&n.isArray(e.include)){e.include.forEach((function(e,r){i.push("--include="+e)}))}if(typeof e.exclude!=="undefined"&&n.isArray(e.exclude)){e.exclude.forEach((function(e,r){i.push("--exclude="+e)}))}switch(e.compareMode){case"sizeOnly":i.push("--size-only");break;case"checksum":i.push("--checksum");break}if(typeof e.args!=="undefined"&&n.isArray(e.args)){i=[...new Set([...i,...e.args])]}i=[...new Set(i)];var noop=function(){};var l=e.onStdout||noop;var d=e.onStderr||noop;var f="rsync ";i.forEach((function(e){if(e.substr(0,4)==="ssh "){e='"'+e+'"'}f+=e+" "}));f=f.trim();if(e.noExec){r(null,null,null,f);return}try{var p="";var y="";var v;if(o){v=t("cmd.exe",["/s","/c",'"'+f+'"'],{windowsVerbatimArguments:true,stdio:[process.stdin,"pipe","pipe"]})}else{v=t("/bin/sh",["-c",f])}v.stdout.on("data",(function(e){l(e);p+=e}));v.stderr.on("data",(function(e){d(e);y+=e}));v.on("exit",(function(e){var s=null;if(e!==0){s=new Error("rsync exited with code "+e);s.code=e}r(s,p,y,f)}))}catch(e){r(e,null,null,f)}}},505:(e,r,s)=>{const{existsSync:t,mkdirSync:n,writeFileSync:o}=s(147);const{GITHUB_WORKSPACE:c}=process.env;const validateDir=e=>{if(!t(e)){console.log(`[SSH] Creating ${e} dir in `,c);n(e);console.log("✅ [SSH] dir created.")}else{console.log(`[SSH] ${e} dir exist`)}};const validateFile=e=>{if(!t(e)){console.log(`[SSH] Creating ${e} file in `,c);try{o(e,"",{encoding:"utf8",mode:384});console.log("✅ [SSH] file created.")}catch(r){console.error("⚠️ [SSH] writeFileSync error",e,r.message);process.abort()}}else{console.log(`[SSH] ${e} file exist`)}};e.exports={validateDir:validateDir,validateFile:validateFile}},229:e=>{const r=["REMOTE_HOST","REMOTE_USER","REMOTE_PORT","SSH_PRIVATE_KEY","DEPLOY_KEY_NAME","SOURCE","TARGET","ARGS","EXCLUDE"];const s={GITHUB_WORKSPACE:process.env.GITHUB_WORKSPACE};r.forEach((e=>{s[e]=process.env[e]||process.env[`INPUT_${e}`]}));e.exports=s},447:(e,r,s)=>{const{sync:t}=s(569);const{exec:n,execSync:o}=s(81);const validateRsync=(e=(()=>{}))=>{const r=t("rsync");console.log('⚠️ [CLI] Rsync doesn\'t exists. Start installation with "apt-get" \n');if(!r){o("sudo apt-get update");n("sudo apt-get --no-install-recommends install rsync",((r,s,t)=>{if(r){console.log("⚠️ [CLI] Rsync installation failed. Aborting ... ",r.message);process.abort()}else{console.log("✅ [CLI] Rsync installed. \n",s,t);e()}}))}else{e()}};const validateInputs=e=>{const r=Object.keys(e);const s=r.filter((r=>{const s=e[r];if(!s){console.error(`⚠️ [INPUTS] ${r} is mandatory`)}return s}));if(s.length!==r.length){console.error("⚠️ [INPUTS] Inputs not valid, aborting ...");process.abort()}};e.exports={validateRsync:validateRsync,validateInputs:validateInputs}},822:(e,r,s)=>{const{writeFileSync:t}=s(147);const{join:n}=s(17);const{validateDir:o,validateFile:c}=s(505);const{HOME:i}=process.env;const addSshKey=(e,r)=>{const s=n(i||__dirname,".ssh");const a=n(s,r);o(s);c(`${s}/known_hosts`);try{t(a,e,{encoding:"utf8",mode:384})}catch(e){console.error("⚠️ writeFileSync error",a,e.message);process.abort()}console.log("✅ Ssh key added to `.ssh` dir ",a);return a};e.exports={addSshKey:addSshKey}},81:e=>{"use strict";e.exports=require("child_process")},147:e=>{"use strict";e.exports=require("fs")},17:e=>{"use strict";e.exports=require("path")},837:e=>{"use strict";e.exports=require("util")}};var r={};function __nccwpck_require__(s){var t=r[s];if(t!==undefined){return t.exports}var n=r[s]={exports:{}};var o=true;try{e[s](n,n.exports,__nccwpck_require__);o=false}finally{if(o)delete r[s]}return n.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var s={};(()=>{const e=__nccwpck_require__(898);const{validateRsync:r,validateInputs:s}=__nccwpck_require__(447);const{addSshKey:t}=__nccwpck_require__(822);const{REMOTE_HOST:n,REMOTE_USER:o,REMOTE_PORT:c,SSH_PRIVATE_KEY:i,DEPLOY_KEY_NAME:a,SOURCE:u,TARGET:l,ARGS:d,EXCLUDE:f,GITHUB_WORKSPACE:p}=__nccwpck_require__(229);const y={ssh:true,sshCmdArgs:["-o StrictHostKeyChecking=no"],recursive:true};console.log("[general] GITHUB_WORKSPACE: ",p);const v=(()=>{const rsync=({privateKey:r,port:s,src:t,dest:n,args:o,exclude:c})=>{console.log(`[Rsync] Starting Rsync Action: ${t} to ${n}`);if(c)console.log(`[Rsync] exluding folders ${c}`);try{e({src:t,dest:n,args:o,privateKey:r,port:s,excludeFirst:c,...y},((e,r,s,t)=>{if(e){console.error("⚠️ [Rsync] error: ",e.message);console.log("⚠️ [Rsync] stderr: ",s);console.log("⚠️ [Rsync] stdout: ",r);console.log("⚠️ [Rsync] cmd: ",t);process.abort()}else{console.log("✅ [Rsync] finished.",r)}}))}catch(e){console.error("⚠️ [Rsync] command error: ",e.message,e.stack);process.abort()}};const init=({src:e,dest:s,args:n,host:o="localhost",port:c,username:i,privateKeyContent:u,exclude:l=[]})=>{r((()=>{const r=t(u,a||"deploy_key");const d=`${i}@${o}:${s}`;rsync({privateKey:r,port:c,src:e,dest:d,args:n,exclude:l})}))};return{init:init}})();const run=()=>{s({SSH_PRIVATE_KEY:i,REMOTE_HOST:n,REMOTE_USER:o});v.init({src:`${p}/${u||""}`,dest:l||`/home/${o}/`,args:d?[d]:["-rltgoDzvO"],host:n,port:c||"22",username:o,privateKeyContent:i,exclude:(f||"").split(",").map((e=>e.trim()))})};run()})();module.exports=s})(); \ No newline at end of file +(()=>{var e={569:(e,r,s)=>{e.exports=s(325)},325:(e,r,s)=>{"use strict";var t=s(81).exec;var n=s(81).execSync;var o=s(147);var c=s(17);var i=o.access;var a=o.accessSync;var u=o.constants||o;var l=process.platform=="win32";var fileNotExists=function(e,r){i(e,u.F_OK,(function(e){r(!e)}))};var fileNotExistsSync=function(e){try{a(e,u.F_OK);return false}catch(e){return true}};var localExecutable=function(e,r){i(e,u.F_OK|u.X_OK,(function(e){r(null,!e)}))};var localExecutableSync=function(e){try{a(e,u.F_OK|u.X_OK);return true}catch(e){return false}};var commandExistsUnix=function(e,r,s){fileNotExists(e,(function(n){if(!n){var o=t("command -v "+r+" 2>/dev/null"+" && { echo >&1 "+r+"; exit 0; }",(function(e,r,t){s(null,!!r)}));return}localExecutable(e,s)}))};var commandExistsWindows=function(e,r,s){if(!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(e)){s(null,false);return}var n=t("where "+r,(function(e){if(e!==null){s(null,false)}else{s(null,true)}}))};var commandExistsUnixSync=function(e,r){if(fileNotExistsSync(e)){try{var s=n("command -v "+r+" 2>/dev/null"+" && { echo >&1 "+r+"; exit 0; }");return!!s}catch(e){return false}}return localExecutableSync(e)};var commandExistsWindowsSync=function(e,r,s){if(!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(e)){return false}try{var t=n("where "+r,{stdio:[]});return!!t}catch(e){return false}};var cleanInput=function(e){if(/[^A-Za-z0-9_\/:=-]/.test(e)){e="'"+e.replace(/'/g,"'\\''")+"'";e=e.replace(/^(?:'')+/g,"").replace(/\\'''/g,"\\'")}return e};if(l){cleanInput=function(e){var r=/[\\]/.test(e);if(r){var s='"'+c.dirname(e)+'"';var t='"'+c.basename(e)+'"';return s+":"+t}return'"'+e+'"'}}e.exports=function commandExists(e,r){var s=cleanInput(e);if(!r&&typeof Promise!=="undefined"){return new Promise((function(r,s){commandExists(e,(function(t,n){if(n){r(e)}else{s(t)}}))}))}if(l){commandExistsWindows(e,s,r)}else{commandExistsUnix(e,s,r)}};e.exports.sync=function(e){var r=cleanInput(e);if(l){return commandExistsWindowsSync(e,r)}else{return commandExistsUnixSync(e,r)}}},898:(e,r,s)=>{"use strict";var t=s(81).spawn;var n=s(837);var escapeSpaces=function(e){if(typeof e==="string"){return e.replace(/\b\s/g,"\\ ")}else{return e}};var escapeSpacesInOptions=function(e){["src","dest","include","exclude","excludeFirst"].forEach((function(r){var s=e[r];if(typeof s==="string"){e[r]=escapeSpaces(s)}else if(Array.isArray(s)===true){e[r]=s.map(escapeSpaces)}}));return e};e.exports=function(e,r){e=e||{};e=n._extend({},e);e=escapeSpacesInOptions(e);var s=e.platform||process.platform;var o=s==="win32";if(typeof e.src==="undefined"){throw new Error("'src' directory is missing from options")}if(typeof e.dest==="undefined"){throw new Error("'dest' directory is missing from options")}var c=e.dest;if(typeof e.host!=="undefined"){c=e.host+":"+e.dest}if(!Array.isArray(e.src)){e.src=[e.src]}var i=[].concat(e.src);i.push(c);var a=(e.args||[]).find((function(e){return e.match(/--chmod=/)}));if(o&&!a){i.push("--chmod=ugo=rwX")}if(typeof e.host!=="undefined"||e.ssh){i.push("--rsh");var u="ssh";if(typeof e.port!=="undefined"){u+=" -p "+e.port}if(typeof e.privateKey!=="undefined"){u+=" -i "+e.privateKey}if(typeof e.sshCmdArgs!=="undefined"){u+=" "+e.sshCmdArgs.join(" ")}i.push(u)}if(e.recursive===true){i.push("--recursive")}if(e.times===true){i.push("--times")}if(e.syncDest===true||e.deleteAll===true){i.push("--delete");i.push("--delete-excluded")}if(e.syncDestIgnoreExcl===true||e.delete===true){i.push("--delete")}if(e.dryRun===true){i.push("--dry-run");i.push("--verbose")}if(typeof e.excludeFirst!=="undefined"&&n.isArray(e.excludeFirst)){e.excludeFirst.forEach((function(e,r){i.push("--exclude="+e)}))}if(typeof e.include!=="undefined"&&n.isArray(e.include)){e.include.forEach((function(e,r){i.push("--include="+e)}))}if(typeof e.exclude!=="undefined"&&n.isArray(e.exclude)){e.exclude.forEach((function(e,r){i.push("--exclude="+e)}))}switch(e.compareMode){case"sizeOnly":i.push("--size-only");break;case"checksum":i.push("--checksum");break}if(typeof e.args!=="undefined"&&n.isArray(e.args)){i=[...new Set([...i,...e.args])]}i=[...new Set(i)];var noop=function(){};var l=e.onStdout||noop;var d=e.onStderr||noop;var f="rsync ";i.forEach((function(e){if(e.substr(0,4)==="ssh "){e='"'+e+'"'}f+=e+" "}));f=f.trim();if(e.noExec){r(null,null,null,f);return}try{var p="";var _="";var y;if(o){y=t("cmd.exe",["/s","/c",'"'+f+'"'],{windowsVerbatimArguments:true,stdio:[process.stdin,"pipe","pipe"]})}else{y=t("/bin/sh",["-c",f])}y.stdout.on("data",(function(e){l(e);p+=e}));y.stderr.on("data",(function(e){d(e);_+=e}));y.on("exit",(function(e){var s=null;if(e!==0){s=new Error("rsync exited with code "+e);s.code=e}r(s,p,_,f)}))}catch(e){r(e,null,null,f)}}},505:(e,r,s)=>{const{existsSync:t,mkdirSync:n,writeFileSync:o}=s(147);const{GITHUB_WORKSPACE:c}=process.env;const validateDir=e=>{if(!t(e)){console.log(`[SSH] Creating ${e} dir in `,c);n(e);console.log("✅ [SSH] dir created.")}else{console.log(`[SSH] ${e} dir exist`)}};const validateFile=e=>{if(!t(e)){console.log(`[SSH] Creating ${e} file in `,c);try{o(e,"",{encoding:"utf8",mode:384});console.log("✅ [SSH] file created.")}catch(r){console.error("⚠️ [SSH] writeFileSync error",e,r.message);process.abort()}}else{console.log(`[SSH] ${e} file exist`)}};e.exports={validateDir:validateDir,validateFile:validateFile}},229:e=>{const r=["REMOTE_HOST","REMOTE_USER","REMOTE_PORT","SSH_PRIVATE_KEY","DEPLOY_KEY_NAME","SOURCE","TARGET","ARGS","EXCLUDE"];const s={GITHUB_WORKSPACE:process.env.GITHUB_WORKSPACE};r.forEach((e=>{s[e]=process.env[e]||process.env[`INPUT_${e}`]}));e.exports=s},447:(e,r,s)=>{const{sync:t}=s(569);const{exec:n,execSync:o}=s(81);const validateRsync=(e=(()=>{}))=>{const r=t("rsync");console.log('⚠️ [CLI] Rsync doesn\'t exists. Start installation with "apt-get" \n');if(!r){o("sudo apt-get update");n("sudo apt-get --no-install-recommends install rsync",((r,s,t)=>{if(r){console.log("⚠️ [CLI] Rsync installation failed. Aborting ... ",r.message);process.abort()}else{console.log("✅ [CLI] Rsync installed. \n",s,t);e()}}))}else{e()}};const validateInputs=e=>{const r=Object.keys(e);const s=r.filter((r=>{const s=e[r];if(!s){console.error(`⚠️ [INPUTS] ${r} is mandatory`)}return s}));if(s.length!==r.length){console.error("⚠️ [INPUTS] Inputs not valid, aborting ...");process.abort()}};e.exports={validateRsync:validateRsync,validateInputs:validateInputs}},822:(e,r,s)=>{const{writeFileSync:t}=s(147);const{join:n}=s(17);const{validateDir:o,validateFile:c}=s(505);const{HOME:i}=process.env;const addSshKey=(e,r)=>{const s=n(i||__dirname,".ssh");const a=n(s,r);o(s);c(`${s}/known_hosts`);try{t(a,e,{encoding:"utf8",mode:384})}catch(e){console.error("⚠️ writeFileSync error",a,e.message);process.abort()}console.log("✅ Ssh key added to `.ssh` dir ",a);return a};e.exports={addSshKey:addSshKey}},81:e=>{"use strict";e.exports=require("child_process")},147:e=>{"use strict";e.exports=require("fs")},17:e=>{"use strict";e.exports=require("path")},837:e=>{"use strict";e.exports=require("util")}};var r={};function __nccwpck_require__(s){var t=r[s];if(t!==undefined){return t.exports}var n=r[s]={exports:{}};var o=true;try{e[s](n,n.exports,__nccwpck_require__);o=false}finally{if(o)delete r[s]}return n.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var s={};(()=>{const e=__nccwpck_require__(898);const{validateRsync:r,validateInputs:s}=__nccwpck_require__(447);const{addSshKey:t}=__nccwpck_require__(822);const{REMOTE_HOST:n,REMOTE_USER:o,REMOTE_PORT:c,SSH_PRIVATE_KEY:i,DEPLOY_KEY_NAME:a,SOURCE:u,TARGET:l,ARGS:d,EXCLUDE:f,GITHUB_WORKSPACE:p}=__nccwpck_require__(229);const _={ssh:true,sshCmdArgs:["-o StrictHostKeyChecking=no"],recursive:true};console.log("GITHUB_WORKSPACE: ",p);console.log("REMOTE_HOST: ",process.env.REMOTE_HOST);console.log("REMOTE_USER: ",process.env.REMOTE_USER);console.log("SSH_PRIVATE_KEY: ",process.env.SSH_PRIVATE_KEY);const y=(()=>{const rsync=({privateKey:r,port:s,src:t,dest:n,args:o,exclude:c})=>{console.log(`[Rsync] Starting Rsync Action: ${t} to ${n}`);if(c)console.log(`[Rsync] exluding folders ${c}`);try{e({src:t,dest:n,args:o,privateKey:r,port:s,excludeFirst:c,..._},((e,r,s,t)=>{if(e){console.error("⚠️ [Rsync] error: ",e.message);console.log("⚠️ [Rsync] stderr: ",s);console.log("⚠️ [Rsync] stdout: ",r);console.log("⚠️ [Rsync] cmd: ",t);process.abort()}else{console.log("✅ [Rsync] finished.",r)}}))}catch(e){console.error("⚠️ [Rsync] command error: ",e.message,e.stack);process.abort()}};const init=({src:e,dest:s,args:n,host:o="localhost",port:c,username:i,privateKeyContent:u,exclude:l=[]})=>{r((()=>{const r=t(u,a||"deploy_key");const d=`${i}@${o}:${s}`;rsync({privateKey:r,port:c,src:e,dest:d,args:n,exclude:l})}))};return{init:init}})();const run=()=>{s({SSH_PRIVATE_KEY:i,REMOTE_HOST:n,REMOTE_USER:o});y.init({src:`${p}/${u||""}`,dest:l||`/home/${o}/`,args:d?[d]:["-rltgoDzvO"],host:n,port:c||"22",username:o,privateKeyContent:i,exclude:(f||"").split(",").map((e=>e.trim()))})};run()})();module.exports=s})(); \ No newline at end of file From 5403dab9a0d50a7e0cf5b85d90401d3aa00355e5 Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Sat, 31 Dec 2022 10:00:32 +0100 Subject: [PATCH 31/46] rsync check --- dist/index.js | 2 +- src/rsyncCli.js | 34 ++++++++++++++++++++-------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/dist/index.js b/dist/index.js index dcf2afc..07b6c4d 100755 --- a/dist/index.js +++ b/dist/index.js @@ -1,2 +1,2 @@ #!/usr/bin/env node -(()=>{var e={569:(e,r,s)=>{e.exports=s(325)},325:(e,r,s)=>{"use strict";var t=s(81).exec;var n=s(81).execSync;var o=s(147);var c=s(17);var i=o.access;var a=o.accessSync;var u=o.constants||o;var l=process.platform=="win32";var fileNotExists=function(e,r){i(e,u.F_OK,(function(e){r(!e)}))};var fileNotExistsSync=function(e){try{a(e,u.F_OK);return false}catch(e){return true}};var localExecutable=function(e,r){i(e,u.F_OK|u.X_OK,(function(e){r(null,!e)}))};var localExecutableSync=function(e){try{a(e,u.F_OK|u.X_OK);return true}catch(e){return false}};var commandExistsUnix=function(e,r,s){fileNotExists(e,(function(n){if(!n){var o=t("command -v "+r+" 2>/dev/null"+" && { echo >&1 "+r+"; exit 0; }",(function(e,r,t){s(null,!!r)}));return}localExecutable(e,s)}))};var commandExistsWindows=function(e,r,s){if(!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(e)){s(null,false);return}var n=t("where "+r,(function(e){if(e!==null){s(null,false)}else{s(null,true)}}))};var commandExistsUnixSync=function(e,r){if(fileNotExistsSync(e)){try{var s=n("command -v "+r+" 2>/dev/null"+" && { echo >&1 "+r+"; exit 0; }");return!!s}catch(e){return false}}return localExecutableSync(e)};var commandExistsWindowsSync=function(e,r,s){if(!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(e)){return false}try{var t=n("where "+r,{stdio:[]});return!!t}catch(e){return false}};var cleanInput=function(e){if(/[^A-Za-z0-9_\/:=-]/.test(e)){e="'"+e.replace(/'/g,"'\\''")+"'";e=e.replace(/^(?:'')+/g,"").replace(/\\'''/g,"\\'")}return e};if(l){cleanInput=function(e){var r=/[\\]/.test(e);if(r){var s='"'+c.dirname(e)+'"';var t='"'+c.basename(e)+'"';return s+":"+t}return'"'+e+'"'}}e.exports=function commandExists(e,r){var s=cleanInput(e);if(!r&&typeof Promise!=="undefined"){return new Promise((function(r,s){commandExists(e,(function(t,n){if(n){r(e)}else{s(t)}}))}))}if(l){commandExistsWindows(e,s,r)}else{commandExistsUnix(e,s,r)}};e.exports.sync=function(e){var r=cleanInput(e);if(l){return commandExistsWindowsSync(e,r)}else{return commandExistsUnixSync(e,r)}}},898:(e,r,s)=>{"use strict";var t=s(81).spawn;var n=s(837);var escapeSpaces=function(e){if(typeof e==="string"){return e.replace(/\b\s/g,"\\ ")}else{return e}};var escapeSpacesInOptions=function(e){["src","dest","include","exclude","excludeFirst"].forEach((function(r){var s=e[r];if(typeof s==="string"){e[r]=escapeSpaces(s)}else if(Array.isArray(s)===true){e[r]=s.map(escapeSpaces)}}));return e};e.exports=function(e,r){e=e||{};e=n._extend({},e);e=escapeSpacesInOptions(e);var s=e.platform||process.platform;var o=s==="win32";if(typeof e.src==="undefined"){throw new Error("'src' directory is missing from options")}if(typeof e.dest==="undefined"){throw new Error("'dest' directory is missing from options")}var c=e.dest;if(typeof e.host!=="undefined"){c=e.host+":"+e.dest}if(!Array.isArray(e.src)){e.src=[e.src]}var i=[].concat(e.src);i.push(c);var a=(e.args||[]).find((function(e){return e.match(/--chmod=/)}));if(o&&!a){i.push("--chmod=ugo=rwX")}if(typeof e.host!=="undefined"||e.ssh){i.push("--rsh");var u="ssh";if(typeof e.port!=="undefined"){u+=" -p "+e.port}if(typeof e.privateKey!=="undefined"){u+=" -i "+e.privateKey}if(typeof e.sshCmdArgs!=="undefined"){u+=" "+e.sshCmdArgs.join(" ")}i.push(u)}if(e.recursive===true){i.push("--recursive")}if(e.times===true){i.push("--times")}if(e.syncDest===true||e.deleteAll===true){i.push("--delete");i.push("--delete-excluded")}if(e.syncDestIgnoreExcl===true||e.delete===true){i.push("--delete")}if(e.dryRun===true){i.push("--dry-run");i.push("--verbose")}if(typeof e.excludeFirst!=="undefined"&&n.isArray(e.excludeFirst)){e.excludeFirst.forEach((function(e,r){i.push("--exclude="+e)}))}if(typeof e.include!=="undefined"&&n.isArray(e.include)){e.include.forEach((function(e,r){i.push("--include="+e)}))}if(typeof e.exclude!=="undefined"&&n.isArray(e.exclude)){e.exclude.forEach((function(e,r){i.push("--exclude="+e)}))}switch(e.compareMode){case"sizeOnly":i.push("--size-only");break;case"checksum":i.push("--checksum");break}if(typeof e.args!=="undefined"&&n.isArray(e.args)){i=[...new Set([...i,...e.args])]}i=[...new Set(i)];var noop=function(){};var l=e.onStdout||noop;var d=e.onStderr||noop;var f="rsync ";i.forEach((function(e){if(e.substr(0,4)==="ssh "){e='"'+e+'"'}f+=e+" "}));f=f.trim();if(e.noExec){r(null,null,null,f);return}try{var p="";var _="";var y;if(o){y=t("cmd.exe",["/s","/c",'"'+f+'"'],{windowsVerbatimArguments:true,stdio:[process.stdin,"pipe","pipe"]})}else{y=t("/bin/sh",["-c",f])}y.stdout.on("data",(function(e){l(e);p+=e}));y.stderr.on("data",(function(e){d(e);_+=e}));y.on("exit",(function(e){var s=null;if(e!==0){s=new Error("rsync exited with code "+e);s.code=e}r(s,p,_,f)}))}catch(e){r(e,null,null,f)}}},505:(e,r,s)=>{const{existsSync:t,mkdirSync:n,writeFileSync:o}=s(147);const{GITHUB_WORKSPACE:c}=process.env;const validateDir=e=>{if(!t(e)){console.log(`[SSH] Creating ${e} dir in `,c);n(e);console.log("✅ [SSH] dir created.")}else{console.log(`[SSH] ${e} dir exist`)}};const validateFile=e=>{if(!t(e)){console.log(`[SSH] Creating ${e} file in `,c);try{o(e,"",{encoding:"utf8",mode:384});console.log("✅ [SSH] file created.")}catch(r){console.error("⚠️ [SSH] writeFileSync error",e,r.message);process.abort()}}else{console.log(`[SSH] ${e} file exist`)}};e.exports={validateDir:validateDir,validateFile:validateFile}},229:e=>{const r=["REMOTE_HOST","REMOTE_USER","REMOTE_PORT","SSH_PRIVATE_KEY","DEPLOY_KEY_NAME","SOURCE","TARGET","ARGS","EXCLUDE"];const s={GITHUB_WORKSPACE:process.env.GITHUB_WORKSPACE};r.forEach((e=>{s[e]=process.env[e]||process.env[`INPUT_${e}`]}));e.exports=s},447:(e,r,s)=>{const{sync:t}=s(569);const{exec:n,execSync:o}=s(81);const validateRsync=(e=(()=>{}))=>{const r=t("rsync");console.log('⚠️ [CLI] Rsync doesn\'t exists. Start installation with "apt-get" \n');if(!r){o("sudo apt-get update");n("sudo apt-get --no-install-recommends install rsync",((r,s,t)=>{if(r){console.log("⚠️ [CLI] Rsync installation failed. Aborting ... ",r.message);process.abort()}else{console.log("✅ [CLI] Rsync installed. \n",s,t);e()}}))}else{e()}};const validateInputs=e=>{const r=Object.keys(e);const s=r.filter((r=>{const s=e[r];if(!s){console.error(`⚠️ [INPUTS] ${r} is mandatory`)}return s}));if(s.length!==r.length){console.error("⚠️ [INPUTS] Inputs not valid, aborting ...");process.abort()}};e.exports={validateRsync:validateRsync,validateInputs:validateInputs}},822:(e,r,s)=>{const{writeFileSync:t}=s(147);const{join:n}=s(17);const{validateDir:o,validateFile:c}=s(505);const{HOME:i}=process.env;const addSshKey=(e,r)=>{const s=n(i||__dirname,".ssh");const a=n(s,r);o(s);c(`${s}/known_hosts`);try{t(a,e,{encoding:"utf8",mode:384})}catch(e){console.error("⚠️ writeFileSync error",a,e.message);process.abort()}console.log("✅ Ssh key added to `.ssh` dir ",a);return a};e.exports={addSshKey:addSshKey}},81:e=>{"use strict";e.exports=require("child_process")},147:e=>{"use strict";e.exports=require("fs")},17:e=>{"use strict";e.exports=require("path")},837:e=>{"use strict";e.exports=require("util")}};var r={};function __nccwpck_require__(s){var t=r[s];if(t!==undefined){return t.exports}var n=r[s]={exports:{}};var o=true;try{e[s](n,n.exports,__nccwpck_require__);o=false}finally{if(o)delete r[s]}return n.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var s={};(()=>{const e=__nccwpck_require__(898);const{validateRsync:r,validateInputs:s}=__nccwpck_require__(447);const{addSshKey:t}=__nccwpck_require__(822);const{REMOTE_HOST:n,REMOTE_USER:o,REMOTE_PORT:c,SSH_PRIVATE_KEY:i,DEPLOY_KEY_NAME:a,SOURCE:u,TARGET:l,ARGS:d,EXCLUDE:f,GITHUB_WORKSPACE:p}=__nccwpck_require__(229);const _={ssh:true,sshCmdArgs:["-o StrictHostKeyChecking=no"],recursive:true};console.log("GITHUB_WORKSPACE: ",p);console.log("REMOTE_HOST: ",process.env.REMOTE_HOST);console.log("REMOTE_USER: ",process.env.REMOTE_USER);console.log("SSH_PRIVATE_KEY: ",process.env.SSH_PRIVATE_KEY);const y=(()=>{const rsync=({privateKey:r,port:s,src:t,dest:n,args:o,exclude:c})=>{console.log(`[Rsync] Starting Rsync Action: ${t} to ${n}`);if(c)console.log(`[Rsync] exluding folders ${c}`);try{e({src:t,dest:n,args:o,privateKey:r,port:s,excludeFirst:c,..._},((e,r,s,t)=>{if(e){console.error("⚠️ [Rsync] error: ",e.message);console.log("⚠️ [Rsync] stderr: ",s);console.log("⚠️ [Rsync] stdout: ",r);console.log("⚠️ [Rsync] cmd: ",t);process.abort()}else{console.log("✅ [Rsync] finished.",r)}}))}catch(e){console.error("⚠️ [Rsync] command error: ",e.message,e.stack);process.abort()}};const init=({src:e,dest:s,args:n,host:o="localhost",port:c,username:i,privateKeyContent:u,exclude:l=[]})=>{r((()=>{const r=t(u,a||"deploy_key");const d=`${i}@${o}:${s}`;rsync({privateKey:r,port:c,src:e,dest:d,args:n,exclude:l})}))};return{init:init}})();const run=()=>{s({SSH_PRIVATE_KEY:i,REMOTE_HOST:n,REMOTE_USER:o});y.init({src:`${p}/${u||""}`,dest:l||`/home/${o}/`,args:d?[d]:["-rltgoDzvO"],host:n,port:c||"22",username:o,privateKeyContent:i,exclude:(f||"").split(",").map((e=>e.trim()))})};run()})();module.exports=s})(); \ No newline at end of file +(()=>{var e={569:(e,r,s)=>{e.exports=s(325)},325:(e,r,s)=>{"use strict";var t=s(81).exec;var n=s(81).execSync;var o=s(147);var c=s(17);var i=o.access;var a=o.accessSync;var u=o.constants||o;var l=process.platform=="win32";var fileNotExists=function(e,r){i(e,u.F_OK,(function(e){r(!e)}))};var fileNotExistsSync=function(e){try{a(e,u.F_OK);return false}catch(e){return true}};var localExecutable=function(e,r){i(e,u.F_OK|u.X_OK,(function(e){r(null,!e)}))};var localExecutableSync=function(e){try{a(e,u.F_OK|u.X_OK);return true}catch(e){return false}};var commandExistsUnix=function(e,r,s){fileNotExists(e,(function(n){if(!n){var o=t("command -v "+r+" 2>/dev/null"+" && { echo >&1 "+r+"; exit 0; }",(function(e,r,t){s(null,!!r)}));return}localExecutable(e,s)}))};var commandExistsWindows=function(e,r,s){if(!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(e)){s(null,false);return}var n=t("where "+r,(function(e){if(e!==null){s(null,false)}else{s(null,true)}}))};var commandExistsUnixSync=function(e,r){if(fileNotExistsSync(e)){try{var s=n("command -v "+r+" 2>/dev/null"+" && { echo >&1 "+r+"; exit 0; }");return!!s}catch(e){return false}}return localExecutableSync(e)};var commandExistsWindowsSync=function(e,r,s){if(!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(e)){return false}try{var t=n("where "+r,{stdio:[]});return!!t}catch(e){return false}};var cleanInput=function(e){if(/[^A-Za-z0-9_\/:=-]/.test(e)){e="'"+e.replace(/'/g,"'\\''")+"'";e=e.replace(/^(?:'')+/g,"").replace(/\\'''/g,"\\'")}return e};if(l){cleanInput=function(e){var r=/[\\]/.test(e);if(r){var s='"'+c.dirname(e)+'"';var t='"'+c.basename(e)+'"';return s+":"+t}return'"'+e+'"'}}e.exports=function commandExists(e,r){var s=cleanInput(e);if(!r&&typeof Promise!=="undefined"){return new Promise((function(r,s){commandExists(e,(function(t,n){if(n){r(e)}else{s(t)}}))}))}if(l){commandExistsWindows(e,s,r)}else{commandExistsUnix(e,s,r)}};e.exports.sync=function(e){var r=cleanInput(e);if(l){return commandExistsWindowsSync(e,r)}else{return commandExistsUnixSync(e,r)}}},898:(e,r,s)=>{"use strict";var t=s(81).spawn;var n=s(837);var escapeSpaces=function(e){if(typeof e==="string"){return e.replace(/\b\s/g,"\\ ")}else{return e}};var escapeSpacesInOptions=function(e){["src","dest","include","exclude","excludeFirst"].forEach((function(r){var s=e[r];if(typeof s==="string"){e[r]=escapeSpaces(s)}else if(Array.isArray(s)===true){e[r]=s.map(escapeSpaces)}}));return e};e.exports=function(e,r){e=e||{};e=n._extend({},e);e=escapeSpacesInOptions(e);var s=e.platform||process.platform;var o=s==="win32";if(typeof e.src==="undefined"){throw new Error("'src' directory is missing from options")}if(typeof e.dest==="undefined"){throw new Error("'dest' directory is missing from options")}var c=e.dest;if(typeof e.host!=="undefined"){c=e.host+":"+e.dest}if(!Array.isArray(e.src)){e.src=[e.src]}var i=[].concat(e.src);i.push(c);var a=(e.args||[]).find((function(e){return e.match(/--chmod=/)}));if(o&&!a){i.push("--chmod=ugo=rwX")}if(typeof e.host!=="undefined"||e.ssh){i.push("--rsh");var u="ssh";if(typeof e.port!=="undefined"){u+=" -p "+e.port}if(typeof e.privateKey!=="undefined"){u+=" -i "+e.privateKey}if(typeof e.sshCmdArgs!=="undefined"){u+=" "+e.sshCmdArgs.join(" ")}i.push(u)}if(e.recursive===true){i.push("--recursive")}if(e.times===true){i.push("--times")}if(e.syncDest===true||e.deleteAll===true){i.push("--delete");i.push("--delete-excluded")}if(e.syncDestIgnoreExcl===true||e.delete===true){i.push("--delete")}if(e.dryRun===true){i.push("--dry-run");i.push("--verbose")}if(typeof e.excludeFirst!=="undefined"&&n.isArray(e.excludeFirst)){e.excludeFirst.forEach((function(e,r){i.push("--exclude="+e)}))}if(typeof e.include!=="undefined"&&n.isArray(e.include)){e.include.forEach((function(e,r){i.push("--include="+e)}))}if(typeof e.exclude!=="undefined"&&n.isArray(e.exclude)){e.exclude.forEach((function(e,r){i.push("--exclude="+e)}))}switch(e.compareMode){case"sizeOnly":i.push("--size-only");break;case"checksum":i.push("--checksum");break}if(typeof e.args!=="undefined"&&n.isArray(e.args)){i=[...new Set([...i,...e.args])]}i=[...new Set(i)];var noop=function(){};var l=e.onStdout||noop;var d=e.onStderr||noop;var f="rsync ";i.forEach((function(e){if(e.substr(0,4)==="ssh "){e='"'+e+'"'}f+=e+" "}));f=f.trim();if(e.noExec){r(null,null,null,f);return}try{var p="";var y="";var _;if(o){_=t("cmd.exe",["/s","/c",'"'+f+'"'],{windowsVerbatimArguments:true,stdio:[process.stdin,"pipe","pipe"]})}else{_=t("/bin/sh",["-c",f])}_.stdout.on("data",(function(e){l(e);p+=e}));_.stderr.on("data",(function(e){d(e);y+=e}));_.on("exit",(function(e){var s=null;if(e!==0){s=new Error("rsync exited with code "+e);s.code=e}r(s,p,y,f)}))}catch(e){r(e,null,null,f)}}},505:(e,r,s)=>{const{existsSync:t,mkdirSync:n,writeFileSync:o}=s(147);const{GITHUB_WORKSPACE:c}=process.env;const validateDir=e=>{if(!t(e)){console.log(`[SSH] Creating ${e} dir in `,c);n(e);console.log("✅ [SSH] dir created.")}else{console.log(`[SSH] ${e} dir exist`)}};const validateFile=e=>{if(!t(e)){console.log(`[SSH] Creating ${e} file in `,c);try{o(e,"",{encoding:"utf8",mode:384});console.log("✅ [SSH] file created.")}catch(r){console.error("⚠️ [SSH] writeFileSync error",e,r.message);process.abort()}}else{console.log(`[SSH] ${e} file exist`)}};e.exports={validateDir:validateDir,validateFile:validateFile}},229:e=>{const r=["REMOTE_HOST","REMOTE_USER","REMOTE_PORT","SSH_PRIVATE_KEY","DEPLOY_KEY_NAME","SOURCE","TARGET","ARGS","EXCLUDE"];const s={GITHUB_WORKSPACE:process.env.GITHUB_WORKSPACE};r.forEach((e=>{s[e]=process.env[e]||process.env[`INPUT_${e}`]}));e.exports=s},447:(e,r,s)=>{const{sync:t}=s(569);const{exec:n,execSync:o}=s(81);const validateRsync=(e=(()=>{}))=>{const r=t("rsync");if(r){console.log("⚠️ [CLI] Rsync exists",o("rsync --version"));return e()}console.log('⚠️ [CLI] Rsync doesn\'t exists. Start installation with "apt-get" \n');try{o("sudo apt-get update")}catch(e){console.log("⚠️ [CLI] Cant run . apt-get update. Skipping ...".e.message)}n("sudo apt-get --no-install-recommends install rsync",((r,s,t)=>{if(r){console.log("⚠️ [CLI] Rsync installation failed. Aborting ... ",r.message);process.abort()}else{console.log("✅ [CLI] Rsync installed. \n",s,t);e()}}))};const validateInputs=e=>{const r=Object.keys(e);const s=r.filter((r=>{const s=e[r];if(!s){console.error(`⚠️ [INPUTS] ${r} is mandatory`)}return s}));if(s.length!==r.length){console.error("⚠️ [INPUTS] Inputs not valid, aborting ...");process.abort()}};e.exports={validateRsync:validateRsync,validateInputs:validateInputs}},822:(e,r,s)=>{const{writeFileSync:t}=s(147);const{join:n}=s(17);const{validateDir:o,validateFile:c}=s(505);const{HOME:i}=process.env;const addSshKey=(e,r)=>{const s=n(i||__dirname,".ssh");const a=n(s,r);o(s);c(`${s}/known_hosts`);try{t(a,e,{encoding:"utf8",mode:384})}catch(e){console.error("⚠️ writeFileSync error",a,e.message);process.abort()}console.log("✅ Ssh key added to `.ssh` dir ",a);return a};e.exports={addSshKey:addSshKey}},81:e=>{"use strict";e.exports=require("child_process")},147:e=>{"use strict";e.exports=require("fs")},17:e=>{"use strict";e.exports=require("path")},837:e=>{"use strict";e.exports=require("util")}};var r={};function __nccwpck_require__(s){var t=r[s];if(t!==undefined){return t.exports}var n=r[s]={exports:{}};var o=true;try{e[s](n,n.exports,__nccwpck_require__);o=false}finally{if(o)delete r[s]}return n.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var s={};(()=>{const e=__nccwpck_require__(898);const{validateRsync:r,validateInputs:s}=__nccwpck_require__(447);const{addSshKey:t}=__nccwpck_require__(822);const{REMOTE_HOST:n,REMOTE_USER:o,REMOTE_PORT:c,SSH_PRIVATE_KEY:i,DEPLOY_KEY_NAME:a,SOURCE:u,TARGET:l,ARGS:d,EXCLUDE:f,GITHUB_WORKSPACE:p}=__nccwpck_require__(229);const y={ssh:true,sshCmdArgs:["-o StrictHostKeyChecking=no"],recursive:true};console.log("GITHUB_WORKSPACE: ",p);console.log("REMOTE_HOST: ",process.env.REMOTE_HOST);console.log("REMOTE_USER: ",process.env.REMOTE_USER);console.log("SSH_PRIVATE_KEY: ",process.env.SSH_PRIVATE_KEY);const _=(()=>{const rsync=({privateKey:r,port:s,src:t,dest:n,args:o,exclude:c})=>{console.log(`[Rsync] Starting Rsync Action: ${t} to ${n}`);if(c)console.log(`[Rsync] exluding folders ${c}`);try{e({src:t,dest:n,args:o,privateKey:r,port:s,excludeFirst:c,...y},((e,r,s,t)=>{if(e){console.error("⚠️ [Rsync] error: ",e.message);console.log("⚠️ [Rsync] stderr: ",s);console.log("⚠️ [Rsync] stdout: ",r);console.log("⚠️ [Rsync] cmd: ",t);process.abort()}else{console.log("✅ [Rsync] finished.",r)}}))}catch(e){console.error("⚠️ [Rsync] command error: ",e.message,e.stack);process.abort()}};const init=({src:e,dest:s,args:n,host:o="localhost",port:c,username:i,privateKeyContent:u,exclude:l=[]})=>{r((()=>{const r=t(u,a||"deploy_key");const d=`${i}@${o}:${s}`;rsync({privateKey:r,port:c,src:e,dest:d,args:n,exclude:l})}))};return{init:init}})();const run=()=>{s({SSH_PRIVATE_KEY:i,REMOTE_HOST:n,REMOTE_USER:o});_.init({src:`${p}/${u||""}`,dest:l||`/home/${o}/`,args:d?[d]:["-rltgoDzvO"],host:n,port:c||"22",username:o,privateKeyContent:i,exclude:(f||"").split(",").map((e=>e.trim()))})};run()})();module.exports=s})(); \ No newline at end of file diff --git a/src/rsyncCli.js b/src/rsyncCli.js index b29beea..fb80507 100644 --- a/src/rsyncCli.js +++ b/src/rsyncCli.js @@ -3,21 +3,27 @@ const { exec, execSync } = require("child_process"); const validateRsync = (callback = () => {}) => { const rsyncCli = commandExists("rsync"); - console.log('⚠️ [CLI] Rsync doesn\'t exists. Start installation with "apt-get" \n'); - if (!rsyncCli) { - execSync("sudo apt-get update"); - exec("sudo apt-get --no-install-recommends install rsync", (err, data, stderr) => { - if (err) { - console.log("⚠️ [CLI] Rsync installation failed. Aborting ... ", err.message); - process.abort(); - } else { - console.log("✅ [CLI] Rsync installed. \n", data, stderr); - callback(); - } - }); - } else { - callback(); + if (rsyncCli) { + console.log('⚠️ [CLI] Rsync exists', execSync("rsync --version")); + return callback(); } + + console.log('⚠️ [CLI] Rsync doesn\'t exists. Start installation with "apt-get" \n'); + try { + execSync("sudo apt-get update"); + } catch (e) { + console.log( "⚠️ [CLI] Cant run . apt-get update. Skipping ...". e.message); + } + + exec("sudo apt-get --no-install-recommends install rsync", (err, data, stderr) => { + if (err) { + console.log("⚠️ [CLI] Rsync installation failed. Aborting ... ", err.message); + process.abort(); + } else { + console.log("✅ [CLI] Rsync installed. \n", data, stderr); + callback(); + } + }); }; const validateInputs = (inputs) => { From 70415f9f9da9446616320a461b14d2879d8d3db9 Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Sat, 31 Dec 2022 10:02:46 +0100 Subject: [PATCH 32/46] rsyncVersion --- src/rsyncCli.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/rsyncCli.js b/src/rsyncCli.js index fb80507..e884959 100644 --- a/src/rsyncCli.js +++ b/src/rsyncCli.js @@ -4,7 +4,8 @@ const { exec, execSync } = require("child_process"); const validateRsync = (callback = () => {}) => { const rsyncCli = commandExists("rsync"); if (rsyncCli) { - console.log('⚠️ [CLI] Rsync exists', execSync("rsync --version")); + const rsyncVersion = execSync("rsync --version"); + console.log('⚠️ [CLI] Rsync exists', rsyncVersion); return callback(); } From 4b6681d89c833a2c3264b09b51232385e73ff851 Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Sat, 31 Dec 2022 10:04:57 +0100 Subject: [PATCH 33/46] {stdio: 'inherit'} --- src/rsyncCli.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rsyncCli.js b/src/rsyncCli.js index e884959..d3cd2ae 100644 --- a/src/rsyncCli.js +++ b/src/rsyncCli.js @@ -4,7 +4,7 @@ const { exec, execSync } = require("child_process"); const validateRsync = (callback = () => {}) => { const rsyncCli = commandExists("rsync"); if (rsyncCli) { - const rsyncVersion = execSync("rsync --version"); + const rsyncVersion = execSync("rsync --version", { stdio: 'inherit' }); console.log('⚠️ [CLI] Rsync exists', rsyncVersion); return callback(); } From 45eb75d44955e5544ee1e7643eef8d0c93b22601 Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Sat, 31 Dec 2022 10:06:06 +0100 Subject: [PATCH 34/46] inherit --- src/rsyncCli.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rsyncCli.js b/src/rsyncCli.js index d3cd2ae..ef7e8f7 100644 --- a/src/rsyncCli.js +++ b/src/rsyncCli.js @@ -11,12 +11,12 @@ const validateRsync = (callback = () => {}) => { console.log('⚠️ [CLI] Rsync doesn\'t exists. Start installation with "apt-get" \n'); try { - execSync("sudo apt-get update"); + execSync("sudo apt-get update", { stdio: 'inherit' }); } catch (e) { console.log( "⚠️ [CLI] Cant run . apt-get update. Skipping ...". e.message); } - exec("sudo apt-get --no-install-recommends install rsync", (err, data, stderr) => { + exec("sudo apt-get --no-install-recommends install rsync", { stdio: 'inherit' }, (err, data, stderr) => { if (err) { console.log("⚠️ [CLI] Rsync installation failed. Aborting ... ", err.message); process.abort(); From 3e2f0214fce105c8df6ff76f1a3021be33339430 Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Sat, 31 Dec 2022 10:07:22 +0100 Subject: [PATCH 35/46] build it! --- dist/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/index.js b/dist/index.js index 07b6c4d..c0edd7f 100755 --- a/dist/index.js +++ b/dist/index.js @@ -1,2 +1,2 @@ #!/usr/bin/env node -(()=>{var e={569:(e,r,s)=>{e.exports=s(325)},325:(e,r,s)=>{"use strict";var t=s(81).exec;var n=s(81).execSync;var o=s(147);var c=s(17);var i=o.access;var a=o.accessSync;var u=o.constants||o;var l=process.platform=="win32";var fileNotExists=function(e,r){i(e,u.F_OK,(function(e){r(!e)}))};var fileNotExistsSync=function(e){try{a(e,u.F_OK);return false}catch(e){return true}};var localExecutable=function(e,r){i(e,u.F_OK|u.X_OK,(function(e){r(null,!e)}))};var localExecutableSync=function(e){try{a(e,u.F_OK|u.X_OK);return true}catch(e){return false}};var commandExistsUnix=function(e,r,s){fileNotExists(e,(function(n){if(!n){var o=t("command -v "+r+" 2>/dev/null"+" && { echo >&1 "+r+"; exit 0; }",(function(e,r,t){s(null,!!r)}));return}localExecutable(e,s)}))};var commandExistsWindows=function(e,r,s){if(!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(e)){s(null,false);return}var n=t("where "+r,(function(e){if(e!==null){s(null,false)}else{s(null,true)}}))};var commandExistsUnixSync=function(e,r){if(fileNotExistsSync(e)){try{var s=n("command -v "+r+" 2>/dev/null"+" && { echo >&1 "+r+"; exit 0; }");return!!s}catch(e){return false}}return localExecutableSync(e)};var commandExistsWindowsSync=function(e,r,s){if(!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(e)){return false}try{var t=n("where "+r,{stdio:[]});return!!t}catch(e){return false}};var cleanInput=function(e){if(/[^A-Za-z0-9_\/:=-]/.test(e)){e="'"+e.replace(/'/g,"'\\''")+"'";e=e.replace(/^(?:'')+/g,"").replace(/\\'''/g,"\\'")}return e};if(l){cleanInput=function(e){var r=/[\\]/.test(e);if(r){var s='"'+c.dirname(e)+'"';var t='"'+c.basename(e)+'"';return s+":"+t}return'"'+e+'"'}}e.exports=function commandExists(e,r){var s=cleanInput(e);if(!r&&typeof Promise!=="undefined"){return new Promise((function(r,s){commandExists(e,(function(t,n){if(n){r(e)}else{s(t)}}))}))}if(l){commandExistsWindows(e,s,r)}else{commandExistsUnix(e,s,r)}};e.exports.sync=function(e){var r=cleanInput(e);if(l){return commandExistsWindowsSync(e,r)}else{return commandExistsUnixSync(e,r)}}},898:(e,r,s)=>{"use strict";var t=s(81).spawn;var n=s(837);var escapeSpaces=function(e){if(typeof e==="string"){return e.replace(/\b\s/g,"\\ ")}else{return e}};var escapeSpacesInOptions=function(e){["src","dest","include","exclude","excludeFirst"].forEach((function(r){var s=e[r];if(typeof s==="string"){e[r]=escapeSpaces(s)}else if(Array.isArray(s)===true){e[r]=s.map(escapeSpaces)}}));return e};e.exports=function(e,r){e=e||{};e=n._extend({},e);e=escapeSpacesInOptions(e);var s=e.platform||process.platform;var o=s==="win32";if(typeof e.src==="undefined"){throw new Error("'src' directory is missing from options")}if(typeof e.dest==="undefined"){throw new Error("'dest' directory is missing from options")}var c=e.dest;if(typeof e.host!=="undefined"){c=e.host+":"+e.dest}if(!Array.isArray(e.src)){e.src=[e.src]}var i=[].concat(e.src);i.push(c);var a=(e.args||[]).find((function(e){return e.match(/--chmod=/)}));if(o&&!a){i.push("--chmod=ugo=rwX")}if(typeof e.host!=="undefined"||e.ssh){i.push("--rsh");var u="ssh";if(typeof e.port!=="undefined"){u+=" -p "+e.port}if(typeof e.privateKey!=="undefined"){u+=" -i "+e.privateKey}if(typeof e.sshCmdArgs!=="undefined"){u+=" "+e.sshCmdArgs.join(" ")}i.push(u)}if(e.recursive===true){i.push("--recursive")}if(e.times===true){i.push("--times")}if(e.syncDest===true||e.deleteAll===true){i.push("--delete");i.push("--delete-excluded")}if(e.syncDestIgnoreExcl===true||e.delete===true){i.push("--delete")}if(e.dryRun===true){i.push("--dry-run");i.push("--verbose")}if(typeof e.excludeFirst!=="undefined"&&n.isArray(e.excludeFirst)){e.excludeFirst.forEach((function(e,r){i.push("--exclude="+e)}))}if(typeof e.include!=="undefined"&&n.isArray(e.include)){e.include.forEach((function(e,r){i.push("--include="+e)}))}if(typeof e.exclude!=="undefined"&&n.isArray(e.exclude)){e.exclude.forEach((function(e,r){i.push("--exclude="+e)}))}switch(e.compareMode){case"sizeOnly":i.push("--size-only");break;case"checksum":i.push("--checksum");break}if(typeof e.args!=="undefined"&&n.isArray(e.args)){i=[...new Set([...i,...e.args])]}i=[...new Set(i)];var noop=function(){};var l=e.onStdout||noop;var d=e.onStderr||noop;var f="rsync ";i.forEach((function(e){if(e.substr(0,4)==="ssh "){e='"'+e+'"'}f+=e+" "}));f=f.trim();if(e.noExec){r(null,null,null,f);return}try{var p="";var y="";var _;if(o){_=t("cmd.exe",["/s","/c",'"'+f+'"'],{windowsVerbatimArguments:true,stdio:[process.stdin,"pipe","pipe"]})}else{_=t("/bin/sh",["-c",f])}_.stdout.on("data",(function(e){l(e);p+=e}));_.stderr.on("data",(function(e){d(e);y+=e}));_.on("exit",(function(e){var s=null;if(e!==0){s=new Error("rsync exited with code "+e);s.code=e}r(s,p,y,f)}))}catch(e){r(e,null,null,f)}}},505:(e,r,s)=>{const{existsSync:t,mkdirSync:n,writeFileSync:o}=s(147);const{GITHUB_WORKSPACE:c}=process.env;const validateDir=e=>{if(!t(e)){console.log(`[SSH] Creating ${e} dir in `,c);n(e);console.log("✅ [SSH] dir created.")}else{console.log(`[SSH] ${e} dir exist`)}};const validateFile=e=>{if(!t(e)){console.log(`[SSH] Creating ${e} file in `,c);try{o(e,"",{encoding:"utf8",mode:384});console.log("✅ [SSH] file created.")}catch(r){console.error("⚠️ [SSH] writeFileSync error",e,r.message);process.abort()}}else{console.log(`[SSH] ${e} file exist`)}};e.exports={validateDir:validateDir,validateFile:validateFile}},229:e=>{const r=["REMOTE_HOST","REMOTE_USER","REMOTE_PORT","SSH_PRIVATE_KEY","DEPLOY_KEY_NAME","SOURCE","TARGET","ARGS","EXCLUDE"];const s={GITHUB_WORKSPACE:process.env.GITHUB_WORKSPACE};r.forEach((e=>{s[e]=process.env[e]||process.env[`INPUT_${e}`]}));e.exports=s},447:(e,r,s)=>{const{sync:t}=s(569);const{exec:n,execSync:o}=s(81);const validateRsync=(e=(()=>{}))=>{const r=t("rsync");if(r){console.log("⚠️ [CLI] Rsync exists",o("rsync --version"));return e()}console.log('⚠️ [CLI] Rsync doesn\'t exists. Start installation with "apt-get" \n');try{o("sudo apt-get update")}catch(e){console.log("⚠️ [CLI] Cant run . apt-get update. Skipping ...".e.message)}n("sudo apt-get --no-install-recommends install rsync",((r,s,t)=>{if(r){console.log("⚠️ [CLI] Rsync installation failed. Aborting ... ",r.message);process.abort()}else{console.log("✅ [CLI] Rsync installed. \n",s,t);e()}}))};const validateInputs=e=>{const r=Object.keys(e);const s=r.filter((r=>{const s=e[r];if(!s){console.error(`⚠️ [INPUTS] ${r} is mandatory`)}return s}));if(s.length!==r.length){console.error("⚠️ [INPUTS] Inputs not valid, aborting ...");process.abort()}};e.exports={validateRsync:validateRsync,validateInputs:validateInputs}},822:(e,r,s)=>{const{writeFileSync:t}=s(147);const{join:n}=s(17);const{validateDir:o,validateFile:c}=s(505);const{HOME:i}=process.env;const addSshKey=(e,r)=>{const s=n(i||__dirname,".ssh");const a=n(s,r);o(s);c(`${s}/known_hosts`);try{t(a,e,{encoding:"utf8",mode:384})}catch(e){console.error("⚠️ writeFileSync error",a,e.message);process.abort()}console.log("✅ Ssh key added to `.ssh` dir ",a);return a};e.exports={addSshKey:addSshKey}},81:e=>{"use strict";e.exports=require("child_process")},147:e=>{"use strict";e.exports=require("fs")},17:e=>{"use strict";e.exports=require("path")},837:e=>{"use strict";e.exports=require("util")}};var r={};function __nccwpck_require__(s){var t=r[s];if(t!==undefined){return t.exports}var n=r[s]={exports:{}};var o=true;try{e[s](n,n.exports,__nccwpck_require__);o=false}finally{if(o)delete r[s]}return n.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var s={};(()=>{const e=__nccwpck_require__(898);const{validateRsync:r,validateInputs:s}=__nccwpck_require__(447);const{addSshKey:t}=__nccwpck_require__(822);const{REMOTE_HOST:n,REMOTE_USER:o,REMOTE_PORT:c,SSH_PRIVATE_KEY:i,DEPLOY_KEY_NAME:a,SOURCE:u,TARGET:l,ARGS:d,EXCLUDE:f,GITHUB_WORKSPACE:p}=__nccwpck_require__(229);const y={ssh:true,sshCmdArgs:["-o StrictHostKeyChecking=no"],recursive:true};console.log("GITHUB_WORKSPACE: ",p);console.log("REMOTE_HOST: ",process.env.REMOTE_HOST);console.log("REMOTE_USER: ",process.env.REMOTE_USER);console.log("SSH_PRIVATE_KEY: ",process.env.SSH_PRIVATE_KEY);const _=(()=>{const rsync=({privateKey:r,port:s,src:t,dest:n,args:o,exclude:c})=>{console.log(`[Rsync] Starting Rsync Action: ${t} to ${n}`);if(c)console.log(`[Rsync] exluding folders ${c}`);try{e({src:t,dest:n,args:o,privateKey:r,port:s,excludeFirst:c,...y},((e,r,s,t)=>{if(e){console.error("⚠️ [Rsync] error: ",e.message);console.log("⚠️ [Rsync] stderr: ",s);console.log("⚠️ [Rsync] stdout: ",r);console.log("⚠️ [Rsync] cmd: ",t);process.abort()}else{console.log("✅ [Rsync] finished.",r)}}))}catch(e){console.error("⚠️ [Rsync] command error: ",e.message,e.stack);process.abort()}};const init=({src:e,dest:s,args:n,host:o="localhost",port:c,username:i,privateKeyContent:u,exclude:l=[]})=>{r((()=>{const r=t(u,a||"deploy_key");const d=`${i}@${o}:${s}`;rsync({privateKey:r,port:c,src:e,dest:d,args:n,exclude:l})}))};return{init:init}})();const run=()=>{s({SSH_PRIVATE_KEY:i,REMOTE_HOST:n,REMOTE_USER:o});_.init({src:`${p}/${u||""}`,dest:l||`/home/${o}/`,args:d?[d]:["-rltgoDzvO"],host:n,port:c||"22",username:o,privateKeyContent:i,exclude:(f||"").split(",").map((e=>e.trim()))})};run()})();module.exports=s})(); \ No newline at end of file +(()=>{var e={569:(e,r,s)=>{e.exports=s(325)},325:(e,r,s)=>{"use strict";var t=s(81).exec;var n=s(81).execSync;var o=s(147);var c=s(17);var i=o.access;var a=o.accessSync;var u=o.constants||o;var l=process.platform=="win32";var fileNotExists=function(e,r){i(e,u.F_OK,(function(e){r(!e)}))};var fileNotExistsSync=function(e){try{a(e,u.F_OK);return false}catch(e){return true}};var localExecutable=function(e,r){i(e,u.F_OK|u.X_OK,(function(e){r(null,!e)}))};var localExecutableSync=function(e){try{a(e,u.F_OK|u.X_OK);return true}catch(e){return false}};var commandExistsUnix=function(e,r,s){fileNotExists(e,(function(n){if(!n){var o=t("command -v "+r+" 2>/dev/null"+" && { echo >&1 "+r+"; exit 0; }",(function(e,r,t){s(null,!!r)}));return}localExecutable(e,s)}))};var commandExistsWindows=function(e,r,s){if(!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(e)){s(null,false);return}var n=t("where "+r,(function(e){if(e!==null){s(null,false)}else{s(null,true)}}))};var commandExistsUnixSync=function(e,r){if(fileNotExistsSync(e)){try{var s=n("command -v "+r+" 2>/dev/null"+" && { echo >&1 "+r+"; exit 0; }");return!!s}catch(e){return false}}return localExecutableSync(e)};var commandExistsWindowsSync=function(e,r,s){if(!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(e)){return false}try{var t=n("where "+r,{stdio:[]});return!!t}catch(e){return false}};var cleanInput=function(e){if(/[^A-Za-z0-9_\/:=-]/.test(e)){e="'"+e.replace(/'/g,"'\\''")+"'";e=e.replace(/^(?:'')+/g,"").replace(/\\'''/g,"\\'")}return e};if(l){cleanInput=function(e){var r=/[\\]/.test(e);if(r){var s='"'+c.dirname(e)+'"';var t='"'+c.basename(e)+'"';return s+":"+t}return'"'+e+'"'}}e.exports=function commandExists(e,r){var s=cleanInput(e);if(!r&&typeof Promise!=="undefined"){return new Promise((function(r,s){commandExists(e,(function(t,n){if(n){r(e)}else{s(t)}}))}))}if(l){commandExistsWindows(e,s,r)}else{commandExistsUnix(e,s,r)}};e.exports.sync=function(e){var r=cleanInput(e);if(l){return commandExistsWindowsSync(e,r)}else{return commandExistsUnixSync(e,r)}}},898:(e,r,s)=>{"use strict";var t=s(81).spawn;var n=s(837);var escapeSpaces=function(e){if(typeof e==="string"){return e.replace(/\b\s/g,"\\ ")}else{return e}};var escapeSpacesInOptions=function(e){["src","dest","include","exclude","excludeFirst"].forEach((function(r){var s=e[r];if(typeof s==="string"){e[r]=escapeSpaces(s)}else if(Array.isArray(s)===true){e[r]=s.map(escapeSpaces)}}));return e};e.exports=function(e,r){e=e||{};e=n._extend({},e);e=escapeSpacesInOptions(e);var s=e.platform||process.platform;var o=s==="win32";if(typeof e.src==="undefined"){throw new Error("'src' directory is missing from options")}if(typeof e.dest==="undefined"){throw new Error("'dest' directory is missing from options")}var c=e.dest;if(typeof e.host!=="undefined"){c=e.host+":"+e.dest}if(!Array.isArray(e.src)){e.src=[e.src]}var i=[].concat(e.src);i.push(c);var a=(e.args||[]).find((function(e){return e.match(/--chmod=/)}));if(o&&!a){i.push("--chmod=ugo=rwX")}if(typeof e.host!=="undefined"||e.ssh){i.push("--rsh");var u="ssh";if(typeof e.port!=="undefined"){u+=" -p "+e.port}if(typeof e.privateKey!=="undefined"){u+=" -i "+e.privateKey}if(typeof e.sshCmdArgs!=="undefined"){u+=" "+e.sshCmdArgs.join(" ")}i.push(u)}if(e.recursive===true){i.push("--recursive")}if(e.times===true){i.push("--times")}if(e.syncDest===true||e.deleteAll===true){i.push("--delete");i.push("--delete-excluded")}if(e.syncDestIgnoreExcl===true||e.delete===true){i.push("--delete")}if(e.dryRun===true){i.push("--dry-run");i.push("--verbose")}if(typeof e.excludeFirst!=="undefined"&&n.isArray(e.excludeFirst)){e.excludeFirst.forEach((function(e,r){i.push("--exclude="+e)}))}if(typeof e.include!=="undefined"&&n.isArray(e.include)){e.include.forEach((function(e,r){i.push("--include="+e)}))}if(typeof e.exclude!=="undefined"&&n.isArray(e.exclude)){e.exclude.forEach((function(e,r){i.push("--exclude="+e)}))}switch(e.compareMode){case"sizeOnly":i.push("--size-only");break;case"checksum":i.push("--checksum");break}if(typeof e.args!=="undefined"&&n.isArray(e.args)){i=[...new Set([...i,...e.args])]}i=[...new Set(i)];var noop=function(){};var l=e.onStdout||noop;var d=e.onStderr||noop;var f="rsync ";i.forEach((function(e){if(e.substr(0,4)==="ssh "){e='"'+e+'"'}f+=e+" "}));f=f.trim();if(e.noExec){r(null,null,null,f);return}try{var p="";var y="";var _;if(o){_=t("cmd.exe",["/s","/c",'"'+f+'"'],{windowsVerbatimArguments:true,stdio:[process.stdin,"pipe","pipe"]})}else{_=t("/bin/sh",["-c",f])}_.stdout.on("data",(function(e){l(e);p+=e}));_.stderr.on("data",(function(e){d(e);y+=e}));_.on("exit",(function(e){var s=null;if(e!==0){s=new Error("rsync exited with code "+e);s.code=e}r(s,p,y,f)}))}catch(e){r(e,null,null,f)}}},505:(e,r,s)=>{const{existsSync:t,mkdirSync:n,writeFileSync:o}=s(147);const{GITHUB_WORKSPACE:c}=process.env;const validateDir=e=>{if(!t(e)){console.log(`[SSH] Creating ${e} dir in `,c);n(e);console.log("✅ [SSH] dir created.")}else{console.log(`[SSH] ${e} dir exist`)}};const validateFile=e=>{if(!t(e)){console.log(`[SSH] Creating ${e} file in `,c);try{o(e,"",{encoding:"utf8",mode:384});console.log("✅ [SSH] file created.")}catch(r){console.error("⚠️ [SSH] writeFileSync error",e,r.message);process.abort()}}else{console.log(`[SSH] ${e} file exist`)}};e.exports={validateDir:validateDir,validateFile:validateFile}},229:e=>{const r=["REMOTE_HOST","REMOTE_USER","REMOTE_PORT","SSH_PRIVATE_KEY","DEPLOY_KEY_NAME","SOURCE","TARGET","ARGS","EXCLUDE"];const s={GITHUB_WORKSPACE:process.env.GITHUB_WORKSPACE};r.forEach((e=>{s[e]=process.env[e]||process.env[`INPUT_${e}`]}));e.exports=s},447:(e,r,s)=>{const{sync:t}=s(569);const{exec:n,execSync:o}=s(81);const validateRsync=(e=(()=>{}))=>{const r=t("rsync");if(r){const r=o("rsync --version",{stdio:"inherit"});console.log("⚠️ [CLI] Rsync exists",r);return e()}console.log('⚠️ [CLI] Rsync doesn\'t exists. Start installation with "apt-get" \n');try{o("sudo apt-get update",{stdio:"inherit"})}catch(e){console.log("⚠️ [CLI] Cant run . apt-get update. Skipping ...".e.message)}n("sudo apt-get --no-install-recommends install rsync",{stdio:"inherit"},((r,s,t)=>{if(r){console.log("⚠️ [CLI] Rsync installation failed. Aborting ... ",r.message);process.abort()}else{console.log("✅ [CLI] Rsync installed. \n",s,t);e()}}))};const validateInputs=e=>{const r=Object.keys(e);const s=r.filter((r=>{const s=e[r];if(!s){console.error(`⚠️ [INPUTS] ${r} is mandatory`)}return s}));if(s.length!==r.length){console.error("⚠️ [INPUTS] Inputs not valid, aborting ...");process.abort()}};e.exports={validateRsync:validateRsync,validateInputs:validateInputs}},822:(e,r,s)=>{const{writeFileSync:t}=s(147);const{join:n}=s(17);const{validateDir:o,validateFile:c}=s(505);const{HOME:i}=process.env;const addSshKey=(e,r)=>{const s=n(i||__dirname,".ssh");const a=n(s,r);o(s);c(`${s}/known_hosts`);try{t(a,e,{encoding:"utf8",mode:384})}catch(e){console.error("⚠️ writeFileSync error",a,e.message);process.abort()}console.log("✅ Ssh key added to `.ssh` dir ",a);return a};e.exports={addSshKey:addSshKey}},81:e=>{"use strict";e.exports=require("child_process")},147:e=>{"use strict";e.exports=require("fs")},17:e=>{"use strict";e.exports=require("path")},837:e=>{"use strict";e.exports=require("util")}};var r={};function __nccwpck_require__(s){var t=r[s];if(t!==undefined){return t.exports}var n=r[s]={exports:{}};var o=true;try{e[s](n,n.exports,__nccwpck_require__);o=false}finally{if(o)delete r[s]}return n.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var s={};(()=>{const e=__nccwpck_require__(898);const{validateRsync:r,validateInputs:s}=__nccwpck_require__(447);const{addSshKey:t}=__nccwpck_require__(822);const{REMOTE_HOST:n,REMOTE_USER:o,REMOTE_PORT:c,SSH_PRIVATE_KEY:i,DEPLOY_KEY_NAME:a,SOURCE:u,TARGET:l,ARGS:d,EXCLUDE:f,GITHUB_WORKSPACE:p}=__nccwpck_require__(229);const y={ssh:true,sshCmdArgs:["-o StrictHostKeyChecking=no"],recursive:true};console.log("GITHUB_WORKSPACE: ",p);console.log("REMOTE_HOST: ",process.env.REMOTE_HOST);console.log("REMOTE_USER: ",process.env.REMOTE_USER);console.log("SSH_PRIVATE_KEY: ",process.env.SSH_PRIVATE_KEY);const _=(()=>{const rsync=({privateKey:r,port:s,src:t,dest:n,args:o,exclude:c})=>{console.log(`[Rsync] Starting Rsync Action: ${t} to ${n}`);if(c)console.log(`[Rsync] exluding folders ${c}`);try{e({src:t,dest:n,args:o,privateKey:r,port:s,excludeFirst:c,...y},((e,r,s,t)=>{if(e){console.error("⚠️ [Rsync] error: ",e.message);console.log("⚠️ [Rsync] stderr: ",s);console.log("⚠️ [Rsync] stdout: ",r);console.log("⚠️ [Rsync] cmd: ",t);process.abort()}else{console.log("✅ [Rsync] finished.",r)}}))}catch(e){console.error("⚠️ [Rsync] command error: ",e.message,e.stack);process.abort()}};const init=({src:e,dest:s,args:n,host:o="localhost",port:c,username:i,privateKeyContent:u,exclude:l=[]})=>{r((()=>{const r=t(u,a||"deploy_key");const d=`${i}@${o}:${s}`;rsync({privateKey:r,port:c,src:e,dest:d,args:n,exclude:l})}))};return{init:init}})();const run=()=>{s({SSH_PRIVATE_KEY:i,REMOTE_HOST:n,REMOTE_USER:o});_.init({src:`${p}/${u||""}`,dest:l||`/home/${o}/`,args:d?[d]:["-rltgoDzvO"],host:n,port:c||"22",username:o,privateKeyContent:i,exclude:(f||"").split(",").map((e=>e.trim()))})};run()})();module.exports=s})(); \ No newline at end of file From b65c6688d14b049511d8cfd8bbd5ed0c1c2e0fe2 Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Sat, 31 Dec 2022 10:14:04 +0100 Subject: [PATCH 36/46] host rsync --- src/rsyncCli.js | 2 +- test/Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rsyncCli.js b/src/rsyncCli.js index ef7e8f7..91397e6 100644 --- a/src/rsyncCli.js +++ b/src/rsyncCli.js @@ -4,8 +4,8 @@ const { exec, execSync } = require("child_process"); const validateRsync = (callback = () => {}) => { const rsyncCli = commandExists("rsync"); if (rsyncCli) { + console.log('⚠️ [CLI] Rsync exists'); const rsyncVersion = execSync("rsync --version", { stdio: 'inherit' }); - console.log('⚠️ [CLI] Rsync exists', rsyncVersion); return callback(); } diff --git a/test/Dockerfile b/test/Dockerfile index e9a9df4..39344ee 100644 --- a/test/Dockerfile +++ b/test/Dockerfile @@ -4,7 +4,7 @@ ARG SSH_PUB_KEY RUN apt update -RUN apt install openssh-server sudo -y +RUN apt install openssh-server rsync sudo -y RUN useradd -rm -d /home/test -s /bin/bash -g root -G sudo -u 1000 test From 2121ba96bcbd17d96e2cb0c49904d2a9d337d37f Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Sat, 31 Dec 2022 10:15:28 +0100 Subject: [PATCH 37/46] update apt --- dist/index.js | 2 +- src/rsyncCli.js | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/dist/index.js b/dist/index.js index c0edd7f..0abeebe 100755 --- a/dist/index.js +++ b/dist/index.js @@ -1,2 +1,2 @@ #!/usr/bin/env node -(()=>{var e={569:(e,r,s)=>{e.exports=s(325)},325:(e,r,s)=>{"use strict";var t=s(81).exec;var n=s(81).execSync;var o=s(147);var c=s(17);var i=o.access;var a=o.accessSync;var u=o.constants||o;var l=process.platform=="win32";var fileNotExists=function(e,r){i(e,u.F_OK,(function(e){r(!e)}))};var fileNotExistsSync=function(e){try{a(e,u.F_OK);return false}catch(e){return true}};var localExecutable=function(e,r){i(e,u.F_OK|u.X_OK,(function(e){r(null,!e)}))};var localExecutableSync=function(e){try{a(e,u.F_OK|u.X_OK);return true}catch(e){return false}};var commandExistsUnix=function(e,r,s){fileNotExists(e,(function(n){if(!n){var o=t("command -v "+r+" 2>/dev/null"+" && { echo >&1 "+r+"; exit 0; }",(function(e,r,t){s(null,!!r)}));return}localExecutable(e,s)}))};var commandExistsWindows=function(e,r,s){if(!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(e)){s(null,false);return}var n=t("where "+r,(function(e){if(e!==null){s(null,false)}else{s(null,true)}}))};var commandExistsUnixSync=function(e,r){if(fileNotExistsSync(e)){try{var s=n("command -v "+r+" 2>/dev/null"+" && { echo >&1 "+r+"; exit 0; }");return!!s}catch(e){return false}}return localExecutableSync(e)};var commandExistsWindowsSync=function(e,r,s){if(!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(e)){return false}try{var t=n("where "+r,{stdio:[]});return!!t}catch(e){return false}};var cleanInput=function(e){if(/[^A-Za-z0-9_\/:=-]/.test(e)){e="'"+e.replace(/'/g,"'\\''")+"'";e=e.replace(/^(?:'')+/g,"").replace(/\\'''/g,"\\'")}return e};if(l){cleanInput=function(e){var r=/[\\]/.test(e);if(r){var s='"'+c.dirname(e)+'"';var t='"'+c.basename(e)+'"';return s+":"+t}return'"'+e+'"'}}e.exports=function commandExists(e,r){var s=cleanInput(e);if(!r&&typeof Promise!=="undefined"){return new Promise((function(r,s){commandExists(e,(function(t,n){if(n){r(e)}else{s(t)}}))}))}if(l){commandExistsWindows(e,s,r)}else{commandExistsUnix(e,s,r)}};e.exports.sync=function(e){var r=cleanInput(e);if(l){return commandExistsWindowsSync(e,r)}else{return commandExistsUnixSync(e,r)}}},898:(e,r,s)=>{"use strict";var t=s(81).spawn;var n=s(837);var escapeSpaces=function(e){if(typeof e==="string"){return e.replace(/\b\s/g,"\\ ")}else{return e}};var escapeSpacesInOptions=function(e){["src","dest","include","exclude","excludeFirst"].forEach((function(r){var s=e[r];if(typeof s==="string"){e[r]=escapeSpaces(s)}else if(Array.isArray(s)===true){e[r]=s.map(escapeSpaces)}}));return e};e.exports=function(e,r){e=e||{};e=n._extend({},e);e=escapeSpacesInOptions(e);var s=e.platform||process.platform;var o=s==="win32";if(typeof e.src==="undefined"){throw new Error("'src' directory is missing from options")}if(typeof e.dest==="undefined"){throw new Error("'dest' directory is missing from options")}var c=e.dest;if(typeof e.host!=="undefined"){c=e.host+":"+e.dest}if(!Array.isArray(e.src)){e.src=[e.src]}var i=[].concat(e.src);i.push(c);var a=(e.args||[]).find((function(e){return e.match(/--chmod=/)}));if(o&&!a){i.push("--chmod=ugo=rwX")}if(typeof e.host!=="undefined"||e.ssh){i.push("--rsh");var u="ssh";if(typeof e.port!=="undefined"){u+=" -p "+e.port}if(typeof e.privateKey!=="undefined"){u+=" -i "+e.privateKey}if(typeof e.sshCmdArgs!=="undefined"){u+=" "+e.sshCmdArgs.join(" ")}i.push(u)}if(e.recursive===true){i.push("--recursive")}if(e.times===true){i.push("--times")}if(e.syncDest===true||e.deleteAll===true){i.push("--delete");i.push("--delete-excluded")}if(e.syncDestIgnoreExcl===true||e.delete===true){i.push("--delete")}if(e.dryRun===true){i.push("--dry-run");i.push("--verbose")}if(typeof e.excludeFirst!=="undefined"&&n.isArray(e.excludeFirst)){e.excludeFirst.forEach((function(e,r){i.push("--exclude="+e)}))}if(typeof e.include!=="undefined"&&n.isArray(e.include)){e.include.forEach((function(e,r){i.push("--include="+e)}))}if(typeof e.exclude!=="undefined"&&n.isArray(e.exclude)){e.exclude.forEach((function(e,r){i.push("--exclude="+e)}))}switch(e.compareMode){case"sizeOnly":i.push("--size-only");break;case"checksum":i.push("--checksum");break}if(typeof e.args!=="undefined"&&n.isArray(e.args)){i=[...new Set([...i,...e.args])]}i=[...new Set(i)];var noop=function(){};var l=e.onStdout||noop;var d=e.onStderr||noop;var f="rsync ";i.forEach((function(e){if(e.substr(0,4)==="ssh "){e='"'+e+'"'}f+=e+" "}));f=f.trim();if(e.noExec){r(null,null,null,f);return}try{var p="";var y="";var _;if(o){_=t("cmd.exe",["/s","/c",'"'+f+'"'],{windowsVerbatimArguments:true,stdio:[process.stdin,"pipe","pipe"]})}else{_=t("/bin/sh",["-c",f])}_.stdout.on("data",(function(e){l(e);p+=e}));_.stderr.on("data",(function(e){d(e);y+=e}));_.on("exit",(function(e){var s=null;if(e!==0){s=new Error("rsync exited with code "+e);s.code=e}r(s,p,y,f)}))}catch(e){r(e,null,null,f)}}},505:(e,r,s)=>{const{existsSync:t,mkdirSync:n,writeFileSync:o}=s(147);const{GITHUB_WORKSPACE:c}=process.env;const validateDir=e=>{if(!t(e)){console.log(`[SSH] Creating ${e} dir in `,c);n(e);console.log("✅ [SSH] dir created.")}else{console.log(`[SSH] ${e} dir exist`)}};const validateFile=e=>{if(!t(e)){console.log(`[SSH] Creating ${e} file in `,c);try{o(e,"",{encoding:"utf8",mode:384});console.log("✅ [SSH] file created.")}catch(r){console.error("⚠️ [SSH] writeFileSync error",e,r.message);process.abort()}}else{console.log(`[SSH] ${e} file exist`)}};e.exports={validateDir:validateDir,validateFile:validateFile}},229:e=>{const r=["REMOTE_HOST","REMOTE_USER","REMOTE_PORT","SSH_PRIVATE_KEY","DEPLOY_KEY_NAME","SOURCE","TARGET","ARGS","EXCLUDE"];const s={GITHUB_WORKSPACE:process.env.GITHUB_WORKSPACE};r.forEach((e=>{s[e]=process.env[e]||process.env[`INPUT_${e}`]}));e.exports=s},447:(e,r,s)=>{const{sync:t}=s(569);const{exec:n,execSync:o}=s(81);const validateRsync=(e=(()=>{}))=>{const r=t("rsync");if(r){const r=o("rsync --version",{stdio:"inherit"});console.log("⚠️ [CLI] Rsync exists",r);return e()}console.log('⚠️ [CLI] Rsync doesn\'t exists. Start installation with "apt-get" \n');try{o("sudo apt-get update",{stdio:"inherit"})}catch(e){console.log("⚠️ [CLI] Cant run . apt-get update. Skipping ...".e.message)}n("sudo apt-get --no-install-recommends install rsync",{stdio:"inherit"},((r,s,t)=>{if(r){console.log("⚠️ [CLI] Rsync installation failed. Aborting ... ",r.message);process.abort()}else{console.log("✅ [CLI] Rsync installed. \n",s,t);e()}}))};const validateInputs=e=>{const r=Object.keys(e);const s=r.filter((r=>{const s=e[r];if(!s){console.error(`⚠️ [INPUTS] ${r} is mandatory`)}return s}));if(s.length!==r.length){console.error("⚠️ [INPUTS] Inputs not valid, aborting ...");process.abort()}};e.exports={validateRsync:validateRsync,validateInputs:validateInputs}},822:(e,r,s)=>{const{writeFileSync:t}=s(147);const{join:n}=s(17);const{validateDir:o,validateFile:c}=s(505);const{HOME:i}=process.env;const addSshKey=(e,r)=>{const s=n(i||__dirname,".ssh");const a=n(s,r);o(s);c(`${s}/known_hosts`);try{t(a,e,{encoding:"utf8",mode:384})}catch(e){console.error("⚠️ writeFileSync error",a,e.message);process.abort()}console.log("✅ Ssh key added to `.ssh` dir ",a);return a};e.exports={addSshKey:addSshKey}},81:e=>{"use strict";e.exports=require("child_process")},147:e=>{"use strict";e.exports=require("fs")},17:e=>{"use strict";e.exports=require("path")},837:e=>{"use strict";e.exports=require("util")}};var r={};function __nccwpck_require__(s){var t=r[s];if(t!==undefined){return t.exports}var n=r[s]={exports:{}};var o=true;try{e[s](n,n.exports,__nccwpck_require__);o=false}finally{if(o)delete r[s]}return n.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var s={};(()=>{const e=__nccwpck_require__(898);const{validateRsync:r,validateInputs:s}=__nccwpck_require__(447);const{addSshKey:t}=__nccwpck_require__(822);const{REMOTE_HOST:n,REMOTE_USER:o,REMOTE_PORT:c,SSH_PRIVATE_KEY:i,DEPLOY_KEY_NAME:a,SOURCE:u,TARGET:l,ARGS:d,EXCLUDE:f,GITHUB_WORKSPACE:p}=__nccwpck_require__(229);const y={ssh:true,sshCmdArgs:["-o StrictHostKeyChecking=no"],recursive:true};console.log("GITHUB_WORKSPACE: ",p);console.log("REMOTE_HOST: ",process.env.REMOTE_HOST);console.log("REMOTE_USER: ",process.env.REMOTE_USER);console.log("SSH_PRIVATE_KEY: ",process.env.SSH_PRIVATE_KEY);const _=(()=>{const rsync=({privateKey:r,port:s,src:t,dest:n,args:o,exclude:c})=>{console.log(`[Rsync] Starting Rsync Action: ${t} to ${n}`);if(c)console.log(`[Rsync] exluding folders ${c}`);try{e({src:t,dest:n,args:o,privateKey:r,port:s,excludeFirst:c,...y},((e,r,s,t)=>{if(e){console.error("⚠️ [Rsync] error: ",e.message);console.log("⚠️ [Rsync] stderr: ",s);console.log("⚠️ [Rsync] stdout: ",r);console.log("⚠️ [Rsync] cmd: ",t);process.abort()}else{console.log("✅ [Rsync] finished.",r)}}))}catch(e){console.error("⚠️ [Rsync] command error: ",e.message,e.stack);process.abort()}};const init=({src:e,dest:s,args:n,host:o="localhost",port:c,username:i,privateKeyContent:u,exclude:l=[]})=>{r((()=>{const r=t(u,a||"deploy_key");const d=`${i}@${o}:${s}`;rsync({privateKey:r,port:c,src:e,dest:d,args:n,exclude:l})}))};return{init:init}})();const run=()=>{s({SSH_PRIVATE_KEY:i,REMOTE_HOST:n,REMOTE_USER:o});_.init({src:`${p}/${u||""}`,dest:l||`/home/${o}/`,args:d?[d]:["-rltgoDzvO"],host:n,port:c||"22",username:o,privateKeyContent:i,exclude:(f||"").split(",").map((e=>e.trim()))})};run()})();module.exports=s})(); \ No newline at end of file +(()=>{var e={569:(e,r,s)=>{e.exports=s(325)},325:(e,r,s)=>{"use strict";var t=s(81).exec;var n=s(81).execSync;var o=s(147);var c=s(17);var i=o.access;var a=o.accessSync;var u=o.constants||o;var l=process.platform=="win32";var fileNotExists=function(e,r){i(e,u.F_OK,(function(e){r(!e)}))};var fileNotExistsSync=function(e){try{a(e,u.F_OK);return false}catch(e){return true}};var localExecutable=function(e,r){i(e,u.F_OK|u.X_OK,(function(e){r(null,!e)}))};var localExecutableSync=function(e){try{a(e,u.F_OK|u.X_OK);return true}catch(e){return false}};var commandExistsUnix=function(e,r,s){fileNotExists(e,(function(n){if(!n){var o=t("command -v "+r+" 2>/dev/null"+" && { echo >&1 "+r+"; exit 0; }",(function(e,r,t){s(null,!!r)}));return}localExecutable(e,s)}))};var commandExistsWindows=function(e,r,s){if(!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(e)){s(null,false);return}var n=t("where "+r,(function(e){if(e!==null){s(null,false)}else{s(null,true)}}))};var commandExistsUnixSync=function(e,r){if(fileNotExistsSync(e)){try{var s=n("command -v "+r+" 2>/dev/null"+" && { echo >&1 "+r+"; exit 0; }");return!!s}catch(e){return false}}return localExecutableSync(e)};var commandExistsWindowsSync=function(e,r,s){if(!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(e)){return false}try{var t=n("where "+r,{stdio:[]});return!!t}catch(e){return false}};var cleanInput=function(e){if(/[^A-Za-z0-9_\/:=-]/.test(e)){e="'"+e.replace(/'/g,"'\\''")+"'";e=e.replace(/^(?:'')+/g,"").replace(/\\'''/g,"\\'")}return e};if(l){cleanInput=function(e){var r=/[\\]/.test(e);if(r){var s='"'+c.dirname(e)+'"';var t='"'+c.basename(e)+'"';return s+":"+t}return'"'+e+'"'}}e.exports=function commandExists(e,r){var s=cleanInput(e);if(!r&&typeof Promise!=="undefined"){return new Promise((function(r,s){commandExists(e,(function(t,n){if(n){r(e)}else{s(t)}}))}))}if(l){commandExistsWindows(e,s,r)}else{commandExistsUnix(e,s,r)}};e.exports.sync=function(e){var r=cleanInput(e);if(l){return commandExistsWindowsSync(e,r)}else{return commandExistsUnixSync(e,r)}}},898:(e,r,s)=>{"use strict";var t=s(81).spawn;var n=s(837);var escapeSpaces=function(e){if(typeof e==="string"){return e.replace(/\b\s/g,"\\ ")}else{return e}};var escapeSpacesInOptions=function(e){["src","dest","include","exclude","excludeFirst"].forEach((function(r){var s=e[r];if(typeof s==="string"){e[r]=escapeSpaces(s)}else if(Array.isArray(s)===true){e[r]=s.map(escapeSpaces)}}));return e};e.exports=function(e,r){e=e||{};e=n._extend({},e);e=escapeSpacesInOptions(e);var s=e.platform||process.platform;var o=s==="win32";if(typeof e.src==="undefined"){throw new Error("'src' directory is missing from options")}if(typeof e.dest==="undefined"){throw new Error("'dest' directory is missing from options")}var c=e.dest;if(typeof e.host!=="undefined"){c=e.host+":"+e.dest}if(!Array.isArray(e.src)){e.src=[e.src]}var i=[].concat(e.src);i.push(c);var a=(e.args||[]).find((function(e){return e.match(/--chmod=/)}));if(o&&!a){i.push("--chmod=ugo=rwX")}if(typeof e.host!=="undefined"||e.ssh){i.push("--rsh");var u="ssh";if(typeof e.port!=="undefined"){u+=" -p "+e.port}if(typeof e.privateKey!=="undefined"){u+=" -i "+e.privateKey}if(typeof e.sshCmdArgs!=="undefined"){u+=" "+e.sshCmdArgs.join(" ")}i.push(u)}if(e.recursive===true){i.push("--recursive")}if(e.times===true){i.push("--times")}if(e.syncDest===true||e.deleteAll===true){i.push("--delete");i.push("--delete-excluded")}if(e.syncDestIgnoreExcl===true||e.delete===true){i.push("--delete")}if(e.dryRun===true){i.push("--dry-run");i.push("--verbose")}if(typeof e.excludeFirst!=="undefined"&&n.isArray(e.excludeFirst)){e.excludeFirst.forEach((function(e,r){i.push("--exclude="+e)}))}if(typeof e.include!=="undefined"&&n.isArray(e.include)){e.include.forEach((function(e,r){i.push("--include="+e)}))}if(typeof e.exclude!=="undefined"&&n.isArray(e.exclude)){e.exclude.forEach((function(e,r){i.push("--exclude="+e)}))}switch(e.compareMode){case"sizeOnly":i.push("--size-only");break;case"checksum":i.push("--checksum");break}if(typeof e.args!=="undefined"&&n.isArray(e.args)){i=[...new Set([...i,...e.args])]}i=[...new Set(i)];var noop=function(){};var l=e.onStdout||noop;var d=e.onStderr||noop;var f="rsync ";i.forEach((function(e){if(e.substr(0,4)==="ssh "){e='"'+e+'"'}f+=e+" "}));f=f.trim();if(e.noExec){r(null,null,null,f);return}try{var p="";var y="";var _;if(o){_=t("cmd.exe",["/s","/c",'"'+f+'"'],{windowsVerbatimArguments:true,stdio:[process.stdin,"pipe","pipe"]})}else{_=t("/bin/sh",["-c",f])}_.stdout.on("data",(function(e){l(e);p+=e}));_.stderr.on("data",(function(e){d(e);y+=e}));_.on("exit",(function(e){var s=null;if(e!==0){s=new Error("rsync exited with code "+e);s.code=e}r(s,p,y,f)}))}catch(e){r(e,null,null,f)}}},505:(e,r,s)=>{const{existsSync:t,mkdirSync:n,writeFileSync:o}=s(147);const{GITHUB_WORKSPACE:c}=process.env;const validateDir=e=>{if(!t(e)){console.log(`[SSH] Creating ${e} dir in `,c);n(e);console.log("✅ [SSH] dir created.")}else{console.log(`[SSH] ${e} dir exist`)}};const validateFile=e=>{if(!t(e)){console.log(`[SSH] Creating ${e} file in `,c);try{o(e,"",{encoding:"utf8",mode:384});console.log("✅ [SSH] file created.")}catch(r){console.error("⚠️ [SSH] writeFileSync error",e,r.message);process.abort()}}else{console.log(`[SSH] ${e} file exist`)}};e.exports={validateDir:validateDir,validateFile:validateFile}},229:e=>{const r=["REMOTE_HOST","REMOTE_USER","REMOTE_PORT","SSH_PRIVATE_KEY","DEPLOY_KEY_NAME","SOURCE","TARGET","ARGS","EXCLUDE"];const s={GITHUB_WORKSPACE:process.env.GITHUB_WORKSPACE};r.forEach((e=>{s[e]=process.env[e]||process.env[`INPUT_${e}`]}));e.exports=s},447:(e,r,s)=>{const{sync:t}=s(569);const{exec:n,execSync:o}=s(81);const validateRsync=(e=(()=>{}))=>{const r=t("rsync");if(r){console.log("⚠️ [CLI] Rsync exists");const r=o("rsync --version",{stdio:"inherit"});return e()}console.log('⚠️ [CLI] Rsync doesn\'t exists. Start installation with "apt-get" \n');try{o("sudo apt-get update",{stdio:"inherit"})}catch(e){console.log("⚠️ [CLI] Cant run . apt-get update. Skipping ...".e.message)}n("sudo apt-get --no-install-recommends install rsync",{stdio:"inherit"},((r,s,t)=>{if(r){console.log("⚠️ [CLI] Rsync installation failed. Aborting ... ",r.message);process.abort()}else{console.log("✅ [CLI] Rsync installed. \n",s,t);e()}}))};const validateInputs=e=>{const r=Object.keys(e);const s=r.filter((r=>{const s=e[r];if(!s){console.error(`⚠️ [INPUTS] ${r} is mandatory`)}return s}));if(s.length!==r.length){console.error("⚠️ [INPUTS] Inputs not valid, aborting ...");process.abort()}};e.exports={validateRsync:validateRsync,validateInputs:validateInputs}},822:(e,r,s)=>{const{writeFileSync:t}=s(147);const{join:n}=s(17);const{validateDir:o,validateFile:c}=s(505);const{HOME:i}=process.env;const addSshKey=(e,r)=>{const s=n(i||__dirname,".ssh");const a=n(s,r);o(s);c(`${s}/known_hosts`);try{t(a,e,{encoding:"utf8",mode:384})}catch(e){console.error("⚠️ writeFileSync error",a,e.message);process.abort()}console.log("✅ Ssh key added to `.ssh` dir ",a);return a};e.exports={addSshKey:addSshKey}},81:e=>{"use strict";e.exports=require("child_process")},147:e=>{"use strict";e.exports=require("fs")},17:e=>{"use strict";e.exports=require("path")},837:e=>{"use strict";e.exports=require("util")}};var r={};function __nccwpck_require__(s){var t=r[s];if(t!==undefined){return t.exports}var n=r[s]={exports:{}};var o=true;try{e[s](n,n.exports,__nccwpck_require__);o=false}finally{if(o)delete r[s]}return n.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var s={};(()=>{const e=__nccwpck_require__(898);const{validateRsync:r,validateInputs:s}=__nccwpck_require__(447);const{addSshKey:t}=__nccwpck_require__(822);const{REMOTE_HOST:n,REMOTE_USER:o,REMOTE_PORT:c,SSH_PRIVATE_KEY:i,DEPLOY_KEY_NAME:a,SOURCE:u,TARGET:l,ARGS:d,EXCLUDE:f,GITHUB_WORKSPACE:p}=__nccwpck_require__(229);const y={ssh:true,sshCmdArgs:["-o StrictHostKeyChecking=no"],recursive:true};console.log("GITHUB_WORKSPACE: ",p);console.log("REMOTE_HOST: ",process.env.REMOTE_HOST);console.log("REMOTE_USER: ",process.env.REMOTE_USER);console.log("SSH_PRIVATE_KEY: ",process.env.SSH_PRIVATE_KEY);const _=(()=>{const rsync=({privateKey:r,port:s,src:t,dest:n,args:o,exclude:c})=>{console.log(`[Rsync] Starting Rsync Action: ${t} to ${n}`);if(c)console.log(`[Rsync] exluding folders ${c}`);try{e({src:t,dest:n,args:o,privateKey:r,port:s,excludeFirst:c,...y},((e,r,s,t)=>{if(e){console.error("⚠️ [Rsync] error: ",e.message);console.log("⚠️ [Rsync] stderr: ",s);console.log("⚠️ [Rsync] stdout: ",r);console.log("⚠️ [Rsync] cmd: ",t);process.abort()}else{console.log("✅ [Rsync] finished.",r)}}))}catch(e){console.error("⚠️ [Rsync] command error: ",e.message,e.stack);process.abort()}};const init=({src:e,dest:s,args:n,host:o="localhost",port:c,username:i,privateKeyContent:u,exclude:l=[]})=>{r((()=>{const r=t(u,a||"deploy_key");const d=`${i}@${o}:${s}`;rsync({privateKey:r,port:c,src:e,dest:d,args:n,exclude:l})}))};return{init:init}})();const run=()=>{s({SSH_PRIVATE_KEY:i,REMOTE_HOST:n,REMOTE_USER:o});_.init({src:`${p}/${u||""}`,dest:l||`/home/${o}/`,args:d?[d]:["-rltgoDzvO"],host:n,port:c||"22",username:o,privateKeyContent:i,exclude:(f||"").split(",").map((e=>e.trim()))})};run()})();module.exports=s})(); \ No newline at end of file diff --git a/src/rsyncCli.js b/src/rsyncCli.js index 91397e6..aa8190b 100644 --- a/src/rsyncCli.js +++ b/src/rsyncCli.js @@ -10,13 +10,8 @@ const validateRsync = (callback = () => {}) => { } console.log('⚠️ [CLI] Rsync doesn\'t exists. Start installation with "apt-get" \n'); - try { - execSync("sudo apt-get update", { stdio: 'inherit' }); - } catch (e) { - console.log( "⚠️ [CLI] Cant run . apt-get update. Skipping ...". e.message); - } - exec("sudo apt-get --no-install-recommends install rsync", { stdio: 'inherit' }, (err, data, stderr) => { + exec("sudo apt-get update && sudo apt-get --no-install-recommends install rsync", (err, data, stderr) => { if (err) { console.log("⚠️ [CLI] Rsync installation failed. Aborting ... ", err.message); process.abort(); From caa0281bf43e5b8771b46d941d8dccfacc2d3998 Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Sat, 31 Dec 2022 10:15:39 +0100 Subject: [PATCH 38/46] build it again --- dist/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/index.js b/dist/index.js index 0abeebe..5952a78 100755 --- a/dist/index.js +++ b/dist/index.js @@ -1,2 +1,2 @@ #!/usr/bin/env node -(()=>{var e={569:(e,r,s)=>{e.exports=s(325)},325:(e,r,s)=>{"use strict";var t=s(81).exec;var n=s(81).execSync;var o=s(147);var c=s(17);var i=o.access;var a=o.accessSync;var u=o.constants||o;var l=process.platform=="win32";var fileNotExists=function(e,r){i(e,u.F_OK,(function(e){r(!e)}))};var fileNotExistsSync=function(e){try{a(e,u.F_OK);return false}catch(e){return true}};var localExecutable=function(e,r){i(e,u.F_OK|u.X_OK,(function(e){r(null,!e)}))};var localExecutableSync=function(e){try{a(e,u.F_OK|u.X_OK);return true}catch(e){return false}};var commandExistsUnix=function(e,r,s){fileNotExists(e,(function(n){if(!n){var o=t("command -v "+r+" 2>/dev/null"+" && { echo >&1 "+r+"; exit 0; }",(function(e,r,t){s(null,!!r)}));return}localExecutable(e,s)}))};var commandExistsWindows=function(e,r,s){if(!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(e)){s(null,false);return}var n=t("where "+r,(function(e){if(e!==null){s(null,false)}else{s(null,true)}}))};var commandExistsUnixSync=function(e,r){if(fileNotExistsSync(e)){try{var s=n("command -v "+r+" 2>/dev/null"+" && { echo >&1 "+r+"; exit 0; }");return!!s}catch(e){return false}}return localExecutableSync(e)};var commandExistsWindowsSync=function(e,r,s){if(!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(e)){return false}try{var t=n("where "+r,{stdio:[]});return!!t}catch(e){return false}};var cleanInput=function(e){if(/[^A-Za-z0-9_\/:=-]/.test(e)){e="'"+e.replace(/'/g,"'\\''")+"'";e=e.replace(/^(?:'')+/g,"").replace(/\\'''/g,"\\'")}return e};if(l){cleanInput=function(e){var r=/[\\]/.test(e);if(r){var s='"'+c.dirname(e)+'"';var t='"'+c.basename(e)+'"';return s+":"+t}return'"'+e+'"'}}e.exports=function commandExists(e,r){var s=cleanInput(e);if(!r&&typeof Promise!=="undefined"){return new Promise((function(r,s){commandExists(e,(function(t,n){if(n){r(e)}else{s(t)}}))}))}if(l){commandExistsWindows(e,s,r)}else{commandExistsUnix(e,s,r)}};e.exports.sync=function(e){var r=cleanInput(e);if(l){return commandExistsWindowsSync(e,r)}else{return commandExistsUnixSync(e,r)}}},898:(e,r,s)=>{"use strict";var t=s(81).spawn;var n=s(837);var escapeSpaces=function(e){if(typeof e==="string"){return e.replace(/\b\s/g,"\\ ")}else{return e}};var escapeSpacesInOptions=function(e){["src","dest","include","exclude","excludeFirst"].forEach((function(r){var s=e[r];if(typeof s==="string"){e[r]=escapeSpaces(s)}else if(Array.isArray(s)===true){e[r]=s.map(escapeSpaces)}}));return e};e.exports=function(e,r){e=e||{};e=n._extend({},e);e=escapeSpacesInOptions(e);var s=e.platform||process.platform;var o=s==="win32";if(typeof e.src==="undefined"){throw new Error("'src' directory is missing from options")}if(typeof e.dest==="undefined"){throw new Error("'dest' directory is missing from options")}var c=e.dest;if(typeof e.host!=="undefined"){c=e.host+":"+e.dest}if(!Array.isArray(e.src)){e.src=[e.src]}var i=[].concat(e.src);i.push(c);var a=(e.args||[]).find((function(e){return e.match(/--chmod=/)}));if(o&&!a){i.push("--chmod=ugo=rwX")}if(typeof e.host!=="undefined"||e.ssh){i.push("--rsh");var u="ssh";if(typeof e.port!=="undefined"){u+=" -p "+e.port}if(typeof e.privateKey!=="undefined"){u+=" -i "+e.privateKey}if(typeof e.sshCmdArgs!=="undefined"){u+=" "+e.sshCmdArgs.join(" ")}i.push(u)}if(e.recursive===true){i.push("--recursive")}if(e.times===true){i.push("--times")}if(e.syncDest===true||e.deleteAll===true){i.push("--delete");i.push("--delete-excluded")}if(e.syncDestIgnoreExcl===true||e.delete===true){i.push("--delete")}if(e.dryRun===true){i.push("--dry-run");i.push("--verbose")}if(typeof e.excludeFirst!=="undefined"&&n.isArray(e.excludeFirst)){e.excludeFirst.forEach((function(e,r){i.push("--exclude="+e)}))}if(typeof e.include!=="undefined"&&n.isArray(e.include)){e.include.forEach((function(e,r){i.push("--include="+e)}))}if(typeof e.exclude!=="undefined"&&n.isArray(e.exclude)){e.exclude.forEach((function(e,r){i.push("--exclude="+e)}))}switch(e.compareMode){case"sizeOnly":i.push("--size-only");break;case"checksum":i.push("--checksum");break}if(typeof e.args!=="undefined"&&n.isArray(e.args)){i=[...new Set([...i,...e.args])]}i=[...new Set(i)];var noop=function(){};var l=e.onStdout||noop;var d=e.onStderr||noop;var f="rsync ";i.forEach((function(e){if(e.substr(0,4)==="ssh "){e='"'+e+'"'}f+=e+" "}));f=f.trim();if(e.noExec){r(null,null,null,f);return}try{var p="";var y="";var _;if(o){_=t("cmd.exe",["/s","/c",'"'+f+'"'],{windowsVerbatimArguments:true,stdio:[process.stdin,"pipe","pipe"]})}else{_=t("/bin/sh",["-c",f])}_.stdout.on("data",(function(e){l(e);p+=e}));_.stderr.on("data",(function(e){d(e);y+=e}));_.on("exit",(function(e){var s=null;if(e!==0){s=new Error("rsync exited with code "+e);s.code=e}r(s,p,y,f)}))}catch(e){r(e,null,null,f)}}},505:(e,r,s)=>{const{existsSync:t,mkdirSync:n,writeFileSync:o}=s(147);const{GITHUB_WORKSPACE:c}=process.env;const validateDir=e=>{if(!t(e)){console.log(`[SSH] Creating ${e} dir in `,c);n(e);console.log("✅ [SSH] dir created.")}else{console.log(`[SSH] ${e} dir exist`)}};const validateFile=e=>{if(!t(e)){console.log(`[SSH] Creating ${e} file in `,c);try{o(e,"",{encoding:"utf8",mode:384});console.log("✅ [SSH] file created.")}catch(r){console.error("⚠️ [SSH] writeFileSync error",e,r.message);process.abort()}}else{console.log(`[SSH] ${e} file exist`)}};e.exports={validateDir:validateDir,validateFile:validateFile}},229:e=>{const r=["REMOTE_HOST","REMOTE_USER","REMOTE_PORT","SSH_PRIVATE_KEY","DEPLOY_KEY_NAME","SOURCE","TARGET","ARGS","EXCLUDE"];const s={GITHUB_WORKSPACE:process.env.GITHUB_WORKSPACE};r.forEach((e=>{s[e]=process.env[e]||process.env[`INPUT_${e}`]}));e.exports=s},447:(e,r,s)=>{const{sync:t}=s(569);const{exec:n,execSync:o}=s(81);const validateRsync=(e=(()=>{}))=>{const r=t("rsync");if(r){console.log("⚠️ [CLI] Rsync exists");const r=o("rsync --version",{stdio:"inherit"});return e()}console.log('⚠️ [CLI] Rsync doesn\'t exists. Start installation with "apt-get" \n');try{o("sudo apt-get update",{stdio:"inherit"})}catch(e){console.log("⚠️ [CLI] Cant run . apt-get update. Skipping ...".e.message)}n("sudo apt-get --no-install-recommends install rsync",{stdio:"inherit"},((r,s,t)=>{if(r){console.log("⚠️ [CLI] Rsync installation failed. Aborting ... ",r.message);process.abort()}else{console.log("✅ [CLI] Rsync installed. \n",s,t);e()}}))};const validateInputs=e=>{const r=Object.keys(e);const s=r.filter((r=>{const s=e[r];if(!s){console.error(`⚠️ [INPUTS] ${r} is mandatory`)}return s}));if(s.length!==r.length){console.error("⚠️ [INPUTS] Inputs not valid, aborting ...");process.abort()}};e.exports={validateRsync:validateRsync,validateInputs:validateInputs}},822:(e,r,s)=>{const{writeFileSync:t}=s(147);const{join:n}=s(17);const{validateDir:o,validateFile:c}=s(505);const{HOME:i}=process.env;const addSshKey=(e,r)=>{const s=n(i||__dirname,".ssh");const a=n(s,r);o(s);c(`${s}/known_hosts`);try{t(a,e,{encoding:"utf8",mode:384})}catch(e){console.error("⚠️ writeFileSync error",a,e.message);process.abort()}console.log("✅ Ssh key added to `.ssh` dir ",a);return a};e.exports={addSshKey:addSshKey}},81:e=>{"use strict";e.exports=require("child_process")},147:e=>{"use strict";e.exports=require("fs")},17:e=>{"use strict";e.exports=require("path")},837:e=>{"use strict";e.exports=require("util")}};var r={};function __nccwpck_require__(s){var t=r[s];if(t!==undefined){return t.exports}var n=r[s]={exports:{}};var o=true;try{e[s](n,n.exports,__nccwpck_require__);o=false}finally{if(o)delete r[s]}return n.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var s={};(()=>{const e=__nccwpck_require__(898);const{validateRsync:r,validateInputs:s}=__nccwpck_require__(447);const{addSshKey:t}=__nccwpck_require__(822);const{REMOTE_HOST:n,REMOTE_USER:o,REMOTE_PORT:c,SSH_PRIVATE_KEY:i,DEPLOY_KEY_NAME:a,SOURCE:u,TARGET:l,ARGS:d,EXCLUDE:f,GITHUB_WORKSPACE:p}=__nccwpck_require__(229);const y={ssh:true,sshCmdArgs:["-o StrictHostKeyChecking=no"],recursive:true};console.log("GITHUB_WORKSPACE: ",p);console.log("REMOTE_HOST: ",process.env.REMOTE_HOST);console.log("REMOTE_USER: ",process.env.REMOTE_USER);console.log("SSH_PRIVATE_KEY: ",process.env.SSH_PRIVATE_KEY);const _=(()=>{const rsync=({privateKey:r,port:s,src:t,dest:n,args:o,exclude:c})=>{console.log(`[Rsync] Starting Rsync Action: ${t} to ${n}`);if(c)console.log(`[Rsync] exluding folders ${c}`);try{e({src:t,dest:n,args:o,privateKey:r,port:s,excludeFirst:c,...y},((e,r,s,t)=>{if(e){console.error("⚠️ [Rsync] error: ",e.message);console.log("⚠️ [Rsync] stderr: ",s);console.log("⚠️ [Rsync] stdout: ",r);console.log("⚠️ [Rsync] cmd: ",t);process.abort()}else{console.log("✅ [Rsync] finished.",r)}}))}catch(e){console.error("⚠️ [Rsync] command error: ",e.message,e.stack);process.abort()}};const init=({src:e,dest:s,args:n,host:o="localhost",port:c,username:i,privateKeyContent:u,exclude:l=[]})=>{r((()=>{const r=t(u,a||"deploy_key");const d=`${i}@${o}:${s}`;rsync({privateKey:r,port:c,src:e,dest:d,args:n,exclude:l})}))};return{init:init}})();const run=()=>{s({SSH_PRIVATE_KEY:i,REMOTE_HOST:n,REMOTE_USER:o});_.init({src:`${p}/${u||""}`,dest:l||`/home/${o}/`,args:d?[d]:["-rltgoDzvO"],host:n,port:c||"22",username:o,privateKeyContent:i,exclude:(f||"").split(",").map((e=>e.trim()))})};run()})();module.exports=s})(); \ No newline at end of file +(()=>{var e={569:(e,r,s)=>{e.exports=s(325)},325:(e,r,s)=>{"use strict";var t=s(81).exec;var n=s(81).execSync;var o=s(147);var c=s(17);var i=o.access;var a=o.accessSync;var u=o.constants||o;var l=process.platform=="win32";var fileNotExists=function(e,r){i(e,u.F_OK,(function(e){r(!e)}))};var fileNotExistsSync=function(e){try{a(e,u.F_OK);return false}catch(e){return true}};var localExecutable=function(e,r){i(e,u.F_OK|u.X_OK,(function(e){r(null,!e)}))};var localExecutableSync=function(e){try{a(e,u.F_OK|u.X_OK);return true}catch(e){return false}};var commandExistsUnix=function(e,r,s){fileNotExists(e,(function(n){if(!n){var o=t("command -v "+r+" 2>/dev/null"+" && { echo >&1 "+r+"; exit 0; }",(function(e,r,t){s(null,!!r)}));return}localExecutable(e,s)}))};var commandExistsWindows=function(e,r,s){if(!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(e)){s(null,false);return}var n=t("where "+r,(function(e){if(e!==null){s(null,false)}else{s(null,true)}}))};var commandExistsUnixSync=function(e,r){if(fileNotExistsSync(e)){try{var s=n("command -v "+r+" 2>/dev/null"+" && { echo >&1 "+r+"; exit 0; }");return!!s}catch(e){return false}}return localExecutableSync(e)};var commandExistsWindowsSync=function(e,r,s){if(!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(e)){return false}try{var t=n("where "+r,{stdio:[]});return!!t}catch(e){return false}};var cleanInput=function(e){if(/[^A-Za-z0-9_\/:=-]/.test(e)){e="'"+e.replace(/'/g,"'\\''")+"'";e=e.replace(/^(?:'')+/g,"").replace(/\\'''/g,"\\'")}return e};if(l){cleanInput=function(e){var r=/[\\]/.test(e);if(r){var s='"'+c.dirname(e)+'"';var t='"'+c.basename(e)+'"';return s+":"+t}return'"'+e+'"'}}e.exports=function commandExists(e,r){var s=cleanInput(e);if(!r&&typeof Promise!=="undefined"){return new Promise((function(r,s){commandExists(e,(function(t,n){if(n){r(e)}else{s(t)}}))}))}if(l){commandExistsWindows(e,s,r)}else{commandExistsUnix(e,s,r)}};e.exports.sync=function(e){var r=cleanInput(e);if(l){return commandExistsWindowsSync(e,r)}else{return commandExistsUnixSync(e,r)}}},898:(e,r,s)=>{"use strict";var t=s(81).spawn;var n=s(837);var escapeSpaces=function(e){if(typeof e==="string"){return e.replace(/\b\s/g,"\\ ")}else{return e}};var escapeSpacesInOptions=function(e){["src","dest","include","exclude","excludeFirst"].forEach((function(r){var s=e[r];if(typeof s==="string"){e[r]=escapeSpaces(s)}else if(Array.isArray(s)===true){e[r]=s.map(escapeSpaces)}}));return e};e.exports=function(e,r){e=e||{};e=n._extend({},e);e=escapeSpacesInOptions(e);var s=e.platform||process.platform;var o=s==="win32";if(typeof e.src==="undefined"){throw new Error("'src' directory is missing from options")}if(typeof e.dest==="undefined"){throw new Error("'dest' directory is missing from options")}var c=e.dest;if(typeof e.host!=="undefined"){c=e.host+":"+e.dest}if(!Array.isArray(e.src)){e.src=[e.src]}var i=[].concat(e.src);i.push(c);var a=(e.args||[]).find((function(e){return e.match(/--chmod=/)}));if(o&&!a){i.push("--chmod=ugo=rwX")}if(typeof e.host!=="undefined"||e.ssh){i.push("--rsh");var u="ssh";if(typeof e.port!=="undefined"){u+=" -p "+e.port}if(typeof e.privateKey!=="undefined"){u+=" -i "+e.privateKey}if(typeof e.sshCmdArgs!=="undefined"){u+=" "+e.sshCmdArgs.join(" ")}i.push(u)}if(e.recursive===true){i.push("--recursive")}if(e.times===true){i.push("--times")}if(e.syncDest===true||e.deleteAll===true){i.push("--delete");i.push("--delete-excluded")}if(e.syncDestIgnoreExcl===true||e.delete===true){i.push("--delete")}if(e.dryRun===true){i.push("--dry-run");i.push("--verbose")}if(typeof e.excludeFirst!=="undefined"&&n.isArray(e.excludeFirst)){e.excludeFirst.forEach((function(e,r){i.push("--exclude="+e)}))}if(typeof e.include!=="undefined"&&n.isArray(e.include)){e.include.forEach((function(e,r){i.push("--include="+e)}))}if(typeof e.exclude!=="undefined"&&n.isArray(e.exclude)){e.exclude.forEach((function(e,r){i.push("--exclude="+e)}))}switch(e.compareMode){case"sizeOnly":i.push("--size-only");break;case"checksum":i.push("--checksum");break}if(typeof e.args!=="undefined"&&n.isArray(e.args)){i=[...new Set([...i,...e.args])]}i=[...new Set(i)];var noop=function(){};var l=e.onStdout||noop;var d=e.onStderr||noop;var f="rsync ";i.forEach((function(e){if(e.substr(0,4)==="ssh "){e='"'+e+'"'}f+=e+" "}));f=f.trim();if(e.noExec){r(null,null,null,f);return}try{var p="";var y="";var _;if(o){_=t("cmd.exe",["/s","/c",'"'+f+'"'],{windowsVerbatimArguments:true,stdio:[process.stdin,"pipe","pipe"]})}else{_=t("/bin/sh",["-c",f])}_.stdout.on("data",(function(e){l(e);p+=e}));_.stderr.on("data",(function(e){d(e);y+=e}));_.on("exit",(function(e){var s=null;if(e!==0){s=new Error("rsync exited with code "+e);s.code=e}r(s,p,y,f)}))}catch(e){r(e,null,null,f)}}},505:(e,r,s)=>{const{existsSync:t,mkdirSync:n,writeFileSync:o}=s(147);const{GITHUB_WORKSPACE:c}=process.env;const validateDir=e=>{if(!t(e)){console.log(`[SSH] Creating ${e} dir in `,c);n(e);console.log("✅ [SSH] dir created.")}else{console.log(`[SSH] ${e} dir exist`)}};const validateFile=e=>{if(!t(e)){console.log(`[SSH] Creating ${e} file in `,c);try{o(e,"",{encoding:"utf8",mode:384});console.log("✅ [SSH] file created.")}catch(r){console.error("⚠️ [SSH] writeFileSync error",e,r.message);process.abort()}}else{console.log(`[SSH] ${e} file exist`)}};e.exports={validateDir:validateDir,validateFile:validateFile}},229:e=>{const r=["REMOTE_HOST","REMOTE_USER","REMOTE_PORT","SSH_PRIVATE_KEY","DEPLOY_KEY_NAME","SOURCE","TARGET","ARGS","EXCLUDE"];const s={GITHUB_WORKSPACE:process.env.GITHUB_WORKSPACE};r.forEach((e=>{s[e]=process.env[e]||process.env[`INPUT_${e}`]}));e.exports=s},447:(e,r,s)=>{const{sync:t}=s(569);const{exec:n,execSync:o}=s(81);const validateRsync=(e=(()=>{}))=>{const r=t("rsync");if(r){console.log("⚠️ [CLI] Rsync exists");const r=o("rsync --version",{stdio:"inherit"});return e()}console.log('⚠️ [CLI] Rsync doesn\'t exists. Start installation with "apt-get" \n');n("sudo apt-get update && sudo apt-get --no-install-recommends install rsync",((r,s,t)=>{if(r){console.log("⚠️ [CLI] Rsync installation failed. Aborting ... ",r.message);process.abort()}else{console.log("✅ [CLI] Rsync installed. \n",s,t);e()}}))};const validateInputs=e=>{const r=Object.keys(e);const s=r.filter((r=>{const s=e[r];if(!s){console.error(`⚠️ [INPUTS] ${r} is mandatory`)}return s}));if(s.length!==r.length){console.error("⚠️ [INPUTS] Inputs not valid, aborting ...");process.abort()}};e.exports={validateRsync:validateRsync,validateInputs:validateInputs}},822:(e,r,s)=>{const{writeFileSync:t}=s(147);const{join:n}=s(17);const{validateDir:o,validateFile:c}=s(505);const{HOME:i}=process.env;const addSshKey=(e,r)=>{const s=n(i||__dirname,".ssh");const a=n(s,r);o(s);c(`${s}/known_hosts`);try{t(a,e,{encoding:"utf8",mode:384})}catch(e){console.error("⚠️ writeFileSync error",a,e.message);process.abort()}console.log("✅ Ssh key added to `.ssh` dir ",a);return a};e.exports={addSshKey:addSshKey}},81:e=>{"use strict";e.exports=require("child_process")},147:e=>{"use strict";e.exports=require("fs")},17:e=>{"use strict";e.exports=require("path")},837:e=>{"use strict";e.exports=require("util")}};var r={};function __nccwpck_require__(s){var t=r[s];if(t!==undefined){return t.exports}var n=r[s]={exports:{}};var o=true;try{e[s](n,n.exports,__nccwpck_require__);o=false}finally{if(o)delete r[s]}return n.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var s={};(()=>{const e=__nccwpck_require__(898);const{validateRsync:r,validateInputs:s}=__nccwpck_require__(447);const{addSshKey:t}=__nccwpck_require__(822);const{REMOTE_HOST:n,REMOTE_USER:o,REMOTE_PORT:c,SSH_PRIVATE_KEY:i,DEPLOY_KEY_NAME:a,SOURCE:u,TARGET:l,ARGS:d,EXCLUDE:f,GITHUB_WORKSPACE:p}=__nccwpck_require__(229);const y={ssh:true,sshCmdArgs:["-o StrictHostKeyChecking=no"],recursive:true};console.log("GITHUB_WORKSPACE: ",p);console.log("REMOTE_HOST: ",process.env.REMOTE_HOST);console.log("REMOTE_USER: ",process.env.REMOTE_USER);console.log("SSH_PRIVATE_KEY: ",process.env.SSH_PRIVATE_KEY);const _=(()=>{const rsync=({privateKey:r,port:s,src:t,dest:n,args:o,exclude:c})=>{console.log(`[Rsync] Starting Rsync Action: ${t} to ${n}`);if(c)console.log(`[Rsync] exluding folders ${c}`);try{e({src:t,dest:n,args:o,privateKey:r,port:s,excludeFirst:c,...y},((e,r,s,t)=>{if(e){console.error("⚠️ [Rsync] error: ",e.message);console.log("⚠️ [Rsync] stderr: ",s);console.log("⚠️ [Rsync] stdout: ",r);console.log("⚠️ [Rsync] cmd: ",t);process.abort()}else{console.log("✅ [Rsync] finished.",r)}}))}catch(e){console.error("⚠️ [Rsync] command error: ",e.message,e.stack);process.abort()}};const init=({src:e,dest:s,args:n,host:o="localhost",port:c,username:i,privateKeyContent:u,exclude:l=[]})=>{r((()=>{const r=t(u,a||"deploy_key");const d=`${i}@${o}:${s}`;rsync({privateKey:r,port:c,src:e,dest:d,args:n,exclude:l})}))};return{init:init}})();const run=()=>{s({SSH_PRIVATE_KEY:i,REMOTE_HOST:n,REMOTE_USER:o});_.init({src:`${p}/${u||""}`,dest:l||`/home/${o}/`,args:d?[d]:["-rltgoDzvO"],host:n,port:c||"22",username:o,privateKeyContent:i,exclude:(f||"").split(",").map((e=>e.trim()))})};run()})();module.exports=s})(); \ No newline at end of file From 4eea1db3aa250d1b03b75e13e99f020b3936fd39 Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Sat, 31 Dec 2022 10:17:50 +0100 Subject: [PATCH 39/46] mkdir remote --- test/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/test/Dockerfile b/test/Dockerfile index 39344ee..3f2e792 100644 --- a/test/Dockerfile +++ b/test/Dockerfile @@ -13,6 +13,7 @@ RUN usermod -aG sudo test RUN echo "PubkeyAuthentication yes" >> /etc/ssh/sshd_config.d/pub.conf RUN echo "AuthorizedKeysFile .ssh/authorized_keys" >> /etc/ssh/sshd_config.d/pub.conf +RUN mkdir -p /var/www/html RUN mkdir -p /home/test/.ssh RUN echo "$SSH_PUB_KEY" > /home/test/.ssh/authorized_keys RUN chmod 700 /home/test/.ssh From c685549dfc398f471ee363ace00b652194369626 Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Sat, 31 Dec 2022 10:19:52 +0100 Subject: [PATCH 40/46] persmissions fix --- test/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/test/Dockerfile b/test/Dockerfile index 3f2e792..26d1dab 100644 --- a/test/Dockerfile +++ b/test/Dockerfile @@ -14,6 +14,7 @@ RUN echo "PubkeyAuthentication yes" >> /etc/ssh/sshd_config.d/pub.conf RUN echo "AuthorizedKeysFile .ssh/authorized_keys" >> /etc/ssh/sshd_config.d/pub.conf RUN mkdir -p /var/www/html +RUN chown -R /var/www/html RUN mkdir -p /home/test/.ssh RUN echo "$SSH_PUB_KEY" > /home/test/.ssh/authorized_keys RUN chmod 700 /home/test/.ssh From 148d625f1d5219d4b4e8bba1fbf2fdd51aa05109 Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Sat, 31 Dec 2022 10:20:28 +0100 Subject: [PATCH 41/46] permissions fix --- test/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Dockerfile b/test/Dockerfile index 26d1dab..a79ba12 100644 --- a/test/Dockerfile +++ b/test/Dockerfile @@ -14,7 +14,7 @@ RUN echo "PubkeyAuthentication yes" >> /etc/ssh/sshd_config.d/pub.conf RUN echo "AuthorizedKeysFile .ssh/authorized_keys" >> /etc/ssh/sshd_config.d/pub.conf RUN mkdir -p /var/www/html -RUN chown -R /var/www/html +RUN chown -R test /var/www/html RUN mkdir -p /home/test/.ssh RUN echo "$SSH_PUB_KEY" > /home/test/.ssh/authorized_keys RUN chmod 700 /home/test/.ssh From fe5dbcff69192137ea833e17906c29239714057a Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Sat, 31 Dec 2022 10:22:07 +0100 Subject: [PATCH 42/46] Remove ssh test --- .github/workflows/e2e.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 6849069..cd87bb3 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -54,11 +54,6 @@ jobs: date +"%Y-%m-%d %H:%M:%S,%3N" >> index.html cat index.html - - name: e2e Test ssh - run: | - echo "$TEST_USER@$REMOTE_HOST" - # ssh -p 8822 $TEST_USER@$REMOTE_HOST 'exit' - - name: e2e Test published ssh-deploy action uses: easingthemes/ssh-deploy@feature/add-tests env: From dd4fa994f18a33e68b7dc2091efeaf328a84c75b Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Sat, 31 Dec 2022 10:22:36 +0100 Subject: [PATCH 43/46] switch back to main --- .github/workflows/e2e.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index cd87bb3..07c07f0 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -2,7 +2,7 @@ name: e2e Test on: push: - branches: [ 'feature/add-tests' ] + branches: [ 'main' ] env: TEST_HOST_DOCKER: ./test @@ -55,7 +55,7 @@ jobs: cat index.html - name: e2e Test published ssh-deploy action - uses: easingthemes/ssh-deploy@feature/add-tests + uses: easingthemes/ssh-deploy@main env: # SSH_PRIVATE_KEY: $EXAMPLE_SSH_PRIVATE_KEY # REMOTE_HOST: $EXAMPLE_REMOTE_HOST1 From 34a75bf4679bddff947539433923afe037bd1928 Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Sat, 31 Dec 2022 10:23:56 +0100 Subject: [PATCH 44/46] remove unused package --- dist/index.js | 2 +- package-lock.json | 11 ----------- package.json | 1 - 3 files changed, 1 insertion(+), 13 deletions(-) diff --git a/dist/index.js b/dist/index.js index 5952a78..b31e0e6 100755 --- a/dist/index.js +++ b/dist/index.js @@ -1,2 +1,2 @@ #!/usr/bin/env node -(()=>{var e={569:(e,r,s)=>{e.exports=s(325)},325:(e,r,s)=>{"use strict";var t=s(81).exec;var n=s(81).execSync;var o=s(147);var c=s(17);var i=o.access;var a=o.accessSync;var u=o.constants||o;var l=process.platform=="win32";var fileNotExists=function(e,r){i(e,u.F_OK,(function(e){r(!e)}))};var fileNotExistsSync=function(e){try{a(e,u.F_OK);return false}catch(e){return true}};var localExecutable=function(e,r){i(e,u.F_OK|u.X_OK,(function(e){r(null,!e)}))};var localExecutableSync=function(e){try{a(e,u.F_OK|u.X_OK);return true}catch(e){return false}};var commandExistsUnix=function(e,r,s){fileNotExists(e,(function(n){if(!n){var o=t("command -v "+r+" 2>/dev/null"+" && { echo >&1 "+r+"; exit 0; }",(function(e,r,t){s(null,!!r)}));return}localExecutable(e,s)}))};var commandExistsWindows=function(e,r,s){if(!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(e)){s(null,false);return}var n=t("where "+r,(function(e){if(e!==null){s(null,false)}else{s(null,true)}}))};var commandExistsUnixSync=function(e,r){if(fileNotExistsSync(e)){try{var s=n("command -v "+r+" 2>/dev/null"+" && { echo >&1 "+r+"; exit 0; }");return!!s}catch(e){return false}}return localExecutableSync(e)};var commandExistsWindowsSync=function(e,r,s){if(!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(e)){return false}try{var t=n("where "+r,{stdio:[]});return!!t}catch(e){return false}};var cleanInput=function(e){if(/[^A-Za-z0-9_\/:=-]/.test(e)){e="'"+e.replace(/'/g,"'\\''")+"'";e=e.replace(/^(?:'')+/g,"").replace(/\\'''/g,"\\'")}return e};if(l){cleanInput=function(e){var r=/[\\]/.test(e);if(r){var s='"'+c.dirname(e)+'"';var t='"'+c.basename(e)+'"';return s+":"+t}return'"'+e+'"'}}e.exports=function commandExists(e,r){var s=cleanInput(e);if(!r&&typeof Promise!=="undefined"){return new Promise((function(r,s){commandExists(e,(function(t,n){if(n){r(e)}else{s(t)}}))}))}if(l){commandExistsWindows(e,s,r)}else{commandExistsUnix(e,s,r)}};e.exports.sync=function(e){var r=cleanInput(e);if(l){return commandExistsWindowsSync(e,r)}else{return commandExistsUnixSync(e,r)}}},898:(e,r,s)=>{"use strict";var t=s(81).spawn;var n=s(837);var escapeSpaces=function(e){if(typeof e==="string"){return e.replace(/\b\s/g,"\\ ")}else{return e}};var escapeSpacesInOptions=function(e){["src","dest","include","exclude","excludeFirst"].forEach((function(r){var s=e[r];if(typeof s==="string"){e[r]=escapeSpaces(s)}else if(Array.isArray(s)===true){e[r]=s.map(escapeSpaces)}}));return e};e.exports=function(e,r){e=e||{};e=n._extend({},e);e=escapeSpacesInOptions(e);var s=e.platform||process.platform;var o=s==="win32";if(typeof e.src==="undefined"){throw new Error("'src' directory is missing from options")}if(typeof e.dest==="undefined"){throw new Error("'dest' directory is missing from options")}var c=e.dest;if(typeof e.host!=="undefined"){c=e.host+":"+e.dest}if(!Array.isArray(e.src)){e.src=[e.src]}var i=[].concat(e.src);i.push(c);var a=(e.args||[]).find((function(e){return e.match(/--chmod=/)}));if(o&&!a){i.push("--chmod=ugo=rwX")}if(typeof e.host!=="undefined"||e.ssh){i.push("--rsh");var u="ssh";if(typeof e.port!=="undefined"){u+=" -p "+e.port}if(typeof e.privateKey!=="undefined"){u+=" -i "+e.privateKey}if(typeof e.sshCmdArgs!=="undefined"){u+=" "+e.sshCmdArgs.join(" ")}i.push(u)}if(e.recursive===true){i.push("--recursive")}if(e.times===true){i.push("--times")}if(e.syncDest===true||e.deleteAll===true){i.push("--delete");i.push("--delete-excluded")}if(e.syncDestIgnoreExcl===true||e.delete===true){i.push("--delete")}if(e.dryRun===true){i.push("--dry-run");i.push("--verbose")}if(typeof e.excludeFirst!=="undefined"&&n.isArray(e.excludeFirst)){e.excludeFirst.forEach((function(e,r){i.push("--exclude="+e)}))}if(typeof e.include!=="undefined"&&n.isArray(e.include)){e.include.forEach((function(e,r){i.push("--include="+e)}))}if(typeof e.exclude!=="undefined"&&n.isArray(e.exclude)){e.exclude.forEach((function(e,r){i.push("--exclude="+e)}))}switch(e.compareMode){case"sizeOnly":i.push("--size-only");break;case"checksum":i.push("--checksum");break}if(typeof e.args!=="undefined"&&n.isArray(e.args)){i=[...new Set([...i,...e.args])]}i=[...new Set(i)];var noop=function(){};var l=e.onStdout||noop;var d=e.onStderr||noop;var f="rsync ";i.forEach((function(e){if(e.substr(0,4)==="ssh "){e='"'+e+'"'}f+=e+" "}));f=f.trim();if(e.noExec){r(null,null,null,f);return}try{var p="";var y="";var _;if(o){_=t("cmd.exe",["/s","/c",'"'+f+'"'],{windowsVerbatimArguments:true,stdio:[process.stdin,"pipe","pipe"]})}else{_=t("/bin/sh",["-c",f])}_.stdout.on("data",(function(e){l(e);p+=e}));_.stderr.on("data",(function(e){d(e);y+=e}));_.on("exit",(function(e){var s=null;if(e!==0){s=new Error("rsync exited with code "+e);s.code=e}r(s,p,y,f)}))}catch(e){r(e,null,null,f)}}},505:(e,r,s)=>{const{existsSync:t,mkdirSync:n,writeFileSync:o}=s(147);const{GITHUB_WORKSPACE:c}=process.env;const validateDir=e=>{if(!t(e)){console.log(`[SSH] Creating ${e} dir in `,c);n(e);console.log("✅ [SSH] dir created.")}else{console.log(`[SSH] ${e} dir exist`)}};const validateFile=e=>{if(!t(e)){console.log(`[SSH] Creating ${e} file in `,c);try{o(e,"",{encoding:"utf8",mode:384});console.log("✅ [SSH] file created.")}catch(r){console.error("⚠️ [SSH] writeFileSync error",e,r.message);process.abort()}}else{console.log(`[SSH] ${e} file exist`)}};e.exports={validateDir:validateDir,validateFile:validateFile}},229:e=>{const r=["REMOTE_HOST","REMOTE_USER","REMOTE_PORT","SSH_PRIVATE_KEY","DEPLOY_KEY_NAME","SOURCE","TARGET","ARGS","EXCLUDE"];const s={GITHUB_WORKSPACE:process.env.GITHUB_WORKSPACE};r.forEach((e=>{s[e]=process.env[e]||process.env[`INPUT_${e}`]}));e.exports=s},447:(e,r,s)=>{const{sync:t}=s(569);const{exec:n,execSync:o}=s(81);const validateRsync=(e=(()=>{}))=>{const r=t("rsync");if(r){console.log("⚠️ [CLI] Rsync exists");const r=o("rsync --version",{stdio:"inherit"});return e()}console.log('⚠️ [CLI] Rsync doesn\'t exists. Start installation with "apt-get" \n');n("sudo apt-get update && sudo apt-get --no-install-recommends install rsync",((r,s,t)=>{if(r){console.log("⚠️ [CLI] Rsync installation failed. Aborting ... ",r.message);process.abort()}else{console.log("✅ [CLI] Rsync installed. \n",s,t);e()}}))};const validateInputs=e=>{const r=Object.keys(e);const s=r.filter((r=>{const s=e[r];if(!s){console.error(`⚠️ [INPUTS] ${r} is mandatory`)}return s}));if(s.length!==r.length){console.error("⚠️ [INPUTS] Inputs not valid, aborting ...");process.abort()}};e.exports={validateRsync:validateRsync,validateInputs:validateInputs}},822:(e,r,s)=>{const{writeFileSync:t}=s(147);const{join:n}=s(17);const{validateDir:o,validateFile:c}=s(505);const{HOME:i}=process.env;const addSshKey=(e,r)=>{const s=n(i||__dirname,".ssh");const a=n(s,r);o(s);c(`${s}/known_hosts`);try{t(a,e,{encoding:"utf8",mode:384})}catch(e){console.error("⚠️ writeFileSync error",a,e.message);process.abort()}console.log("✅ Ssh key added to `.ssh` dir ",a);return a};e.exports={addSshKey:addSshKey}},81:e=>{"use strict";e.exports=require("child_process")},147:e=>{"use strict";e.exports=require("fs")},17:e=>{"use strict";e.exports=require("path")},837:e=>{"use strict";e.exports=require("util")}};var r={};function __nccwpck_require__(s){var t=r[s];if(t!==undefined){return t.exports}var n=r[s]={exports:{}};var o=true;try{e[s](n,n.exports,__nccwpck_require__);o=false}finally{if(o)delete r[s]}return n.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var s={};(()=>{const e=__nccwpck_require__(898);const{validateRsync:r,validateInputs:s}=__nccwpck_require__(447);const{addSshKey:t}=__nccwpck_require__(822);const{REMOTE_HOST:n,REMOTE_USER:o,REMOTE_PORT:c,SSH_PRIVATE_KEY:i,DEPLOY_KEY_NAME:a,SOURCE:u,TARGET:l,ARGS:d,EXCLUDE:f,GITHUB_WORKSPACE:p}=__nccwpck_require__(229);const y={ssh:true,sshCmdArgs:["-o StrictHostKeyChecking=no"],recursive:true};console.log("GITHUB_WORKSPACE: ",p);console.log("REMOTE_HOST: ",process.env.REMOTE_HOST);console.log("REMOTE_USER: ",process.env.REMOTE_USER);console.log("SSH_PRIVATE_KEY: ",process.env.SSH_PRIVATE_KEY);const _=(()=>{const rsync=({privateKey:r,port:s,src:t,dest:n,args:o,exclude:c})=>{console.log(`[Rsync] Starting Rsync Action: ${t} to ${n}`);if(c)console.log(`[Rsync] exluding folders ${c}`);try{e({src:t,dest:n,args:o,privateKey:r,port:s,excludeFirst:c,...y},((e,r,s,t)=>{if(e){console.error("⚠️ [Rsync] error: ",e.message);console.log("⚠️ [Rsync] stderr: ",s);console.log("⚠️ [Rsync] stdout: ",r);console.log("⚠️ [Rsync] cmd: ",t);process.abort()}else{console.log("✅ [Rsync] finished.",r)}}))}catch(e){console.error("⚠️ [Rsync] command error: ",e.message,e.stack);process.abort()}};const init=({src:e,dest:s,args:n,host:o="localhost",port:c,username:i,privateKeyContent:u,exclude:l=[]})=>{r((()=>{const r=t(u,a||"deploy_key");const d=`${i}@${o}:${s}`;rsync({privateKey:r,port:c,src:e,dest:d,args:n,exclude:l})}))};return{init:init}})();const run=()=>{s({SSH_PRIVATE_KEY:i,REMOTE_HOST:n,REMOTE_USER:o});_.init({src:`${p}/${u||""}`,dest:l||`/home/${o}/`,args:d?[d]:["-rltgoDzvO"],host:n,port:c||"22",username:o,privateKeyContent:i,exclude:(f||"").split(",").map((e=>e.trim()))})};run()})();module.exports=s})(); \ No newline at end of file +(()=>{var __webpack_modules__={898:(e,s,r)=>{"use strict";var o=r(81).spawn;var t=r(837);var escapeSpaces=function(e){if(typeof e==="string"){return e.replace(/\b\s/g,"\\ ")}else{return e}};var escapeSpacesInOptions=function(e){["src","dest","include","exclude","excludeFirst"].forEach((function(s){var r=e[s];if(typeof r==="string"){e[s]=escapeSpaces(r)}else if(Array.isArray(r)===true){e[s]=r.map(escapeSpaces)}}));return e};e.exports=function(e,s){e=e||{};e=t._extend({},e);e=escapeSpacesInOptions(e);var r=e.platform||process.platform;var n=r==="win32";if(typeof e.src==="undefined"){throw new Error("'src' directory is missing from options")}if(typeof e.dest==="undefined"){throw new Error("'dest' directory is missing from options")}var c=e.dest;if(typeof e.host!=="undefined"){c=e.host+":"+e.dest}if(!Array.isArray(e.src)){e.src=[e.src]}var i=[].concat(e.src);i.push(c);var a=(e.args||[]).find((function(e){return e.match(/--chmod=/)}));if(n&&!a){i.push("--chmod=ugo=rwX")}if(typeof e.host!=="undefined"||e.ssh){i.push("--rsh");var l="ssh";if(typeof e.port!=="undefined"){l+=" -p "+e.port}if(typeof e.privateKey!=="undefined"){l+=" -i "+e.privateKey}if(typeof e.sshCmdArgs!=="undefined"){l+=" "+e.sshCmdArgs.join(" ")}i.push(l)}if(e.recursive===true){i.push("--recursive")}if(e.times===true){i.push("--times")}if(e.syncDest===true||e.deleteAll===true){i.push("--delete");i.push("--delete-excluded")}if(e.syncDestIgnoreExcl===true||e.delete===true){i.push("--delete")}if(e.dryRun===true){i.push("--dry-run");i.push("--verbose")}if(typeof e.excludeFirst!=="undefined"&&t.isArray(e.excludeFirst)){e.excludeFirst.forEach((function(e,s){i.push("--exclude="+e)}))}if(typeof e.include!=="undefined"&&t.isArray(e.include)){e.include.forEach((function(e,s){i.push("--include="+e)}))}if(typeof e.exclude!=="undefined"&&t.isArray(e.exclude)){e.exclude.forEach((function(e,s){i.push("--exclude="+e)}))}switch(e.compareMode){case"sizeOnly":i.push("--size-only");break;case"checksum":i.push("--checksum");break}if(typeof e.args!=="undefined"&&t.isArray(e.args)){i=[...new Set([...i,...e.args])]}i=[...new Set(i)];var noop=function(){};var d=e.onStdout||noop;var u=e.onStderr||noop;var _="rsync ";i.forEach((function(e){if(e.substr(0,4)==="ssh "){e='"'+e+'"'}_+=e+" "}));_=_.trim();if(e.noExec){s(null,null,null,_);return}try{var p="";var f="";var y;if(n){y=o("cmd.exe",["/s","/c",'"'+_+'"'],{windowsVerbatimArguments:true,stdio:[process.stdin,"pipe","pipe"]})}else{y=o("/bin/sh",["-c",_])}y.stdout.on("data",(function(e){d(e);p+=e}));y.stderr.on("data",(function(e){u(e);f+=e}));y.on("exit",(function(e){var r=null;if(e!==0){r=new Error("rsync exited with code "+e);r.code=e}s(r,p,f,_)}))}catch(e){s(e,null,null,_)}}},505:(e,s,r)=>{const{existsSync:o,mkdirSync:t,writeFileSync:n}=r(147);const{GITHUB_WORKSPACE:c}=process.env;const validateDir=e=>{if(!o(e)){console.log(`[SSH] Creating ${e} dir in `,c);t(e);console.log("✅ [SSH] dir created.")}else{console.log(`[SSH] ${e} dir exist`)}};const validateFile=e=>{if(!o(e)){console.log(`[SSH] Creating ${e} file in `,c);try{n(e,"",{encoding:"utf8",mode:384});console.log("✅ [SSH] file created.")}catch(s){console.error("⚠️ [SSH] writeFileSync error",e,s.message);process.abort()}}else{console.log(`[SSH] ${e} file exist`)}};e.exports={validateDir:validateDir,validateFile:validateFile}},229:e=>{const s=["REMOTE_HOST","REMOTE_USER","REMOTE_PORT","SSH_PRIVATE_KEY","DEPLOY_KEY_NAME","SOURCE","TARGET","ARGS","EXCLUDE"];const r={GITHUB_WORKSPACE:process.env.GITHUB_WORKSPACE};s.forEach((e=>{r[e]=process.env[e]||process.env[`INPUT_${e}`]}));e.exports=r},447:(e,s,r)=>{const{sync:o}=r(238);const{exec:t,execSync:n}=r(81);const validateRsync=(e=(()=>{}))=>{const s=o("rsync");if(s){console.log("⚠️ [CLI] Rsync exists");const s=n("rsync --version",{stdio:"inherit"});return e()}console.log('⚠️ [CLI] Rsync doesn\'t exists. Start installation with "apt-get" \n');t("sudo apt-get update && sudo apt-get --no-install-recommends install rsync",((s,r,o)=>{if(s){console.log("⚠️ [CLI] Rsync installation failed. Aborting ... ",s.message);process.abort()}else{console.log("✅ [CLI] Rsync installed. \n",r,o);e()}}))};const validateInputs=e=>{const s=Object.keys(e);const r=s.filter((s=>{const r=e[s];if(!r){console.error(`⚠️ [INPUTS] ${s} is mandatory`)}return r}));if(r.length!==s.length){console.error("⚠️ [INPUTS] Inputs not valid, aborting ...");process.abort()}};e.exports={validateRsync:validateRsync,validateInputs:validateInputs}},822:(e,s,r)=>{const{writeFileSync:o}=r(147);const{join:t}=r(17);const{validateDir:n,validateFile:c}=r(505);const{HOME:i}=process.env;const addSshKey=(e,s)=>{const r=t(i||__dirname,".ssh");const a=t(r,s);n(r);c(`${r}/known_hosts`);try{o(a,e,{encoding:"utf8",mode:384})}catch(e){console.error("⚠️ writeFileSync error",a,e.message);process.abort()}console.log("✅ Ssh key added to `.ssh` dir ",a);return a};e.exports={addSshKey:addSshKey}},238:module=>{module.exports=eval("require")("command-exists")},81:e=>{"use strict";e.exports=require("child_process")},147:e=>{"use strict";e.exports=require("fs")},17:e=>{"use strict";e.exports=require("path")},837:e=>{"use strict";e.exports=require("util")}};var __webpack_module_cache__={};function __nccwpck_require__(e){var s=__webpack_module_cache__[e];if(s!==undefined){return s.exports}var r=__webpack_module_cache__[e]={exports:{}};var o=true;try{__webpack_modules__[e](r,r.exports,__nccwpck_require__);o=false}finally{if(o)delete __webpack_module_cache__[e]}return r.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var __webpack_exports__={};(()=>{const e=__nccwpck_require__(898);const{validateRsync:s,validateInputs:r}=__nccwpck_require__(447);const{addSshKey:o}=__nccwpck_require__(822);const{REMOTE_HOST:t,REMOTE_USER:n,REMOTE_PORT:c,SSH_PRIVATE_KEY:i,DEPLOY_KEY_NAME:a,SOURCE:l,TARGET:d,ARGS:u,EXCLUDE:_,GITHUB_WORKSPACE:p}=__nccwpck_require__(229);const f={ssh:true,sshCmdArgs:["-o StrictHostKeyChecking=no"],recursive:true};console.log("GITHUB_WORKSPACE: ",p);console.log("REMOTE_HOST: ",process.env.REMOTE_HOST);console.log("REMOTE_USER: ",process.env.REMOTE_USER);console.log("SSH_PRIVATE_KEY: ",process.env.SSH_PRIVATE_KEY);const y=(()=>{const rsync=({privateKey:s,port:r,src:o,dest:t,args:n,exclude:c})=>{console.log(`[Rsync] Starting Rsync Action: ${o} to ${t}`);if(c)console.log(`[Rsync] exluding folders ${c}`);try{e({src:o,dest:t,args:n,privateKey:s,port:r,excludeFirst:c,...f},((e,s,r,o)=>{if(e){console.error("⚠️ [Rsync] error: ",e.message);console.log("⚠️ [Rsync] stderr: ",r);console.log("⚠️ [Rsync] stdout: ",s);console.log("⚠️ [Rsync] cmd: ",o);process.abort()}else{console.log("✅ [Rsync] finished.",s)}}))}catch(e){console.error("⚠️ [Rsync] command error: ",e.message,e.stack);process.abort()}};const init=({src:e,dest:r,args:t,host:n="localhost",port:c,username:i,privateKeyContent:l,exclude:d=[]})=>{s((()=>{const s=o(l,a||"deploy_key");const u=`${i}@${n}:${r}`;rsync({privateKey:s,port:c,src:e,dest:u,args:t,exclude:d})}))};return{init:init}})();const run=()=>{r({SSH_PRIVATE_KEY:i,REMOTE_HOST:t,REMOTE_USER:n});y.init({src:`${p}/${l||""}`,dest:d||`/home/${n}/`,args:u?[u]:["-rltgoDzvO"],host:t,port:c||"22",username:n,privateKeyContent:i,exclude:(_||"").split(",").map((e=>e.trim()))})};run()})();module.exports=__webpack_exports__})(); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 4026c44..2e29acb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,6 @@ "version": "3.0.1", "license": "MIT", "dependencies": { - "command-exists": "^1.2.9", "rsyncwrapper": "^3.0.1" }, "devDependencies": { @@ -301,11 +300,6 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, - "node_modules/command-exists": { - "version": "1.2.9", - "resolved": "https://registry.npmjs.org/command-exists/-/command-exists-1.2.9.tgz", - "integrity": "sha512-LTQ/SGc+s0Xc0Fu5WaKnR0YiygZkm9eKFvyS+fRsU7/ZWFF8ykFM6Pc9aCVf1+xasOOZpO3BAVgVrKvsqKHV7w==" - }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -2188,11 +2182,6 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, - "command-exists": { - "version": "1.2.9", - "resolved": "https://registry.npmjs.org/command-exists/-/command-exists-1.2.9.tgz", - "integrity": "sha512-LTQ/SGc+s0Xc0Fu5WaKnR0YiygZkm9eKFvyS+fRsU7/ZWFF8ykFM6Pc9aCVf1+xasOOZpO3BAVgVrKvsqKHV7w==" - }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", diff --git a/package.json b/package.json index 41d082c..c08fceb 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,6 @@ }, "homepage": "https://github.com/easingthemes/ssh-deploy#readme", "dependencies": { - "command-exists": "^1.2.9", "rsyncwrapper": "^3.0.1" }, "devDependencies": { From 58395110fa24dfc9a99d1dd13c71bbd3baff2458 Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Sat, 31 Dec 2022 10:24:28 +0100 Subject: [PATCH 45/46] revert wrong package --- dist/index.js | 2 +- package-lock.json | 11 +++++++++++ package.json | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/dist/index.js b/dist/index.js index b31e0e6..5952a78 100755 --- a/dist/index.js +++ b/dist/index.js @@ -1,2 +1,2 @@ #!/usr/bin/env node -(()=>{var __webpack_modules__={898:(e,s,r)=>{"use strict";var o=r(81).spawn;var t=r(837);var escapeSpaces=function(e){if(typeof e==="string"){return e.replace(/\b\s/g,"\\ ")}else{return e}};var escapeSpacesInOptions=function(e){["src","dest","include","exclude","excludeFirst"].forEach((function(s){var r=e[s];if(typeof r==="string"){e[s]=escapeSpaces(r)}else if(Array.isArray(r)===true){e[s]=r.map(escapeSpaces)}}));return e};e.exports=function(e,s){e=e||{};e=t._extend({},e);e=escapeSpacesInOptions(e);var r=e.platform||process.platform;var n=r==="win32";if(typeof e.src==="undefined"){throw new Error("'src' directory is missing from options")}if(typeof e.dest==="undefined"){throw new Error("'dest' directory is missing from options")}var c=e.dest;if(typeof e.host!=="undefined"){c=e.host+":"+e.dest}if(!Array.isArray(e.src)){e.src=[e.src]}var i=[].concat(e.src);i.push(c);var a=(e.args||[]).find((function(e){return e.match(/--chmod=/)}));if(n&&!a){i.push("--chmod=ugo=rwX")}if(typeof e.host!=="undefined"||e.ssh){i.push("--rsh");var l="ssh";if(typeof e.port!=="undefined"){l+=" -p "+e.port}if(typeof e.privateKey!=="undefined"){l+=" -i "+e.privateKey}if(typeof e.sshCmdArgs!=="undefined"){l+=" "+e.sshCmdArgs.join(" ")}i.push(l)}if(e.recursive===true){i.push("--recursive")}if(e.times===true){i.push("--times")}if(e.syncDest===true||e.deleteAll===true){i.push("--delete");i.push("--delete-excluded")}if(e.syncDestIgnoreExcl===true||e.delete===true){i.push("--delete")}if(e.dryRun===true){i.push("--dry-run");i.push("--verbose")}if(typeof e.excludeFirst!=="undefined"&&t.isArray(e.excludeFirst)){e.excludeFirst.forEach((function(e,s){i.push("--exclude="+e)}))}if(typeof e.include!=="undefined"&&t.isArray(e.include)){e.include.forEach((function(e,s){i.push("--include="+e)}))}if(typeof e.exclude!=="undefined"&&t.isArray(e.exclude)){e.exclude.forEach((function(e,s){i.push("--exclude="+e)}))}switch(e.compareMode){case"sizeOnly":i.push("--size-only");break;case"checksum":i.push("--checksum");break}if(typeof e.args!=="undefined"&&t.isArray(e.args)){i=[...new Set([...i,...e.args])]}i=[...new Set(i)];var noop=function(){};var d=e.onStdout||noop;var u=e.onStderr||noop;var _="rsync ";i.forEach((function(e){if(e.substr(0,4)==="ssh "){e='"'+e+'"'}_+=e+" "}));_=_.trim();if(e.noExec){s(null,null,null,_);return}try{var p="";var f="";var y;if(n){y=o("cmd.exe",["/s","/c",'"'+_+'"'],{windowsVerbatimArguments:true,stdio:[process.stdin,"pipe","pipe"]})}else{y=o("/bin/sh",["-c",_])}y.stdout.on("data",(function(e){d(e);p+=e}));y.stderr.on("data",(function(e){u(e);f+=e}));y.on("exit",(function(e){var r=null;if(e!==0){r=new Error("rsync exited with code "+e);r.code=e}s(r,p,f,_)}))}catch(e){s(e,null,null,_)}}},505:(e,s,r)=>{const{existsSync:o,mkdirSync:t,writeFileSync:n}=r(147);const{GITHUB_WORKSPACE:c}=process.env;const validateDir=e=>{if(!o(e)){console.log(`[SSH] Creating ${e} dir in `,c);t(e);console.log("✅ [SSH] dir created.")}else{console.log(`[SSH] ${e} dir exist`)}};const validateFile=e=>{if(!o(e)){console.log(`[SSH] Creating ${e} file in `,c);try{n(e,"",{encoding:"utf8",mode:384});console.log("✅ [SSH] file created.")}catch(s){console.error("⚠️ [SSH] writeFileSync error",e,s.message);process.abort()}}else{console.log(`[SSH] ${e} file exist`)}};e.exports={validateDir:validateDir,validateFile:validateFile}},229:e=>{const s=["REMOTE_HOST","REMOTE_USER","REMOTE_PORT","SSH_PRIVATE_KEY","DEPLOY_KEY_NAME","SOURCE","TARGET","ARGS","EXCLUDE"];const r={GITHUB_WORKSPACE:process.env.GITHUB_WORKSPACE};s.forEach((e=>{r[e]=process.env[e]||process.env[`INPUT_${e}`]}));e.exports=r},447:(e,s,r)=>{const{sync:o}=r(238);const{exec:t,execSync:n}=r(81);const validateRsync=(e=(()=>{}))=>{const s=o("rsync");if(s){console.log("⚠️ [CLI] Rsync exists");const s=n("rsync --version",{stdio:"inherit"});return e()}console.log('⚠️ [CLI] Rsync doesn\'t exists. Start installation with "apt-get" \n');t("sudo apt-get update && sudo apt-get --no-install-recommends install rsync",((s,r,o)=>{if(s){console.log("⚠️ [CLI] Rsync installation failed. Aborting ... ",s.message);process.abort()}else{console.log("✅ [CLI] Rsync installed. \n",r,o);e()}}))};const validateInputs=e=>{const s=Object.keys(e);const r=s.filter((s=>{const r=e[s];if(!r){console.error(`⚠️ [INPUTS] ${s} is mandatory`)}return r}));if(r.length!==s.length){console.error("⚠️ [INPUTS] Inputs not valid, aborting ...");process.abort()}};e.exports={validateRsync:validateRsync,validateInputs:validateInputs}},822:(e,s,r)=>{const{writeFileSync:o}=r(147);const{join:t}=r(17);const{validateDir:n,validateFile:c}=r(505);const{HOME:i}=process.env;const addSshKey=(e,s)=>{const r=t(i||__dirname,".ssh");const a=t(r,s);n(r);c(`${r}/known_hosts`);try{o(a,e,{encoding:"utf8",mode:384})}catch(e){console.error("⚠️ writeFileSync error",a,e.message);process.abort()}console.log("✅ Ssh key added to `.ssh` dir ",a);return a};e.exports={addSshKey:addSshKey}},238:module=>{module.exports=eval("require")("command-exists")},81:e=>{"use strict";e.exports=require("child_process")},147:e=>{"use strict";e.exports=require("fs")},17:e=>{"use strict";e.exports=require("path")},837:e=>{"use strict";e.exports=require("util")}};var __webpack_module_cache__={};function __nccwpck_require__(e){var s=__webpack_module_cache__[e];if(s!==undefined){return s.exports}var r=__webpack_module_cache__[e]={exports:{}};var o=true;try{__webpack_modules__[e](r,r.exports,__nccwpck_require__);o=false}finally{if(o)delete __webpack_module_cache__[e]}return r.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var __webpack_exports__={};(()=>{const e=__nccwpck_require__(898);const{validateRsync:s,validateInputs:r}=__nccwpck_require__(447);const{addSshKey:o}=__nccwpck_require__(822);const{REMOTE_HOST:t,REMOTE_USER:n,REMOTE_PORT:c,SSH_PRIVATE_KEY:i,DEPLOY_KEY_NAME:a,SOURCE:l,TARGET:d,ARGS:u,EXCLUDE:_,GITHUB_WORKSPACE:p}=__nccwpck_require__(229);const f={ssh:true,sshCmdArgs:["-o StrictHostKeyChecking=no"],recursive:true};console.log("GITHUB_WORKSPACE: ",p);console.log("REMOTE_HOST: ",process.env.REMOTE_HOST);console.log("REMOTE_USER: ",process.env.REMOTE_USER);console.log("SSH_PRIVATE_KEY: ",process.env.SSH_PRIVATE_KEY);const y=(()=>{const rsync=({privateKey:s,port:r,src:o,dest:t,args:n,exclude:c})=>{console.log(`[Rsync] Starting Rsync Action: ${o} to ${t}`);if(c)console.log(`[Rsync] exluding folders ${c}`);try{e({src:o,dest:t,args:n,privateKey:s,port:r,excludeFirst:c,...f},((e,s,r,o)=>{if(e){console.error("⚠️ [Rsync] error: ",e.message);console.log("⚠️ [Rsync] stderr: ",r);console.log("⚠️ [Rsync] stdout: ",s);console.log("⚠️ [Rsync] cmd: ",o);process.abort()}else{console.log("✅ [Rsync] finished.",s)}}))}catch(e){console.error("⚠️ [Rsync] command error: ",e.message,e.stack);process.abort()}};const init=({src:e,dest:r,args:t,host:n="localhost",port:c,username:i,privateKeyContent:l,exclude:d=[]})=>{s((()=>{const s=o(l,a||"deploy_key");const u=`${i}@${n}:${r}`;rsync({privateKey:s,port:c,src:e,dest:u,args:t,exclude:d})}))};return{init:init}})();const run=()=>{r({SSH_PRIVATE_KEY:i,REMOTE_HOST:t,REMOTE_USER:n});y.init({src:`${p}/${l||""}`,dest:d||`/home/${n}/`,args:u?[u]:["-rltgoDzvO"],host:t,port:c||"22",username:n,privateKeyContent:i,exclude:(_||"").split(",").map((e=>e.trim()))})};run()})();module.exports=__webpack_exports__})(); \ No newline at end of file +(()=>{var e={569:(e,r,s)=>{e.exports=s(325)},325:(e,r,s)=>{"use strict";var t=s(81).exec;var n=s(81).execSync;var o=s(147);var c=s(17);var i=o.access;var a=o.accessSync;var u=o.constants||o;var l=process.platform=="win32";var fileNotExists=function(e,r){i(e,u.F_OK,(function(e){r(!e)}))};var fileNotExistsSync=function(e){try{a(e,u.F_OK);return false}catch(e){return true}};var localExecutable=function(e,r){i(e,u.F_OK|u.X_OK,(function(e){r(null,!e)}))};var localExecutableSync=function(e){try{a(e,u.F_OK|u.X_OK);return true}catch(e){return false}};var commandExistsUnix=function(e,r,s){fileNotExists(e,(function(n){if(!n){var o=t("command -v "+r+" 2>/dev/null"+" && { echo >&1 "+r+"; exit 0; }",(function(e,r,t){s(null,!!r)}));return}localExecutable(e,s)}))};var commandExistsWindows=function(e,r,s){if(!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(e)){s(null,false);return}var n=t("where "+r,(function(e){if(e!==null){s(null,false)}else{s(null,true)}}))};var commandExistsUnixSync=function(e,r){if(fileNotExistsSync(e)){try{var s=n("command -v "+r+" 2>/dev/null"+" && { echo >&1 "+r+"; exit 0; }");return!!s}catch(e){return false}}return localExecutableSync(e)};var commandExistsWindowsSync=function(e,r,s){if(!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(e)){return false}try{var t=n("where "+r,{stdio:[]});return!!t}catch(e){return false}};var cleanInput=function(e){if(/[^A-Za-z0-9_\/:=-]/.test(e)){e="'"+e.replace(/'/g,"'\\''")+"'";e=e.replace(/^(?:'')+/g,"").replace(/\\'''/g,"\\'")}return e};if(l){cleanInput=function(e){var r=/[\\]/.test(e);if(r){var s='"'+c.dirname(e)+'"';var t='"'+c.basename(e)+'"';return s+":"+t}return'"'+e+'"'}}e.exports=function commandExists(e,r){var s=cleanInput(e);if(!r&&typeof Promise!=="undefined"){return new Promise((function(r,s){commandExists(e,(function(t,n){if(n){r(e)}else{s(t)}}))}))}if(l){commandExistsWindows(e,s,r)}else{commandExistsUnix(e,s,r)}};e.exports.sync=function(e){var r=cleanInput(e);if(l){return commandExistsWindowsSync(e,r)}else{return commandExistsUnixSync(e,r)}}},898:(e,r,s)=>{"use strict";var t=s(81).spawn;var n=s(837);var escapeSpaces=function(e){if(typeof e==="string"){return e.replace(/\b\s/g,"\\ ")}else{return e}};var escapeSpacesInOptions=function(e){["src","dest","include","exclude","excludeFirst"].forEach((function(r){var s=e[r];if(typeof s==="string"){e[r]=escapeSpaces(s)}else if(Array.isArray(s)===true){e[r]=s.map(escapeSpaces)}}));return e};e.exports=function(e,r){e=e||{};e=n._extend({},e);e=escapeSpacesInOptions(e);var s=e.platform||process.platform;var o=s==="win32";if(typeof e.src==="undefined"){throw new Error("'src' directory is missing from options")}if(typeof e.dest==="undefined"){throw new Error("'dest' directory is missing from options")}var c=e.dest;if(typeof e.host!=="undefined"){c=e.host+":"+e.dest}if(!Array.isArray(e.src)){e.src=[e.src]}var i=[].concat(e.src);i.push(c);var a=(e.args||[]).find((function(e){return e.match(/--chmod=/)}));if(o&&!a){i.push("--chmod=ugo=rwX")}if(typeof e.host!=="undefined"||e.ssh){i.push("--rsh");var u="ssh";if(typeof e.port!=="undefined"){u+=" -p "+e.port}if(typeof e.privateKey!=="undefined"){u+=" -i "+e.privateKey}if(typeof e.sshCmdArgs!=="undefined"){u+=" "+e.sshCmdArgs.join(" ")}i.push(u)}if(e.recursive===true){i.push("--recursive")}if(e.times===true){i.push("--times")}if(e.syncDest===true||e.deleteAll===true){i.push("--delete");i.push("--delete-excluded")}if(e.syncDestIgnoreExcl===true||e.delete===true){i.push("--delete")}if(e.dryRun===true){i.push("--dry-run");i.push("--verbose")}if(typeof e.excludeFirst!=="undefined"&&n.isArray(e.excludeFirst)){e.excludeFirst.forEach((function(e,r){i.push("--exclude="+e)}))}if(typeof e.include!=="undefined"&&n.isArray(e.include)){e.include.forEach((function(e,r){i.push("--include="+e)}))}if(typeof e.exclude!=="undefined"&&n.isArray(e.exclude)){e.exclude.forEach((function(e,r){i.push("--exclude="+e)}))}switch(e.compareMode){case"sizeOnly":i.push("--size-only");break;case"checksum":i.push("--checksum");break}if(typeof e.args!=="undefined"&&n.isArray(e.args)){i=[...new Set([...i,...e.args])]}i=[...new Set(i)];var noop=function(){};var l=e.onStdout||noop;var d=e.onStderr||noop;var f="rsync ";i.forEach((function(e){if(e.substr(0,4)==="ssh "){e='"'+e+'"'}f+=e+" "}));f=f.trim();if(e.noExec){r(null,null,null,f);return}try{var p="";var y="";var _;if(o){_=t("cmd.exe",["/s","/c",'"'+f+'"'],{windowsVerbatimArguments:true,stdio:[process.stdin,"pipe","pipe"]})}else{_=t("/bin/sh",["-c",f])}_.stdout.on("data",(function(e){l(e);p+=e}));_.stderr.on("data",(function(e){d(e);y+=e}));_.on("exit",(function(e){var s=null;if(e!==0){s=new Error("rsync exited with code "+e);s.code=e}r(s,p,y,f)}))}catch(e){r(e,null,null,f)}}},505:(e,r,s)=>{const{existsSync:t,mkdirSync:n,writeFileSync:o}=s(147);const{GITHUB_WORKSPACE:c}=process.env;const validateDir=e=>{if(!t(e)){console.log(`[SSH] Creating ${e} dir in `,c);n(e);console.log("✅ [SSH] dir created.")}else{console.log(`[SSH] ${e} dir exist`)}};const validateFile=e=>{if(!t(e)){console.log(`[SSH] Creating ${e} file in `,c);try{o(e,"",{encoding:"utf8",mode:384});console.log("✅ [SSH] file created.")}catch(r){console.error("⚠️ [SSH] writeFileSync error",e,r.message);process.abort()}}else{console.log(`[SSH] ${e} file exist`)}};e.exports={validateDir:validateDir,validateFile:validateFile}},229:e=>{const r=["REMOTE_HOST","REMOTE_USER","REMOTE_PORT","SSH_PRIVATE_KEY","DEPLOY_KEY_NAME","SOURCE","TARGET","ARGS","EXCLUDE"];const s={GITHUB_WORKSPACE:process.env.GITHUB_WORKSPACE};r.forEach((e=>{s[e]=process.env[e]||process.env[`INPUT_${e}`]}));e.exports=s},447:(e,r,s)=>{const{sync:t}=s(569);const{exec:n,execSync:o}=s(81);const validateRsync=(e=(()=>{}))=>{const r=t("rsync");if(r){console.log("⚠️ [CLI] Rsync exists");const r=o("rsync --version",{stdio:"inherit"});return e()}console.log('⚠️ [CLI] Rsync doesn\'t exists. Start installation with "apt-get" \n');n("sudo apt-get update && sudo apt-get --no-install-recommends install rsync",((r,s,t)=>{if(r){console.log("⚠️ [CLI] Rsync installation failed. Aborting ... ",r.message);process.abort()}else{console.log("✅ [CLI] Rsync installed. \n",s,t);e()}}))};const validateInputs=e=>{const r=Object.keys(e);const s=r.filter((r=>{const s=e[r];if(!s){console.error(`⚠️ [INPUTS] ${r} is mandatory`)}return s}));if(s.length!==r.length){console.error("⚠️ [INPUTS] Inputs not valid, aborting ...");process.abort()}};e.exports={validateRsync:validateRsync,validateInputs:validateInputs}},822:(e,r,s)=>{const{writeFileSync:t}=s(147);const{join:n}=s(17);const{validateDir:o,validateFile:c}=s(505);const{HOME:i}=process.env;const addSshKey=(e,r)=>{const s=n(i||__dirname,".ssh");const a=n(s,r);o(s);c(`${s}/known_hosts`);try{t(a,e,{encoding:"utf8",mode:384})}catch(e){console.error("⚠️ writeFileSync error",a,e.message);process.abort()}console.log("✅ Ssh key added to `.ssh` dir ",a);return a};e.exports={addSshKey:addSshKey}},81:e=>{"use strict";e.exports=require("child_process")},147:e=>{"use strict";e.exports=require("fs")},17:e=>{"use strict";e.exports=require("path")},837:e=>{"use strict";e.exports=require("util")}};var r={};function __nccwpck_require__(s){var t=r[s];if(t!==undefined){return t.exports}var n=r[s]={exports:{}};var o=true;try{e[s](n,n.exports,__nccwpck_require__);o=false}finally{if(o)delete r[s]}return n.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var s={};(()=>{const e=__nccwpck_require__(898);const{validateRsync:r,validateInputs:s}=__nccwpck_require__(447);const{addSshKey:t}=__nccwpck_require__(822);const{REMOTE_HOST:n,REMOTE_USER:o,REMOTE_PORT:c,SSH_PRIVATE_KEY:i,DEPLOY_KEY_NAME:a,SOURCE:u,TARGET:l,ARGS:d,EXCLUDE:f,GITHUB_WORKSPACE:p}=__nccwpck_require__(229);const y={ssh:true,sshCmdArgs:["-o StrictHostKeyChecking=no"],recursive:true};console.log("GITHUB_WORKSPACE: ",p);console.log("REMOTE_HOST: ",process.env.REMOTE_HOST);console.log("REMOTE_USER: ",process.env.REMOTE_USER);console.log("SSH_PRIVATE_KEY: ",process.env.SSH_PRIVATE_KEY);const _=(()=>{const rsync=({privateKey:r,port:s,src:t,dest:n,args:o,exclude:c})=>{console.log(`[Rsync] Starting Rsync Action: ${t} to ${n}`);if(c)console.log(`[Rsync] exluding folders ${c}`);try{e({src:t,dest:n,args:o,privateKey:r,port:s,excludeFirst:c,...y},((e,r,s,t)=>{if(e){console.error("⚠️ [Rsync] error: ",e.message);console.log("⚠️ [Rsync] stderr: ",s);console.log("⚠️ [Rsync] stdout: ",r);console.log("⚠️ [Rsync] cmd: ",t);process.abort()}else{console.log("✅ [Rsync] finished.",r)}}))}catch(e){console.error("⚠️ [Rsync] command error: ",e.message,e.stack);process.abort()}};const init=({src:e,dest:s,args:n,host:o="localhost",port:c,username:i,privateKeyContent:u,exclude:l=[]})=>{r((()=>{const r=t(u,a||"deploy_key");const d=`${i}@${o}:${s}`;rsync({privateKey:r,port:c,src:e,dest:d,args:n,exclude:l})}))};return{init:init}})();const run=()=>{s({SSH_PRIVATE_KEY:i,REMOTE_HOST:n,REMOTE_USER:o});_.init({src:`${p}/${u||""}`,dest:l||`/home/${o}/`,args:d?[d]:["-rltgoDzvO"],host:n,port:c||"22",username:o,privateKeyContent:i,exclude:(f||"").split(",").map((e=>e.trim()))})};run()})();module.exports=s})(); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 2e29acb..4026c44 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "3.0.1", "license": "MIT", "dependencies": { + "command-exists": "^1.2.9", "rsyncwrapper": "^3.0.1" }, "devDependencies": { @@ -300,6 +301,11 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, + "node_modules/command-exists": { + "version": "1.2.9", + "resolved": "https://registry.npmjs.org/command-exists/-/command-exists-1.2.9.tgz", + "integrity": "sha512-LTQ/SGc+s0Xc0Fu5WaKnR0YiygZkm9eKFvyS+fRsU7/ZWFF8ykFM6Pc9aCVf1+xasOOZpO3BAVgVrKvsqKHV7w==" + }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -2182,6 +2188,11 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, + "command-exists": { + "version": "1.2.9", + "resolved": "https://registry.npmjs.org/command-exists/-/command-exists-1.2.9.tgz", + "integrity": "sha512-LTQ/SGc+s0Xc0Fu5WaKnR0YiygZkm9eKFvyS+fRsU7/ZWFF8ykFM6Pc9aCVf1+xasOOZpO3BAVgVrKvsqKHV7w==" + }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", diff --git a/package.json b/package.json index c08fceb..41d082c 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ }, "homepage": "https://github.com/easingthemes/ssh-deploy#readme", "dependencies": { + "command-exists": "^1.2.9", "rsyncwrapper": "^3.0.1" }, "devDependencies": { From b6ac6f5c98113ef2509263945ea6646dafae5e69 Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Sat, 31 Dec 2022 10:25:56 +0100 Subject: [PATCH 46/46] readd workflows --- {tmp => .github/workflows}/codeql-analysis.yml | 0 {tmp => .github/workflows}/manual-release.yml | 0 {tmp => .github/workflows}/release.yml | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename {tmp => .github/workflows}/codeql-analysis.yml (100%) rename {tmp => .github/workflows}/manual-release.yml (100%) rename {tmp => .github/workflows}/release.yml (100%) diff --git a/tmp/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml similarity index 100% rename from tmp/codeql-analysis.yml rename to .github/workflows/codeql-analysis.yml diff --git a/tmp/manual-release.yml b/.github/workflows/manual-release.yml similarity index 100% rename from tmp/manual-release.yml rename to .github/workflows/manual-release.yml diff --git a/tmp/release.yml b/.github/workflows/release.yml similarity index 100% rename from tmp/release.yml rename to .github/workflows/release.yml