-
Notifications
You must be signed in to change notification settings - Fork 32
130 lines (117 loc) · 4.53 KB
/
e2e-external-phase-2.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: Run end-to-end tests on external PR approval
on:
workflow_run:
workflows: ["Trigger end-to-end tests on external PR approval"]
types:
- completed
concurrency:
group: ${{ github.event_name }}-${{ github.ref }}
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
checks: write
steps:
- name: Extract PR number from artifact
id: extract_pr_number
run: >
gh api
--method GET
"/repos/py-cov-action/python-coverage-comment-action/actions/runs/${RUN_ID}/artifacts"
-F name="pr_number"
--jq '[.artifacts[]] | last | .archive_download_url'
| xargs gh api
| funzip
> "${GITHUB_OUTPUT}"
env:
GH_TOKEN: ${{ github.token }}
RUN_ID: ${{ github.event.workflow_run.id }}
- name: Extract the approved commit
id: extract_commit
run: |
COMMIT_ID=$(gh pr --repo py-cov-action/python-coverage-comment-action view "${PR_NUMBER}" --json reviews --jq '[.reviews[] | select(.state == "APPROVED" and .authorAssociation == "MEMBER" and (.body | contains("/e2e")) ) | .commit.oid] | last')
if [ -z "${COMMIT_ID}" ]; then
echo "No approved commit found"
exit 1
fi
echo "COMMIT_ID=${COMMIT_ID}" > "${GITHUB_OUTPUT}"
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ steps.extract_pr_number.outputs.PR_NUMBER }}
- name: Extract the current job id
id: extract_job_id
run: >
gh api
"repos/py-cov-action/python-coverage-comment-action/actions/runs/${RUN_ID}/attempts/${RUN_ATTEMPT}/jobs"
--jq '
.jobs[]
| select(.runner_name=="'"${RUNNER_NAME}"'")
| "JOB_ID=" + (.id | tostring)'
> "${GITHUB_OUTPUT}"
env:
GH_TOKEN: ${{ github.token }}
RUN_ID: ${{ github.run_id }}
RUN_ATTEMPT: ${{ github.run_attempt }}
RUNNER_NAME: ${{ runner.name }}
- name: Create PR check
id: create_check
run: >
gh api
"repos/py-cov-action/python-coverage-comment-action/check-runs"
-X POST
-F name="End-to-end tests (external PR)"
-F head_sha="${HEAD_SHA}"
-F status="in_progress"
-F started_at="$(date -u +%FT%TZ)"
-F details_url="$(gh api "/repos/py-cov-action/python-coverage-comment-action/actions/jobs/${JOB_ID}" --jq '.html_url')"
--jq '"CHECK_RUN_ID=" + (.id | tostring)' > "${GITHUB_OUTPUT}"
env:
GITHUB_TOKEN: ${{ github.token }}
HEAD_SHA: ${{ steps.extract_commit.outputs.COMMIT_ID }}
JOB_ID: ${{ steps.extract_job_id.outputs.JOB_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_commit.outputs.COMMIT_ID }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install Poetry
# https://github.com/pypa/pipx/issues/1195
run: |
pipx install poetry --python="$(command -v python3.12)"
- name: Poetry caches
uses: actions/cache@v4
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_commit.outputs.COMMIT_ID }}
COVERAGE_COMMENT_E2E_REPO_SUFFIX: ${{ steps.extract_pr_number.outputs.PR_NUMBER }}
- name: Report results to Check
if: always() && steps.create_check.outputs.CHECK_RUN_ID
run: >
gh api
"repos/py-cov-action/python-coverage-comment-action/check-runs/${CHECK_RUN_ID}"
-X PATCH
-F conclusion=${JOB_STATUS}
-F status=completed
env:
GITHUB_TOKEN: ${{ github.token }}
CHECK_RUN_ID: ${{ steps.create_check.outputs.CHECK_RUN_ID }}
JOB_STATUS: ${{ job.status }}