bitwarden_workflow_linter 0.13.0__tar.gz → 0.14.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/PKG-INFO +1 -1
  2. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/src/bitwarden_workflow_linter/__about__.py +1 -1
  3. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/src/bitwarden_workflow_linter/default_actions.json +5 -0
  4. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/src/bitwarden_workflow_linter/rules/run_actionlint.py +32 -15
  5. bitwarden_workflow_linter-0.14.0/tests/rules/test_run_actionlint.py +377 -0
  6. bitwarden_workflow_linter-0.13.0/tests/rules/test_run_actionlint.py +0 -190
  7. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/.editorconfig +0 -0
  8. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/.gitattributes +0 -0
  9. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/.github/CODEOWNERS +0 -0
  10. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/.github/ISSUE_TEMPLATE/config.yml +0 -0
  11. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
  12. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/.github/renovate.json +0 -0
  13. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/.github/workflows/_version_type.yml +0 -0
  14. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/.github/workflows/actionlint_windows.yml +0 -0
  15. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/.github/workflows/bwwl_operations.yml +0 -0
  16. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/.github/workflows/cd.yml +0 -0
  17. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/.github/workflows/ci.yml +0 -0
  18. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/.github/workflows/enforce-labels.yml +0 -0
  19. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/.github/workflows/examples/ci.yaml +0 -0
  20. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/.github/workflows/examples/example-references/_build.yml +0 -0
  21. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/.github/workflows/examples/example-references/_docker.yml +0 -0
  22. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/.github/workflows/examples/example-references/_test.yml +0 -0
  23. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/.github/workflows/examples/example-references/_version.yml +0 -0
  24. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/.github/workflows/examples/example.yaml +0 -0
  25. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/.github/workflows/examples/scan.yaml +0 -0
  26. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/.github/workflows/scan.yml +0 -0
  27. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/.gitignore +0 -0
  28. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/.husky/pre-commit +0 -0
  29. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/.python-version +0 -0
  30. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/CONTRIBUTING.md +0 -0
  31. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/LICENSE.txt +0 -0
  32. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/Pipfile +0 -0
  33. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/Pipfile.lock +0 -0
  34. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/README.md +0 -0
  35. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/RULE_ROLLOUT.md +0 -0
  36. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/SECURITY.md +0 -0
  37. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/Taskfile.yml +0 -0
  38. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/actionlint_version.json +0 -0
  39. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/package-lock.json +0 -0
  40. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/package.json +0 -0
  41. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/pylintrc +0 -0
  42. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/pyproject.toml +0 -0
  43. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/pyproject.toml.tpl +0 -0
  44. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/settings.yaml +0 -0
  45. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/src/bitwarden_workflow_linter/__init__.py +0 -0
  46. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/src/bitwarden_workflow_linter/actionlint_version.yaml +0 -0
  47. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/src/bitwarden_workflow_linter/actions.py +0 -0
  48. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/src/bitwarden_workflow_linter/cli.py +0 -0
  49. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/src/bitwarden_workflow_linter/default_settings.yaml +0 -0
  50. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/src/bitwarden_workflow_linter/lint.py +0 -0
  51. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/src/bitwarden_workflow_linter/load.py +0 -0
  52. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/src/bitwarden_workflow_linter/models/__init__.py +0 -0
  53. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/src/bitwarden_workflow_linter/models/job.py +0 -0
  54. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/src/bitwarden_workflow_linter/models/step.py +0 -0
  55. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/src/bitwarden_workflow_linter/models/workflow.py +0 -0
  56. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/src/bitwarden_workflow_linter/rule.py +0 -0
  57. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/src/bitwarden_workflow_linter/rules/__init__.py +0 -0
  58. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/src/bitwarden_workflow_linter/rules/check_pr_target.py +0 -0
  59. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/src/bitwarden_workflow_linter/rules/job_environment_prefix.py +0 -0
  60. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/src/bitwarden_workflow_linter/rules/name_capitalized.py +0 -0
  61. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/src/bitwarden_workflow_linter/rules/name_exists.py +0 -0
  62. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/src/bitwarden_workflow_linter/rules/permissions_exist.py +0 -0
  63. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/src/bitwarden_workflow_linter/rules/pinned_job_runner.py +0 -0
  64. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/src/bitwarden_workflow_linter/rules/step_approved.py +0 -0
  65. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/src/bitwarden_workflow_linter/rules/step_pinned.py +0 -0
  66. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/src/bitwarden_workflow_linter/rules/underscore_outputs.py +0 -0
  67. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/src/bitwarden_workflow_linter/utils.py +0 -0
  68. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/tests/__init__.py +0 -0
  69. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/tests/conftest.py +0 -0
  70. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/tests/fixtures/test-alt.yml +0 -0
  71. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/tests/fixtures/test-min-incorrect.yaml +0 -0
  72. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/tests/fixtures/test-min.yaml +0 -0
  73. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/tests/fixtures/test-outputs-incorrect.yml +0 -0
  74. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/tests/fixtures/test.yml +0 -0
  75. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/tests/fixtures/test_a.yaml +0 -0
  76. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/tests/fixtures/test_workflow.yaml +0 -0
  77. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/tests/fixtures/test_workflow_incorrect.yaml +0 -0
  78. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/tests/rules/__init__.py +0 -0
  79. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/tests/rules/test_check_pr_target.py +0 -0
  80. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/tests/rules/test_job_environment_prefix.py +0 -0
  81. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/tests/rules/test_name_capitalized.py +0 -0
  82. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/tests/rules/test_name_exists.py +0 -0
  83. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/tests/rules/test_permissions_exist.py +0 -0
  84. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/tests/rules/test_pinned_job_runner.py +0 -0
  85. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/tests/rules/test_step_approved.py +0 -0
  86. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/tests/rules/test_step_pinned.py +0 -0
  87. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/tests/rules/test_underscore_output.py +0 -0
  88. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/tests/test_job.py +0 -0
  89. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/tests/test_lint.py +0 -0
  90. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/tests/test_load.py +0 -0
  91. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/tests/test_rule.py +0 -0
  92. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/tests/test_step.py +0 -0
  93. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/tests/test_utils.py +0 -0
  94. {bitwarden_workflow_linter-0.13.0 → bitwarden_workflow_linter-0.14.0}/tests/test_workflow.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bitwarden_workflow_linter
3
- Version: 0.13.0
3
+ Version: 0.14.0
4
4
  Summary: Custom GitHub Action Workflow Linter
5
5
  Project-URL: Homepage, https://github.com/bitwarden/workflow-linter
6
6
  Project-URL: Issues, https://github.com/bitwarden/workflow-linter/issues
@@ -1,3 +1,3 @@
1
1
  """Metadata for Workflow Linter."""
2
2
 
3
- __version__ = "0.13.0"
3
+ __version__ = "0.14.0"
@@ -324,6 +324,11 @@
324
324
  "sha": "0025e74a8c7512023d06dc019c617aa3cf561fde",
325
325
  "version": "v1.10.0"
326
326
  },
327
+ "launchdarkly/find-code-references": {
328
+ "name": "launchdarkly/find-code-references",
329
+ "sha": "e3e9da201b87ada54eb4c550c14fb783385c5c8a",
330
+ "version": "v2.13.0"
331
+ },
327
332
  "launchdarkly/find-code-references-in-pull-request": {
328
333
  "name": "launchdarkly/find-code-references-in-pull-request",
329
334
  "sha": "d008aa4f321d8cd35314d9cb095388dcfde84439",
@@ -17,17 +17,12 @@ def install_actionlint(platform_system: str, version: str) -> Tuple[bool, str]:
17
17
 
18
18
  error = f"An error occurred when installing Actionlint on {platform_system}"
19
19
 
20
- if platform_system.startswith("Linux"):
20
+ if platform_system.startswith(("Linux", "Darwin")):
21
+ """Homebrew does not maintain non-latest versions of actionlint so Mac will install from source"""
21
22
  return install_actionlint_source(error,version)
22
- elif platform_system == "Darwin":
23
- try:
24
- subprocess.run(["brew", "install", "actionlint"], check=True)
25
- return True, ""
26
- except (FileNotFoundError, subprocess.CalledProcessError):
27
- return False, f"{error} : check Brew installation"
28
23
  elif platform_system.startswith("Win"):
29
24
  try:
30
- subprocess.run(["choco", "install", "actionlint", "-y"], check=True)
25
+ subprocess.run(["choco", "install", "actionlint", "-y", f"--version='{version}'"], check=True)
31
26
  return True, ""
32
27
  except (FileNotFoundError, subprocess.CalledProcessError):
33
28
  return False, f"{error} : check Choco installation"
@@ -42,21 +37,24 @@ def install_actionlint_source(error, version) -> Tuple[bool, str]:
42
37
  fp.write(request.read())
43
38
  try:
44
39
  subprocess.run(["bash", "download-actionlint.bash", version], check=True)
45
- return True, os.getcwd()
40
+ return True, "./actionlint"
46
41
  except (FileNotFoundError, subprocess.CalledProcessError):
47
42
  return False, error
48
43
 
49
44
 
50
- def check_actionlint(platform_system: str, version: str) -> Tuple[bool, str]:
45
+ def check_actionlint_path(platform_system: str, version: str) -> Tuple[bool, str]:
51
46
  """Check if the actionlint is in the system's PATH."""
52
47
  try:
53
- subprocess.run(
48
+ installed = subprocess.run(
54
49
  ["actionlint", "--version"],
55
50
  stdout=subprocess.PIPE,
56
51
  stderr=subprocess.PIPE,
57
52
  check=True,
58
53
  )
59
- return True, ""
54
+ if version in f"{installed}":
55
+ return True, ""
56
+ else:
57
+ return install_actionlint(platform_system, version)
60
58
  except subprocess.CalledProcessError:
61
59
  return (
62
60
  False,
@@ -64,7 +62,23 @@ def check_actionlint(platform_system: str, version: str) -> Tuple[bool, str]:
64
62
  please check your package installer or manually install it",
65
63
  )
66
64
  except FileNotFoundError:
67
- return install_actionlint(platform_system, version)
65
+ return check_actionlint_local(platform_system, version)
66
+
67
+ def check_actionlint_local(platform_system: str, version: str) -> Tuple[bool, str]:
68
+
69
+ try:
70
+ installed = subprocess.run(
71
+ ["./actionlint", "--version"],
72
+ stdout=subprocess.PIPE,
73
+ stderr=subprocess.PIPE,
74
+ check=True,
75
+ )
76
+ if version in f"{installed}":
77
+ return True, "./actionlint"
78
+ else:
79
+ return install_actionlint(platform_system, version)
80
+ except FileNotFoundError:
81
+ return install_actionlint(platform_system, version)
68
82
 
69
83
 
70
84
  class RunActionlint(Rule):
@@ -82,12 +96,15 @@ class RunActionlint(Rule):
82
96
  "Running actionlint without a filename is not currently supported"
83
97
  )
84
98
 
99
+ if not self.settings.actionlint_version:
100
+ raise KeyError("The 'actionlint_version' is missing in the configuration file.")
101
+
85
102
  """Check if Actionlint is alerady installed and if it is installed somewhere not on the PATH (location)"""
86
- installed, location = check_actionlint(platform.system(), self.settings.actionlint_version)
103
+ installed, location = check_actionlint_path(platform.system(), self.settings.actionlint_version)
87
104
  if installed:
88
105
  if location:
89
106
  result = subprocess.run(
90
- [location + "/actionlint", obj.filename],
107
+ [location, obj.filename],
91
108
  capture_output=True,
92
109
  text=True,
93
110
  check=False,
@@ -0,0 +1,377 @@
1
+ """Test src/bitwarden_workflow_linter/rules/run_actionlint."""
2
+
3
+ import pytest
4
+ import subprocess
5
+ import os
6
+
7
+ from ruamel.yaml import YAML
8
+
9
+ from src.bitwarden_workflow_linter.utils import Settings
10
+ from src.bitwarden_workflow_linter.load import WorkflowBuilder
11
+ from src.bitwarden_workflow_linter.rules.run_actionlint import (
12
+ RunActionlint,
13
+ install_actionlint_source,
14
+ check_actionlint_path,
15
+ install_actionlint,
16
+ check_actionlint_local,
17
+ )
18
+
19
+ yaml = YAML()
20
+ settings = Settings.factory()
21
+
22
+ @pytest.fixture(name="rule")
23
+ def fixture_rule():
24
+ return RunActionlint(settings)
25
+
26
+
27
+ def test_rule_on_correct_workflow(rule):
28
+ rule.settings = settings
29
+ correct_workflow = WorkflowBuilder.build("tests/fixtures/test_workflow.yaml")
30
+ result, _ = rule.fn(correct_workflow)
31
+ assert result is True
32
+
33
+
34
+ def test_rule_on_incorrect_workflow(rule):
35
+ rule.settings = settings
36
+ incorrect_workflow = WorkflowBuilder.build(
37
+ "tests/fixtures/test_workflow_incorrect.yaml"
38
+ )
39
+ result, _ = rule.fn(incorrect_workflow)
40
+ assert result is False
41
+
42
+
43
+ def test_pass_install_actionlint_linux():
44
+ result, _ = install_actionlint("Linux", settings.actionlint_version)
45
+ assert result is True
46
+
47
+
48
+ def test_install_actionlint_darwin(monkeypatch):
49
+ def mock_run(*args, **kwargs):
50
+ return subprocess.CompletedProcess(args, 0)
51
+
52
+ monkeypatch.setattr(subprocess, "run", mock_run)
53
+ result, _ = install_actionlint("Darwin", settings.actionlint_version)
54
+ assert result is True
55
+
56
+
57
+ def test_failed_install_actionlint_darwin(monkeypatch):
58
+ def mock_run(*args, **kwargs):
59
+ raise subprocess.CalledProcessError(1, "cmd")
60
+
61
+ monkeypatch.setattr(subprocess, "run", mock_run)
62
+ result, error = install_actionlint("Darwin", settings.actionlint_version)
63
+ assert result is False
64
+ assert "An error occurred" in error
65
+
66
+
67
+ def test_install_actionlint_windows(monkeypatch):
68
+ def mock_run(*args, **kwargs):
69
+ return subprocess.CompletedProcess(args, 0)
70
+
71
+ monkeypatch.setattr(subprocess, "run", mock_run)
72
+ result, _ = install_actionlint("Windows", settings.actionlint_version)
73
+ assert result is True
74
+
75
+
76
+ def test_failed_install_actionlint_windows(monkeypatch):
77
+ def mock_run(*args, **kwargs):
78
+ raise subprocess.CalledProcessError(1, "cmd")
79
+
80
+ monkeypatch.setattr(subprocess, "run", mock_run)
81
+ result, error = install_actionlint("Windows", settings.actionlint_version)
82
+ assert result is False
83
+ assert "An error occurred" in error
84
+
85
+
86
+ def test_install_actionlint_source(monkeypatch):
87
+ def mock_run(*args, **kwargs):
88
+ return subprocess.CompletedProcess(args, 0)
89
+
90
+ monkeypatch.setattr(subprocess, "run", mock_run)
91
+
92
+ result, _ = install_actionlint_source("An error occurred", settings.actionlint_version)
93
+ assert result is True
94
+
95
+
96
+ def test_failed_install_actionlint_source(monkeypatch):
97
+ def mock_run(*args, **kwargs):
98
+ raise subprocess.CalledProcessError(1, "cmd")
99
+
100
+ monkeypatch.setattr(subprocess, "run", mock_run)
101
+
102
+ result, error = install_actionlint_source("An error occurred", settings.actionlint_version)
103
+ assert result is False
104
+ assert "An error occurred" in error
105
+
106
+ # test_check_actionlint in path
107
+ def test_check_actionlint_in_path(monkeypatch):
108
+ def mock_installed(*args, **kwargs):
109
+ return settings.actionlint_version
110
+
111
+ monkeypatch.setattr(subprocess, "run", mock_installed)
112
+
113
+ result, message = check_actionlint_path("Linux", settings.actionlint_version)
114
+ assert result is True
115
+ assert message == ""
116
+
117
+ def test_check_actionlint_not_in_path(monkeypatch):
118
+ def mock_run(*args, **kwargs):
119
+ raise subprocess.CalledProcessError(1, args[0])
120
+
121
+ monkeypatch.setattr(subprocess, "run", mock_run)
122
+
123
+ result, message = check_actionlint_path("Linux", settings.actionlint_version)
124
+ assert result is False
125
+ assert message == "Failed to install Actionlint, please check your package installer or manually install it"
126
+
127
+ def test_run_actionlint_not_installed(monkeypatch, rule):
128
+ def mock_check_actionlint_path(*args, **kwargs):
129
+ return False, ""
130
+
131
+ monkeypatch.setattr(
132
+ "src.bitwarden_workflow_linter.rules.run_actionlint.check_actionlint_path",
133
+ mock_check_actionlint_path,
134
+ )
135
+
136
+ workflow = WorkflowBuilder.build("tests/fixtures/test_workflow.yaml")
137
+ result, error = rule.fn(workflow)
138
+ assert result is False
139
+ assert "Actionlint must pass" in error
140
+
141
+ def test_run_actionlint_installed_error(monkeypatch, rule):
142
+ def mock_check_actionlint_path(*args, **kwargs):
143
+ return True, "/mock/location"
144
+
145
+ def mock_run(*args, **kwargs):
146
+ return subprocess.CompletedProcess(args, 110, stdout="An error occurred")
147
+
148
+ monkeypatch.setattr(subprocess, "run", mock_run)
149
+ monkeypatch.setattr(
150
+ "src.bitwarden_workflow_linter.rules.run_actionlint.check_actionlint_path",
151
+ mock_check_actionlint_path,
152
+ )
153
+
154
+ workflow = WorkflowBuilder.build("tests/fixtures/test_workflow.yaml")
155
+ result, error = rule.fn(workflow)
156
+ assert result is False
157
+ assert "An error occurred" in error
158
+
159
+ # test_check_actionlint_installed
160
+ def test_check_actionlint_installed_linux(monkeypatch):
161
+ def mock_run(*args, **kwargs):
162
+ return subprocess.CompletedProcess(args, 0)
163
+
164
+ monkeypatch.setattr(subprocess, "run", mock_run)
165
+
166
+ result, _ = check_actionlint_path("Linux", settings.actionlint_version)
167
+ assert result is True
168
+
169
+ def test_check_actionlint_installed_darwin(monkeypatch):
170
+ def mock_run(*args, **kwargs):
171
+ return subprocess.CompletedProcess(args, 0)
172
+
173
+ monkeypatch.setattr(subprocess, "run", mock_run)
174
+
175
+ result, _ = check_actionlint_path("Darwin", settings.actionlint_version)
176
+ assert result is True
177
+
178
+ def test_check_actionlint_installed_windows(monkeypatch):
179
+ def mock_run(*args, **kwargs):
180
+ return subprocess.CompletedProcess(args, 0)
181
+
182
+ monkeypatch.setattr(subprocess, "run", mock_run)
183
+
184
+ result, _ = check_actionlint_path("Windows", settings.actionlint_version)
185
+ assert result is True
186
+
187
+
188
+ #test_failed_check_actionlint_installed
189
+ def test_failed_check_actionlint_installed_linux(monkeypatch):
190
+ def mock_run(*args, **kwargs):
191
+ raise subprocess.CalledProcessError(1, "cmd")
192
+
193
+ monkeypatch.setattr(subprocess, "run", mock_run)
194
+
195
+ result, _ = check_actionlint_path("Linux", settings.actionlint_version)
196
+ assert result is False
197
+
198
+ def test_failed_check_actionlint_installed_darwin(monkeypatch):
199
+ def mock_run(*args, **kwargs):
200
+ raise subprocess.CalledProcessError(1, "cmd")
201
+
202
+ monkeypatch.setattr(subprocess, "run", mock_run)
203
+
204
+ result, _ = check_actionlint_path("Darwin", settings.actionlint_version)
205
+ assert result is False
206
+
207
+ def test_failed_check_actionlint_installed_windows(monkeypatch):
208
+ def mock_run(*args, **kwargs):
209
+ raise subprocess.CalledProcessError(1, "cmd")
210
+
211
+ monkeypatch.setattr(subprocess, "run", mock_run)
212
+
213
+ result, _ = check_actionlint_path("Windows", settings.actionlint_version)
214
+ assert result is False
215
+
216
+ # test_check_actionlint_installed_locally
217
+ def test_check_actionlint_installed_locally_linux(monkeypatch):
218
+ monkeypatch.setattr(os.path, "exists", True)
219
+
220
+ result, message = check_actionlint_local("Linux", settings.actionlint_version)
221
+
222
+ assert result is True
223
+ assert message == "./actionlint"
224
+
225
+ def test_check_actionlint_installed_locally_darwin(monkeypatch):
226
+ monkeypatch.setattr(os.path, "exists", True)
227
+
228
+ result, message = check_actionlint_local("Darwin", settings.actionlint_version)
229
+
230
+ assert result is True
231
+ assert message == "./actionlint"
232
+
233
+ def test_check_actionlint_installed_locally_windows(monkeypatch):
234
+ def mock_exists(*args, **kwargs):
235
+ return True
236
+
237
+ def mock_run(*args, **kwargs):
238
+ return subprocess.CompletedProcess(args, 0)
239
+
240
+ monkeypatch.setattr(os.path, "exists", mock_exists)
241
+ monkeypatch.setattr(subprocess, "run", mock_run)
242
+
243
+ result, _ = check_actionlint_local("Windows", settings.actionlint_version)
244
+
245
+ assert result is True
246
+
247
+ # test_install_actionlint
248
+ def test_install_actionlint_linux():
249
+ result, _ = install_actionlint("Linux", settings.actionlint_version)
250
+ assert result is True
251
+
252
+ def test_install_actionlint_darwin(monkeypatch):
253
+ def mock_run(*args, **kwargs):
254
+ return subprocess.CompletedProcess(args, 0)
255
+
256
+ monkeypatch.setattr(subprocess, "run", mock_run)
257
+ result, _ = install_actionlint("Darwin", settings.actionlint_version)
258
+ assert result is True
259
+
260
+ def test_install_actionlint_windows(monkeypatch):
261
+ def mock_run(*args, **kwargs):
262
+ return subprocess.CompletedProcess(args, 0)
263
+
264
+ monkeypatch.setattr(subprocess, "run", mock_run)
265
+ result, _ = install_actionlint("Windows", settings.actionlint_version)
266
+ assert result is True
267
+
268
+ def test_install_actionlint_source(monkeypatch):
269
+ def mock_run(*args, **kwargs):
270
+ return subprocess.CompletedProcess(args, 0)
271
+
272
+ monkeypatch.setattr(subprocess, "run", mock_run)
273
+
274
+ result, _ = install_actionlint_source("An error occurred", settings.actionlint_version)
275
+ assert result is True
276
+
277
+ # test non available OS
278
+ def test_install_actionlint_non_available_os():
279
+ result, error = install_actionlint("MockOS", settings.actionlint_version)
280
+ assert result is False
281
+ assert "An error occurred when installing Actionlint on MockOS" in error
282
+
283
+ # test_failed_install_actionlint
284
+ def test_failed_install_actionlint_darwin(monkeypatch):
285
+ def mock_run(*args, **kwargs):
286
+ raise subprocess.CalledProcessError(1, "cmd")
287
+
288
+ monkeypatch.setattr(subprocess, "run", mock_run)
289
+ result, error = install_actionlint("Darwin", settings.actionlint_version)
290
+ assert result is False
291
+ assert "An error occurred" in error
292
+
293
+ def test_failed_install_actionlint_windows(monkeypatch):
294
+ def mock_run(*args, **kwargs):
295
+ raise subprocess.CalledProcessError(1, "cmd")
296
+
297
+ monkeypatch.setattr(subprocess, "run", mock_run)
298
+ result, error = install_actionlint("Windows", settings.actionlint_version)
299
+ assert result is False
300
+ assert "An error occurred" in error
301
+
302
+ def test_failed_install_actionlint_linux(monkeypatch):
303
+ def mock_run(*args, **kwargs):
304
+ raise subprocess.CalledProcessError(1, "cmd")
305
+
306
+ monkeypatch.setattr(subprocess, "run", mock_run)
307
+
308
+ result, error = install_actionlint_source("An error occurred", settings.actionlint_version)
309
+ assert result is False
310
+ assert "An error occurred" in error
311
+
312
+ def test_check_actionlint_not_installed(monkeypatch):
313
+ def mock_run(*args, **kwargs):
314
+ raise FileNotFoundError
315
+
316
+ monkeypatch.setattr(subprocess, "run", mock_run)
317
+
318
+ result, _ = check_actionlint_path("Linux", settings.actionlint_version)
319
+ assert result is False
320
+
321
+
322
+ def test_run_actionlint_installed(monkeypatch, rule):
323
+ rule.settings = settings
324
+
325
+ def mock_check_actionlint(*args, **kwargs):
326
+ return True, "/mock/location"
327
+
328
+ def mock_run(*args, **kwargs):
329
+ return subprocess.CompletedProcess(args, 0, stdout="")
330
+
331
+ monkeypatch.setattr(subprocess, "run", mock_run)
332
+ monkeypatch.setattr(
333
+ "src.bitwarden_workflow_linter.rules.run_actionlint.check_actionlint_path",
334
+ mock_check_actionlint,
335
+ )
336
+
337
+ workflow = WorkflowBuilder.build("tests/fixtures/test_workflow.yaml")
338
+ result, _ = rule.fn(workflow)
339
+ assert result is True
340
+
341
+
342
+ def test_run_actionlint_not_installed(monkeypatch, rule):
343
+ rule.settings = settings
344
+
345
+ def mock_check_actionlint(*args, **kwargs):
346
+ return False, ""
347
+
348
+ monkeypatch.setattr(
349
+ "src.bitwarden_workflow_linter.rules.run_actionlint.check_actionlint_path",
350
+ mock_check_actionlint,
351
+ )
352
+
353
+ workflow = WorkflowBuilder.build("tests/fixtures/test_workflow.yaml")
354
+ result, error = rule.fn(workflow)
355
+ assert result is False
356
+ assert "Actionlint must pass" in error
357
+
358
+
359
+ def test_run_actionlint_installed_error(monkeypatch, rule):
360
+ rule.settings = settings
361
+
362
+ def mock_check_actionlint(*args, **kwargs):
363
+ return True, "/mock/location"
364
+
365
+ def mock_run(*args, **kwargs):
366
+ return subprocess.CompletedProcess(args, 110, stdout="An error occurred")
367
+
368
+ monkeypatch.setattr(subprocess, "run", mock_run)
369
+ monkeypatch.setattr(
370
+ "src.bitwarden_workflow_linter.rules.run_actionlint.check_actionlint_path",
371
+ mock_check_actionlint,
372
+ )
373
+
374
+ workflow = WorkflowBuilder.build("tests/fixtures/test_workflow.yaml")
375
+ result, error = rule.fn(workflow)
376
+ assert result is False
377
+ assert "An error occurred" in error
@@ -1,190 +0,0 @@
1
- """Test src/bitwarden_workflow_linter/rules/run_actionlint."""
2
-
3
- import pytest
4
- import subprocess
5
-
6
- from ruamel.yaml import YAML
7
-
8
- from src.bitwarden_workflow_linter.utils import Settings
9
- from src.bitwarden_workflow_linter.load import WorkflowBuilder
10
- from src.bitwarden_workflow_linter.rules.run_actionlint import (
11
- RunActionlint,
12
- install_actionlint_source,
13
- check_actionlint,
14
- install_actionlint,
15
- )
16
-
17
- yaml = YAML()
18
- settings = Settings.factory()
19
-
20
- @pytest.fixture(name="rule")
21
- def fixture_rule():
22
- return RunActionlint()
23
-
24
-
25
- def test_rule_on_correct_workflow(rule):
26
- rule.settings = settings
27
- correct_workflow = WorkflowBuilder.build("tests/fixtures/test_workflow.yaml")
28
- result, _ = rule.fn(correct_workflow)
29
- assert result is True
30
-
31
-
32
- def test_rule_on_incorrect_workflow(rule):
33
- rule.settings = settings
34
- incorrect_workflow = WorkflowBuilder.build(
35
- "tests/fixtures/test_workflow_incorrect.yaml"
36
- )
37
- result, _ = rule.fn(incorrect_workflow)
38
- assert result is False
39
-
40
-
41
- def test_pass_install_actionlint_linux():
42
- result, _ = install_actionlint("Linux", settings.actionlint_version)
43
- assert result is True
44
-
45
-
46
- def test_install_actionlint_darwin(monkeypatch):
47
- def mock_run(*args, **kwargs):
48
- return subprocess.CompletedProcess(args, 0)
49
-
50
- monkeypatch.setattr(subprocess, "run", mock_run)
51
- result, _ = install_actionlint("Darwin", settings.actionlint_version)
52
- assert result is True
53
-
54
-
55
- def test_failed_install_actionlint_darwin(monkeypatch):
56
- def mock_run(*args, **kwargs):
57
- raise subprocess.CalledProcessError(1, "cmd")
58
-
59
- monkeypatch.setattr(subprocess, "run", mock_run)
60
- result, error = install_actionlint("Darwin", settings.actionlint_version)
61
- assert result is False
62
- assert "An error occurred" in error
63
-
64
-
65
- def test_install_actionlint_windows(monkeypatch):
66
- def mock_run(*args, **kwargs):
67
- return subprocess.CompletedProcess(args, 0)
68
-
69
- monkeypatch.setattr(subprocess, "run", mock_run)
70
- result, _ = install_actionlint("Windows", settings.actionlint_version)
71
- assert result is True
72
-
73
-
74
- def test_failed_install_actionlint_windows(monkeypatch):
75
- def mock_run(*args, **kwargs):
76
- raise subprocess.CalledProcessError(1, "cmd")
77
-
78
- monkeypatch.setattr(subprocess, "run", mock_run)
79
- result, error = install_actionlint("Windows", settings.actionlint_version)
80
- assert result is False
81
- assert "An error occurred" in error
82
-
83
-
84
- def test_install_actionlint_source(monkeypatch):
85
- def mock_run(*args, **kwargs):
86
- return subprocess.CompletedProcess(args, 0)
87
-
88
- monkeypatch.setattr(subprocess, "run", mock_run)
89
-
90
- result, _ = install_actionlint_source("An error occurred", settings.actionlint_version)
91
- assert result is True
92
-
93
-
94
- def test_failed_install_actionlint_source(monkeypatch):
95
- def mock_run(*args, **kwargs):
96
- raise subprocess.CalledProcessError(1, "cmd")
97
-
98
- monkeypatch.setattr(subprocess, "run", mock_run)
99
-
100
- result, error = install_actionlint_source("An error occurred", settings.actionlint_version)
101
- assert result is False
102
- assert "An error occurred" in error
103
-
104
-
105
- def test_check_actionlint_installed(monkeypatch):
106
- def mock_run(*args, **kwargs):
107
- return subprocess.CompletedProcess(args, 0)
108
-
109
- monkeypatch.setattr(subprocess, "run", mock_run)
110
-
111
- result, _ = check_actionlint("Linux", settings.actionlint_version)
112
- assert result is True
113
-
114
-
115
- def test_failed_check_actionlint_installed(monkeypatch):
116
- def mock_run(*args, **kwargs):
117
- raise subprocess.CalledProcessError(1, "cmd")
118
-
119
- monkeypatch.setattr(subprocess, "run", mock_run)
120
-
121
- result, _ = check_actionlint("Linux", settings.actionlint_version)
122
- assert result is False
123
-
124
-
125
- def test_check_actionlint_not_installed(monkeypatch):
126
- def mock_run(*args, **kwargs):
127
- raise FileNotFoundError
128
-
129
- monkeypatch.setattr(subprocess, "run", mock_run)
130
-
131
- result, _ = check_actionlint("Linux", settings.actionlint_version)
132
- assert result is False
133
-
134
-
135
- def test_run_actionlint_installed(monkeypatch, rule):
136
- rule.settings = settings
137
-
138
- def mock_check_actionlint(*args, **kwargs):
139
- return True, "/mock/location"
140
-
141
- def mock_run(*args, **kwargs):
142
- return subprocess.CompletedProcess(args, 0, stdout="")
143
-
144
- monkeypatch.setattr(subprocess, "run", mock_run)
145
- monkeypatch.setattr(
146
- "src.bitwarden_workflow_linter.rules.run_actionlint.check_actionlint",
147
- mock_check_actionlint,
148
- )
149
-
150
- workflow = WorkflowBuilder.build("tests/fixtures/test_workflow.yaml")
151
- result, _ = rule.fn(workflow)
152
- assert result is True
153
-
154
-
155
- def test_run_actionlint_not_installed(monkeypatch, rule):
156
- rule.settings = settings
157
-
158
- def mock_check_actionlint(*args, **kwargs):
159
- return False, ""
160
-
161
- monkeypatch.setattr(
162
- "src.bitwarden_workflow_linter.rules.run_actionlint.check_actionlint",
163
- mock_check_actionlint,
164
- )
165
-
166
- workflow = WorkflowBuilder.build("tests/fixtures/test_workflow.yaml")
167
- result, error = rule.fn(workflow)
168
- assert result is False
169
- assert "Actionlint must pass" in error
170
-
171
-
172
- def test_run_actionlint_installed_error(monkeypatch, rule):
173
- rule.settings = settings
174
-
175
- def mock_check_actionlint(*args, **kwargs):
176
- return True, "/mock/location"
177
-
178
- def mock_run(*args, **kwargs):
179
- return subprocess.CompletedProcess(args, 110, stdout="An error occurred")
180
-
181
- monkeypatch.setattr(subprocess, "run", mock_run)
182
- monkeypatch.setattr(
183
- "src.bitwarden_workflow_linter.rules.run_actionlint.check_actionlint",
184
- mock_check_actionlint,
185
- )
186
-
187
- workflow = WorkflowBuilder.build("tests/fixtures/test_workflow.yaml")
188
- result, error = rule.fn(workflow)
189
- assert result is False
190
- assert "An error occurred" in error