diff --git a/tests/end_to_end/conftest.py b/tests/end_to_end/conftest.py index 07e2f794..14741fc7 100644 --- a/tests/end_to_end/conftest.py +++ b/tests/end_to_end/conftest.py @@ -191,7 +191,7 @@ def gh_other_username(gh_other): @pytest.fixture -def git_repo(cd, git, action_ref, code_path): +def git_repo(cd, git, action_ref, code_path, subproject_id): with cd("repo") as repo: git("init", "-b", "main") # Copy .github @@ -213,6 +213,7 @@ def git_repo(cd, git, action_ref, code_path): file.read_text() .replace("__ACTION_REF__", action_ref) .replace("__ACTION_COVERAGE_PATH__", str(code_path)) + .replace("__ACTION_SUBPROJECT_ID__", str(subproject_id)) ) file.write_text(content) @@ -239,6 +240,12 @@ def code_path(request): return pathlib.Path(*mark.args) if mark else pathlib.Path(".") +@pytest.fixture +def subproject_id(request): + mark = request.node.get_closest_marker("subproject_id") + return mark.args[0] if mark else None + + @pytest.fixture def repo_full_name(repo_name, gh_me_username): return f"{gh_me_username}/{repo_name}" diff --git a/tests/end_to_end/repo/.github/workflows/ci.yml b/tests/end_to_end/repo/.github/workflows/ci.yml index 5d64e222..49b95415 100644 --- a/tests/end_to_end/repo/.github/workflows/ci.yml +++ b/tests/end_to_end/repo/.github/workflows/ci.yml @@ -41,6 +41,7 @@ jobs: ANNOTATE_MISSING_LINES: true ANNOTATION_TYPE: notice COVERAGE_PATH: __ACTION_COVERAGE_PATH__ + SUBPROJECT_ID: __ACTION_SUBPROJECT_ID__ - name: Store Pull Request comment to be posted uses: actions/upload-artifact@v3 diff --git a/tests/end_to_end/repo/.github/workflows/coverage-comment.yml b/tests/end_to_end/repo/.github/workflows/coverage-comment.yml index 9db6642d..26668d71 100644 --- a/tests/end_to_end/repo/.github/workflows/coverage-comment.yml +++ b/tests/end_to_end/repo/.github/workflows/coverage-comment.yml @@ -22,3 +22,4 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_PR_RUN_ID: ${{ github.event.workflow_run.id }} COVERAGE_PATH: __ACTION_COVERAGE_PATH__ + SUBPROJECT_ID: __ACTION_SUBPROJECT_ID__ diff --git a/tests/end_to_end/test_all.py b/tests/end_to_end/test_all.py index 4b445295..29b2a419 100644 --- a/tests/end_to_end/test_all.py +++ b/tests/end_to_end/test_all.py @@ -6,6 +6,7 @@ @pytest.mark.repo_suffix("public") @pytest.mark.code_path("subdir") +@pytest.mark.subproject_id("my-great-project") def test_public_repo( gh_create_repo, wait_for_run_to_start, @@ -71,15 +72,11 @@ def test_public_repo( assert number_of_svgs == 3 # Check that logs point to the branch that has the readme file. - data_branch_url = ( - f"https://github.com/{repo_full_name}/tree/python-coverage-comment-action-data" - ) + data_branch_url = f"https://github.com/{repo_full_name}/tree/python-coverage-comment-action-data-my-great-project" assert data_branch_url in links # Time to check the Readme contents - raw_url_prefix = ( - f"https://github.com/{repo_full_name}/raw/python-coverage-comment-action-data" - ) + raw_url_prefix = f"https://github.com/{repo_full_name}/raw/python-coverage-comment-action-data-my-great-project" readme_url = f"{raw_url_prefix}/README.md" response = client.get(readme_url, follow_redirects=True) @@ -124,6 +121,11 @@ def test_public_repo( fail_value="\n", ) assert ":arrow_up:" in comment + assert "## Coverage report (my-great-project)" in comment + assert ( + "This comment was produced by python-coverage-comment-action (my-great-project)" + in comment + ) # Let's merge the PR and see if everything works fine gh_me("pr", "merge", "1", "--merge")