Skip to content

Use workflow ID in wheel upload #20253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 59 additions & 19 deletions .builders/tests/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
import upload


@pytest.fixture
def workflow_id():
return '1234567890'


@pytest.fixture
def setup_fake_bucket(monkeypatch):
"""Patch google storage functions to simulate a bucket."""
Expand Down Expand Up @@ -89,13 +94,6 @@ def fake_hash(path: Path):
return _setup_hash


@pytest.fixture
def frozen_timestamp(monkeypatch):
timestamp = 20241327_090504
monkeypatch.setattr(upload, 'timestamp_build_number', mock.Mock(return_value=timestamp))
return timestamp


def test_upload_external(setup_targets_dir, setup_fake_bucket):
wheels = {
'external': [
Expand All @@ -114,7 +112,7 @@ def test_upload_external(setup_targets_dir, setup_fake_bucket):
}
bucket, uploads = setup_fake_bucket(bucket_files)

upload.upload(targets_dir)
upload.upload(targets_dir, workflow_id)

bucket_files = [f.name for f in bucket.list_blobs()]
assert 'external/all-new/all_new-2.31.0-py3-none-any.whl' in bucket_files
Expand All @@ -124,7 +122,7 @@ def test_upload_external(setup_targets_dir, setup_fake_bucket):
assert {'all_new-2.31.0-py3-none-any.whl', 'updated_version-3.14.1-cp311-cp311-manylinux1_x86_64.whl'} <= uploads


def test_upload_built_no_conflict(setup_targets_dir, setup_fake_bucket, frozen_timestamp):
def test_upload_built_no_conflict(setup_targets_dir, setup_fake_bucket, workflow_id):
wheels = {
'built': [
('without_collision-3.14.1-cp311-cp311-manylinux2010_x86_64.whl', 'without-collision', '3.14.1', '>=3.7'),
Expand All @@ -134,11 +132,11 @@ def test_upload_built_no_conflict(setup_targets_dir, setup_fake_bucket, frozen_t

bucket, uploads = setup_fake_bucket({})

upload.upload(targets_dir)
upload.upload(targets_dir, workflow_id)

bucket_files = [f.name for f in bucket.list_blobs()]
assert (
f'built/without-collision/without_collision-3.14.1-{frozen_timestamp}-cp311-cp311-manylinux2010_x86_64.whl'
f'built/without-collision/without_collision-3.14.1-{workflow_id}WID-cp311-cp311-manylinux2010_x86_64.whl'
in bucket_files
)

Expand All @@ -147,6 +145,7 @@ def test_upload_built_existing_sha_match_does_not_upload(
setup_targets_dir,
setup_fake_bucket,
setup_fake_hash,
workflow_id,
):
whl_hash = 'some-hash'

Expand All @@ -167,7 +166,7 @@ def test_upload_built_existing_sha_match_does_not_upload(
'existing-1.1.1-cp311-cp311-manylinux2010_x86_64.whl': whl_hash,
})

upload.upload(targets_dir)
upload.upload(targets_dir, workflow_id)

assert not uploads

Expand All @@ -176,7 +175,7 @@ def test_upload_built_existing_different_sha_does_upload(
setup_targets_dir,
setup_fake_bucket,
setup_fake_hash,
frozen_timestamp,
workflow_id,
):
original_hash = 'first-hash'
new_hash = 'second-hash'
Expand All @@ -198,20 +197,21 @@ def test_upload_built_existing_different_sha_does_upload(
'existing-1.1.1-cp311-cp311-manylinux2010_x86_64.whl': new_hash,
})

upload.upload(targets_dir)
upload.upload(targets_dir, workflow_id)

uploads = {str(Path(f).name) for f in uploads}

assert uploads == {'existing-1.1.1-cp311-cp311-manylinux2010_x86_64.whl'}

bucket_files = {f.name for f in bucket.list_blobs()}
assert f'built/existing/existing-1.1.1-{frozen_timestamp}-cp311-cp311-manylinux2010_x86_64.whl' in bucket_files
assert f'built/existing/existing-1.1.1-{workflow_id}WID-cp311-cp311-manylinux2010_x86_64.whl' in bucket_files


def test_upload_built_existing_sha_match_does_not_upload_multiple_existing_builds(
setup_targets_dir,
setup_fake_bucket,
setup_fake_hash,
workflow_id,
):
matching_hash = 'some-hash'
non_matching_hash = 'xxxx'
Expand Down Expand Up @@ -242,7 +242,7 @@ def test_upload_built_existing_sha_match_does_not_upload_multiple_existing_build
'existing-1.1.1-cp311-cp311-manylinux2010_x86_64.whl': matching_hash,
})

upload.upload(targets_dir)
upload.upload(targets_dir, workflow_id)

assert not uploads

Expand All @@ -251,16 +251,55 @@ def test_upload_built_existing_different_sha_does_upload_multiple_existing_build
setup_targets_dir,
setup_fake_bucket,
setup_fake_hash,
frozen_timestamp,
workflow_id,
):
original_hash = 'first-hash'
new_hash = 'second-hash'

wheels = {
'built': [
('existing-1.1.1-cp311-cp311-manylinux2010_x86_64.whl', 'existing', '1.1.1', '>=3.7'),
]
}
targets_dir = setup_targets_dir(wheels)

bucket_files = {
'built/existing/existing-1.1.1-2024132600000-cp311-cp311-manylinux2010_x86_64.whl':
{'requires-python': '', 'sha256': 'b'},
'built/existing/existing-1.1.1-2024132700000-cp311-cp311-manylinux2010_x86_64.whl':
{'requires-python': '', 'sha256': original_hash},
}
bucket, uploads = setup_fake_bucket(bucket_files)

setup_fake_hash({
'existing-1.1.1-cp311-cp311-manylinux2010_x86_64.whl': new_hash,
})

upload.upload(targets_dir, workflow_id)

uploads = {str(Path(f).name) for f in uploads}

assert uploads == {'existing-1.1.1-cp311-cp311-manylinux2010_x86_64.whl'}

bucket_files = {f.name for f in bucket.list_blobs()}
assert f'built/existing/existing-1.1.1-{workflow_id}WID-cp311-cp311-manylinux2010_x86_64.whl' in bucket_files


def test_build_tag_use_workflow_id(
setup_targets_dir,
setup_fake_bucket,
setup_fake_hash,
):
original_hash = 'first-hash'
new_hash = 'second-hash'
workflow_id = '1234567890'

wheels = {
'built': [
('existing-1.1.1-cp311-cp311-manylinux2010_x86_64.whl', 'existing', '1.1.1', '>=3.7'),
]
}

targets_dir = setup_targets_dir(wheels)

bucket_files = {
Expand All @@ -269,17 +308,18 @@ def test_upload_built_existing_different_sha_does_upload_multiple_existing_build
'built/existing/existing-1.1.1-2024132700000-cp311-cp311-manylinux2010_x86_64.whl':
{'requires-python': '', 'sha256': original_hash},
}

bucket, uploads = setup_fake_bucket(bucket_files)

setup_fake_hash({
'existing-1.1.1-cp311-cp311-manylinux2010_x86_64.whl': new_hash,
})

upload.upload(targets_dir)
upload.upload(targets_dir, workflow_id)

uploads = {str(Path(f).name) for f in uploads}

assert uploads == {'existing-1.1.1-cp311-cp311-manylinux2010_x86_64.whl'}

bucket_files = {f.name for f in bucket.list_blobs()}
assert f'built/existing/existing-1.1.1-{frozen_timestamp}-cp311-cp311-manylinux2010_x86_64.whl' in bucket_files
assert f'built/existing/existing-1.1.1-{workflow_id}WID-cp311-cp311-manylinux2010_x86_64.whl' in bucket_files
2 changes: 1 addition & 1 deletion .github/workflows/resolve-build-deps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ jobs:
workload_identity_provider: projects/574011472402/locations/global/workloadIdentityPools/github/providers/integrations-core

- name: Upload wheels
run: python .builders/upload.py targets
run: python .builders/upload.py targets ${{ github.run_id }}

- name: Lock files
run: python .builders/lock.py targets
Expand Down
Loading