Add deploy key functionality (#120)

* Add deploy key functionality
This commit is contained in:
Pascal Zimmermann 2022-06-15 13:46:08 +02:00 committed by GitHub
parent dda7a419b6
commit e69c0c047e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 14 deletions

View File

@ -7,14 +7,14 @@ on:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Verify action syntax
# The action should not publish any real changes, but should succeed.
uses: './'
with:
github_token: '${{ secrets.GITHUB_TOKEN }}'
branch: '${{ github.ref }}'
- uses: actions/checkout@master
- name: Verify action syntax
# The action should not publish any real changes, but should succeed.
uses: './'
with:
github_token: '${{ secrets.GITHUB_TOKEN }}'
branch: '${{ github.ref }}'

View File

@ -39,6 +39,32 @@ jobs:
branch: ${{ github.ref }}
```
An example workflow to authenticate with GitHub Platform via Deploy Keys or in general SSH:
```yaml
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
persist-credentials: true
- name: Create local changes
run: |
...
- name: Commit files
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git commit -m "Add changes" -a
- name: Push changes
uses: ad-m/github-push-action@master
with:
ssh: true
branch: ${{ github.ref }}
```
### Inputs
| name | value | default | description |

View File

@ -13,6 +13,9 @@ inputs:
description: 'GitHub url or GitHub Enterprise url'
required: true
default: ${{ github.server_url }}
ssh:
description: 'Specify if ssh should be used'
required: false
repository:
description: 'Repository name to push. Default or empty value represents current github repository (${GITHUB_REPOSITORY})'
default: ''

View File

@ -2,6 +2,7 @@
set -e
INPUT_FORCE=${INPUT_FORCE:-false}
INPUT_SSH=${INPUT_SSH:-false}
INPUT_TAGS=${INPUT_TAGS:-false}
INPUT_DIRECTORY=${INPUT_DIRECTORY:-'.'}
_FORCE_OPTION=''
@ -13,17 +14,18 @@ echo "Push to branch $INPUT_BRANCH";
exit 1;
};
if ${INPUT_FORCE}; then
_FORCE_OPTION='--force'
fi
if ${INPUT_TAGS}; then
_TAGS='--tags'
fi
cd ${INPUT_DIRECTORY}
remote_repo="${INPUT_GITHUB_URL_PROTOCOL}//${GITHUB_ACTOR}:${INPUT_GITHUB_TOKEN}@${INPUT_GITHUB_URL}/${REPOSITORY}.git"
if ${INPUT_SSH}; then
remote_repo="git@${INPUT_GITHUB_URL}:${REPOSITORY}.git"
else
remote_repo="${INPUT_GITHUB_URL_PROTOCOL}//${GITHUB_ACTOR}:${INPUT_GITHUB_TOKEN}@${INPUT_GITHUB_URL}/${REPOSITORY}.git"
fi
git config --local --add safe.directory ${INPUT_DIRECTORY}
git push "${remote_repo}" HEAD:${INPUT_BRANCH} --follow-tags $_FORCE_OPTION $_TAGS;