Skip to content

Commit

Permalink
wip: Test workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
snaselj committed Mar 4, 2024
1 parent cb301cf commit 2db3bf7
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 17 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/pylint_nautobot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
name: "Latest pylint-nautobot"

on: # yamllint disable-line rule:truthy rule:comments
schedule:
- cron: "0 3 */2 * *" # every other day at 3am
# TBD: Remove running on push
push: ~


jobs:
latest-pylint-nautobot:
runs-on: "ubuntu-22.04"
env:
INVOKE_NAUTOBOT_DEV_EXAMPLE_LOCAL: "True"
steps:
- name: "Check out repository code"
uses: "actions/checkout@v4"
- name: "Setup environment"
uses: "networktocode/gh-action-setup-poetry-environment@v6"
- name: "Linting: black"
# TBD: Fix ref to `develop` branch
run: "poetry run invoke pylint ref=u/snaselj-fix-deps"

40 changes: 23 additions & 17 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,46 +682,52 @@ def hadolint(context):

@task(
help={
"latest": "Use the latest version of pylint-nautobot from GitHub.",
"local_pylint_path": "Path to a local pylint-nautobot repository to use for analysis.",
"ref": "`pylint-nautobot` git reference to use for the analysis, can be a local path to the repository"
", or a git reference e.g. `--ref=develop`. Use currently installed version if empty. (default: Empty)",
}
)
def pylint(context, latest=False, local_pylint_path=""):
def pylint(context, ref=""):
"""Run pylint code analysis."""
command = [

pylint_command = [
"pylint",
'--init-hook="import nautobot; nautobot.setup()"',
"--rcfile=pyproject.toml",
"nautobot_dev_example",
]

if not latest and not local_pylint_path:
run_command(context, " ".join(command))
if not ref:
run_command(context, " ".join(pylint_command))
return

if local_pylint_path:
local_pylint_path = str(Path(local_pylint_path).resolve().absolute())
pip_and_pylint_command = ["pip install"]

command = [
"pip install",
f"-e {local_pylint_path}" if local_pylint_path else "git+https://github.com/nautobot/pylint-nautobot.git",
local_pylint_nautobot_path = Path(ref).resolve().absolute()
if local_pylint_nautobot_path.is_dir() and (local_pylint_nautobot_path / "pyproject.toml").is_file():
pip_and_pylint_command.append(f"-e {local_pylint_nautobot_path}")
else:
local_pylint_nautobot_path = None
pip_and_pylint_command.append(f"git+https://github.com/nautobot/pylint-nautobot.git@{ref}")

pip_and_pylint_command += [
"&&",
*command,
*pylint_command,
]

if is_truthy(context.nautobot_dev_example.local):
context.run(" ".join(command))
context.run(" ".join(pip_and_pylint_command))
return

command = [
docker_run_command = [
"run --rm --entrypoint=''",
f"--volume {local_pylint_path}:{local_pylint_path}" if local_pylint_path else "",
f"--volume {local_pylint_nautobot_path}:{local_pylint_nautobot_path}" if local_pylint_nautobot_path else "",
"-- nautobot sh -c '",
*command,
*pip_and_pylint_command,
"'",
]

docker_compose(context, " ".join(command))
# Do not use `run_command()` to avoid poluting the running container with the installed package
docker_compose(context, " ".join(docker_run_command))


@task(aliases=("a",))
Expand Down

0 comments on commit 2db3bf7

Please sign in to comment.