diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 95e9d19..0576199 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,3 +18,4 @@ jobs: github_token: ${{ secrets.GITHUB_TOKEN }} source_repo_path: AndreasAugustin/template.git upstream_branch: main + is_dry_run: true diff --git a/.gitignore b/.gitignore index de6a67a..5861889 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .env tmp* +TODO.md diff --git a/README.md b/README.md index da63973..b2d1887 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/action.yml b/action.yml index bf42ef4..1112e28 100644 --- a/action.yml +++ b/action.yml @@ -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' @@ -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 }} diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 2320fc2..7db2f18 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -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"] @@ -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 diff --git a/src/sync_template.sh b/src/sync_template.sh index 10e9746..d01629c 100755 --- a/src/sync_template.sh +++ b/src/sync_template.sh @@ -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