Skip to content

Commit 845d2f7

Browse files
authored
Combine artifacts for pypi upload (#158)
* Combine artifacts for pypi upload
1 parent b8b018a commit 845d2f7

File tree

3 files changed

+203
-0
lines changed

3 files changed

+203
-0
lines changed

.github/workflows/python-release.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,3 +287,63 @@ jobs:
287287
with:
288288
name: wheel-quantum-pecos
289289
path: python/quantum-pecos/dist/*.whl
290+
291+
collect_artifacts:
292+
needs: [build_wheels_pecos_rslib, build_sdist_quantum_pecos, build_wheels_quantum_pecos, test_abi3_wheels]
293+
runs-on: ubuntu-latest
294+
steps:
295+
- name: Create distribution directories
296+
run: |
297+
mkdir -p dist/pecos-rslib
298+
mkdir -p dist/quantum-pecos
299+
300+
# Download artifacts into temp directory first
301+
- name: Download all artifacts
302+
uses: actions/download-artifact@v4
303+
with:
304+
path: temp-artifacts/
305+
306+
- name: Organize distribution files
307+
run: |
308+
# Debug: Show what we downloaded
309+
echo "=== Downloaded artifacts structure ==="
310+
ls -la temp-artifacts/
311+
312+
# Move pecos-rslib wheels to distribution directory
313+
for artifact in temp-artifacts/wheel-pecos-rslib-*/; do
314+
if [ -d "$artifact" ]; then
315+
echo "Processing $artifact"
316+
mv "$artifact"*.whl dist/pecos-rslib/ 2>/dev/null || true
317+
fi
318+
done
319+
320+
# Move quantum-pecos files to distribution directory
321+
for artifact in temp-artifacts/*-quantum-pecos*/; do
322+
if [ -d "$artifact" ]; then
323+
echo "Processing $artifact"
324+
mv "$artifact"*.whl dist/quantum-pecos/ 2>/dev/null || true
325+
mv "$artifact"*.tar.gz dist/quantum-pecos/ 2>/dev/null || true
326+
fi
327+
done
328+
329+
# Clean up
330+
rm -rf temp-artifacts
331+
332+
- name: List all collected artifacts
333+
run: |
334+
echo "=== pecos-rslib artifacts ==="
335+
ls -la dist/pecos-rslib/
336+
echo ""
337+
echo "=== quantum-pecos artifacts ==="
338+
ls -la dist/quantum-pecos/
339+
echo ""
340+
echo "=== Summary ==="
341+
echo "pecos-rslib wheels: $(ls -1 dist/pecos-rslib/*.whl 2>/dev/null | wc -l)"
342+
echo "quantum-pecos distributions: $(ls -1 dist/quantum-pecos/* 2>/dev/null | wc -l)"
343+
344+
345+
- name: Upload distribution bundle
346+
uses: actions/upload-artifact@v4
347+
with:
348+
name: pecos-distribution
349+
path: dist/

python/pecos-rslib/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ maintainers =[
1212
dependencies = []
1313
readme = "README.md"
1414
requires-python = ">= 3.8"
15+
license = "Apache-2.0"
1516

1617
[build-system]
1718
requires = ["maturin>=1.2,<2.0"]

scripts/publish-wheels.sh

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
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+
ARTIFACT_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+
ARTIFACT_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 GitHub Actions artifact zip (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 artifact file exists
55+
if [ ! -f "$ARTIFACT_FILE" ]; then
56+
echo -e "${RED}Error: Artifact file '$ARTIFACT_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 "$ARTIFACT_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+
# Run twine check
96+
echo -e "\n${GREEN}Running twine check...${NC}"
97+
if twine check "$package_dir"/* 2>&1 | grep -v "license-file"; then
98+
echo -e "${GREEN}Distribution checks passed${NC}"
99+
else
100+
# Check if there are errors other than license-file
101+
if twine check "$package_dir"/* 2>&1 | grep -v "license-file" | grep -q "ERROR"; then
102+
echo -e "${RED}Distribution checks failed${NC}"
103+
echo "Run 'twine check $package_dir/*' to see details"
104+
return 1
105+
else
106+
echo -e "${YELLOW}Only license-file warnings found (safe to ignore for maturin wheels)${NC}"
107+
fi
108+
fi
109+
110+
if [ "$DRY_RUN" = true ]; then
111+
echo -e "\n${YELLOW}DRY RUN: Would upload the following files:${NC}"
112+
ls -1 "$package_dir"
113+
else
114+
echo -e "\n${GREEN}Uploading to PyPI...${NC}"
115+
read -p "Are you sure you want to upload $package_name to PyPI? (y/N) " -n 1 -r
116+
echo
117+
if [[ $REPLY =~ ^[Yy]$ ]]; then
118+
twine upload "$package_dir"/*
119+
echo -e "${GREEN}Successfully uploaded $package_name!${NC}"
120+
else
121+
echo -e "${YELLOW}Skipped uploading $package_name${NC}"
122+
fi
123+
fi
124+
}
125+
126+
# Main execution
127+
if [ -n "$PACKAGE" ]; then
128+
# Publish specific package
129+
if [[ "$PACKAGE" != "pecos-rslib" && "$PACKAGE" != "quantum-pecos" ]]; then
130+
echo -e "${RED}Error: Invalid package name '$PACKAGE'${NC}"
131+
echo "Valid options are: pecos-rslib, quantum-pecos"
132+
exit 1
133+
fi
134+
publish_package "$PACKAGE"
135+
else
136+
# Publish all packages
137+
echo -e "${GREEN}Publishing all PECOS packages${NC}"
138+
publish_package "pecos-rslib"
139+
publish_package "quantum-pecos"
140+
fi
141+
142+
echo -e "\n${GREEN}Done!${NC}"

0 commit comments

Comments
 (0)