feat: add command line argument to irgnore new git commits
- add new argument `--ignore-git-status` to continue even if there are no new commits
- update `update_git_repo` function to accept new argument and skip git status check if argument is passed
- update README.md with new Parameters section
🤖
This commit is contained in:
parent
16bc0974e1
commit
db6fd25741
3 changed files with 27 additions and 14 deletions
|
@ -18,6 +18,10 @@ See `requirements.txt`
|
|||
2. Adapt `config.yml.example` to your needs and save it as `config.yml`
|
||||
3. Run `dc-ops` from the shell or from a cron job
|
||||
|
||||
## Parameters
|
||||
|
||||
See `dc-ops --help`
|
||||
|
||||
## Configuration Options
|
||||
- `loglevel`: (optional) define loglevel. Defaults to "INFO" if not set.
|
||||
- `compose-opts`: (optional) define additional parameters to `docker compose up -d`.
|
||||
|
|
9
dc-ops
9
dc-ops
|
@ -5,6 +5,7 @@
|
|||
# CC-BY-SA (https://creativecommons.org/licenses/by-sa/4.0/deed.de)
|
||||
# for civil use only
|
||||
|
||||
import argparse
|
||||
import logging as log
|
||||
from pathlib import Path
|
||||
|
||||
|
@ -17,6 +18,12 @@ configfile = Path(__file__).with_name("config.yml")
|
|||
with configfile.open("r") as f:
|
||||
cfg = yaml.safe_load(f.read())
|
||||
|
||||
# fmt: off
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--ignore-git-status", action="store_true", help="continue even if there are no new commits") # noqa
|
||||
args = parser.parse_args()
|
||||
# fmt: on
|
||||
|
||||
# init logging
|
||||
loglevel = cfg.get("loglevel", "INFO").upper()
|
||||
log.basicConfig(format="%(message)s", level=loglevel)
|
||||
|
@ -35,7 +42,7 @@ for stack in cfg["stacks"]:
|
|||
log.info(f"* processing {stackdir}")
|
||||
|
||||
# update repo and check for new commits
|
||||
if not update_git_repo(stackdir):
|
||||
if not update_git_repo(stackdir, args.ignore_git_status):
|
||||
continue
|
||||
|
||||
# run pre-command
|
||||
|
|
|
@ -22,22 +22,24 @@ def run_subprocess(command: str, workdir: str) -> bool:
|
|||
return True
|
||||
|
||||
|
||||
def update_git_repo(repo: str) -> bool:
|
||||
def update_git_repo(repo_path: str, ignore_git_status: bool) -> bool:
|
||||
"""update repo and check for new commits
|
||||
|
||||
Args:
|
||||
repo (str): path to git repo
|
||||
repo_path (str): path to git repo
|
||||
ignore_git_status (bool): continue even if no changes
|
||||
|
||||
Returns:
|
||||
bool: False if any step fails
|
||||
"""
|
||||
# create repo instance if it exists
|
||||
try:
|
||||
repo = git.Repo(repo)
|
||||
repo = git.Repo(repo_path)
|
||||
except git.exc.NoSuchPathError:
|
||||
log.error("directory not found")
|
||||
return False
|
||||
|
||||
if not ignore_git_status:
|
||||
# try to fetch latest changes
|
||||
try:
|
||||
repo.git.fetch()
|
||||
|
|
Loading…
Reference in a new issue