Skip to content

Commit

Permalink
Chore/dry run (#232)
Browse files Browse the repository at this point in the history
 feat(dry-run): (#209) add option for dry_run 🚀
  • Loading branch information
AndreasAugustin authored Dec 5, 2022
1 parent 4509e27 commit 8b2b8ab
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 12 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}
source_repo_path: AndreasAugustin/template.git
upstream_branch: main
is_dry_run: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.env
tmp*
TODO.md
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ You will receive a pull request within your repository if there are some changes
| pr_title | `[optional]` the title of PRs opened by this action. Must be already created. | `false` | `upstream merge template repository` |
| pr_labels | `[optional]` comma separated list. [pull request labels][pr-labels]. Must be already created. | `false` | |
| hostname | `[optional]` the hostname of the repository | `false` | `github.com` |
| is_dry_run | `[optional]` set to `true` if you do not want to push the changes and not want to create a PR | `false` | |

### Example

Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ inputs:
hostname:
description: '[optional] the hostname of the GitHub repository'
default: 'github.com'
is_dry_run:
description: '[optional] set to true if you do not want to push the changes and not want to create a PR'
runs:
using: 'docker'
image: 'src/Dockerfile'
Expand All @@ -40,3 +42,4 @@ runs:
PR_TITLE: ${{ inputs.pr_title }}
PR_LABELS: ${{ inputs.pr_labels }}
HOSTNAME: ${{ inputs.hostname }}
IS_DRY_RUN: ${{ inputs.is_dry_run }}
6 changes: 5 additions & 1 deletion docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ GitPullSync["pull from remote repository"]
CheckIgnoreFileExistsSync{"check if .templatesyncignore file exists"}
ResetChangesSync["Reset the changes listed within the ignore file"]
GitCommitSync["commit the changes"]
CheckIsDryRun{"check if is_dry_run is set to true"}
GitPushSync["Push the changes to GitHub"]
GitPullRequestSync["create a pull request on GitHub"]
Expand Down Expand Up @@ -82,7 +84,9 @@ ResetChangesSync --> GitCommitSync
end
subgraph github["gitHub actions"]
GitCommitSync --> GitPushSync
GitCommitSync --> CheckIsDryRun
CheckIsDryRun -->|is true| Exit
CheckIsDryRun -->|is not true| GitPushSync
GitPushSync --> GitPullRequestSync
GitPullRequestSync --> Exit
Expand Down
30 changes: 19 additions & 11 deletions src/sync_template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,22 @@ fi

git commit -m "chore(template): merge template changes :up:"

echo "::debug::push changes"
git push --set-upstream origin "${NEW_BRANCH}"
echo "::endgroup::"

echo "::group::create pull request"
gh pr create \
--title "${PR_TITLE}" \
--body "Merge ${SOURCE_REPO_PATH} ${NEW_TEMPLATE_GIT_HASH}" \
-B "${UPSTREAM_BRANCH}" \
-l "${PR_LABELS}"
echo "::endgroup::"
push_and_create_pr () {
if [ "$IS_DRY_RUN" != "true" ]; then
echo "::debug::push changes"
git push --set-upstream origin "${NEW_BRANCH}"
echo "::endgroup::"

echo "::group::create pull request"
gh pr create \
--title "${PR_TITLE}" \
--body "Merge ${SOURCE_REPO_PATH} ${NEW_TEMPLATE_GIT_HASH}" \
-B "${UPSTREAM_BRANCH}" \
-l "${PR_LABELS}"
echo "::endgroup::"
else
echo "::warn::dry_run option is set to off. Skipping push changes and skip create pr"
fi
}

push_and_create_pr

0 comments on commit 8b2b8ab

Please sign in to comment.