Repository navigation
ci(release): restructure the release workflow #264
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
006df96
Security updates for the pipeline
david-ruiz-cko a72b35b
Updated comments
david-ruiz-cko 632bbcb
SonarCube security fixes
david-ruiz-cko f0c73d3
Versioning fine tune
david-ruiz-cko b7ebaf3
build release update
david-ruiz-cko cdaeec3
SonarCube code smell alerts fix
david-ruiz-cko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| #!/usr/bin/env bash | ||
| # Regenerates the hash-locked requirements of .github/workflows/build-release.yml: | ||
| # requirements-release-test.txt from requirements-ci.txt and PIP below | ||
| # requirements-release-build.txt from BUILD_TOOLS and PIP below | ||
| # Resolves inside linux/amd64 CPython 3.10, the interpreter and platform of the release job, | ||
| # so environment markers and wheel tags match what the runner installs. Requires Docker. | ||
| # Existing pins are kept; pass --upgrade to move every package to its latest version. | ||
| # Usage, from the repository root: bash .github/scripts/compile-release-locks.sh [--upgrade] | ||
| set -euo pipefail | ||
|
|
||
| # setuptools and wheel must satisfy [build-system] requires in pyproject.toml: the build job | ||
| # runs python -m build --no-isolation, which fails if the installed versions do not. | ||
| BUILD_TOOLS='build==1.6.1 | ||
| setuptools==84.2.1 | ||
| wheel==0.48.0' | ||
| PIP='pip==26.3' | ||
|
|
||
| cd "$(dirname "$0")/../.." | ||
|
|
||
| docker run --rm --platform linux/amd64 -v "$PWD":/src -w /src \ | ||
| -e CUSTOM_COMPILE_COMMAND="bash .github/scripts/compile-release-locks.sh" \ | ||
| -e BUILD_TOOLS="$BUILD_TOOLS" -e PIP="$PIP" -e EXTRA_ARGS="${1:-}" \ | ||
| python:3.10-slim bash -euo pipefail -c ' | ||
| pip install --quiet --root-user-action=ignore pip-tools==7.6.2 | ||
| compile() { | ||
| pip-compile --quiet --generate-hashes --allow-unsafe --strip-extras --no-emit-index-url \ | ||
| --pip-args="--only-binary :all:" $EXTRA_ARGS "$@" | ||
| } | ||
| printf "%s\n" "$PIP" | compile -o requirements-release-test.txt requirements-ci.txt - | ||
| printf "%s\n" "$BUILD_TOOLS" "$PIP" | compile -o requirements-release-build.txt - | ||
| ' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| """Checks the release artifacts in dist/ before they are handed to the publish job. | ||
| Fails unless the directory holds exactly the wheel and the sdist of the expected version, | ||
| both archives contain only the entries the package is meant to ship, and the version in | ||
| the metadata and in checkout_sdk/properties.py matches. Standard library only, so it adds | ||
| nothing to the release job's locked dependencies. | ||
| Run from the repository root: python -I .github/scripts/verify_dist.py <version> | ||
| """ | ||
| import email.parser | ||
| import pathlib | ||
| import re | ||
| import sys | ||
| import tarfile | ||
| import zipfile | ||
|
|
||
| PACKAGE = 'checkout_sdk' | ||
| DIST = pathlib.Path('dist') | ||
| VERSION_PATTERN = re.compile(r'\d+\.\d+\.\d+((a|b|rc)\d+)?(\.dev\d+)?', re.ASCII) | ||
|
|
||
|
|
||
| def fail(message): | ||
| sys.exit(f'verify_dist: {message}') | ||
|
|
||
|
|
||
| def read_metadata(raw): | ||
| return email.parser.Parser().parsestr(raw.decode('utf-8')) | ||
|
|
||
|
|
||
| def check_metadata(metadata, version, source): | ||
| if metadata['Name'] != PACKAGE: | ||
| fail(f'{source}: Name is {metadata["Name"]!r}, expected {PACKAGE!r}') | ||
| if metadata['Version'] != version: | ||
| fail(f'{source}: Version is {metadata["Version"]!r}, expected {version!r}') | ||
|
|
||
|
|
||
| def check_properties(raw, version, source): | ||
| expected = f'VERSION = "{version}"' | ||
| if expected not in raw.decode('utf-8'): | ||
| fail(f'{source}: checkout_sdk/properties.py does not contain {expected}') | ||
|
|
||
|
|
||
| def check_wheel(path, version): | ||
| allowed = {PACKAGE, f'{PACKAGE}-{version}.dist-info'} | ||
| with zipfile.ZipFile(path) as wheel: | ||
| names = wheel.namelist() | ||
| unexpected = sorted({name.split('/')[0] for name in names} - allowed) | ||
| if unexpected: | ||
| fail(f'{path.name}: unexpected top-level entries {unexpected}') | ||
| check_metadata(read_metadata(wheel.read(f'{PACKAGE}-{version}.dist-info/METADATA')), | ||
| version, path.name) | ||
| check_properties(wheel.read(f'{PACKAGE}/properties.py'), version, path.name) | ||
| return len(names) | ||
|
|
||
|
|
||
| def check_sdist(path, version): | ||
| root = f'{PACKAGE}-{version}' | ||
| allowed = {'LICENSE.md', 'PKG-INFO', 'README.md', PACKAGE, f'{PACKAGE}.egg-info', | ||
| 'pyproject.toml', 'setup.cfg', 'setup.py'} | ||
| with tarfile.open(path) as sdist: | ||
| members = [member for member in sdist.getmembers() if member.name != root] | ||
| for member in members: | ||
| parts = member.name.split('/') | ||
| if parts[0] != root or parts[1] not in allowed: | ||
| fail(f'{path.name}: unexpected entry {member.name}') | ||
| if not (member.isfile() or member.isdir()): | ||
| fail(f'{path.name}: {member.name} is not a regular file or directory') | ||
| check_metadata(read_metadata(sdist.extractfile(f'{root}/PKG-INFO').read()), | ||
| version, path.name) | ||
| check_properties(sdist.extractfile(f'{root}/{PACKAGE}/properties.py').read(), | ||
| version, path.name) | ||
| return len(members) | ||
|
|
||
|
|
||
| def main(version): | ||
| if not VERSION_PATTERN.fullmatch(version): | ||
| fail(f'{version!r} is not a release or dev version') | ||
| # The version is only compared with file names; the files opened come from the listing. | ||
| files = sorted(DIST.iterdir()) | ||
| expected = sorted([f'{PACKAGE}-{version}-py3-none-any.whl', f'{PACKAGE}-{version}.tar.gz']) | ||
| if [path.name for path in files] != expected: | ||
| fail(f'{DIST}: found {[path.name for path in files]}, expected exactly {expected}') | ||
| wheel, sdist = files # '-py3' sorts before '.tar', so the wheel comes first | ||
| print(f'{wheel.name}: {check_wheel(wheel, version)} entries OK') | ||
| print(f'{sdist.name}: {check_sdist(sdist, version)} entries OK') | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| if len(sys.argv) != 2: | ||
| fail('usage: verify_dist.py <version>') | ||
| main(sys.argv[1]) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| [build-system] | ||
| # Exact pins for reproducible builds. | ||
| # Keep in sync with BUILD_TOOLS in .github/scripts/compile-release-locks.sh. | ||
| requires = ["setuptools==84.2.1", "wheel==0.48.0"] | ||
| build-backend = "setuptools.build_meta" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.