Skip to content

Commit d4a6a78

Browse files
authored
Add deploy key functionality (ad-m#115)
* Add deploy key functionality
1 parent 694e694 commit d4a6a78

File tree

4 files changed

+45
-10
lines changed

4 files changed

+45
-10
lines changed

.github/workflows/build.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ on:
77
jobs:
88

99
build:
10-
10+
1111
runs-on: ubuntu-latest
12-
12+
1313
steps:
14-
- uses: actions/checkout@master
15-
- name: Verify action syntax
16-
# The action should not publish any real changes, but should succeed.
17-
uses: './'
18-
with:
19-
github_token: '${{ secrets.GITHUB_TOKEN }}'
20-
branch: '${{ github.ref }}'
14+
- uses: actions/checkout@master
15+
- name: Verify action syntax
16+
# The action should not publish any real changes, but should succeed.
17+
uses: './'
18+
with:
19+
github_token: '${{ secrets.GITHUB_TOKEN }}'
20+
branch: '${{ github.ref }}'

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,37 @@ jobs:
3939
branch: ${{ github.ref }}
4040
```
4141
42+
An example workflow to authenticate with GitHub Platform via Deploy Keys or in general SSH:
43+
44+
```yaml
45+
jobs:
46+
build:
47+
runs-on: ubuntu-latest
48+
steps:
49+
- uses: actions/checkout@v3
50+
with:
51+
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
52+
- name: Create local changes
53+
run: |
54+
...
55+
- name: Commit files
56+
run: |
57+
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
58+
git config --local user.name "github-actions[bot]"
59+
git commit -m "Add changes" -a
60+
- name: Push changes
61+
uses: ad-m/github-push-action@master
62+
with:
63+
branch: ${{ github.ref }}
64+
ssh: true
65+
```
66+
4267
### Inputs
4368

4469
| name | value | default | description |
4570
| ---- | ----- | ------- | ----------- |
4671
| github_token | string | `${{ github.token }}` | [GITHUB_TOKEN](https://docs.github.com/en/actions/security-guides/automatic-token-authentication#using-the-github_token-in-a-workflow) <br /> or a repo scoped <br /> [Personal Access Token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token). |
72+
| ssh | boolean | false | Determines if ssh is used. |
4773
| branch | string | (default) | Destination branch to push changes. <br /> Can be passed in using `${{ github.ref }}`. |
4874
| force | boolean | false | Determines if force push is used. |
4975
| tags | boolean | false | Determines if `--tags` is used. |

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ inputs:
1313
description: 'GitHub url or GitHub Enterprise url'
1414
required: true
1515
default: ${{ github.server_url }}
16+
ssh:
17+
description: 'Specify if ssh should be used'
18+
required: false
1619
repository:
1720
description: 'Repository name to push. Default or empty value represents current github repository (${GITHUB_REPOSITORY})'
1821
default: ''

start.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@ fi
2323

2424
cd ${INPUT_DIRECTORY}
2525

26-
remote_repo="${INPUT_GITHUB_URL_PROTOCOL}//${GITHUB_ACTOR}:${INPUT_GITHUB_TOKEN}@${INPUT_GITHUB_URL}/${REPOSITORY}.git"
26+
27+
if ${INPUT_SSH}; then
28+
remote_repo="git@${INPUT_GITHUB_URL}:${REPOSITORY}.git"
29+
else
30+
remote_repo="${INPUT_GITHUB_URL_PROTOCOL}//${GITHUB_ACTOR}:${INPUT_GITHUB_TOKEN}@${INPUT_GITHUB_URL}/${REPOSITORY}.git"
31+
fi
32+
2733
git config --local --add safe.directory ${INPUT_DIRECTORY}
2834

2935
git push "${remote_repo}" HEAD:${INPUT_BRANCH} --follow-tags $_FORCE_OPTION $_TAGS;

0 commit comments

Comments
 (0)