Skip to content

Commit

Permalink
Merge pull request #35 from camptocamp/fix3
Browse files Browse the repository at this point in the history
Some little fix
  • Loading branch information
sbrunner authored Dec 14, 2020
2 parents 8006cad + e4f39a8 commit 06a5ab5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/clean.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,7 @@ jobs:
ci-gpg-private-key: ${{secrets.CI_GPG_PRIVATE_KEY}}
github-gopass-ci-token: ${{secrets.GOPASS_CI_GITHUB_TOKEN}}

- run: |
sudo rm /etc/apt/sources.list.d/*.list
sudo apt update
sudo apt install --yes python3-wheel
- run: python3 -m pip install --user c2cciutils
- run: echo ~/.local/bin >> $GITHUB_PATH

- name: Clean docker hub tags
run: c2cciutils-clean
9 changes: 5 additions & 4 deletions c2cciutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,17 @@ def get_config():
if isinstance(config.get("checks", {}).get("required_workflows", {}), dict):
merge(
{
"clean.yaml": {"steps": [{"runs_re": ["c2cciutils-clean$"]}]},
"clean.yaml": {"steps": [{"run_re": "c2cciutils-clean$"}]},
"audit.yaml": {
"steps": [{"runs_re": ["c2cciutils-audit --branch=.*$"], "env": "GITHUB_TOKEN"}],
"steps": [{"run_re": "c2cciutils-audit --branch=.*$", "env": ["GITHUB_TOKEN"]}],
"strategy-fail-fast": False,
},
},
config.get("checks", {}).get("required_workflows", {}),
)
elif (
config["checks"]["versions"].get("rebuild", False)
config["checks"]["versions"]
and config["checks"]["versions"].get("rebuild", False)
and len(config["checks"]["versions"]["rebuild"].get("files", [])) == 0
):
config["checks"]["versions"]["rebuild"] = False
Expand All @@ -196,7 +197,7 @@ def get_config():
required_workflows = {
rebuild: {
"noif": True,
"steps": [{"runs_re": [r"^c2cciutils-publish .*--type.*$"]}],
"steps": [{"run_re": r"^c2cciutils-publish .*--type.*$"}],
"strategy-fail-fast": False,
}
for rebuild in config["checks"]["versions"]["rebuild"].get("files", ["rebuild.yaml"])
Expand Down
21 changes: 12 additions & 9 deletions c2cciutils/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import configparser
import glob
import json
import os
import re
import subprocess
Expand Down Expand Up @@ -313,13 +312,13 @@ def required_workflows(config, full_config, args):
)
success = False
for step_conf in conf.get("steps", []):
run_re = re.compile(step_conf["run_re"]) if "run_re" in conf else None
run_re = re.compile(step_conf["run_re"]) if "run_re" in step_conf else None
found = False
for step in job["steps"]:
current_ok = True
if run_re is not None and run_re.match(step.get("run", "")) is None:
current_ok = False
elif "env" in conf:
elif "env" in step_conf:
# Verify that all the env specified in the config is present in the step of
# the workflow
conf_env = set(step_conf["env"])
Expand All @@ -334,8 +333,8 @@ def required_workflows(config, full_config, args):
if not found:
error(
"required_workflows",
"The workflow '{}', job '{}' doesn't have the step for '{}'.".format(
filename, name, json.dumps(step_conf, indent=2)
"The workflow '{}', job '{}' doesn't have the step for:\n{}".format(
filename, name, yaml.dump(step_conf, Dumper=yaml.SafeDumper).strip()
),
filename,
)
Expand Down Expand Up @@ -621,8 +620,10 @@ def black(config, full_config, args):
if not args.fix:
cmd += ["--color", "--diff"]
cmd.append("--")
cmd += _get_python_files(config.get("ignore_patterns_re", []))
subprocess.check_call(cmd)
python_files = _get_python_files(config.get("ignore_patterns_re", []))
cmd += python_files
if len(python_files) > 0:
subprocess.check_call(cmd)
return True
except subprocess.CalledProcessError:
error(
Expand Down Expand Up @@ -650,8 +651,10 @@ def isort(config, full_config, args):
else:
cmd += ["--check-only", "--diff"]
cmd.append("--")
cmd += _get_python_files(config.get("ignore_patterns_re", []))
subprocess.check_call(cmd)
python_files = _get_python_files(config.get("ignore_patterns_re", []))
cmd += python_files
if len(python_files) > 0:
subprocess.check_call(cmd)
return True
except subprocess.CalledProcessError:
error(
Expand Down
10 changes: 8 additions & 2 deletions c2cciutils/scripts/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,14 @@ def main() -> None:
headers={"Content-Type": "application/json"},
data=json.dumps(
{
"username": subprocess.check_output(["gopass", "show", "gs/ci/dockerhub/username"]).decode(),
"password": subprocess.check_output(["gopass", "show", "gs/ci/dockerhub/password"]).decode(),
"username": os.environ.get(
"DOCKERHUB_USERNAME",
subprocess.check_output(["gopass", "show", "gs/ci/dockerhub/username"]).decode(),
),
"password": os.environ.get(
"DOCKERHUB_PASSWORD",
subprocess.check_output(["gopass", "show", "gs/ci/dockerhub/password"]).decode(),
),
}
),
).json()["token"]
Expand Down

0 comments on commit 06a5ab5

Please sign in to comment.