Skip to content

Commit

Permalink
Rework file structure (#113)
Browse files Browse the repository at this point in the history
* Moves python code into python/
  • Loading branch information
EnricoMi authored Apr 16, 2021
1 parent 9a10b41 commit 1ae8efe
Show file tree
Hide file tree
Showing 50 changed files with 49 additions and 59 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ jobs:
- name: Install Python dependencies
run: |
python -m pip install --upgrade --force --no-cache-dir pip
pip install --force --no-cache-dir -r requirements.txt
pip install --force --no-cache-dir -r test/requirements.txt
pip install --force --no-cache-dir -r python/requirements.txt
pip install --force --no-cache-dir -r python/test/requirements.txt
- name: PyTest
env:
PYTHONPATH: ..
run: |
cd test
python -m pytest --capture=tee-sys --continue-on-collection-errors --junit-xml ../test-results/pytest.xml
cd python/test
python -m pytest --capture=tee-sys --continue-on-collection-errors --junit-xml ../../test-results/pytest.xml
- name: Upload Test Results
if: always()
Expand Down
9 changes: 3 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@ LABEL com.github.actions.description="A GitHub Action to publish unit test resul
LABEL com.github.actions.icon="check-circle"
LABEL com.github.actions.color="green"

COPY requirements.txt /action/
COPY python/requirements.txt /action/
RUN pip install --upgrade --force --no-cache-dir pip && pip install --upgrade --force --no-cache-dir -r /action/requirements.txt

COPY github_action /action/github_action
COPY junit /action/junit
COPY publish /action/publish
COPY unittestresults /action/unittestresults
COPY publish_unit_test_results.py /action/
COPY python/publish /action/publish
COPY python/publish_unit_test_results.py /action/

ENTRYPOINT ["python", "/action/publish_unit_test_results.py"]
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,26 @@ The `if: always()` clause guarantees that this action always runs, even if earli

Unit test results are published in the GitHub Actions section of the respective commit:

![checks comment example](github-checks-comment.png)
![checks comment example](misc/github-checks-comment.png)

***Note:** This action does not fail if unit tests failed. The action that executed the unit tests should
fail on test failure. The published results however indicate failure if tests fail or errors occur.
This behaviour is configurable.*

Each failing test will produce an annotation with failure details:
![annotations example](github-checks-annotation.png)
![annotations example](misc/github-checks-annotation.png)

***Note:** Only the first failure of a test is shown. If you want to see all failures, set `report_individual_runs: "true"`.*

A comment is posted on the pull request of that commit, if one exists.
In presence of failures or errors, the comment links to the respective check page with failure details:

![pull request comment example](github-pull-request-comment.png)
![pull request comment example](misc/github-pull-request-comment.png)

The checks section of the pull request also lists a short summary (here `1 fail, 1 skipped, 17 pass in 12s`),
and a link to the GitHub Actions section (here `Details`):

![pull request checks example](github-pull-request-checks.png)
![pull request checks example](misc/github-pull-request-checks.png)

The result distinguishes between tests and runs. In some situations, tests run multiple times,
e.g. in different environments. Displaying the number of runs allows spotting unexpected
Expand All @@ -65,7 +65,7 @@ changes in the number of runs as well.
The change statistics (e.g. 5 tests ±0) might sometimes hide test removal.
Those are highlighted in pull request comments to easily spot unintended test removal:

![pull request comment example with test changes](github-pull-request-comment-with-test-changes.png)
![pull request comment example with test changes](misc/github-pull-request-comment-with-test-changes.png)

***Note:** This requires `check_run_annotations` to be set to `all tests, skipped tests`.*

Expand Down
4 changes: 2 additions & 2 deletions composite/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ runs:
python3 -m pip install --upgrade --force --no-cache-dir virtualenv
python3 -m virtualenv -p python3 venv
[ -f venv/bin/activate ] && source venv/bin/activate || source venv/Scripts/Activate
python3 -m pip install --upgrade --force --no-cache-dir -r $GITHUB_ACTION_PATH/../requirements.txt
python3 -m pip install --upgrade --force --no-cache-dir -r $GITHUB_ACTION_PATH/../python/requirements.txt
echo '##[endgroup]'
shell: bash

- name: Publish Unit Test Results
run: |
echo '##[group]Publish Unit Test Results'
[ -f venv/bin/activate ] && source venv/bin/activate || source venv/Scripts/Activate
python3 $GITHUB_ACTION_PATH/../publish_unit_test_results.py
python3 $GITHUB_ACTION_PATH/../python/publish_unit_test_results.py
echo '##[endgroup]'
env:
GITHUB_TOKEN: ${{ inputs.github_token }}
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
6 changes: 2 additions & 4 deletions publish/__init__.py → python/publish/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
import logging
import re
from collections import defaultdict
from typing import List, Any, Union, Optional, Tuple, Mapping, Iterator, Set, Iterable

from dataclasses import dataclass
from typing import List, Any, Union, Optional, Tuple, Mapping, Iterator, Set, Iterable

from unittestresults import Numeric, UnitTestCaseResults, UnitTestRunResults, \
from publish.unittestresults import Numeric, UnitTestCaseResults, UnitTestRunResults, \
UnitTestRunDeltaResults, UnitTestRunResultsOrDeltaResults, ParseError


logger = logging.getLogger('publish')
digest_prefix = '[test-results]:data:application/gzip;base64,'
digit_space = '  '
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import logging
import os
import sys
from io import TextIOWrapper
from typing import Mapping, Any, Optional


logger = logging.getLogger('github_action')
from publish import logger


class GithubAction:
Expand Down
8 changes: 5 additions & 3 deletions junit/__init__.py → python/publish/junit.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import os
from collections import defaultdict
from html import unescape
from typing import Optional, Iterable, Union, Any, List
from collections import defaultdict
from junitparser import *
from unittestresults import ParsedUnitTestResults, UnitTestCase, ParseError

from junitparser import Element, JUnitXml, TestCase, TestSuite

from publish.unittestresults import ParsedUnitTestResults, UnitTestCase, ParseError


def get_results(results: Union[Element, List[Element]]) -> List[Element]:
Expand Down
9 changes: 3 additions & 6 deletions publish/publisher.py → python/publish/publisher.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import re
from dataclasses import dataclass
from typing import List, Any, Optional, Tuple, Mapping
Expand All @@ -8,17 +7,15 @@
from github.CheckRunAnnotation import CheckRunAnnotation
from github.PullRequest import PullRequest

from github_action import GithubAction
from publish import hide_comments_mode_orphaned, hide_comments_mode_all_but_latest, \
get_stats_from_digest, digest_prefix, get_short_summary, get_long_summary_md, \
get_long_summary_with_digest_md, get_error_annotations, get_case_annotations, \
get_all_tests_list_annotation, get_skipped_tests_list_annotation, get_all_tests_list, \
get_skipped_tests_list, all_tests_list, skipped_tests_list, pull_request_build_mode_merge, \
Annotation, SomeTestChanges
from unittestresults import UnitTestCaseResults, UnitTestRunResults, get_stats_delta


logger = logging.getLogger('publish.publisher')
from publish import logger
from publish.github_action import GithubAction
from publish.unittestresults import UnitTestCaseResults, UnitTestRunResults, get_stats_delta


@dataclass(frozen=True)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from collections import defaultdict
from dataclasses import dataclass
from typing import Optional, List, Mapping, Any, Union, Dict
from xml.etree.ElementTree import ParseError as XmlParseError
from dataclasses import dataclass


@dataclass(frozen=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
import github
from urllib3.util.retry import Retry

import github_action
import publish
from github_action import GithubAction
from junit import parse_junit_xml_files
from publish import hide_comments_modes, available_annotations, default_annotations, \
pull_request_build_modes, publisher, fail_on_modes, fail_on_mode_errors, fail_on_mode_failures
pull_request_build_modes, fail_on_modes, fail_on_mode_errors, fail_on_mode_failures
from publish.github_action import GithubAction
from publish.junit import parse_junit_xml_files
from publish.publisher import Publisher, Settings
from unittestresults import get_test_results, get_stats, ParsedUnitTestResults
from publish.unittestresults import get_test_results, get_stats, ParsedUnitTestResults

logger = logging.getLogger('publish-unit-test-results')

Expand Down Expand Up @@ -194,9 +193,7 @@ def get_settings(options: dict) -> Settings:

log_level = get_var('LOG_LEVEL', options) or 'INFO'
logger.level = logging.getLevelName(log_level)
github_action.logger.level = logging.getLevelName(log_level)
publish.logger.level = logging.getLevelName(log_level)
publisher.logger.level = logging.getLevelName(log_level)

settings = get_settings(options)
main(settings)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

from publish import pull_request_build_mode_merge, fail_on_mode_failures, fail_on_mode_errors, \
fail_on_mode_nothing
from publish.unittestresults import ParsedUnitTestResults, ParseError
from publish_unit_test_results import get_conclusion, get_commit_sha, \
get_settings, get_annotations_config, Settings
from unittestresults import ParsedUnitTestResults, ParseError

event = dict(pull_request=dict(head=dict(sha='event_sha')))

Expand Down
7 changes: 4 additions & 3 deletions test/test_action_yml.py → python/test/test_action_yml.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import unittest

import yaml
from yaml import Loader


class TestActionYml(unittest.TestCase):

def test_composite_action(self):
with open('../action.yml') as r:
with open('../../action.yml') as r:
dockerfile_action = yaml.load(r, Loader=Loader)

with open('../composite/action.yml') as r:
with open('../../composite/action.yml') as r:
composite_action = yaml.load(r, Loader=Loader)

self.assertIn('runs', dockerfile_action)
Expand All @@ -20,7 +21,7 @@ def test_composite_action(self):
self.assertIn(('using', 'composite'), composite_action.get('runs', {}).items())

def test_composite_inputs(self):
with open('../composite/action.yml') as r:
with open('../../composite/action.yml') as r:
action = yaml.load(r, Loader=Loader)

# these are not documented in the action.yml files but still needs to be forwarded
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import unittest
from contextlib import contextmanager

from github_action import GithubAction
from publish.github_action import GithubAction


@contextmanager
Expand Down
6 changes: 3 additions & 3 deletions test/test_junit.py → python/test/test_junit.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import unittest
from typing import Optional
from distutils.version import LooseVersion
from typing import Optional

from junitparser import JUnitXml, Element, version

from junit import parse_junit_xml_files, get_results, get_result, get_content, get_message
from unittestresults import ParsedUnitTestResults, UnitTestCase, ParseError
from publish.junit import parse_junit_xml_files, get_results, get_result, get_content, get_message
from publish.unittestresults import ParsedUnitTestResults, UnitTestCase, ParseError


class TestElement(Element):
Expand Down
9 changes: 5 additions & 4 deletions test/test_publish.py → python/test/test_publish.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import mock
import contextlib
import locale
import unittest

import mock

from publish import *
from unittestresults import get_test_results
from junit import parse_junit_xml_files
from publish.junit import parse_junit_xml_files
from publish.unittestresults import get_stats, UnitTestCase, ParseError
from publish.unittestresults import get_test_results
from test import d, n
from unittestresults import get_stats, UnitTestCase, ParseError


@contextlib.contextmanager
Expand Down
7 changes: 3 additions & 4 deletions test/test_publisher.py → python/test/test_publisher.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import unittest
from collections.abc import Collection

import mock
from github import Github
from github_action import GithubAction

from publish import *
from publish.github_action import GithubAction
from publish.publisher import Publisher, Settings
from unittestresults import UnitTestCase, ParseError
from collections.abc import Collection

from publish.unittestresults import UnitTestCase, ParseError

errors = [ParseError('file', 'error', 1, 2)]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import unittest
from xml.etree.ElementTree import ParseError as XmlParseError

from test import d, n
from unittestresults import get_test_results, get_stats, get_stats_delta, \
from publish.unittestresults import get_test_results, get_stats, get_stats_delta, \
ParsedUnitTestResults, ParsedUnitTestResultsWithCommit, \
UnitTestCase, UnitTestResults, UnitTestCaseResults, \
UnitTestRunResults, UnitTestRunDeltaResults, ParseError
from test import d, n

errors = [ParseError('file', 'error', None, None)]

Expand Down

0 comments on commit 1ae8efe

Please sign in to comment.