-
Notifications
You must be signed in to change notification settings - Fork 0
179 lines (163 loc) · 6.38 KB
/
Copy pathpython-lib-ci-e2e-slice.yml
File metadata and controls
179 lines (163 loc) · 6.38 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# Reusable generated-library hermetic e2e slice verification.
name: Python Library CI E2E Slice
on:
workflow_call:
inputs:
python-version:
description: Python version to install.
required: false
type: string
default: "3.13"
e2e-path:
description: Pytest path for one hermetic e2e slice.
required: true
type: string
playwright-browsers:
description: Space-separated Playwright browser names to install.
required: false
type: string
default: ""
env:
PYTEST_XDIST_AUTO_NUM_WORKERS: "2"
jobs:
e2e-slice:
name: E2E Slice
runs-on: ${{ github.event.repository.private == true && fromJSON(vars.CI_RUNNER_LABELS_JSON || '["ubuntu-latest"]') || 'ubuntu-latest' }}
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
ref: ${{ github.sha }}
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: ${{ inputs.python-version }}
- name: Set up uv
uses: astral-sh/setup-uv@v8.2.0
with:
enable-cache: auto
- name: Install Linux runtime libraries
run: |
missing=()
dpkg-query -W libgl1 >/dev/null 2>&1 || missing+=(libgl1)
if ! dpkg-query -W libglib2.0-0 >/dev/null 2>&1 &&
! dpkg-query -W libglib2.0-0t64 >/dev/null 2>&1; then
missing+=(libglib2.0-0)
fi
if [ "${#missing[@]}" -gt 0 ]; then
sudo apt-get update
sudo apt-get install -y "${missing[@]}"
fi
- name: Prepare shared package token scope
id: token-scope
run: |
set -euo pipefail
current_repository="${GITHUB_REPOSITORY#*/}"
python3 - "${current_repository}" <<'PY' >> "${GITHUB_OUTPUT}"
import sys
seen = set()
repositories = []
for repository in (sys.argv[1], "py-lib-starter"):
if repository not in seen:
repositories.append(repository)
seen.add(repository)
print("repositories<<EOF")
print("\n".join(repositories))
print("EOF")
PY
- name: Create shared package token
id: app-token
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
with:
client-id: ${{ vars.PY_LIB_AUTOMATION_CLIENT_ID }}
private-key: ${{ secrets.PY_LIB_AUTOMATION_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: ${{ steps.token-scope.outputs.repositories }}
permission-contents: read
- name: Verify shared py-lib Git access
env:
SHARED_PACKAGE_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
set -euo pipefail
auth_header="$(printf 'x-access-token:%s' "${SHARED_PACKAGE_TOKEN}" | base64 | tr -d '\n')"
printf '::add-mask::%s\n' "${auth_header}"
export GIT_CONFIG_COUNT=1
export GIT_CONFIG_KEY_0=http.https://github.com/.extraheader
export GIT_CONFIG_VALUE_0="AUTHORIZATION: basic ${auth_header}"
read_shared_repository() {
local repository="$1"
git ls-remote "https://github.com/${repository}.git" HEAD >/dev/null 2>&1
}
for repository in "${GITHUB_REPOSITORY}" "betabitplus/py-lib-starter"; do
for attempt in 1 2 3 4 5; do
if read_shared_repository "${repository}"; then
continue 2
fi
if [ "${attempt}" -lt 5 ]; then
sleep 10
fi
done
echo "::error::The betabitplus-py-lib-automation GitHub App cannot read ${repository}. Install or re-authorize the App for that repository before dependency installation."
exit 1
done
- name: Install dependencies (dev)
env:
SHARED_PACKAGE_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
set -euo pipefail
auth_header="$(printf 'x-access-token:%s' "${SHARED_PACKAGE_TOKEN}" | base64 | tr -d '\n')"
printf '::add-mask::%s\n' "${auth_header}"
export GIT_CONFIG_COUNT=1
export GIT_CONFIG_KEY_0=http.https://github.com/.extraheader
export GIT_CONFIG_VALUE_0="AUTHORIZATION: basic ${auth_header}"
python_path="$(command -v python)"
uv sync --group dev --frozen --python "${python_path}"
- name: Cache Playwright browsers
if: inputs.playwright-browsers != ''
uses: actions/cache@v5
with:
path: ~/.cache/ms-playwright
key: playwright-${{ runner.os }}-${{ runner.arch }}-${{ inputs.playwright-browsers }}-${{ hashFiles('uv.lock') }}
restore-keys: |
playwright-${{ runner.os }}-${{ runner.arch }}-${{ inputs.playwright-browsers }}-
- name: Install Playwright browsers
if: inputs.playwright-browsers != ''
env:
PLAYWRIGHT_BROWSERS: ${{ inputs.playwright-browsers }}
run: |
set -euo pipefail
read -r -a browsers <<< "${PLAYWRIGHT_BROWSERS}"
for browser in "${browsers[@]}"; do
case "${browser}" in
chromium|firefox|webkit) ;;
*) echo "Unsupported Playwright browser: ${browser}" >&2; exit 2 ;;
esac
done
PLAYWRIGHT_BROWSERS="${browsers[*]}"
if [ "${{ runner.environment }}" = "self-hosted" ]; then
install_command="uv run playwright install ${PLAYWRIGHT_BROWSERS}"
else
install_command="uv run playwright install --with-deps ${PLAYWRIGHT_BROWSERS}"
fi
read -r -a command <<< "${install_command}"
"${command[@]}"
- name: Run hermetic e2e slice
env:
E2E_PATH: ${{ inputs.e2e-path }}
run: |
set -euo pipefail
if [[ ! "${E2E_PATH}" =~ ^tests/[A-Za-z0-9_]+/e2e/[A-Za-z0-9_/-]+$ ]] ||
[[ "${E2E_PATH}" == *".."* ]]; then
echo "Invalid e2e path: ${E2E_PATH}" >&2
exit 2
fi
if [ ! -d "${E2E_PATH}" ]; then
echo "Configured e2e path does not exist: ${E2E_PATH}" >&2
exit 2
fi
uv run pytest "${E2E_PATH}" \
-m "not slow" \
-q -rs --no-cov