From 7f61bbc4aeb0ba6591e6d31b4ccd49d08f7a6c9d Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Mon, 1 Mar 2021 09:41:11 +0000 Subject: [PATCH] Use different ssh-add command for Windows/!Windows --- .github/workflows/demo.yml | 49 +++++++++++++++++++++++++++++++------- dist/index.js | 9 +++++-- index.js | 9 +++++-- 3 files changed, 55 insertions(+), 12 deletions(-) diff --git a/.github/workflows/demo.yml b/.github/workflows/demo.yml index 0252633..e177a4f 100644 --- a/.github/workflows/demo.yml +++ b/.github/workflows/demo.yml @@ -1,13 +1,53 @@ on: [push, pull_request] jobs: + single_key_demo: + strategy: + matrix: + os: [ubuntu-latest, macOS-latest, windows-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v2 + - name: Setup key + uses: ./ + with: + ssh-private-key: | + ${{ secrets.DEMO_KEY }} + ${{ secrets.DEMO_KEY_2 }} + + multiple_keys_demo: + strategy: + matrix: + os: [ubuntu-latest, macOS-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v2 + - name: Setup key + uses: ./ + with: + ssh-private-key: ${{ secrets.DEMO_KEY }} + + docker_demo: + runs-on: ubuntu-latest + container: + image: ubuntu:latest + steps: + - uses: actions/checkout@v2 + - run: apt update && apt install -y openssh-client + - name: Setup key + uses: ./ + with: + ssh-private-key: | + ${{ secrets.DEMO_KEY }} + ${{ secrets.DEMO_KEY_2 }} + deployment_keys_demo: env: GIT_SSH_COMMAND: ssh -v strategy: fail-fast: false matrix: - os: [windows-latest] + os: [ubuntu-latest, macOS-latest, windows-latest] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 @@ -17,13 +57,6 @@ jobs: ssh-private-key: | ${{ secrets.MPDUDE_TEST_1_DEPLOY_KEY }} ${{ secrets.MPDUDE_TEST_2_DEPLOY_KEY }} - - name: Start SSH session - uses: luchihoratiu/debug-via-ssh@main - if: ${{ failure() }} - with: - NGROK_AUTH_TOKEN: ${{ secrets.NGROK_AUTH_TOKEN }} - SSH_PASS: ${{ secrets.SSH_PASS }} - - run: | cat ~/.ssh/config ls -alh ~/.ssh diff --git a/dist/index.js b/dist/index.js index 4dfcbdd..aac8f20 100644 --- a/dist/index.js +++ b/dist/index.js @@ -120,6 +120,7 @@ const child_process = __webpack_require__(129); const fs = __webpack_require__(747); const os = __webpack_require__(87); const token = __webpack_require__(417).randomBytes(64).toString('hex'); +const isWindows = (process.env['OS'] == 'Windows_NT'); try { const privateKey = core.getInput('ssh-private-key'); @@ -132,7 +133,7 @@ try { var home; - if (process.env['OS'] == 'Windows_NT') { + if (isWindows) { console.log('Preparing ssh-agent service on Windows'); child_process.execSync('sc config ssh-agent start=demand', { stdio: 'inherit' }); @@ -191,7 +192,11 @@ try { } // Load key into agent - child_process.execFileSync('ssh-add', [keyFile], { env: { ...process.env, ...{ 'DISPLAY': 'fake', 'SSH_PASS': token, 'SSH_ASKPASS': 'D:\\a\\ssh-agent\\ssh-agent\\askpass.exe' } } }); + if (isWindows) { + child_process.execFileSync('ssh-add', [keyFile], { env: { ...process.env, ...{ 'DISPLAY': 'fake', 'SSH_PASS': token, 'SSH_ASKPASS': 'D:\\a\\ssh-agent\\ssh-agent\\askpass.exe' } } }); + } else { + child_process.execFileSync('ssh-add', [keyFile], { input: token }); + } output.toString().split(/\r?\n/).forEach(function(key) { let parts = key.match(/^Key has comment '.*\bgithub\.com[:/]([_.a-z0-9-]+\/[_.a-z0-9-]+?)(?=\.git|\s|\')/); diff --git a/index.js b/index.js index 55e6ff3..06d7a10 100644 --- a/index.js +++ b/index.js @@ -3,6 +3,7 @@ const child_process = require('child_process'); const fs = require('fs'); const os = require('os'); const token = require('crypto').randomBytes(64).toString('hex'); +const isWindows = (process.env['OS'] == 'Windows_NT'); try { const privateKey = core.getInput('ssh-private-key'); @@ -15,7 +16,7 @@ try { var home; - if (process.env['OS'] == 'Windows_NT') { + if (isWindows) { console.log('Preparing ssh-agent service on Windows'); child_process.execSync('sc config ssh-agent start=demand', { stdio: 'inherit' }); @@ -74,7 +75,11 @@ try { } // Load key into agent - child_process.execFileSync('ssh-add', [keyFile], { env: { ...process.env, ...{ 'DISPLAY': 'fake', 'SSH_PASS': token, 'SSH_ASKPASS': 'D:\\a\\ssh-agent\\ssh-agent\\askpass.exe' } } }); + if (isWindows) { + child_process.execFileSync('ssh-add', [keyFile], { env: { ...process.env, ...{ 'DISPLAY': 'fake', 'SSH_PASS': token, 'SSH_ASKPASS': 'D:\\a\\ssh-agent\\ssh-agent\\askpass.exe' } } }); + } else { + child_process.execFileSync('ssh-add', [keyFile], { input: token }); + } output.toString().split(/\r?\n/).forEach(function(key) { let parts = key.match(/^Key has comment '.*\bgithub\.com[:/]([_.a-z0-9-]+\/[_.a-z0-9-]+?)(?=\.git|\s|\')/);