Skip to content

Commit

Permalink
Merge pull request #325 from py-cov-action/fix-e2e-external
Browse files Browse the repository at this point in the history
  • Loading branch information
ewjoachim authored Dec 22, 2023
2 parents 5986309 + fc51d6f commit 9d750b4
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 56 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ jobs:
COVERAGE_COMMENT_E2E_GITHUB_TOKEN_USER_2: ${{ secrets.COVERAGE_COMMENT_E2E_GITHUB_TOKEN_USER_2 }}
COVERAGE_COMMENT_E2E_ACTION_REF: ${{ github.sha }}
COVERAGE_COMMENT_E2E_REPO_SUFFIX: ${{ github.event.number }}
COVERAGE_COMMENT_E2E_PR_AUTHOR: ${{ github.event.pull_request.user.login }}

- name: Coverage comment
id: coverage_comment
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/e2e-external-phase-1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Scheduling end-to-end tests on external PR approval

on:
pull_request_review:
types: [submitted]

concurrency:
group: ${{ github.event_name }}-${{ github.ref }}

jobs:
test:
name: Run end to end tests
# If reviewed by a repo(/org) owner
if: |
github.event.pull_request.author_association != 'MEMBER'
&& github.event.review.author_association == 'MEMBER'
&& github.event.review.state == 'approved'
&& contains(github.event.review.body, '/e2e')
runs-on: ubuntu-latest
steps:
- run: true
69 changes: 69 additions & 0 deletions .github/workflows/e2e-external-phase-2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Running end-to-end tests on external PR approval

on:
workflow_run:
workflows: ["Scheduling end-to-end tests on external PR approval"]
types:
- completed

jobs:
e2e:
name: End-to-end tests
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion == 'success'
permissions:
actions: read
pull-requests: write
contents: write
steps:
- name: Extract the approved commit
id: extract
run: |
PR_NUMBER=$(gh api "repos/:owner/:repo/actions/runs/${RUN_ID}" --jq '.pull_requests | first | .number')
if [ -z "${PR_NUMBER}" ]; then
echo "No PR number found"
exit 1
fi
COMMIT_ID=$(gh pr view "${PR_NUMBER}" --json reviews --jq '[.reviews[] | select(.state == "APPROVED" and .authorAssociation == "MEMBER") | .commit.oid] | last')
if [ -z "${COMMIT_ID}" ]; then
echo "No approved commit found"
exit 1
fi
echo "PR_NUMBER=${PR_NUMBER}" >> "${GITHUB_OUTPUT}"
echo "COMMIT_ID=${COMMIT_ID}" > "${GITHUB_OUTPUT}"
env:
RUN_ID: ${{ github.event.workflow_run.id }}

- name: Checkout
uses: actions/checkout@v4
with:
# Important: use the commit that was reviewed. GitHub is making sure
# that this is race-condition-proof
ref: ${{ steps.extract.outputs.COMMIT_ID }}

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Install Poetry
run: |
pipx install poetry --python=python3.11
- name: Poetry caches
uses: actions/cache@v3
with:
path: |
~/.cache/
key: ${{ hashFiles('poetry.lock') }}

- name: Install deps
run: poetry install

- name: Run end-to-end tests
run: poetry run pytest tests/end_to_end
env:
COVERAGE_COMMENT_E2E_GITHUB_TOKEN_USER_1: ${{ secrets.COVERAGE_COMMENT_E2E_GITHUB_TOKEN_USER_1 }}
COVERAGE_COMMENT_E2E_GITHUB_TOKEN_USER_2: ${{ secrets.COVERAGE_COMMENT_E2E_GITHUB_TOKEN_USER_2 }}
COVERAGE_COMMENT_E2E_ACTION_REF: ${{ steps.extract.outputs.COMMIT_ID }}
COVERAGE_COMMENT_E2E_REPO_SUFFIX: ${{ steps.extract.outputs.PR_NUMBER }}
54 changes: 0 additions & 54 deletions .github/workflows/e2e-external.yml

This file was deleted.

7 changes: 6 additions & 1 deletion .github/workflows/e2e-public-link-in-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ jobs:
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 public repo](https://github.com/mihcaojwe/python-coverage-comment-action-end-to-end-${NUMBER}-public)
Other commands:
- Have an admin approve a review with /e2e to trigger end-to-end tests on external contributions
- Comment with /invite to invite the author & admins to the end-to-end private repo
EOF
env:
LINK: ${{ github.event.pull_request.html_url }}
Expand Down

0 comments on commit 9d750b4

Please sign in to comment.