1+ #! /bin/bash
2+ # Script to help publish PECOS wheels to PyPI from GitHub Actions artifacts
3+
4+ set -e
5+
6+ # Colors for output
7+ RED=' \033[0;31m'
8+ GREEN=' \033[0;32m'
9+ YELLOW=' \033[1;33m'
10+ NC=' \033[0m' # No Color
11+
12+ # Default values
13+ ZIP_FILE=" pecos-distribution.zip"
14+ DRY_RUN=false
15+ PACKAGE=" "
16+
17+ # Parse command line arguments
18+ while [[ $# -gt 0 ]]; do
19+ case $1 in
20+ -f|--file)
21+ ZIP_FILE=" $2 "
22+ shift 2
23+ ;;
24+ -p|--package)
25+ PACKAGE=" $2 "
26+ shift 2
27+ ;;
28+ --dry-run)
29+ DRY_RUN=true
30+ shift
31+ ;;
32+ -h|--help)
33+ echo " Usage: $0 [OPTIONS]"
34+ echo " "
35+ echo " Options:"
36+ echo " -f, --file FILE Path to the distribution zip file (default: pecos-distribution.zip)"
37+ echo " -p, --package PKG Publish only specific package (pecos-rslib or quantum-pecos)"
38+ echo " --dry-run Show what would be uploaded without actually uploading"
39+ echo " -h, --help Show this help message"
40+ echo " "
41+ echo " Examples:"
42+ echo " $0 # Publish all packages"
43+ echo " $0 -p pecos-rslib # Publish only pecos-rslib"
44+ echo " $0 -p quantum-pecos --dry-run # Dry run for quantum-pecos"
45+ exit 0
46+ ;;
47+ * )
48+ echo -e " ${RED} Unknown option: $1 ${NC} "
49+ exit 1
50+ ;;
51+ esac
52+ done
53+
54+ # Check if zip file exists
55+ if [ ! -f " $ZIP_FILE " ]; then
56+ echo -e " ${RED} Error: Distribution file '$ZIP_FILE ' not found!${NC} "
57+ echo " Please download the 'pecos-distribution' artifact from GitHub Actions."
58+ exit 1
59+ fi
60+
61+ # Check if twine is installed
62+ if ! command -v twine & > /dev/null; then
63+ echo -e " ${RED} Error: twine is not installed!${NC} "
64+ echo " Install it with: pip install twine"
65+ exit 1
66+ fi
67+
68+ # Create temporary directory
69+ TEMP_DIR=$( mktemp -d)
70+ trap " rm -rf $TEMP_DIR " EXIT
71+
72+ echo -e " ${GREEN} Extracting distribution bundle...${NC} "
73+ unzip -q " $ZIP_FILE " -d " $TEMP_DIR "
74+
75+ # Function to publish a package
76+ publish_package () {
77+ local package_name=$1
78+ local package_dir=" $TEMP_DIR /dist/$package_name "
79+
80+ if [ ! -d " $package_dir " ]; then
81+ echo -e " ${YELLOW} Warning: $package_name directory not found in distribution${NC} "
82+ return
83+ fi
84+
85+ local file_count=$( ls -1 " $package_dir " | wc -l)
86+ if [ " $file_count " -eq 0 ]; then
87+ echo -e " ${YELLOW} Warning: No files found in $package_name directory${NC} "
88+ return
89+ fi
90+
91+ echo -e " \n${GREEN} === Publishing $package_name ===${NC} "
92+ echo " Found $file_count distribution file(s):"
93+ ls -la " $package_dir "
94+
95+ if [ " $DRY_RUN " = true ]; then
96+ echo -e " \n${YELLOW} DRY RUN: Would upload the following files:${NC} "
97+ ls -1 " $package_dir "
98+ else
99+ echo -e " \n${GREEN} Uploading to PyPI...${NC} "
100+ read -p " Are you sure you want to upload $package_name to PyPI? (y/N) " -n 1 -r
101+ echo
102+ if [[ $REPLY =~ ^[Yy]$ ]]; then
103+ twine upload " $package_dir " /*
104+ echo -e " ${GREEN} Successfully uploaded $package_name !${NC} "
105+ else
106+ echo -e " ${YELLOW} Skipped uploading $package_name ${NC} "
107+ fi
108+ fi
109+ }
110+
111+ # Main execution
112+ if [ -n " $PACKAGE " ]; then
113+ # Publish specific package
114+ if [[ " $PACKAGE " != " pecos-rslib" && " $PACKAGE " != " quantum-pecos" ]]; then
115+ echo -e " ${RED} Error: Invalid package name '$PACKAGE '${NC} "
116+ echo " Valid options are: pecos-rslib, quantum-pecos"
117+ exit 1
118+ fi
119+ publish_package " $PACKAGE "
120+ else
121+ # Publish all packages
122+ echo -e " ${GREEN} Publishing all PECOS packages${NC} "
123+ publish_package " pecos-rslib"
124+ publish_package " quantum-pecos"
125+ fi
126+
127+ echo -e " \n${GREEN} Done!${NC} "
0 commit comments