Skip to content

Commit 8b7f16d

Browse files
jackton1ZPascal
authored andcommitted
chore: remove redundant safe-directory configuration
This has been resolved in the [checkout](actions/checkout#770) action and would already be set by default. Update README.md Fix removed code lines * Add force with lease support * Update the documentation fix: github_token and github_url optional Add atomic push Since time elapses between the checkout the github workflow performs and the eventual push this action invokes the remote HEAD may have changed. If this is the case the HEAD update will be rejected but any tag (and their commits) will be pushed. In general I think this operation should be atomic, either we push everything or we push nothing. Force pushes still work the way you would expect (i.e. if we force the HEAD update with --atomic everything is still pushed) This also protects from the situation where someone else has seized your tag name in the meantime but not updated your HEAD. See git docs for more information - https://git-scm.com/docs/git-push#Documentation/git-push.txt---no-atomic Add option to control atomic switch Use node16 to run action Node.js 12 actions are deprecated. For more information see: https://github.blog/changelog/2022-09-22-github-actions-all-actions-will-begin-running-on-node16-instead-of-node12/. Update the documentation and the push process feat: Restructure the code Update the documentation and the push process
1 parent e69c0c0 commit 8b7f16d

File tree

3 files changed

+96
-13
lines changed

3 files changed

+96
-13
lines changed

README.md

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,53 @@ jobs:
3939
branch: ${{ github.ref }}
4040
```
4141
42+
An example workflow to use the force-with-lease parameter to force push to a repository:
43+
44+
```yaml
45+
jobs:
46+
build:
47+
runs-on: ubuntu-latest
48+
steps:
49+
- uses: actions/checkout@v3
50+
with:
51+
ref: ${{ github.head_ref }}
52+
fetch-depth: 0
53+
- name: Commit files
54+
run: |
55+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
56+
git config --local user.name "github-actions[bot]"
57+
git commit -m "Add changes" -a
58+
- name: Push changes
59+
uses: ad-m/github-push-action@master
60+
with:
61+
force_with_lease: true
62+
```
63+
64+
An example workflow to update/ overwrite an existing tag:
65+
66+
```yaml
67+
jobs:
68+
build:
69+
runs-on: ubuntu-latest
70+
steps:
71+
- uses: actions/checkout@v3
72+
with:
73+
ref: ${{ github.head_ref }}
74+
fetch-depth: 0
75+
- name: Commit files
76+
run: |
77+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
78+
git config --local user.name "github-actions[bot]"
79+
git tag -d $GITHUB_REF_NAME
80+
git tag $GITHUB_REF_NAME
81+
git commit -m "Add changes" -a
82+
- name: Push changes
83+
uses: ad-m/github-push-action@master
84+
with:
85+
force: true
86+
tags: true
87+
```
88+
4289
An example workflow to authenticate with GitHub Platform via Deploy Keys or in general SSH:
4390
4491
```yaml
@@ -67,18 +114,21 @@ jobs:
67114
68115
### Inputs
69116
70-
| name | value | default | description |
71-
| ---- | ----- | ------- | ----------- |
72-
| 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). |
73-
| branch | string | (default) | Destination branch to push changes. <br /> Can be passed in using `${{ github.ref }}`. |
74-
| force | boolean | false | Determines if force push is used. |
75-
| tags | boolean | false | Determines if `--tags` is used. |
76-
| directory | string | '.' | Directory to change to before pushing. |
77-
| 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. |
117+
| name | value | default | description |
118+
|------------------| ----- | ------- |-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
119+
| 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). |
120+
| ssh | boolean | false | Determines if ssh/ Deploy Keys is used. |
121+
| branch | string | (default) | Destination branch to push changes. <br /> Can be passed in using `${{ github.ref }}`. |
122+
| force | boolean | false | Determines if force push is used. |
123+
| 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 }}`. |
124+
| atomic | boolean | true | Determines if [atomic](https://git-scm.com/docs/git-push#Documentation/git-push.txt---no-atomic) push is used. |
125+
| tags | boolean | false | Determines if `--tags` is used. |
126+
| directory | string | '.' | Directory to change to before pushing. |
127+
| 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. |
78128

79129
## Troubeshooting
80130

81-
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`:
131+
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`:
82132
```log
83133
Push to branch ***************
84134
fatal: unsafe repository ('/github/workspace' is owned by someone else)
@@ -87,6 +137,15 @@ To add an exception for this directory, call:
87137
git config --global --add safe.directory /github/workspace
88138
```
89139

140+
If you see the following error inside the output of the job, and you want to update an existing Tag:
141+
```log
142+
To https://github.com/Test/test_repository
143+
! [rejected] 0.0.9 -> 0.0.9 (stale info)
144+
error: failed to push some refs to 'https://github.com/Test/test_repository'
145+
```
146+
147+
Please use the `force` instead the `force_with_lease` parameter. The update of the tag is with the `--force-with-lease` parameter not possible.
148+
90149
## License
91150

92151
The Dockerfile and associated scripts and documentation in this project are released under the [MIT License](LICENSE).

action.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ branding:
77
inputs:
88
github_token:
99
description: 'GitHub token or PAT token'
10-
required: true
10+
required: false
1111
default: ${{ github.token }}
1212
github_url:
1313
description: 'GitHub url or GitHub Enterprise url'
14-
required: true
14+
required: false
1515
default: ${{ github.server_url }}
1616
ssh:
1717
description: 'Specify if ssh should be used'
@@ -26,6 +26,12 @@ inputs:
2626
force:
2727
description: 'Determines if force push is used'
2828
required: false
29+
force_with_lease:
30+
description: 'Determines if force-with-lease push is used'
31+
required: false
32+
atomic:
33+
description: 'Determines if atomic push is used, default true'
34+
required: false
2935
tags:
3036
description: 'Determines if --tags is used'
3137
required: false
@@ -34,5 +40,5 @@ inputs:
3440
required: false
3541
default: '.'
3642
runs:
37-
using: 'node12'
43+
using: 'node16'
3844
main: 'start.js'

start.sh

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
set -e
33

44
INPUT_FORCE=${INPUT_FORCE:-false}
5+
INPUT_FORCE_WITH_LEASE=${INPUT_FORCE_WITH_LEASE:-false}
56
INPUT_SSH=${INPUT_SSH:-false}
67
INPUT_TAGS=${INPUT_TAGS:-false}
78
INPUT_DIRECTORY=${INPUT_DIRECTORY:-'.'}
@@ -14,6 +15,19 @@ echo "Push to branch $INPUT_BRANCH";
1415
exit 1;
1516
};
1617

18+
if ${INPUT_FORCE} && ${INPUT_FORCE_WITH_LEASE}; then
19+
echo 'Please, specify only force or force_with_lease and not both.';
20+
exit 1;
21+
fi
22+
23+
if ${INPUT_FORCE}; then
24+
_FORCE_OPTION='--force'
25+
fi
26+
27+
if ${INPUT_FORCE_WITH_LEASE}; then
28+
_FORCE_OPTION='--force-with-lease'
29+
fi
30+
1731
if ${INPUT_TAGS}; then
1832
_TAGS='--tags'
1933
fi
@@ -28,4 +42,8 @@ fi
2842

2943
git config --local --add safe.directory ${INPUT_DIRECTORY}
3044

31-
git push "${remote_repo}" HEAD:${INPUT_BRANCH} --follow-tags $_FORCE_OPTION $_TAGS;
45+
if ! ${INPUT_FORCE_WITH_LEASE}; then
46+
ADDITIONAL_PARAMETERS="${remote_repo} HEAD:${INPUT_BRANCH}"
47+
fi
48+
49+
git push $ADDITIONAL_PARAMETERS --follow-tags $_FORCE_OPTION $_TAGS;

0 commit comments

Comments
 (0)