tooling: detect ci to commit as github actions bot

+ better dupe pbar
This commit is contained in:
Mark Joshwel 2024-07-29 22:55:51 +08:00
parent a830d5ddb5
commit dce2d72b43

20
sync.py
View file

@ -2,6 +2,7 @@
# forge -> github one-way repo sync script
# licence: 0BSD
from multiprocessing.pool import ThreadPool
from os import getenv
from pathlib import Path
from pprint import pformat
from shutil import copy2, copytree
@ -44,6 +45,7 @@ COMMIT_AUTHOR: Final[str] = "sota staircase ReStepper <ssrestepper@joshwel.co>"
NEUTERED_GITATTRIBUTES: Final[str] = (
"""# auto detect text files and perform lf normalization\n* text=auto\n"""
)
IS_GH_ACT: Final[bool] = getenv("GITHUB_ACTIONS", "").lower() == "true"
# dictionary to share state across steps
r: dict[str, str] = {}
@ -100,6 +102,7 @@ class CopyHighway:
# ignore check 1: dir
for ign_dir in self.lff_result.ignore_directories:
if str(ign_dir) in str(source):
self.pbar.update()
return None
# ignore check 2: file
@ -107,6 +110,7 @@ class CopyHighway:
# ... because we already did that as part of the large file filter,
# ... and as such we checked for it with the first check above
if self.lff_result.matcher.match(source):
self.pbar.update()
return None
self.pool.apply_async(copy2, args=(source, dest), callback=self.callback)
@ -405,7 +409,9 @@ def main() -> None:
"\n"
"directories\n"
f" real repo : {REPO_DIR}\n"
f" temp repo : {dir_temp}\n"
f" temp repo : {dir_temp}\n",
f" is gh act : {IS_GH_ACT}\n" if IS_GH_ACT else "",
sep="",
)
# helper partial function for command
@ -571,9 +577,21 @@ def main() -> None:
)
def add_and_commit() -> CompletedProcess:
if IS_GH_ACT:
cp = cmd("git config user.name 'github-actions[bot]'")()
if cp.returncode != 0:
return cp
cp = cmd(
"git config user.email 'github-actions[bot]@users.noreply.github.com'"
)()
if cp.returncode != 0:
return cp
cp = cmd("git add -A")()
if cp.returncode != 0:
return cp
return cmd(
"git commit --allow-empty "
f'-am "{COMMIT_MESSAGE}" --author="{COMMIT_AUTHOR}"',