Skip to content

Commit 11575b2

Browse files
authored
Update the docs about submodules and action ordering.
Fixes webfactory#91
1 parent 5f066a3 commit 11575b2

File tree

1 file changed

+42
-15
lines changed

1 file changed

+42
-15
lines changed

Diff for: README.md

+42-15
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,25 @@ GitHub Actions only have access to the repository they run for. So, in order to
2626
This key should start with `-----BEGIN ... PRIVATE KEY-----`, consist of many lines and ends with `-----END ... PRIVATE KEY-----`.
2727
4. In your workflow definition file, add the following step. Preferably this would be rather on top, near the `actions/checkout@v2` line.
2828

29-
```yaml
30-
# .github/workflows/my-workflow.yml
31-
jobs:
32-
my_job:
33-
...
34-
steps:
35-
- actions/checkout@v2
36-
# Make sure the @v0.5.3 matches the current version of the
37-
# action
38-
- uses: webfactory/[email protected]
39-
with:
40-
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
41-
- ... other steps
42-
```
29+
```yaml
30+
# .github/workflows/my-workflow.yml
31+
jobs:
32+
my_job:
33+
...
34+
steps:
35+
# This action has to precede ssh-agent, since it undoes its effects
36+
- uses: actions/checkout@v2
37+
38+
# Make sure the @v0.5.3 matches the current version of the
39+
# action
40+
- uses: webfactory/[email protected]
41+
with:
42+
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
43+
44+
# Here the ssh keys are available for use
45+
- ... other steps where the repositories are cloned and/or or a submodule update
46+
```
47+
4348
5. If, for some reason, you need to change the location of the SSH agent socket, you can use the `ssh-auth-sock` input to provide a path.
4449

4550
### Using Multiple Keys
@@ -49,7 +54,7 @@ There are cases where you might need to use multiple keys. For example, "[deploy
4954
You can set up different keys as different secrets and pass them all to the action like so:
5055

5156
```yaml
52-
# ... contens as before
57+
# ... contents as before
5358
- uses: webfactory/[email protected]
5459
with:
5560
ssh-private-key: |
@@ -73,6 +78,22 @@ To support picking the right key in this use case, this action scans _key commen
7378
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`.
7479
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.
7580

81+
### Support for Submodules
82+
83+
The submodules are supported, but not directly in the `checkout` action. They have to be cloned *after* the `ssh-agent` step. For example:
84+
85+
```
86+
- uses: webfactory/[email protected]
87+
with:
88+
ssh-private-key: |
89+
${{ secrets.SSH_SUBMODULE1 }}
90+
${{ secrets.SSH_SUBMODULE2 }} # etc.
91+
- name: Checkout submodules
92+
run: git submodule update --init --recursive
93+
```
94+
95+
This works under both Windows and Linux.
96+
7697
## Exported variables
7798
The action exports the `SSH_AUTH_SOCK` and `SSH_AGENT_PID` environment variables through the Github Actions core module.
7899
The `$SSH_AUTH_SOCK` is used by several applications like git or rsync to connect to the SSH authentication agent.
@@ -84,6 +105,12 @@ The `$SSH_AGENT_PID` contains the process id of the agent. This is used to kill
84105

85106
Since each job [runs in a fresh instance](https://help.github.com/en/articles/about-github-actions#job) of the virtual environment, the SSH key will only be available in the job where this action has been referenced. You can, of course, add the action in multiple jobs or even workflows. All instances can use the same `SSH_PRIVATE_KEY` secret.
86107

108+
### Cannot Precede the `checkout` Action
109+
110+
The `ssh-agent` step *cannot* precede the `checkout` step, though. The `checkout` action undoes the effects of `ssh-agent`. This will cause errors like:
111+
112+
ssh: Could not resolve hostname key-<hex-key-id>.github.com: Name or service not known
113+
87114
### SSH Private Key Format
88115

89116
If the private key is not in the `PEM` format, you will see an `Error loading key "(stdin)": invalid format` message.

0 commit comments

Comments
 (0)