Skip to content

Commit 7fe5ce6

Browse files
Add tracing to Sourcegraph client (#9)
Co-authored-by: Amp <amp@ampcode.com>
1 parent 9015212 commit 7fe5ce6

12 files changed

Lines changed: 922 additions & 142 deletions

File tree

.github/workflows/ci.yml

Lines changed: 6 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -2,92 +2,15 @@ name: CI
22

33
on:
44
pull_request:
5-
push:
6-
branches:
7-
- main
85

96
permissions:
107
contents: read
118

12-
defaults:
13-
run:
14-
shell: bash
9+
concurrency:
10+
group: ci-${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
1512

1613
jobs:
17-
test:
18-
name: Build and test
19-
runs-on: ubuntu-24.04
20-
env:
21-
IMPORT_NAME: src_py_lib
22-
PYTHON_VERSION: "3.11"
23-
UV_VERSION: "0.11.7"
24-
25-
steps:
26-
- name: Check out code
27-
uses: actions/checkout@v6
28-
with:
29-
persist-credentials: false
30-
31-
- name: Set up Python
32-
uses: actions/setup-python@v6
33-
with:
34-
python-version: ${{ env.PYTHON_VERSION }}
35-
cache: pip
36-
37-
- name: Install uv
38-
run: |
39-
python -m pip install --upgrade pip
40-
python -m pip install "uv==${UV_VERSION}"
41-
42-
- name: Validate lockfile
43-
run: uv lock --check
44-
45-
- name: Lint Markdown
46-
run: npx --yes markdownlint-cli2
47-
48-
- name: Lint Python
49-
run: uv run --frozen ruff check .
50-
51-
- name: Check Python formatting
52-
run: uv run --frozen ruff format --check .
53-
54-
- name: Type check
55-
run: uv run --frozen pyright
56-
57-
- name: Run tests
58-
run: uv run --frozen python -m unittest discover -s tests
59-
60-
- name: Smoke test source checkout import
61-
run: |
62-
uv run --frozen python - <<'PY'
63-
import os
64-
65-
import src_py_lib
66-
67-
if src_py_lib.__name__ != os.environ["IMPORT_NAME"]:
68-
raise SystemExit(f"unexpected import name: {src_py_lib.__name__}")
69-
PY
70-
71-
- name: Build wheel
72-
run: uv build --wheel --out-dir dist --no-create-gitignore
73-
74-
- name: Smoke test installed wheel
75-
run: |
76-
python -m venv build/ci-venv
77-
. build/ci-venv/bin/activate
78-
python -m pip install --upgrade pip
79-
python -m pip install dist/*.whl
80-
python - <<'PY'
81-
import os
82-
83-
import src_py_lib
84-
85-
if src_py_lib.__name__ != os.environ["IMPORT_NAME"]:
86-
raise SystemExit(f"unexpected import name: {src_py_lib.__name__}")
87-
PY
88-
89-
- name: Upload wheel artifact
90-
uses: actions/upload-artifact@v7
91-
with:
92-
name: src-py-lib-wheel
93-
path: dist/*.whl
14+
validate:
15+
name: Validate
16+
uses: ./.github/workflows/validate.yml

.github/workflows/release.yml

Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,15 @@ defaults:
2323
shell: bash
2424

2525
jobs:
26+
validate:
27+
name: Validate
28+
uses: ./.github/workflows/validate.yml
29+
with:
30+
ref: ${{ github.event.inputs.tag || github.ref }}
31+
2632
wheel:
2733
name: Build wheel
34+
needs: validate
2835
runs-on: ubuntu-24.04
2936
env:
3037
IMPORT_NAME: src_py_lib
@@ -45,6 +52,14 @@ jobs:
4552
python-version: ${{ env.PYTHON_VERSION }}
4653
cache: pip
4754

55+
- name: Cache uv
56+
uses: actions/cache@v4
57+
with:
58+
path: ~/.cache/uv
59+
key: uv-${{ runner.os }}-py${{ env.PYTHON_VERSION }}-${{ hashFiles('uv.lock') }}
60+
restore-keys: |
61+
uv-${{ runner.os }}-py${{ env.PYTHON_VERSION }}-
62+
4863
- name: Install build tools
4964
run: |
5065
python -m pip install --upgrade pip
@@ -62,6 +77,14 @@ jobs:
6277
echo "::error title=Missing tag::Tag '${release_tag}' was not fetched. Create and push it before running this workflow."
6378
exit 1
6479
fi
80+
tag_revision="$(git rev-list -n 1 "${release_tag}")"
81+
git fetch --no-tags origin main
82+
main_revision="$(git rev-parse origin/main)"
83+
if ! git merge-base --is-ancestor "${tag_revision}" "${main_revision}"; then
84+
echo "::error title=Tag is not on main::Tag '${release_tag}' points at ${tag_revision}, which is not reachable from origin/main."
85+
echo "::error::Merge the release PR first, then tag the main commit."
86+
exit 1
87+
fi
6588
6689
project_version=$(uv run --frozen python - <<'PY'
6790
import tomllib
@@ -77,22 +100,6 @@ jobs:
77100
78101
echo "tag=${release_tag}" >> "${GITHUB_OUTPUT}"
79102
80-
- name: Validate package
81-
run: |
82-
uv lock --check
83-
uv run --frozen ruff check .
84-
uv run --frozen ruff format --check .
85-
uv run --frozen pyright
86-
uv run --frozen python -m unittest discover -s tests
87-
uv run --frozen python - <<'PY'
88-
import os
89-
90-
import src_py_lib
91-
92-
if src_py_lib.__name__ != os.environ["IMPORT_NAME"]:
93-
raise SystemExit(f"unexpected import name: {src_py_lib.__name__}")
94-
PY
95-
96103
- name: Build distributions
97104
id: build
98105
run: |
@@ -115,17 +122,24 @@ jobs:
115122
wheel_path="${project_wheels[0]}"
116123
wheel_name="$(basename "${wheel_path}")"
117124
source_distribution_path="${source_distributions[0]}"
118-
checksum_path="${wheel_path}.sha256"
125+
source_distribution_name="$(basename "${source_distribution_path}")"
126+
wheel_checksum_path="${wheel_path}.sha256"
127+
source_distribution_checksum_path="${source_distribution_path}.sha256"
119128
120129
(
121130
cd "$(dirname "${wheel_path}")"
122-
shasum -a 256 "${wheel_name}" > "$(basename "${checksum_path}")"
131+
shasum -a 256 "${wheel_name}" > "$(basename "${wheel_checksum_path}")"
132+
shasum -a 256 "${source_distribution_name}" > "$(basename "${source_distribution_checksum_path}")"
123133
)
124134
125-
echo "wheel_path=${wheel_path}" >> "${GITHUB_OUTPUT}"
126-
echo "wheel_name=${wheel_name}" >> "${GITHUB_OUTPUT}"
127-
echo "source_distribution_path=${source_distribution_path}" >> "${GITHUB_OUTPUT}"
128-
echo "checksum_path=${checksum_path}" >> "${GITHUB_OUTPUT}"
135+
{
136+
echo "wheel_path=${wheel_path}"
137+
echo "wheel_name=${wheel_name}"
138+
echo "source_distribution_path=${source_distribution_path}"
139+
echo "source_distribution_name=${source_distribution_name}"
140+
echo "wheel_checksum_path=${wheel_checksum_path}"
141+
echo "source_distribution_checksum_path=${source_distribution_checksum_path}"
142+
} >> "${GITHUB_OUTPUT}"
129143
130144
- name: Smoke test installed wheel
131145
run: |
@@ -147,6 +161,7 @@ jobs:
147161
run: |
148162
release_tag="${{ steps.release.outputs.tag }}"
149163
wheel_name="${{ steps.build.outputs.wheel_name }}"
164+
source_distribution_name="${{ steps.build.outputs.source_distribution_name }}"
150165
notes_path="build/release/release-notes.md"
151166
cat > "${notes_path}" <<EOF
152167
## Install
@@ -163,13 +178,19 @@ jobs:
163178
pip install "https://github.com/sourcegraph/src-py-lib/releases/download/${release_tag}/${wheel_name}"
164179
\`\`\`
165180
181+
Source distribution:
182+
183+
\`\`\`sh
184+
curl -LO "https://github.com/sourcegraph/src-py-lib/releases/download/${release_tag}/${source_distribution_name}"
185+
\`\`\`
186+
166187
Or install this tag with uv:
167188
168189
\`\`\`sh
169190
uv add "git+https://github.com/sourcegraph/src-py-lib.git@${release_tag}"
170191
\`\`\`
171192
172-
Verify downloaded wheel assets with the matching \`.sha256\` file.
193+
Verify downloaded assets with the matching \`.sha256\` files.
173194
EOF
174195
echo "path=${notes_path}" >> "${GITHUB_OUTPUT}"
175196
@@ -179,7 +200,9 @@ jobs:
179200
name: src-py-lib-release
180201
path: |
181202
${{ steps.build.outputs.wheel_path }}
182-
${{ steps.build.outputs.checksum_path }}
203+
${{ steps.build.outputs.source_distribution_path }}
204+
${{ steps.build.outputs.wheel_checksum_path }}
205+
${{ steps.build.outputs.source_distribution_checksum_path }}
183206
${{ steps.notes.outputs.path }}
184207
185208
- name: Upload PyPI artifact
@@ -196,16 +219,23 @@ jobs:
196219
run: |
197220
release_tag="${{ steps.release.outputs.tag }}"
198221
wheel_path="${{ steps.build.outputs.wheel_path }}"
199-
checksum_path="${{ steps.build.outputs.checksum_path }}"
222+
source_distribution_path="${{ steps.build.outputs.source_distribution_path }}"
223+
wheel_checksum_path="${{ steps.build.outputs.wheel_checksum_path }}"
224+
source_distribution_checksum_path="${{ steps.build.outputs.source_distribution_checksum_path }}"
200225
notes_path="${{ steps.notes.outputs.path }}"
226+
release_assets=(
227+
"${wheel_path}"
228+
"${source_distribution_path}"
229+
"${wheel_checksum_path}"
230+
"${source_distribution_checksum_path}"
231+
)
201232
202233
if gh release view "${release_tag}" >/dev/null 2>&1; then
203234
gh release edit "${release_tag}" --title "${release_tag}" --notes-file "${notes_path}"
204-
gh release upload "${release_tag}" "${wheel_path}" "${checksum_path}" --clobber
235+
gh release upload "${release_tag}" "${release_assets[@]}" --clobber
205236
else
206237
gh release create "${release_tag}" \
207-
"${wheel_path}" \
208-
"${checksum_path}" \
238+
"${release_assets[@]}" \
209239
--title "${release_tag}" \
210240
--notes-file "${notes_path}" \
211241
--verify-tag

.github/workflows/validate.yml

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
name: Validate
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
ref:
7+
description: "Git ref to validate. Defaults to the caller's ref."
8+
required: false
9+
type: string
10+
11+
permissions:
12+
contents: read
13+
14+
defaults:
15+
run:
16+
shell: bash
17+
18+
jobs:
19+
package:
20+
name: Validate package
21+
runs-on: ubuntu-24.04
22+
env:
23+
ACTIONLINT_VERSION: "1.7.12"
24+
IMPORT_NAME: src_py_lib
25+
MARKDOWNLINT_CLI2_VERSION: "0.22.1"
26+
PYTHON_VERSION: "3.11"
27+
UV_VERSION: "0.11.7"
28+
29+
steps:
30+
- name: Check out code
31+
uses: actions/checkout@v6
32+
with:
33+
persist-credentials: false
34+
ref: ${{ inputs.ref || github.ref }}
35+
36+
- name: Cache actionlint
37+
id: cache-actionlint
38+
uses: actions/cache@v4
39+
with:
40+
path: ~/.local/bin/actionlint
41+
key: actionlint-${{ runner.os }}-${{ runner.arch }}-${{ env.ACTIONLINT_VERSION }}
42+
43+
- name: Install actionlint
44+
if: steps.cache-actionlint.outputs.cache-hit != 'true'
45+
run: |
46+
mkdir -p "${HOME}/.local/bin"
47+
go install "github.com/rhysd/actionlint/cmd/actionlint@v${ACTIONLINT_VERSION}"
48+
install -m 0755 "${HOME}/go/bin/actionlint" "${HOME}/.local/bin/actionlint"
49+
50+
- name: Lint GitHub Actions
51+
run: |
52+
"${HOME}/.local/bin/actionlint"
53+
54+
- name: Cache npm
55+
uses: actions/cache@v4
56+
with:
57+
path: ~/.npm
58+
key: npm-${{ runner.os }}-markdownlint-cli2-${{ env.MARKDOWNLINT_CLI2_VERSION }}
59+
60+
- name: Lint Markdown
61+
run: npx --yes "markdownlint-cli2@${MARKDOWNLINT_CLI2_VERSION}"
62+
63+
- name: Set up Python
64+
uses: actions/setup-python@v6
65+
with:
66+
python-version: ${{ env.PYTHON_VERSION }}
67+
cache: pip
68+
69+
- name: Cache uv
70+
uses: actions/cache@v4
71+
with:
72+
path: ~/.cache/uv
73+
key: uv-${{ runner.os }}-py${{ env.PYTHON_VERSION }}-${{ hashFiles('uv.lock') }}
74+
restore-keys: |
75+
uv-${{ runner.os }}-py${{ env.PYTHON_VERSION }}-
76+
77+
- name: Install uv
78+
run: |
79+
python -m pip install --upgrade pip
80+
python -m pip install "uv==${UV_VERSION}"
81+
82+
- name: Validate lockfile
83+
run: uv lock --check
84+
85+
- name: Lint Python
86+
run: uv run --frozen ruff check .
87+
88+
- name: Check Python formatting
89+
run: uv run --frozen ruff format --check .
90+
91+
- name: Type check
92+
run: uv run --frozen pyright
93+
94+
- name: Run tests
95+
run: uv run --frozen python -m unittest discover -s tests
96+
97+
- name: Smoke test source checkout import
98+
run: |
99+
uv run --frozen python - <<'PY'
100+
import os
101+
102+
import src_py_lib
103+
104+
if src_py_lib.__name__ != os.environ["IMPORT_NAME"]:
105+
raise SystemExit(f"unexpected import name: {src_py_lib.__name__}")
106+
PY
107+
108+
- name: Build wheel
109+
run: uv build --wheel --out-dir dist --no-create-gitignore
110+
111+
- name: Smoke test installed wheel
112+
run: |
113+
python -m venv build/ci-venv
114+
. build/ci-venv/bin/activate
115+
python -m pip install --upgrade pip
116+
python -m pip install dist/*.whl
117+
python - <<'PY'
118+
import os
119+
120+
import src_py_lib
121+
122+
if src_py_lib.__name__ != os.environ["IMPORT_NAME"]:
123+
raise SystemExit(f"unexpected import name: {src_py_lib.__name__}")
124+
PY

0 commit comments

Comments
 (0)