Skip to content

Commit 2d52bc4

Browse files
committed
Introduce a composite action to check a test project and expect errors conditionally
1 parent 77dbb2d commit 2d52bc4

File tree

9 files changed

+699
-19
lines changed

9 files changed

+699
-19
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Test Analyze Project
2+
description: Test the analyze-project action with configurable project directory and failure expectations
3+
4+
inputs:
5+
project-directory:
6+
description: Path to the directory containing pyproject.toml
7+
required: true
8+
type: string
9+
expect-failure:
10+
description: Whether the analyze-project step is expected to fail
11+
required: false
12+
default: 'false'
13+
type: string
14+
15+
runs:
16+
using: composite
17+
steps:
18+
- name: Analyze project
19+
uses: ../../analyze-project
20+
id: analyze-project
21+
continue-on-error: ${{ inputs.expect-failure == 'true' }}
22+
with:
23+
project-directory: ${{ inputs.project-directory }}
24+
- name: Check expected outcome
25+
run: |
26+
if [[ "${{ inputs.expect-failure }}" == "true" ]]; then
27+
if [[ "${{ steps.analyze-project.outcome }}" != "failure" ]]; then
28+
echo "::error title=Test Failure::Expected analyze-project to fail, but it succeeded."
29+
exit 1
30+
else
31+
echo "::notice title=Test Success::analyze-project failed as expected."
32+
fi
33+
fi
34+
shell: bash

.github/test_projects/mypy-errors/src/test_project/mypy-errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Required docstring."""
22

33

4-
def foo(x: int, y: int):
4+
def foo(x: int, y: int): # mypy error: Function is missing a return type annotation
55
"""Required docstring."""
66
print("Hello, world!")
77
return x + y

.github/test_projects/pyright-errors/README.md

Whitespace-only changes.

.github/test_projects/pyright-errors/poetry.lock

Lines changed: 613 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[project]
2+
name = "mypy-errors"
3+
version = "0.1.0"
4+
description = "Tests actions/analyze-project with a project that has mypy errors"
5+
authors = [
6+
{name = "Joel Dixon",email = "[email protected]"}
7+
]
8+
readme = "README.md"
9+
requires-python = ">=3.9,<4.0"
10+
dynamic = ["dependencies"]
11+
12+
[tool.poetry]
13+
packages = [{include = "test_project", from = "src"}]
14+
15+
[tool.poetry.group.lint.dependencies]
16+
ni-python-styleguide = ">=0.4.1"
17+
pyright = { version = ">=1.1.400", extras = ["nodejs"] }
18+
19+
[tool.pyright]
20+
include = ["src/", "tests/"]
21+
22+
[build-system]
23+
requires = ["poetry-core>=2.0.0,<3.0.0"]
24+
build-backend = "poetry.core.masonry.api"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Docstring required."""
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""Required docstring."""
2+
3+
4+
def foo(x: int, y: int) -> int:
5+
"""Required docstring."""
6+
print("Hello, world!")
7+
return x + y
8+
9+
10+
# Definitive Pyright errors:
11+
def broken_function(x: str) -> int:
12+
"""This function has type errors."""
13+
return x # Error: returning str when int expected
14+
15+
16+
# Type mismatch
17+
numbers: list[int] = [1, 2, "three"] # Error: str in int list
18+
19+
# Wrong argument types
20+
result = foo("not", "numbers") # Error: str args to int params
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Module docstring."""

.github/workflows/test_actions.yml

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -229,32 +229,19 @@ jobs:
229229
- name: Set up Poetry
230230
uses: ./setup-poetry
231231
- name: Analyze Valid Minimal
232-
uses: ./analyze-project
233-
id: minimal
232+
uses: ./.github/actions/test_analyze_project
234233
with:
235234
project-directory: ${{ github.workspace }}/.github/test_projects/minimal
236235
- name: Analyze ni-python-styleguide Errors Project
237-
uses: ./analyze-project
238-
id: ni-python-styleguide-errors
239-
continue-on-error: true
236+
uses: ./.github/actions/test_analyze_project
240237
with:
241238
project-directory: ${{ github.workspace }}/.github/test_projects/ni-python-styleguide-errors
242-
- name: Error if the previous step didn't fail
243-
if: steps.ni-python-styleguide-errors.outcome != 'failure'
244-
run: |
245-
echo "::error title=Test Failure::The previous step did not fail as expected."
246-
exit 1
239+
expect-failure: 'true'
247240
- name: Analyze mypy Errors Project
248-
uses: ./analyze-project
249-
id: mypy-errors
250-
continue-on-error: true
241+
uses: ./.github/actions/test_analyze_project
251242
with:
252243
project-directory: ${{ github.workspace }}/.github/test_projects/mypy-errors
253-
- name: Error if the previous step didn't fail
254-
if: steps.mypy-errors.outcome != 'failure'
255-
run: |
256-
echo "::error title=Test Failure::The previous step did not fail as expected."
257-
exit 1
244+
expect-failure: 'true'
258245

259246
# This job is intended to combine the test results so we don't have to list
260247
# each matrix combination in the required status check settings. There are a

0 commit comments

Comments
 (0)