summaryrefslogtreecommitdiff
path: root/.github/workflows/dependencies
diff options
context:
space:
mode:
authorCarlo Sala <carlosalag@protonmail.com>2024-05-21 20:43:26 +0200
committerCarlo Sala <carlosalag@protonmail.com>2024-05-21 20:43:26 +0200
commit0621944db50aec931850806644b673e39b650163 (patch)
tree4009c300a84720c655c1c30771182de3f8eb1559 /.github/workflows/dependencies
parent309129f651eeeca62c3a3b7f6817f0ac601db9f0 (diff)
downloadzsh-0621944db50aec931850806644b673e39b650163.tar.gz
zsh-0621944db50aec931850806644b673e39b650163.tar.bz2
zsh-0621944db50aec931850806644b673e39b650163.zip
fix(dependencies): only open PR if there are changes
Diffstat (limited to '.github/workflows/dependencies')
-rw-r--r--.github/workflows/dependencies/updater.py78
1 files changed, 44 insertions, 34 deletions
diff --git a/.github/workflows/dependencies/updater.py b/.github/workflows/dependencies/updater.py
index 4533b7aeb..e64d69939 100644
--- a/.github/workflows/dependencies/updater.py
+++ b/.github/workflows/dependencies/updater.py
@@ -228,21 +228,22 @@ class Dependency:
self.__apply_upstream_changes()
# Add all changes and commit
- Git.add_and_commit(self.name, short_sha)
+ has_new_commit = Git.add_and_commit(self.name, short_sha)
- # Push changes to remote
- Git.push(branch)
+ if has_new_commit:
+ # Push changes to remote
+ Git.push(branch)
- # Create GitHub PR
- GitHub.create_pr(
- branch,
- f"feat({self.name}): update to version {new_version}",
- f"""## Description
+ # Create GitHub PR
+ GitHub.create_pr(
+ branch,
+ f"feat({self.name}): update to version {new_version}",
+ f"""## Description
-Update for **{self.desc}**: update to version [{new_version}]({status['head_url']}).
-Check out the [list of changes]({status['compare_url']}).
-""",
- )
+ Update for **{self.desc}**: update to version [{new_version}]({status['head_url']}).
+ Check out the [list of changes]({status['compare_url']}).
+ """,
+ )
# Clean up repository
Git.clean_repo()
@@ -377,7 +378,21 @@ class Git:
return branch_name
@staticmethod
- def add_and_commit(scope: str, version: str):
+ def add_and_commit(scope: str, version: str) -> bool:
+ """
+ Returns `True` if there were changes and were indeed commited.
+ Returns `False` if the repo was clean and no changes were commited.
+ """
+ # check if repo is clean (clean => no error, no commit)
+ try:
+ CommandRunner.run_or_fail(
+ ["git", "diff", "--exit-code"], stage="CheckRepoClean"
+ )
+ return False
+ except CommandRunner.Exception:
+ # if it's other kind of error just throw!
+ pass
+
user_name = os.environ.get("GIT_APP_NAME")
user_email = os.environ.get("GIT_APP_EMAIL")
@@ -390,27 +405,22 @@ class Git:
clean_env["GIT_CONFIG_GLOBAL"] = "/dev/null"
clean_env["GIT_CONFIG_NOSYSTEM"] = "1"
- # check if repo is clean (clean => no error, no commit)
- try:
- CommandRunner.run_or_fail(
- ["git", "diff", "--exit-code"], stage="CheckRepoClean", env=clean_env
- )
- except CommandRunner.Exception:
- # Commit with settings above
- CommandRunner.run_or_fail(
- [
- "git",
- "-c",
- f"user.name={user_name}",
- "-c",
- f"user.email={user_email}",
- "commit",
- "-m",
- f"feat({scope}): update to {version}",
- ],
- stage="CreateCommit",
- env=clean_env,
- )
+ # Commit with settings above
+ CommandRunner.run_or_fail(
+ [
+ "git",
+ "-c",
+ f"user.name={user_name}",
+ "-c",
+ f"user.email={user_email}",
+ "commit",
+ "-m",
+ f"feat({scope}): update to {version}",
+ ],
+ stage="CreateCommit",
+ env=clean_env,
+ )
+ return True
@staticmethod
def push(branch: str):