Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demo go get #84

Open
wants to merge 15 commits into
base: debug-windows-ssh
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 35 additions & 48 deletions .github/workflows/demo.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,47 @@
on: [push, pull_request]
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:
deployment_keys_demo:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macOS-latest]
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 }}
- uses: actions/checkout@v2
- name: Setup key
uses: ./
with:
ssh-private-key: |
${{ secrets.MPDUDE_TEST_1_DEPLOY_KEY }}
${{ secrets.MPDUDE_TEST_2_DEPLOY_KEY }}
- run: |
git clone https://github.com/mpdude/test-1.git test-1-http
git clone [email protected]:mpdude/test-1.git test-1-git
git clone ssh://[email protected]/mpdude/test-1.git test-1-git-ssh
git clone https://github.com/mpdude/test-2.git test-2-http
git clone [email protected]:mpdude/test-2.git test-2-git
git clone ssh://[email protected]/mpdude/test-2.git test-2-git-ssh
go get -v github.com/mpdude/test-2

docker_demo:
runs-on: ubuntu-latest
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 }}
- uses: actions/checkout@v2
- run: apt update && apt install -y openssh-client git
- name: Setup key
uses: ./
with:
ssh-private-key: |
${{ secrets.MPDUDE_TEST_1_DEPLOY_KEY }}
${{ secrets.MPDUDE_TEST_2_DEPLOY_KEY }}
- run: |
git clone https://github.com/mpdude/test-1.git test-1-http
git clone [email protected]:mpdude/test-1.git test-1-git
git clone ssh://[email protected]/mpdude/test-1.git test-1-git-ssh
git clone https://github.com/mpdude/test-2.git test-2-http
git clone [email protected]:mpdude/test-2.git test-2-git
git clone ssh://[email protected]/mpdude/test-2.git test-2-git-ssh

deployment_keys_demo:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup key
uses: ./
with:
ssh-private-key: |
${{ secrets.MPDUDE_TEST_1_DEPLOY_KEY }}
${{ secrets.MPDUDE_TEST_2_DEPLOY_KEY }}
- run: |
git clone https://github.com/mpdude/test-1.git test-1-http
git clone [email protected]:mpdude/test-1.git test-1-git
git clone ssh://[email protected]/mpdude/test-1.git test-1-git-ssh
git clone https://github.com/mpdude/test-2.git test-2-http
git clone [email protected]:mpdude/test-2.git test-2-git
git clone ssh://[email protected]/mpdude/test-2.git test-2-git-ssh
48 changes: 44 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ jobs:
...
steps:
- actions/checkout@v2
# Make sure the @v0.5.0 matches the current version of the
# Make sure the @v0.5.3 matches the current version of the
# action
- uses: webfactory/[email protected].0
- uses: webfactory/[email protected].3
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- ... other steps
Expand All @@ -50,7 +50,7 @@ You can set up different keys as different secrets and pass them all to the acti

```yaml
# ... contens as before
- uses: webfactory/[email protected].0
- uses: webfactory/[email protected].3
with:
ssh-private-key: |
${{ secrets.FIRST_KEY }}
Expand All @@ -68,7 +68,7 @@ When using **Github deploy keys**, GitHub servers will accept the _first_ known

To support picking the right key in this use case, this action scans _key comments_ and will set up extra Git and SSH configuration to make things work.

1. When creating the deploy key for a repository like `[email protected]:owner/repo.git` or `https://github.com/owner/repo`, put that URL into the key comment.
1. When creating the deploy key for a repository like `[email protected]:owner/repo.git` or `https://github.com/owner/repo`, put that URL into the key comment. (Hint: Try `ssh-keygen ... -C "[email protected]:owner/repo.git"`.)
2. After keys have been added to the agent, this action will scan the key comments.
3. For key comments containing such URLs, a Git config setting is written that uses [`url.<base>.insteadof`](https://git-scm.com/docs/git-config#Documentation/git-config.txt-urlltbasegtinsteadOf). It will redirect `git` requests to URLs starting with either `https://github.com/owner/repo` or `[email protected]:owner/repo` to a fake hostname/URL like `[email protected]...:owner/repo`.
4. An SSH configuration section is generated that applies to the fake hostname. It will map the SSH connection back to `github.com`, while at the same time pointing SSH to a file containing the appropriate key's public part. That will make SSH use the right key when connecting to GitHub.com.
Expand All @@ -90,6 +90,46 @@ If the private key is not in the `PEM` format, you will see an `Error loading ke

Use `ssh-keygen -p -f path/to/your/key -m pem` to convert your key file to `PEM`, but be sure to make a backup of the file first 😉.

## Additional Information for Particular Tools or Platforms

If you know that your favorite tool or platform of choice requires extra tweaks or has some caveats when running with SSH, feel free to open a PR to amend this section here.

### Container-based Workflows

If you are using this action on container-based workflows, make sure the container has the necessary SSH binaries or package(s) installed.

### Cargo's (Rust) Private Dependencies on Windows

If you are using private repositories in your dependencies like this:

```
stuff = { git = "ssh://[email protected]/myorg/stuff.git", branch = "main" }
```

... you will need to change a configuration in the workflow for Windows machines in order to make cargo able to clone private repositories.

There are 2 ways you can achieve this:

1. Add this step once in your job **before** any cargo command:

```
- name: Update cargo config to use Git CLI
run: Set-Content -Path $env:USERPROFILE\.cargo\config.toml "[net]`ngit-fetch-with-cli = true"
```

This will configure Cargo to use the Git CLI as explained in the [Cargo's documentation](https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli).

2. Alternatively you can set it to the environment variables for the entire workflow:

```
env:
CARGO_NET_GIT_FETCH_WITH_CLI: true
```

### Using Deploy Keys with Swift Package Manager

`xcodebuild` by default uses Xcode's built-in Git tooling. If you want to use GitHub Deploy Keys as supported by this action, however, that version of Git will lack the necessary URL remapping. In this case, pass `-scmProvider system` to the `xcodebuild` command, as mentioned in [Apple's documentation](https://developer.apple.com/documentation/swift_packages/building_swift_packages_or_apps_that_use_them_in_continuous_integration_workflows#3680255).

## What this Action *cannot* do for you

The following items are not issues, but beyond what this Action is supposed to do.
Expand Down
1 change: 1 addition & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ runs:
using: 'node12'
main: 'dist/index.js'
post: 'dist/cleanup.js'
post-if: 'always()'
branding:
icon: loader
color: 'yellow'
9 changes: 5 additions & 4 deletions cleanup.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const core = require('@actions/core')
const { execSync } = require('child_process')
const core = require('@actions/core');
const { execFileSync } = require('child_process');
const { sshAgent } = require('./paths.js');

try {
// Kill the started SSH agent
console.log('Stopping SSH agent')
execSync('kill ${SSH_AGENT_PID}', { stdio: 'inherit' })
console.log('Stopping SSH agent');
execFileSync(sshAgent, ['-k'], { stdio: 'inherit' });
} catch (error) {
console.log(error.message);
console.log('Error stopping the SSH agent, proceeding anyway');
Expand Down
34 changes: 30 additions & 4 deletions dist/cleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,14 @@ module.exports = require("child_process");
/***/ 175:
/***/ (function(__unusedmodule, __unusedexports, __webpack_require__) {

const core = __webpack_require__(470)
const { execSync } = __webpack_require__(129)
const core = __webpack_require__(470);
const { execFileSync } = __webpack_require__(129);
const { sshAgent } = __webpack_require__(972);

try {
// Kill the started SSH agent
console.log('Stopping SSH agent')
execSync('kill ${SSH_AGENT_PID}', { stdio: 'inherit' })
console.log('Stopping SSH agent');
execFileSync(sshAgent, ['-k'], { stdio: 'inherit' });
} catch (error) {
console.log(error.message);
console.log('Error stopping the SSH agent, proceeding anyway');
Expand Down Expand Up @@ -480,6 +481,31 @@ module.exports = require("path");

module.exports = require("fs");

/***/ }),

/***/ 972:
/***/ (function(module, __unusedexports, __webpack_require__) {

const os = __webpack_require__(87);

module.exports = (process.env['OS'] != 'Windows_NT') ? {

// Use getent() system call, since this is what ssh does; makes a difference in Docker-based
// Action runs, where $HOME is different from the pwent
home: os.userInfo().homedir,
sshAgent: 'ssh-agent',
sshAdd: 'ssh-add'

} : {

home: os.homedir(),
sshAgent: 'c://progra~1//git//usr//bin//ssh-agent.exe',
sshAdd: 'c://progra~1//git//usr//bin//ssh-add.exe'

};



/***/ })

/******/ });
Loading