From bb3766ad6abf5b7209c3284683821505139e5065 Mon Sep 17 00:00:00 2001 From: Elliot Date: Fri, 2 Sep 2022 10:53:40 +0100 Subject: [PATCH 1/2] 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 --- start.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/start.sh b/start.sh index 1bbc320..bf8c48a 100755 --- a/start.sh +++ b/start.sh @@ -43,8 +43,8 @@ fi git config --local --add safe.directory ${INPUT_DIRECTORY} if ${INPUT_FORCE_WITH_LEASE}; then - git push --follow-tags $_FORCE_OPTION $_TAGS; + git push --atomic --follow-tags $_FORCE_OPTION $_TAGS; else - git push "${remote_repo}" HEAD:${INPUT_BRANCH} --verbose --follow-tags $_FORCE_OPTION $_TAGS; + git push "${remote_repo}" HEAD:${INPUT_BRANCH} --atomic --verbose --follow-tags $_FORCE_OPTION $_TAGS; fi From 00483b0482e0b4fd07f827d99e04e1ccde99cf36 Mon Sep 17 00:00:00 2001 From: Elliot Iddon Date: Tue, 4 Oct 2022 13:36:07 +0100 Subject: [PATCH 2/2] Add option to control atomic switch --- README.md | 1 + action.yml | 3 +++ start.sh | 10 ++++++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5fbd420..eb9b57a 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,7 @@ jobs: | 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. | diff --git a/action.yml b/action.yml index fc15686..d3af2ce 100644 --- a/action.yml +++ b/action.yml @@ -29,6 +29,9 @@ inputs: 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 diff --git a/start.sh b/start.sh index bf8c48a..b3c0394 100755 --- a/start.sh +++ b/start.sh @@ -1,11 +1,13 @@ #!/bin/sh set -e +INPUT_ATOMIC=${INPUT_ATOMIC:-true} 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:-'.'} +_ATOMIC_OPTION='' _FORCE_OPTION='' REPOSITORY=${INPUT_REPOSITORY:-$GITHUB_REPOSITORY} @@ -20,6 +22,10 @@ if ${INPUT_FORCE} && ${INPUT_FORCE_WITH_LEASE}; then exit 1; fi +if ${INPUT_ATOMIC}; then + _ATOMIC_OPTION='--atomic' +fi + if ${INPUT_FORCE}; then _FORCE_OPTION='--force' fi @@ -43,8 +49,8 @@ fi git config --local --add safe.directory ${INPUT_DIRECTORY} if ${INPUT_FORCE_WITH_LEASE}; then - git push --atomic --follow-tags $_FORCE_OPTION $_TAGS; + git push $_ATOMIC_OPTION --follow-tags $_FORCE_OPTION $_TAGS; else - git push "${remote_repo}" HEAD:${INPUT_BRANCH} --atomic --verbose --follow-tags $_FORCE_OPTION $_TAGS; + git push "${remote_repo}" HEAD:${INPUT_BRANCH} $_ATOMIC_OPTION --verbose --follow-tags $_FORCE_OPTION $_TAGS; fi