Skip to content

Commit

Permalink
Merge pull request #219 from py-cov-action/delete-e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
ewjoachim authored Aug 4, 2023
2 parents 277f911 + c9544af commit 23c1f67
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 34 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/e2e-delete-repo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Delete end-to-end test repos on PR close

on:
pull_request_target:
types:
- closed

jobs:
test:
name: Publish coverage comment
runs-on: ubuntu-latest
steps:
- run: |
gh repo delete --yes https://github.com/mihcaojwe/python-coverage-comment-action-end-to-end-${NUMBER}-public || true
env:
GITHUB_TOKEN: ${{ secrets.COVERAGE_COMMENT_E2E_GITHUB_TOKEN_USER_1 }}
- run: |
gh repo delete --yes https://github.com/mihcaojwe/python-coverage-comment-action-end-to-end-${NUMBER}-private || true
env:
GITHUB_TOKEN: ${{ secrets.COVERAGE_COMMENT_E2E_GITHUB_TOKEN_USER_2 }}
58 changes: 58 additions & 0 deletions .github/workflows/e2e-private-link-in-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Post link to private end-to-end test repository

on:
issue_comment:
types: [created]

jobs:
invite:
name: Invite everyone to the e2e private repo
if: |
github.event.issue.pull_request
&& contains(github.event.comment.body, '/invite')
runs-on: ubuntu-latest
strategy:
matrix:
collaborator:
- LOGIN: kieferro
PERMISSION: admin
ENABLED: "true"

- LOGIN: ewjoachim
PERMISSION: admin
ENABLED: "true"

- LOGIN: ${{ github.event.issue.user.login }}
PERMISSION: push
ENABLED: ${{ !contains(fromJson('["kieferro", "ewjoachim"]'), github.event.issue.user.login) }}

steps:

- name: Invite @${{ matrix.collaborator.LOGIN }} to the e2e private repo
run: gh api --method PUT /repos/mihcaojwe/python-coverage-comment-action-end-to-end-${NUMBER}-private/collaborators/${LOGIN} -f permission=${PERMISSION}
if: ${{ matrix.collaborator.ENABLED == 'true' }}
env:
LOGIN: ${{ matrix.collaborator.LOGIN }}
NUMBER: ${{ github.event.issue.number }}
PERMISSION: ${{ matrix.collaborator.PERMISSION }}
GITHUB_TOKEN: ${{ secrets.COVERAGE_COMMENT_E2E_GITHUB_TOKEN_USER_1 }}

comment:
name: Add comment with link to e2e repos
if: |
github.event.issue.pull_request
&& contains(github.event.comment.body, '/invite')
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- run: |
gh pr comment ${LINK} --body-file - <<EOF
[End-to-end private repo](https://github.com/mihcaojwe/python-coverage-comment-action-end-to-end-${NUMBER}-private)
In addition to repo admin, @${LOGIN} has been added to the private e2e repo
EOF
env:
LINK: ${{ github.event.issue.html_url }}
NUMBER: ${{ github.event.issue.number }}
LOGIN: ${{ github.event.issue.user.login }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Post links to end-to-end test repositories
name: Post link to public end-to-end test repository

on:
pull_request_target:
Expand All @@ -7,19 +7,15 @@ on:

jobs:
test:
name: Publish coverage comment
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- run: |
gh pr comment ${LINK} --body-file - <<EOF
[End-to-end public repo](https://github.com/mihcaojwe/python-coverage-comment-action-end-to-end-${NUMBER}-public)
[End-to-end private repo](https://github.com/mihcaojwe/python-coverage-comment-action-end-to-end-${NUMBER}-private)
If the tests fail, @${AUTHOR} will be added to the private repo
EOF
env:
LINK: ${{ github.event.pull_request.html_url }}
NUMBER: ${{ github.event.pull_request.number }}
AUTHOR: ${{ github.event.pull_request.user.login }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31 changes: 2 additions & 29 deletions tests/end_to_end/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,18 +257,7 @@ def f(gh):


@pytest.fixture
def team_users_permissions():
team = {"ewjoachim": "admin", "kieferro": "admin"}
if pr_author := os.environ.get("COVERAGE_COMMENT_E2E_PR_AUTHOR"):
if "[bot]" not in pr_author and pr_author not in team:
team[pr_author] = "push"
return team


@pytest.fixture
def gh_create_repo(
is_failed, gh_delete_repo, gh_me, git_repo, repo_name, team_users_permissions
):
def gh_create_repo(is_failed, gh_delete_repo, gh_me, git_repo, repo_name):
gh_delete_repo(gh_me)

def f(*args):
Expand All @@ -292,21 +281,7 @@ def f(*args):
)
return git_repo

yield f

if not is_failed():
gh_delete_repo(gh_me)

else:
for username, permission in team_users_permissions.items():
gh_me(
"api",
"--method",
"PUT",
f"/repos/{{owner}}/{{repo}}/collaborators/{username}",
"-f",
f"permission={permission}",
)
return f


@pytest.fixture
Expand All @@ -321,8 +296,6 @@ def f():
gh_other("repo", "fork", "--clone", f"{gh_me_username}/{repo_name}", "--", ".")

yield f
if not is_failed():
gh_delete_repo(gh_other)


@pytest.fixture
Expand Down

0 comments on commit 23c1f67

Please sign in to comment.