Skip to content

Commit

Permalink
Merge branch 'master' into patch-4
Browse files Browse the repository at this point in the history
  • Loading branch information
ZPascal committed Jun 30, 2022
2 parents 84236bd + 9a46ba8 commit 7e6f17c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 13 deletions.
39 changes: 31 additions & 8 deletions README.md
Expand Up @@ -39,6 +39,27 @@ jobs:
branch: ${{ github.ref }}
```

An example workflow to use the force-with-lease parameter to force push to a repository:

```yaml
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
fetch-depth: 0
- name: Commit files
run: |
git config --local user.email "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:
force_with_lease: true
```
An example workflow to authenticate with GitHub Platform via Deploy Keys or in general SSH:

```yaml
Expand Down Expand Up @@ -67,14 +88,16 @@ jobs:

### Inputs

| name | value | default | description |
| ---- | ----- | ------- | ----------- |
| 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). |
| branch | string | (default) | Destination branch to push changes. <br /> Can be passed in using `${{ github.ref }}`. |
| force | boolean | false | Determines if force push is used. |
| tags | boolean | false | Determines if `--tags` is used. |
| directory | string | '.' | Directory to change to before pushing. |
| repository | string | '' | Repository name. <br /> Default or empty repository name represents <br /> current github repository. <br /> If you want to push to other repository, <br /> you should make a [personal access token](https://github.com/settings/tokens) <br /> and use it as the `github_token` input. |
| name | value | default | description |
|------------------| ----- | ------- |-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 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). |
| ssh | boolean | false | Determines if ssh/ Deploy Keys is used. |
| branch | string | (default) | Destination branch to push changes. <br /> Can be passed in using `${{ github.ref }}`. |
| force | boolean | false | Determines if force push is used. |
| force_with_lease | boolean | false | Determines if force-with-lease push is used. Please specify the corresponding branch inside `ref` section of the checkout action e.g. `ref: ${{ github.head_ref }}`. |
| tags | boolean | false | Determines if `--tags` is used. |
| directory | string | '.' | Directory to change to before pushing. |
| repository | string | '' | Repository name. <br /> Default or empty repository name represents <br /> current github repository. <br /> If you want to push to other repository, <br /> you should make a [personal access token](https://github.com/settings/tokens) <br /> and use it as the `github_token` input. |

## License

Expand Down
7 changes: 5 additions & 2 deletions action.yml
Expand Up @@ -7,11 +7,11 @@ branding:
inputs:
github_token:
description: 'GitHub token or PAT token'
required: true
required: false
default: ${{ github.token }}
github_url:
description: 'GitHub url or GitHub Enterprise url'
required: true
required: false
default: ${{ github.server_url }}
ssh:
description: 'Specify if ssh should be used'
Expand All @@ -26,6 +26,9 @@ inputs:
force:
description: 'Determines if force push is used'
required: false
force_with_lease:
description: 'Determines if force-with-lease push is used'
required: false
tags:
description: 'Determines if --tags is used'
required: false
Expand Down
20 changes: 17 additions & 3 deletions start.sh
Expand Up @@ -2,6 +2,7 @@
set -e

INPUT_FORCE=${INPUT_FORCE:-false}
INPUT_FORCE_WITH_LEASE=${INPUT_FORCE_WITH_LEASE:-false}
INPUT_SSH=${INPUT_SSH:-false}
INPUT_TAGS=${INPUT_TAGS:-false}
INPUT_DIRECTORY=${INPUT_DIRECTORY:-'.'}
Expand All @@ -14,9 +15,18 @@ echo "Push to branch $INPUT_BRANCH";
exit 1;
};

if ${INPUT_FORCE} && ${INPUT_FORCE_WITH_LEASE}; then
echo 'Please, specify only force or force_with_lease and not both.';
exit 1;
fi

if ${INPUT_FORCE}; then
_FORCE_OPTION='--force'
fi
_FORCE_OPTION='--force'
fi

if ${INPUT_FORCE_WITH_LEASE}; then
_FORCE_OPTION='--force-with-lease'
fi

if ${INPUT_TAGS}; then
_TAGS='--tags'
Expand All @@ -30,4 +40,8 @@ else
remote_repo="${INPUT_GITHUB_URL_PROTOCOL}//${GITHUB_ACTOR}:${INPUT_GITHUB_TOKEN}@${INPUT_GITHUB_URL}/${REPOSITORY}.git"
fi

git push "${remote_repo}" HEAD:${INPUT_BRANCH} --follow-tags $_FORCE_OPTION $_TAGS;
if ${INPUT_FORCE_WITH_LEASE}; then
git push --follow-tags $_FORCE_OPTION $_TAGS;
else
git push "${remote_repo}" HEAD:${INPUT_BRANCH} --verbose --follow-tags $_FORCE_OPTION $_TAGS;
fi

0 comments on commit 7e6f17c

Please sign in to comment.