Skip to content

Instantly share code, notes, and snippets.

@lunhg
Created January 26, 2022 19:23
Show Gist options
  • Save lunhg/6cc9f4642aee8a8a1151288e6a522e38 to your computer and use it in GitHub Desktop.
Save lunhg/6cc9f4642aee8a8a1151288e6a522e38 to your computer and use it in GitHub Desktop.
A build script CI/CD job that download a testpypi whl, change the current version and build a whl file again to install it with pip. Must define PROGRAM and VERSION variables.
.build_testpypi_to_oficial_pypi: &build_production_script
- pip install virtualenv wheel
- python -m virtualenv venv && source venv/bin/activate
- python -m pip download --no-deps --index-url https://test.pypi.org/simple/ $PROGRAM
- PACKAGE=$(ls -la $PROGRAM* | awk '{ print $9 }')
- wheel unpack $PACKAGE
- rm $PACKAGE
- WHEEL_FOLDER=$(ls -la | awk '{ print $9 }' | grep $PROGRAM)
- mkdir $PROGRAM-$VERSION
- mkdir $PROGRAM-$VERSION/$PROGRAM
- mkdir $PROGRAM-$VERSION/$PROGRAM-$VERSION.dist-info
- cp $WHEEL_FOLDER/$WHEEL_FOLDER.dist-info/** $PROGRAM-$VERSION/$PROGRAM-$VERSION.dist-info/
- cp -r $WHEEL_FOLDER/$PROGRAM $PROGRAM-$VERSION
- CURRENT_VERSION=`cat $WHEEL_FOLDER/$WHEEL_FOLDER.dist-info/METADATA | grep ^Version | cut -d ' ' -f2`
- echo $CURRENT_VERSION
- sed -i 's/'$CURRENT_VERSION'$/'$VERSION'/g' $PROGRAM-$VERSION/$PROGRAM-$VERSION.dist-info/METADATA
- rm $PROGRAM-$VERSION/$PROGRAM-$VERSION.dist-info/RECORD
- wheel pack $PROGRAM-$VERSION
- rm -rf $PROGRAM-$VERSION
- rm -rf $WHEEL_FOLDER
- PACKAGE=$(ls -la $PROGRAM*.whl | awk '{ print $9 }')
- python -m pip install $PACKAGE
- python -m pip list
@lunhg
Copy link
Author

lunhg commented Jan 26, 2022

This script do this:

  • Download .whl file from testpypi index
  • rename the version
  • test it (again)

Used in CI/CD jobs where i dont want to rebuild while project again, just download a tested version (like 0.0.16394798343) and re-use it, but with a simplified version (0.0.1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment