From b07b55db3e6627071426c797eb99f4e690bb7c01 Mon Sep 17 00:00:00 2001 From: Andy Augustin Date: Sun, 14 Apr 2024 19:59:36 +0200 Subject: [PATCH] feat(#478): :sparkles: WIP add possibility to execute single steps Signed-off-by: Andy Augustin --- Dockerfile | 3 +-- README.md | 28 +++++++++++++++++++++++++++ src/sync_template.sh | 45 +++++++++++++++++++++++++++----------------- 3 files changed, 57 insertions(+), 19 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9ad0e8dc..03008ad1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,8 +27,7 @@ ADD src/*.sh /bin/ RUN chmod +x /bin/entrypoint.sh \ && chmod +x /bin/sync_template.sh \ && chmod +x /bin/sync_common.sh \ - && chmod +x /bin/gpg_no_tty.sh \ - && chmod +x /bin/cli.sh + && chmod +x /bin/gpg_no_tty.sh RUN mkdir -p /root/.ssh \ && ssh-keyscan -t rsa github.com >> /root/.ssh/known_hosts diff --git a/README.md b/README.md index 0d615718..23b1669b 100644 --- a/README.md +++ b/README.md @@ -395,6 +395,34 @@ jobs: ``` +## Lifecycle actions + +The action has different phases which are executed in the following order + +* **preparation** prepare and configure git related things + * init git + * auth related (ssh or github auth) + * [optional] gpg setup +* **prechecks** run some prechecks + * skipped if `is_force_push_pr` parameter is set to `true` + * check if the sync branch is already existing in target repository + * check if new changes of the source repository are already within history +* **pull** pull the changes from the remote repository into the action runtime +* **commit** commit the changes within the action runtime +* **push** + * if `is_force_push_pr` is set to true then a force push will be executed +* **pr** + * eventual create registered labels (:ninja: emojis are supported) + * create a new PR + * if `is_force_push_pr` is set to true then the PR will be created or edited + * [optional] **cleanup** eventual cleanup older PRs of the action +* set **github action outputs** + +If `is_dry_run` parameter is set to true then all stages modifying the github state are not run (e.g. push, cleanup and pr). + +It is possible to run a subset of the mentioned lifecycle actions. +**preparation** and **github action outputs** will be run every time. + ## Lifecycle hooks Different lifecycle hooks are supported. You need to enable the functionality with the option `is_allow_hooks` and set it to `true` diff --git a/src/sync_template.sh b/src/sync_template.sh index 2c080730..e5e92131 100755 --- a/src/sync_template.sh +++ b/src/sync_template.sh @@ -372,7 +372,7 @@ function handle_templatesyncignore() { # Logic ####################################################### -function prechecks() { +function arr_prechecks() { info "prechecks" echo "::group::prechecks" if [ "${IS_FORCE_PUSH_PR}" == "true" ]; then @@ -387,7 +387,7 @@ function prechecks() { } -function checkout_branch_and_pull() { +function arr_checkout_branch_and_pull() { info "checkout branch and pull" cmd_from_yml "prepull" @@ -409,7 +409,7 @@ function checkout_branch_and_pull() { } -function commit() { +function arr_commit() { info "commit" cmd_from_yml "precommit" @@ -428,7 +428,20 @@ function commit() { } -function push_prepare_pr_create_pr() { +function arr_push() { + info "push" + + echo "::group::push" + if [ "$IS_DRY_RUN" == "true" ]; then + warn "dry_run option is set to on. skipping push" + return 0 + fi + cmd_from_yml "prepush" + push "${PR_BRANCH}" "${IS_FORCE_PUSH_PR}" + echo "::endgroup::" +} + +function arr_push_prepare_pr_create_pr() { info "push_prepare_pr_create_pr" if [ "$IS_DRY_RUN" == "true" ]; then warn "dry_run option is set to on. skipping labels check, cleanup older PRs, push and create pr" @@ -456,8 +469,6 @@ function push_prepare_pr_create_pr() { echo "::group::push changes and create PR" - cmd_from_yml "prepush" - push "${PR_BRANCH}" "${IS_FORCE_PUSH_PR}" cmd_from_yml "prepr" if [ "$IS_FORCE_PUSH_PR" == true ] ; then create_or_edit_pr "${PR_TITLE}" "${PR_BODY}" "${UPSTREAM_BRANCH}" "${PR_LABELS}" "${PR_REVIEWERS}" @@ -471,16 +482,16 @@ function push_prepare_pr_create_pr() { declare -A arr -arr["pull"]=checkout_branch_and_pull -arr["commit"]=commit -arr["pr"]=push_prepare_pr_create_pr - -prechecks - -checkout_branch_and_pull - -commit - -push_prepare_pr_create_pr +arr["prechecks"]=arr_prechecks +arr["pull"]=arr_checkout_branch_and_pull +arr["commit"]=arr_commit +arr["push"]=arr_push +arr["pr"]=arr_push_prepare_pr_create_pr + +${arr["prechecks"]} +${arr["pull"]} +${arr["commit"]} +${arr["push"]} +${arr["pr"]} set_github_action_outputs "${PR_BRANCH}" "${TEMPLATE_GIT_HASH}"