Skip to content
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

NH-26173 Add sdist and wheel extension checks at package build #75

Merged
merged 22 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5dbd83a
(WIP) attempt to translate install shell to Makefile
tammy-baylis-swi Nov 9, 2022
49f50bb
Revert "(WIP) attempt to translate install shell to Makefile"
tammy-baylis-swi Nov 9, 2022
c0985b4
Refactor check_sdist to separate script
tammy-baylis-swi Nov 9, 2022
baefe99
Permissions for _helper_check_sdist
tammy-baylis-swi Nov 9, 2022
fbae0cf
Add target check-sdist-local
tammy-baylis-swi Nov 9, 2022
fbcf294
Parameterize agent_root
tammy-baylis-swi Nov 9, 2022
798a372
make package calls check-sdist-local target
tammy-baylis-swi Nov 9, 2022
6654e61
Parameterize PIP_INSTALL; fix APM_ROOT set/usage
tammy-baylis-swi Nov 9, 2022
629f9ce
check-sdist-local depends on sdist
tammy-baylis-swi Nov 9, 2022
89d839c
Refactor separate _helper_check_wheell
tammy-baylis-swi Nov 9, 2022
0f4ba31
make package does check-wheel-local
tammy-baylis-swi Nov 9, 2022
bf36c0d
Refactor separate _helper_check_extension_files
tammy-baylis-swi Nov 9, 2022
8960b24
Rename and simplify var SOLARWINDS_APM_VERSION
tammy-baylis-swi Nov 9, 2022
11ba992
shellcheck cleanups
tammy-baylis-swi Nov 10, 2022
629ac1f
Reorganize prod release actions
tammy-baylis-swi Nov 10, 2022
9448800
Update changelog
tammy-baylis-swi Nov 10, 2022
5496b3b
Reduce target deps; update log
tammy-baylis-swi Nov 10, 2022
0f755db
Rm unneeded package_solarwinds_apm call
tammy-baylis-swi Nov 10, 2022
70e469b
Rm checkout, add --repo flag to create draft release
tammy-baylis-swi Nov 10, 2022
c527b02
Test create_draft_release
tammy-baylis-swi Nov 10, 2022
9000a6e
Revert "Test create_draft_release"
tammy-baylis-swi Nov 10, 2022
aec44cb
Revert "Rm checkout, add --repo flag to create draft release"
tammy-baylis-swi Nov 10, 2022
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
10 changes: 9 additions & 1 deletion .github/workflows/build_publish_pypi_and_draft_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ env:

jobs:
is_publishable:
name: Check if version valid and package not already published
name: Check if version valid
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Check version
run: cd .github/scripts && ./is_publishable.sh ${{ github.event.inputs.version }}

build_publish_and_release:
name: Build and publish to PyPI
needs: is_publishable
runs-on: ubuntu-latest
steps:
Expand All @@ -35,6 +36,13 @@ jobs:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.SW_APM_PYPI_UPLOAD_TOKEN }}
run: twine upload dist/*

create_release:
name: Create draft release
needs: build_publish_and_release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Initialize git
run: |
git config user.name "GitHub Actions"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/create_release_pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
git commit --message "Update agent version to ${{ env.RELEASE_VERSION }}"
- name: Push new release branch to remote repositories
run: git push origin release/${{ env.RELEASE_NAME }}
- name: Open Pull Request for version bump
run: gh pr create --title "Update agent version to ${{ env.RELEASE_VERSION }}" --body "Upgrade agent version"
- name: Open draft Pull Request for version bump
run: gh pr create --draft --title "solarwinds-apm ${{ env.RELEASE_VERSION }}" --body "For PyPI release of solarwinds-apm ${{ env.RELEASE_VERSION }}. See also CHANGELOG.md."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased](https://github.com/appoptics/solarwinds-apm-python/compare/v0.1.0...HEAD)
## [Unreleased](https://github.com/appoptics/solarwinds-apm-python/compare/rel-0.2.1...HEAD)
### Added
- Added sdist and wheel extension file checks as part of library packaging ([#75](https://github.com/appoptics/solarwinds-apm-python/pull/75))

## [0.2.1](https://github.com/appoptics/solarwinds-apm-python/releases/tag/v0.2.1) - 2022-11-08
Version bump for rebuild of 0.2.0.
### Changed
* Version bump for rebuild of 0.2.0 ([#73](https://github.com/appoptics/solarwinds-apm-python/pull/73))

## [0.2.0](https://github.com/appoptics/solarwinds-apm-python/releases/tag/v0.2.0) - 2022-11-07
### Added
Expand Down
15 changes: 13 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ sdist: wrapper
@python3.8 setup.py sdist
@echo -e "\nDone."

# Check local package source distribution archive contents, without install
CURR_DIR := $(shell pwd)
check-sdist-local:
@cd ./tests/docker/install && MODE=local APM_ROOT=$(CURR_DIR) ./_helper_check_sdist.sh
@cd $(CURR_DIR)

# Build the Python agent package bdist (wheels) for 64 bit many linux systems (except Alpine).
# The recipe builds the wheels for all Python versions available in the docker image EXCEPT py36, similarly to the example provided
# in the corresponding repo of the Docker images: https://github.com/pypa/manylinux#example.
Expand All @@ -153,8 +159,13 @@ manylinux-wheels: wrapper
@rm -rf ./tmp_dist
@echo -e "\nDone."

# Build the full Python agent distribution (sdist and wheels)
package: sdist manylinux-wheels
# Check local package wheel contents, without install
check-wheel-local:
@cd ./tests/docker/install && MODE=local APM_ROOT=$(CURR_DIR) ./_helper_check_wheel.sh
@cd $(CURR_DIR)

# Build and check the full Python agent distribution (sdist and wheels)
package: sdist check-sdist-local manylinux-wheels check-wheel-local
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, the check-* tasks already depend on the sdist and manylinux-wheels tasks, so don't need them in the package task... or if it seems clearer, the check-* tasks don't have them as deps.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes good call! Addressed in 5496b3b


# Build the AWS lambda layer.
# temporary target directory for AWS Lambda build artifacts
Expand Down
26 changes: 26 additions & 0 deletions tests/docker/install/_helper_check_extension_files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

# Verifies content in the extension directory solarwinds_apm/extension. The absolute path of the directory to be verified
# needs to be passed in as the first argument of this function. As the second argument, a string containing the
# files expected under solarwinds_apm/extension needs to be provided.
echo "---- Check content of extension directory located at $1 ----"
if [ -z "$2" ]; then
echo "Failed! Files expected in the extension directory not provided."
exit 1
fi

expected_files="$2"

pushd "$1" >/dev/null || exit 1
found_swig_files=$(find . -not -path '.' | LC_ALL=C sort)
popd >/dev/null || exit 1

if [[ ! "$found_swig_files" =~ $expected_files ]]; then
echo "FAILED! expected these files under the extension directory:"
echo "$expected_files"
echo "found:"
echo "$found_swig_files"
exit 1
fi

echo -e "Content of extension directory checked successfully.\n"
119 changes: 119 additions & 0 deletions tests/docker/install/_helper_check_sdist.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#!/usr/bin/env bash

# stop on error
set -e

# get test mode
TEST_MODES=(
"local"
"testpypi"
"packagecloud"
"pypi"
)
if [ -z "$MODE" ]
then
echo "WARNING: Did not provide MODE for check_sdist test."
echo "Defaulting to MODE=local"
MODE=local
fi
if [[ ! " ${TEST_MODES[*]} " =~ ${MODE} ]]
then
echo "FAILED: Did not provide valid MODE for check_sdist test. Must be one of: testpypi (default), local, packagecloud, pypi."
exit 1
else
echo "Using provided MODE=$MODE for check_sdist test."
fi

if [ -z "$APM_ROOT" ]
then
echo "FAILED: Did not provide valid APM_ROOT for check_sdist test."
exit 1
fi


function get_sdist(){
sdist_dir="$PWD/tmp/sdist"
rm -rf sdist_dir

if [ "$MODE" == "local" ]
then
# optionally test a previous version on local for debugging
if [ -z "$SOLARWINDS_APM_VERSION" ]; then
# no SOLARWINDS_APM_VERSION provided, thus test version of current source code
version_file=$APM_ROOT/solarwinds_apm/version.py
SOLARWINDS_APM_VERSION="$(sed -n 's/__version__ = "\(.*\)"/\1/p' "$version_file")"
echo "No SOLARWINDS_APM_VERSION provided, thus testing source code version ($SOLARWINDS_APM_VERSION)"
fi

sdist_tar=$APM_ROOT/dist/solarwinds_apm-${SOLARWINDS_APM_VERSION}.tar.gz
if [ ! -f "$sdist_tar" ]; then
echo "FAILED: Did not find sdist for version $SOLARWINDS_APM_VERSION. Please run 'make package' before running tests."
echo "Aborting tests."
exit 1
fi
else
pip_options=(--no-binary solarwinds-apm --dest "$sdist_dir")
if [ "$MODE" == "testpypi" ]
then
pip_options+=(--extra-index-url https://test.pypi.org/simple/)
elif [ "$MODE" == "packagecloud" ]
then
curl -s https://packagecloud.io/install/repositories/solarwinds/solarwinds-apm-python/script.python.sh | bash
fi

if [ -z "$SOLARWINDS_APM_VERSION" ]
then
pip_options+=(solarwinds-apm)
else
pip_options+=(solarwinds-apm=="$SOLARWINDS_APM_VERSION")
fi

# shellcheck disable=SC2048
# shellcheck disable=SC2086
pip download ${pip_options[*]}
sdist_tar=$(find "$sdist_dir"/* -name "solarwinds_apm-*.tar.gz")
fi
}

function check_sdist(){
unpack_directory="$PWD/unpack/sdist"
rm -rf "$unpack_directory"
mkdir -p "$unpack_directory"
expected_files="./VERSION
./__init__.py
./bson
./bson/bson.h
./bson/platform_hacks.h
./liboboe-1.0-alpine-x86_64.so.0.0.0
./liboboe-1.0-lambda-x86_64.so.0.0.0
./liboboe-1.0-x86_64.so.0.0.0
./oboe.h
./oboe.py
./oboe_api.cpp
./oboe_api.h
./oboe_debug.h
./oboe_wrap.cxx"
tar xzf "$1" --directory "$unpack_directory"
unpack_agent=$(find "$unpack_directory"/* -type d -name "solarwinds_apm-*")
# shellcheck disable=SC1091
source ./_helper_check_extension_files.sh "$unpack_agent/solarwinds_apm/extension" "$expected_files"

if [ -z "$PIP_INSTALL" ]; then
echo -e "PIP_INSTALL not specified."
echo -e "Source distribution verified successfully.\n"
rm -rf "$unpack_directory"
exit 0
else
echo "Installing Python agent from source"
pip install -I "$1"
fi
}

function get_and_check_sdist(){
echo "#### Verifying Python agent source distribution ####"
get_sdist
check_sdist "$sdist_tar"
}

# start testing
get_and_check_sdist
131 changes: 131 additions & 0 deletions tests/docker/install/_helper_check_wheel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
#!/usr/bin/env bash

# stop on error
set -e

# get test mode
TEST_MODES=(
"local"
"testpypi"
"packagecloud"
"pypi"
)
if [ -z "$MODE" ]
then
echo "WARNING: Did not provide MODE for check_sdist test."
echo "Defaulting to MODE=local"
MODE=local
fi
if [[ ! " ${TEST_MODES[*]} " =~ ${MODE} ]]
then
echo "FAILED: Did not provide valid MODE for check_sdist test. Must be one of: testpypi (default), local, packagecloud, pypi."
exit 1
else
echo "Using provided MODE=$MODE for check_sdist test."
fi

if [ -z "$APM_ROOT" ]
then
echo "FAILED: Did not provide valid APM_ROOT for check_sdist test."
exit 1
fi


function get_wheel(){
wheel_dir="$PWD/tmp/wheel"
rm -rf "$wheel_dir"
if [ "$MODE" == "local" ]
then
# optionally test a previous version on local for debugging
if [ -z "$SOLARWINDS_APM_VERSION" ]; then
# no SOLARWINDS_APM_VERSION provided, thus test version of current source code
version_file=$APM_ROOT/solarwinds_apm/version.py
SOLARWINDS_APM_VERSION="$(sed -n 's/__version__ = "\(.*\)"/\1/p' "$version_file")"
echo "No SOLARWINDS_APM_VERSION provided, thus testing source code version ($SOLARWINDS_APM_VERSION)"
fi

if [ -z "$PIP_INSTALL" ]; then
echo -e "PIP_INSTALL not specified."
echo -e "Only testing the cp38 x86_64 wheel under ${APM_ROOT}"
tested_wheel=$(find "$APM_ROOT"/dist/* -name "solarwinds_apm-$SOLARWINDS_APM_VERSION-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl")
else
# we need to select the right wheel (there might be multiple wheel versions in the dist directory)
pip download \
--only-binary solarwinds_apm \
--find-links "$APM_ROOT"/dist \
--no-index \
--dest "$wheel_dir" \
--no-deps \
solarwinds_apm=="$SOLARWINDS_APM_VERSION"
tested_wheel=$(find "$wheel_dir"/* -name "solarwinds_apm-$SOLARWINDS_APM_VERSION*.*.whl")
fi

if [ ! -f "$tested_wheel" ]; then
echo "FAILED: Did not find wheel for version $SOLARWINDS_APM_VERSION. Please run 'make package' before running tests."
echo "Aborting tests."
exit 1
fi
else
pip_options=(--only-binary solarwinds-apm --dest "$wheel_dir")
if [ "$MODE" == "testpypi" ]
then
pip_options+=(--extra-index-url https://test.pypi.org/simple/)
elif [ "$MODE" == "packagecloud" ]
then
curl -s https://packagecloud.io/install/repositories/solarwinds/solarwinds-apm-python/script.python.sh | bash
fi

if [ -z "$SOLARWINDS_APM_VERSION" ]
then
pip_options+=(solarwinds-apm)
else
pip_options+=(solarwinds-apm=="$SOLARWINDS_APM_VERSION")
fi

# shellcheck disable=SC2048
# shellcheck disable=SC2086
pip download ${pip_options[*]}
tested_wheel=$(find "$wheel_dir"/* -name "solarwinds_apm-*.*.whl")
fi
}

function check_wheel(){
unpack_directory="$PWD/unpack/wheel"
rm -rf "$unpack_directory"
mkdir -p "$unpack_directory"
expected_files="./VERSION
./__init__.py
./_oboe.*.so
./bson
./bson/bson.h
./bson/platform_hacks.h
./liboboe-1.0.so.0
./oboe.py"
unzip "$tested_wheel" -d "$unpack_directory"
# shellcheck disable=SC1091
source ./_helper_check_extension_files.sh "$unpack_directory/solarwinds_apm/extension" "$expected_files"

if [ -z "$PIP_INSTALL" ]; then
echo -e "PIP_INSTALL not specified."
echo -e "Python wheel verified successfully.\n"
rm -rf "$unpack_directory"
exit 0
else
echo "Installing Python agent from wheel"
pip install -I "$tested_wheel"
fi
}

function get_and_check_wheel(){
echo "#### Verifying Python agent wheel distribution ####"
# Python wheels are not available under Alpine Linux
if [[ -f /etc/os-release && "$(cat /etc/os-release)" =~ "Alpine" ]]; then
echo "Wheels are not available on Alpine Linux, skip wheel tests."
else
get_wheel
check_wheel "$tested_wheel"
fi
}

# start testing
get_and_check_wheel
2 changes: 1 addition & 1 deletion tests/docker/install/_helper_run_install_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ set -e
# get Python version from container hostname, e.g. "3.7", "3.10"
python_version=$(grep -Eo 'py3.[0-9]+[0-9]*' /etc/hostname | grep -Eo '3.[0-9]+[0-9]*')
# no-dot Python version, e.g. "36", "310"
python_version_no_dot=$(echo "$python_version" | sed 's/\.//')
python_version_no_dot="${python_version//\./}"

pretty_name=$(grep PRETTY_NAME /etc/os-release | sed 's/PRETTY_NAME="//' | sed 's/"//')
echo "Installing test dependencies for Python $python_version on $pretty_name"
Expand Down
3 changes: 3 additions & 0 deletions tests/docker/install/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ x-volumes-codebase: &volumes-codebase
volumes:
- ../../../:/code/python-solarwinds
- ./_helper_run_install_tests.sh:/workspace/_helper_run_install_tests.sh
- ./_helper_check_extension_files.sh:/workspace/_helper_check_extension_files.sh
- ./_helper_check_sdist.sh:/workspace/_helper_check_sdist.sh
- ./_helper_check_wheel.sh:/workspace/_helper_check_wheel.sh
- ./install_tests.sh:/workspace/install_tests.sh
- ./client.py:/workspace/client.py
- ./app.py:/workspace/app.py
Expand Down
Loading