diff --git a/README.md b/README.md
index 092b27d..dbe2064 100644
--- a/README.md
+++ b/README.md
@@ -39,6 +39,53 @@ 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 update/ overwrite an existing tag:
+
+```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 tag -d $GITHUB_REF_NAME
+ git tag $GITHUB_REF_NAME
+ git commit -m "Add changes" -a
+ - name: Push changes
+ uses: ad-m/github-push-action@master
+ with:
+ force: true
+ tags: true
+```
+
An example workflow to authenticate with GitHub Platform via Deploy Keys or in general SSH:
```yaml
@@ -67,18 +114,21 @@ 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 }}`. |
+| atomic | boolean | true | Determines if [atomic](https://git-scm.com/docs/git-push#Documentation/git-push.txt---no-atomic) 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. |
## Troubeshooting
-Please be aware, if your job fails and the corresponding output log looks like the following error, update your used verson of the action to `ad-m/github-push-action@master`:
+Please be aware, if your job fails and the corresponding output log looks like the following error, update your used version of the action to `ad-m/github-push-action@master`:
```log
Push to branch ***************
fatal: unsafe repository ('/github/workspace' is owned by someone else)
@@ -87,6 +137,15 @@ To add an exception for this directory, call:
git config --global --add safe.directory /github/workspace
```
+If you see the following error inside the output of the job, and you want to update an existing Tag:
+```log
+To https://github.com/Test/test_repository
+ ! [rejected] 0.0.9 -> 0.0.9 (stale info)
+error: failed to push some refs to 'https://github.com/Test/test_repository'
+```
+
+Please use the `force` instead the `force_with_lease` parameter. The update of the tag is with the `--force-with-lease` parameter not possible.
+
## License
The Dockerfile and associated scripts and documentation in this project are released under the [MIT License](LICENSE).
diff --git a/action.yml b/action.yml
index 1f3d910..1b54480 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,12 @@ 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
+ atomic:
+ description: 'Determines if atomic push is used, default true'
+ required: false
tags:
description: 'Determines if --tags is used'
required: false
@@ -34,5 +40,5 @@ inputs:
required: false
default: '.'
runs:
- using: 'node12'
+ using: 'node16'
main: 'start.js'
diff --git a/start.sh b/start.sh
index c14e139..a7ce947 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,6 +15,19 @@ 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
+
+if ${INPUT_FORCE_WITH_LEASE}; then
+ _FORCE_OPTION='--force-with-lease'
+fi
+
if ${INPUT_TAGS}; then
_TAGS='--tags'
fi
@@ -28,4 +42,8 @@ fi
git config --local --add safe.directory ${INPUT_DIRECTORY}
-git push "${remote_repo}" HEAD:${INPUT_BRANCH} --follow-tags $_FORCE_OPTION $_TAGS;
+if ! ${INPUT_FORCE_WITH_LEASE}; then
+ ADDITIONAL_PARAMETERS="${remote_repo} HEAD:${INPUT_BRANCH}"
+fi
+
+git push $ADDITIONAL_PARAMETERS --follow-tags $_FORCE_OPTION $_TAGS;