Skip to content

Commit

Permalink
feat(#478): ✨ WIP add possibility to execute single steps
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Augustin <dev@andreas-augustin.org>
  • Loading branch information
AndreasAugustin committed Apr 14, 2024
1 parent cafbaa5 commit b07b55d
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 19 deletions.
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
45 changes: 28 additions & 17 deletions src/sync_template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"

Expand All @@ -409,7 +409,7 @@ function checkout_branch_and_pull() {
}


function commit() {
function arr_commit() {
info "commit"

cmd_from_yml "precommit"
Expand All @@ -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"
Expand Down Expand Up @@ -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}"
Expand All @@ -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}"

0 comments on commit b07b55d

Please sign in to comment.