-
Notifications
You must be signed in to change notification settings - Fork 39
1072 lines (878 loc) · 35.7 KB
/
main.yml
File metadata and controls
1072 lines (878 loc) · 35.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
name: PyQPanda Algorithm CI/CD Pipeline
on:
push:
branches: [main, master, develop]
pull_request:
branches: [main, master]
workflow_dispatch: # 允许手动触发
jobs:
# 1. Linux 平台构建 (Python 3.10, 3.11, 3.12)
linux-build-310:
name: Linux Build (Python 3.10)
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential python3-dev
- name: Build Linux wheel (Python ${{ matrix.python-version }})
run: |
set -e
echo "========== 开始构建 Linux Python ${{ matrix.python-version }} 包 =========="
# 进入项目目录
cd pyqpanda-algorithm
# 创建虚拟环境
python -m venv /tmp/alg-build-linux-${{ matrix.python-version }}-venv
source /tmp/alg-build-linux-${{ matrix.python-version }}-venv/bin/activate
# 清理旧构建
rm -rf build dist *.egg-info 2>/dev/null || true
# 安装构建工具
pip install wheel setuptools build
pip install --upgrade pip
# 构建wheel包
echo "开始构建wheel包..."
python setup.py bdist_wheel
# 检查是否生成了wheel文件
if [ ! -d "dist" ] || [ -z "$(ls -A dist/*.whl 2>/dev/null)" ]; then
echo "⚠️ 尝试使用build工具构建..."
python -m build --wheel
fi
# 重命名为Linux平台格式
for whl in dist/*.whl; do
filename=$(basename "$whl")
# 根据Python版本生成正确的平台标签
if [ "${{ matrix.python-version }}" = "3.10" ]; then
newname=$(echo "$filename" | sed "s/-any-/-cp310-cp310-manylinux_2_31_x86_64-/")
elif [ "${{ matrix.python-version }}" = "3.11" ]; then
newname=$(echo "$filename" | sed "s/-any-/-cp311-cp311-manylinux_2_31_x86_64-/")
elif [ "${{ matrix.python-version }}" = "3.12" ]; then
newname=$(echo "$filename" | sed "s/-any-/-cp312-cp312-manylinux_2_31_x86_64-/")
fi
if [ "$filename" != "$newname" ]; then
mv "dist/$filename" "dist/$newname"
echo "重命名: $filename -> $newname"
fi
done
# 创建输出目录
mkdir -p ../output/linux/${{ matrix.python-version }}
cp dist/*.whl ../output/linux/${{ matrix.python-version }}/
echo "✅ Linux Python ${{ matrix.python-version }} 构建完成"
ls -lh dist/
- name: Upload Linux wheel artifact
uses: actions/upload-artifact@v4
with:
name: linux-wheel-${{ matrix.python-version }}
path: output/linux/${{ matrix.python-version }}/
retention-days: 7
linux-build-311:
name: Linux Build (Python 3.11)
runs-on: ubuntu-latest
needs: linux-build-310
strategy:
matrix:
python-version: ["3.11"]
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential python3-dev
- name: Build Linux wheel (Python ${{ matrix.python-version }})
run: |
set -e
echo "========== 开始构建 Linux Python ${{ matrix.python-version }} 包 =========="
cd pyqpanda-algorithm
python -m venv /tmp/alg-build-linux-${{ matrix.python-version }}-venv
source /tmp/alg-build-linux-${{ matrix.python-version }}-venv/bin/activate
rm -rf build dist *.egg-info 2>/dev/null || true
pip install wheel setuptools build
pip install --upgrade pip
echo "开始构建wheel包..."
python setup.py bdist_wheel
if [ ! -d "dist" ] || [ -z "$(ls -A dist/*.whl 2>/dev/null)" ]; then
echo "⚠️ 尝试使用build工具构建..."
python -m build --wheel
fi
for whl in dist/*.whl; do
filename=$(basename "$whl")
if [ "${{ matrix.python-version }}" = "3.11" ]; then
newname=$(echo "$filename" | sed "s/-any-/-cp311-cp311-manylinux_2_31_x86_64-/")
fi
if [ "$filename" != "$newname" ]; then
mv "dist/$filename" "dist/$newname"
echo "重命名: $filename -> $newname"
fi
done
mkdir -p ../output/linux/${{ matrix.python-version }}
cp dist/*.whl ../output/linux/${{ matrix.python-version }}/
echo "✅ Linux Python ${{ matrix.python-version }} 构建完成"
ls -lh dist/
- name: Upload Linux wheel artifact
uses: actions/upload-artifact@v4
with:
name: linux-wheel-${{ matrix.python-version }}
path: output/linux/${{ matrix.python-version }}/
retention-days: 7
linux-build-312:
name: Linux Build (Python 3.12)
runs-on: ubuntu-latest
needs: linux-build-311
strategy:
matrix:
python-version: ["3.12"]
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential python3-dev
- name: Build Linux wheel (Python ${{ matrix.python-version }})
run: |
set -e
echo "========== 开始构建 Linux Python ${{ matrix.python-version }} 包 =========="
cd pyqpanda-algorithm
python -m venv /tmp/alg-build-linux-${{ matrix.python-version }}-venv
source /tmp/alg-build-linux-${{ matrix.python-version }}-venv/bin/activate
rm -rf build dist *.egg-info 2>/dev/null || true
pip install wheel setuptools build
pip install --upgrade pip
echo "开始构建wheel包..."
python setup.py bdist_wheel
if [ ! -d "dist" ] || [ -z "$(ls -A dist/*.whl 2>/dev/null)" ]; then
echo "⚠️ 尝试使用build工具构建..."
python -m build --wheel
fi
for whl in dist/*.whl; do
filename=$(basename "$whl")
if [ "${{ matrix.python-version }}" = "3.12" ]; then
newname=$(echo "$filename" | sed "s/-any-/-cp312-cp312-manylinux_2_31_x86_64-/")
fi
if [ "$filename" != "$newname" ]; then
mv "dist/$filename" "dist/$newname"
echo "重命名: $filename -> $newname"
fi
done
mkdir -p ../output/linux/${{ matrix.python-version }}
cp dist/*.whl ../output/linux/${{ matrix.python-version }}/
echo "✅ Linux Python ${{ matrix.python-version }} 构建完成"
ls -lh dist/
- name: Upload Linux wheel artifact
uses: actions/upload-artifact@v4
with:
name: linux-wheel-${{ matrix.python-version }}
path: output/linux/${{ matrix.python-version }}/
retention-days: 7
# 2. Windows 平台构建
windows-build-310:
name: Windows Build (Python 3.10)
runs-on: windows-latest
strategy:
matrix:
python-version: ["3.10"]
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Build Windows wheel (Python ${{ matrix.python-version }})
shell: pwsh
run: |
Write-Host "========== 开始构建 Windows Python ${{ matrix.python-version }} 包 =========="
cd pyqpanda-algorithm
# 创建虚拟环境
python -m venv C:\alg-build-windows-${{ matrix.python-version }}-venv
C:\alg-build-windows-${{ matrix.python-version }}-venv\Scripts\Activate.ps1
# 清理旧构建
Remove-Item -Recurse -Force build, dist, *.egg-info -ErrorAction SilentlyContinue
# 安装构建工具
pip install wheel setuptools build
pip install --upgrade pip
# 构建wheel包
Write-Host "开始构建wheel包..."
python setup.py bdist_wheel
# 检查是否生成了wheel文件
if (-not (Test-Path "dist") -or -not (Get-ChildItem "dist\*.whl" -ErrorAction SilentlyContinue)) {
Write-Host "⚠️ 尝试使用build工具构建..."
python -m build --wheel
}
# 重命名为Windows平台格式
Get-ChildItem "dist\*.whl" | ForEach-Object {
$filename = $_.Name
if (${{ matrix.python-version }} -eq "3.10") {
$newname = $filename -replace "-any-", "-cp310-cp310-win_amd64-"
} elseif (${{ matrix.python-version }} -eq "3.11") {
$newname = $filename -replace "-any-", "-cp311-cp311-win_amd64-"
} elseif (${{ matrix.python-version }} -eq "3.12") {
$newname = $filename -replace "-any-", "-cp312-cp312-win_amd64-"
}
if ($filename -ne $newname) {
Rename-Item -Path "dist\$filename" -NewName $newname
Write-Host "重命名: $filename -> $newname"
}
}
# 创建输出目录
New-Item -ItemType Directory -Force -Path "..\output\windows\${{ matrix.python-version }}" | Out-Null
Copy-Item "dist\*.whl" -Destination "..\output\windows\${{ matrix.python-version }}\"
Write-Host "✅ Windows Python ${{ matrix.python-version }} 构建完成"
Get-ChildItem dist\
- name: Upload Windows wheel artifact
uses: actions/upload-artifact@v4
with:
name: windows-wheel-${{ matrix.python-version }}
path: output/windows/${{ matrix.python-version }}/
retention-days: 7
windows-build-311:
name: Windows Build (Python 3.11)
runs-on: windows-latest
needs: windows-build-310
strategy:
matrix:
python-version: ["3.11"]
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Build Windows wheel (Python ${{ matrix.python-version }})
shell: pwsh
run: |
Write-Host "========== 开始构建 Windows Python ${{ matrix.python-version }} 包 =========="
cd pyqpanda-algorithm
python -m venv C:\alg-build-windows-${{ matrix.python-version }}-venv
C:\alg-build-windows-${{ matrix.python-version }}-venv\Scripts\Activate.ps1
Remove-Item -Recurse -Force build, dist, *.egg-info -ErrorAction SilentlyContinue
pip install wheel setuptools build
pip install --upgrade pip
Write-Host "开始构建wheel包..."
python setup.py bdist_wheel
if (-not (Test-Path "dist") -or -not (Get-ChildItem "dist\*.whl" -ErrorAction SilentlyContinue)) {
Write-Host "⚠️ 尝试使用build工具构建..."
python -m build --wheel
}
Get-ChildItem "dist\*.whl" | ForEach-Object {
$filename = $_.Name
if (${{ matrix.python-version }} -eq "3.11") {
$newname = $filename -replace "-any-", "-cp311-cp311-win_amd64-"
}
if ($filename -ne $newname) {
Rename-Item -Path "dist\$filename" -NewName $newname
Write-Host "重命名: $filename -> $newname"
}
}
New-Item -ItemType Directory -Force -Path "..\output\windows\${{ matrix.python-version }}" | Out-Null
Copy-Item "dist\*.whl" -Destination "..\output\windows\${{ matrix.python-version }}\"
Write-Host "✅ Windows Python ${{ matrix.python-version }} 构建完成"
Get-ChildItem dist\
- name: Upload Windows wheel artifact
uses: actions/upload-artifact@v4
with:
name: windows-wheel-${{ matrix.python-version }}
path: output/windows/${{ matrix.python-version }}/
retention-days: 7
windows-build-312:
name: Windows Build (Python 3.12)
runs-on: windows-latest
needs: windows-build-311
strategy:
matrix:
python-version: ["3.12"]
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Build Windows wheel (Python ${{ matrix.python-version }})
shell: pwsh
run: |
Write-Host "========== 开始构建 Windows Python ${{ matrix.python-version }} 包 =========="
cd pyqpanda-algorithm
python -m venv C:\alg-build-windows-${{ matrix.python-version }}-venv
C:\alg-build-windows-${{ matrix.python-version }}-venv\Scripts\Activate.ps1
Remove-Item -Recurse -Force build, dist, *.egg-info -ErrorAction SilentlyContinue
pip install wheel setuptools build
pip install --upgrade pip
Write-Host "开始构建wheel包..."
python setup.py bdist_wheel
if (-not (Test-Path "dist") -or -not (Get-ChildItem "dist\*.whl" -ErrorAction SilentlyContinue)) {
Write-Host "⚠️ 尝试使用build工具构建..."
python -m build --wheel
}
Get-ChildItem "dist\*.whl" | ForEach-Object {
$filename = $_.Name
if (${{ matrix.python-version }} -eq "3.12") {
$newname = $filename -replace "-any-", "-cp312-cp312-win_amd64-"
}
if ($filename -ne $newname) {
Rename-Item -Path "dist\$filename" -NewName $newname
Write-Host "重命名: $filename -> $newname"
}
}
New-Item -ItemType Directory -Force -Path "..\output\windows\${{ matrix.python-version }}" | Out-Null
Copy-Item "dist\*.whl" -Destination "..\output\windows\${{ matrix.python-version }}\"
Write-Host "✅ Windows Python ${{ matrix.python-version }} 构建完成"
Get-ChildItem dist\
- name: Upload Windows wheel artifact
uses: actions/upload-artifact@v4
with:
name: windows-wheel-${{ matrix.python-version }}
path: output/windows/${{ matrix.python-version }}/
retention-days: 7
# 3. macOS 平台构建
macos-build-310:
name: macOS Build (Python 3.10)
runs-on: macos-latest
strategy:
matrix:
python-version: ["3.10"]
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Build macOS wheel (Python ${{ matrix.python-version }})
run: |
set -e
echo "========== 开始构建 macOS Python ${{ matrix.python-version }} 包 =========="
cd pyqpanda-algorithm
# 创建虚拟环境
python -m venv /tmp/alg-build-macos-${{ matrix.python-version }}-venv
source /tmp/alg-build-macos-${{ matrix.python-version }}-venv/bin/activate
# 清理旧构建
rm -rf build dist *.egg-info 2>/dev/null || true
# 安装构建工具
pip install wheel setuptools build
pip install --upgrade pip
# 构建wheel包
echo "开始构建wheel包..."
python setup.py bdist_wheel
# 检查是否生成了wheel文件
if [ ! -d "dist" ] || [ -z "$(ls -A dist/*.whl 2>/dev/null)" ]; then
echo "⚠️ 尝试使用build工具构建..."
python -m build --wheel
fi
# 重命名为macOS平台格式
for whl in dist/*.whl; do
filename=$(basename "$whl")
# 根据Python版本和架构生成正确的平台标签
if [ "${{ matrix.python-version }}" = "3.10" ]; then
# macOS 有不同的架构,这里假设构建通用架构
newname=$(echo "$filename" | sed "s/-any-/-cp310-cp310-macosx_10_15_x86_64-/")
elif [ "${{ matrix.python-version }}" = "3.11" ]; then
newname=$(echo "$filename" | sed "s/-any-/-cp311-cp311-macosx_10_15_x86_64-/")
elif [ "${{ matrix.python-version }}" = "3.12" ]; then
newname=$(echo "$filename" | sed "s/-any-/-cp312-cp312-macosx_10_15_x86_64-/")
fi
if [ "$filename" != "$newname" ]; then
mv "dist/$filename" "dist/$newname"
echo "重命名: $filename -> $newname"
fi
done
# 创建输出目录
mkdir -p ../output/macos/${{ matrix.python-version }}
cp dist/*.whl ../output/macos/${{ matrix.python-version }}/
echo "✅ macOS Python ${{ matrix.python-version }} 构建完成"
ls -lh dist/
- name: Upload macOS wheel artifact
uses: actions/upload-artifact@v4
with:
name: macos-wheel-${{ matrix.python-version }}
path: output/macos/${{ matrix.python-version }}/
retention-days: 7
macos-build-311:
name: macOS Build (Python 3.11)
runs-on: macos-latest
needs: macos-build-310
strategy:
matrix:
python-version: ["3.11"]
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Build macOS wheel (Python ${{ matrix.python-version }})
run: |
set -e
echo "========== 开始构建 macOS Python ${{ matrix.python-version }} 包 =========="
cd pyqpanda-algorithm
python -m venv /tmp/alg-build-macos-${{ matrix.python-version }}-venv
source /tmp/alg-build-macos-${{ matrix.python-version }}-venv/bin/activate
rm -rf build dist *.egg-info 2>/dev/null || true
pip install wheel setuptools build
pip install --upgrade pip
echo "开始构建wheel包..."
python setup.py bdist_wheel
if [ ! -d "dist" ] || [ -z "$(ls -A dist/*.whl 2>/dev/null)" ]; then
echo "⚠️ 尝试使用build工具构建..."
python -m build --wheel
fi
for whl in dist/*.whl; do
filename=$(basename "$whl")
if [ "${{ matrix.python-version }}" = "3.11" ]; then
newname=$(echo "$filename" | sed "s/-any-/-cp311-cp311-macosx_10_15_x86_64-/")
fi
if [ "$filename" != "$newname" ]; then
mv "dist/$filename" "dist/$newname"
echo "重命名: $filename -> $newname"
fi
done
mkdir -p ../output/macos/${{ matrix.python-version }}
cp dist/*.whl ../output/macos/${{ matrix.python-version }}/
echo "✅ macOS Python ${{ matrix.python-version }} 构建完成"
ls -lh dist/
- name: Upload macOS wheel artifact
uses: actions/upload-artifact@v4
with:
name: macos-wheel-${{ matrix.python-version }}
path: output/macos/${{ matrix.python-version }}/
retention-days: 7
macos-build-312:
name: macOS Build (Python 3.12)
runs-on: macos-latest
needs: macos-build-311
strategy:
matrix:
python-version: ["3.12"]
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Build macOS wheel (Python ${{ matrix.python-version }})
run: |
set -e
echo "========== 开始构建 macOS Python ${{ matrix.python-version }} 包 =========="
cd pyqpanda-algorithm
python -m venv /tmp/alg-build-macos-${{ matrix.python-version }}-venv
source /tmp/alg-build-macos-${{ matrix.python-version }}-venv/bin/activate
rm -rf build dist *.egg-info 2>/dev/null || true
pip install wheel setuptools build
pip install --upgrade pip
echo "开始构建wheel包..."
python setup.py bdist_wheel
if [ ! -d "dist" ] || [ -z "$(ls -A dist/*.whl 2>/dev/null)" ]; then
echo "⚠️ 尝试使用build工具构建..."
python -m build --wheel
fi
for whl in dist/*.whl; do
filename=$(basename "$whl")
if [ "${{ matrix.python-version }}" = "3.12" ]; then
newname=$(echo "$filename" | sed "s/-any-/-cp312-cp312-macosx_10_15_x86_64-/")
fi
if [ "$filename" != "$newname" ]; then
mv "dist/$filename" "dist/$newname"
echo "重命名: $filename -> $newname"
fi
done
mkdir -p ../output/macos/${{ matrix.python-version }}
cp dist/*.whl ../output/macos/${{ matrix.python-version }}/
echo "✅ macOS Python ${{ matrix.python-version }} 构建完成"
ls -lh dist/
- name: Upload macOS wheel artifact
uses: actions/upload-artifact@v4
with:
name: macos-wheel-${{ matrix.python-version }}
path: output/macos/${{ matrix.python-version }}/
retention-days: 7
# 4. 文档构建
docs-build:
name: Documentation Build
runs-on: ubuntu-latest
needs: [linux-build-312, windows-build-312, macos-build-312]
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Build Documentation
run: |
set -e
echo "========== 开始构建项目文档 =========="
# 检查目录结构
echo "当前工作目录: $(pwd)"
echo "目录内容:"
ls -la
# 创建虚拟环境
python -m venv /tmp/alg-build-docs-venv
source /tmp/alg-build-docs-venv/bin/activate
# 检查 Tutorials/source 目录是否存在
if [ ! -d "Tutorials/source" ]; then
echo "❌ 错误: Tutorials/source 目录不存在"
echo "当前目录内容:"
ls -la
echo "Tutorials 目录内容:"
ls -la Tutorials/ 2>/dev/null || echo "Tutorials 目录不存在"
exit 1
fi
# 安装文档构建依赖
echo "安装文档构建工具..."
pip install sphinx sphinx_autoapi sphinx-material beautifulsoup4
# 进入文档源目录
cd Tutorials/source
echo "当前文档源目录: $(pwd)"
echo "文档源目录内容:"
ls -la
# 清理旧的构建输出
rm -rf build 2>/dev/null || true
# 构建HTML文档
echo "正在构建HTML文档..."
sphinx-build -b html ./ ./build/
# 回到根目录
cd ../..
# 创建文档输出目录
mkdir -p output/docs/html
# 复制生成的文档
echo "复制生成的文档..."
cp -r Tutorials/source/build/* output/docs/html/
echo "✅ 文档构建完成"
echo "生成的文档文件:"
find output/docs/html -name "*.html" | wc -l
echo "主文档文件: output/docs/html/index.html"
# 创建文档索引文件
cat > output/docs/README.md << EOF
# PyQPanda Algorithm 项目文档
## 文档说明
本文档使用 Sphinx + AutoAPI 自动生成,包含了项目的完整 API 文档。
## 查看文档
1. 打开 \`html/index.html\` 文件在浏览器中查看
2. 支持搜索功能
## 构建信息
- 构建时间: $(date)
- 构建工具: Sphinx $(sphinx-build --version 2>&1 | head -1)
- 文档页数: $(find output/docs/html -name "*.html" | wc -l) 个HTML文件
## 包含的模块文档
- pyqpanda_alg.Grover - Grover搜索算法
- pyqpanda_alg.QAE - 量子幅度估计
- pyqpanda_alg.QAOA - 量子近似优化算法
- pyqpanda_alg.QARM - 量子关联规则挖掘
- pyqpanda_alg.QCmp - 量子比较器
- pyqpanda_alg.QPCA - 量子主成分分析
- pyqpanda_alg.QSVD - 量子奇异值分解
- pyqpanda_alg.QSVM - 量子支持向量机
- pyqpanda_alg.QSVR - 量子支持向量回归
- pyqpanda_alg.QUBO - 量子无约束二进制优化
- pyqpanda_alg.QmRMR - 量子最小冗余最大相关性
- pyqpanda_alg.QKmeans - 量子K-means聚类
- pyqpanda_alg.QSEncode - 量子状态编码
- pyqpanda_alg.plugin - 插件系统
## 重新构建
如需重新构建文档,请运行:
\`\`\`bash
cd Tutorials/source
sphinx-build -b html ./ ./build/
\`\`\`
EOF
echo "✅ 文档打包完成"
echo "输出目录结构:"
ls -lh output/docs/
echo ""
echo "HTML文档示例:"
ls -lh output/docs/html/*.html | head -5
- name: Upload Documentation Artifact
uses: actions/upload-artifact@v4
with:
name: documentation-html
path: output/docs/
retention-days: 7
# 5. 自动化测试
automated-testing:
name: Automated Testing
runs-on: ubuntu-latest
needs: [linux-build-312]
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Download Linux wheel artifact
uses: actions/download-artifact@v4
with:
name: linux-wheel-3.10
path: downloaded-wheels/
- name: Run Automated Tests
run: |
set -e
echo "开始自动化测试"
# 创建虚拟环境
python -m venv /tmp/alg-test-venv
source /tmp/alg-test-venv/bin/activate
# 查找wheel包
WHEEL_FILE=$(find downloaded-wheels -name "*.whl" | head -1)
if [ -n "$WHEEL_FILE" ]; then
echo "安装wheel包: $WHEEL_FILE"
pip install "$WHEEL_FILE"
else
if [ -f "pyqpanda-algorithm/setup.py" ]; then
cd pyqpanda-algorithm
pip install -e .
cd ..
else
echo "❌ 错误: 未找到wheel包且没有setup.py"
exit 1
fi
fi
# 安装项目依赖
pip install numpy scipy sympy pandas
if [ -f "pyqpanda-algorithm/requirements.txt" ]; then
pip install -r pyqpanda-algorithm/requirements.txt
fi
# 安装测试依赖
pip install pytest allure-pytest pytest-html pytest-rerunfailures pytest-xdist
# 检查测试目录
if [ ! -d "test" ]; then
echo "❌ 错误: test 目录不存在"
exit 1
fi
# 进入测试目录
cd test
# 创建测试输出目录
mkdir -p ../output/test_results
mkdir -p ../output/test_results/allure-results
mkdir -p ../output/test_results/html-report
# 运行测试
echo "运行单元测试..."
pytest -v \
--junitxml=../output/test_results/junit-results.xml \
--alluredir=../output/test_results/allure-results \
--clean-alluredir \
--tb=short \
--disable-warnings \
--maxfail=5 \
|| true
# 生成HTML报告
echo "生成HTML报告..."
pytest -v \
--html=../output/test_results/html-report/report.html \
--self-contained-html \
--tb=short \
--disable-warnings \
--maxfail=5 \
|| true
# 生成Allure报告
if [ -d "../output/test_results/allure-results" ] && [ -n "$(ls -A ../output/test_results/allure-results 2>/dev/null)" ]; then
echo "安装Allure报告工具..."
curl -o allure-2.17.3.tgz -Ls https://github.com/allure-framework/allure2/releases/download/2.17.3/allure-2.17.3.tgz
tar -zxvf allure-2.17.3.tgz
echo "生成Allure报告..."
./allure-2.17.3/bin/allure generate ../output/test_results/allure-results -o ../output/test_results/allure-report --clean
fi
cd ..
echo "✅ 自动化测试完成"
- name: Upload Test Results
uses: actions/upload-artifact@v4
with:
name: test-results
path: output/test_results/
retention-days: 7
# 6. 打包所有产物
package-all:
name: Package All Artifacts
runs-on: ubuntu-latest
needs: [docs-build, automated-testing]
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Download all artifacts
run: |
mkdir -p all-artifacts
mkdir -p all-artifacts/wheels
mkdir -p all-artifacts/docs
mkdir -p all-artifacts/tests
- name: Download Linux wheels
uses: actions/download-artifact@v4
with:
name: linux-wheel-3.10
path: all-artifacts/wheels/
- name: Download Windows wheels
uses: actions/download-artifact@v4
with:
name: windows-wheel-3.10
path: all-artifacts/wheels/
- name: Download macOS wheels
uses: actions/download-artifact@v4
with:
name: macos-wheel-3.10
path: all-artifacts/wheels/
- name: Download Documentation
uses: actions/download-artifact@v4
with:
name: documentation-html
path: all-artifacts/docs/
- name: Download Test Results
uses: actions/download-artifact@v4
with:
name: test-results
path: all-artifacts/tests/
- name: Create Release Package
run: |
echo "========== 打包所有构建产物 =========="
# 创建发布目录
mkdir -p release_package/wheels
mkdir -p release_package/docs
mkdir -p release_package/test_reports
# 复制所有wheel文件
echo "收集所有平台的wheel文件..."
find all-artifacts/wheels -name "*.whl" -type f -exec cp {} release_package/wheels/ \;
# 复制文档
if [ -d "all-artifacts/docs" ]; then
cp -r all-artifacts/docs/* release_package/docs/
fi
# 复制测试结果
if [ -d "all-artifacts/tests" ]; then
cp -r all-artifacts/tests/* release_package/test_reports/
fi
# 创建README文件
cat > release_package/README.md << EOF
# PyQPanda Algorithm 多平台多版本发布包
## 支持的平台和Python版本
| 平台 | Python版本 | 架构 | 备注 |
|------|------------|------|------|
| Linux | 3.10, 3.11, 3.12 | x86_64 | 在Ubuntu环境中构建 |
| Windows | 3.10, 3.11, 3.12 | AMD64 | 在Windows环境中构建 |
| macOS | 3.10, 3.11, 3.12 | x86_64 | 在macOS环境中构建 |
## 包含内容
1. **Wheel包** (\`wheels/\` 目录)
- 所有平台的预编译包
- 按平台和Python版本分类
2. **项目文档** (\`docs/\` 目录)
- 完整的API文档
- HTML格式,可直接在浏览器中查看
- 打开 \`docs/html/index.html\` 开始浏览
3. **测试报告** (\`test_reports/\` 目录)
- 自动化测试结果
- JUnit格式报告
- HTML可视化报告
- Allure高级报告
## 文件命名规范
- Linux: \`包名-版本-cp{版本号}-cp{版本号}-manylinux_2_31_x86_64.whl\`
- Windows: \`包名-版本-cp{版本号}-cp{版本号}-win_amd64.whl\`
- macOS: \`包名-版本-cp{版本号}-cp{版本号}-macosx_10_15_x86_64.whl\`
## 使用说明
\`\`\`bash
# 根据您的平台和Python版本选择合适的文件
pip install wheels/your_package-*.whl
# 查看文档
# 打开 docs/html/index.html 在浏览器中查看
# 查看测试报告
# 打开 test_reports/html-report/report.html 查看测试结果
\`\`\`
## 构建环境
- 构建系统: GitHub Actions
- 构建时间: $(date)
- 总包数量: \$(ls -1 release_package/wheels/*.whl 2>/dev/null | wc -l 2>/dev/null || echo "0")
EOF