diff --git a/README.md b/README.md
index ae3faf4..e919f16 100644
--- a/README.md
+++ b/README.md
@@ -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
@@ -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)
or a repo scoped
[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.
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.
Default or empty repository name represents
current github repository.
If you want to push to other repository,
you should make a [personal access token](https://github.com/settings/tokens)
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)
or a repo scoped
[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.
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.
Default or empty repository name represents
current github repository.
If you want to push to other repository,
you should make a [personal access token](https://github.com/settings/tokens)
and use it as the `github_token` input. |
## License
diff --git a/action.yml b/action.yml
index 1f3d910..fc15686 100644
--- a/action.yml
+++ b/action.yml
@@ -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'
@@ -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
diff --git a/start.sh b/start.sh
index ce5a4a7..cd6c1d9 100755
--- a/start.sh
+++ b/start.sh
@@ -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:-'.'}
@@ -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'
@@ -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