加入dos2unix的安装并修复artifact上传问题 #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: 构建 | |
| on: | |
| push: | |
| branches: | |
| - main | |
| schedule: | |
| - cron: '0 0 */7 * *' | |
| jobs: | |
| build: | |
| concurrency: | |
| group: build-${{ github.ref }} | |
| cancel-in-progress: true | |
| runs-on: ${{ matrix.runner }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| msystem: ['MINGW64','MINGW32','CLANGARM64'] | |
| build_type: # 新增构建类型矩阵 | |
| - { optimization: "O3", link_type: "dynamic", cflag: "-O3", shared_flag: "--enable-shared --with-lto=yes" } | |
| - { optimization: "O3", link_type: "static", cflag: "-O3", shared_flag: "--with-static-libpython" } | |
| - { optimization: "O2", link_type: "dynamic", cflag: "-O2", shared_flag: "--enable-shared --with-lto=yes" } | |
| - { optimization: "O2", link_type: "static", cflag: "-O2", shared_flag: "--disable-shared" } | |
| - { optimization: "Os", link_type: "dynamic", cflag: "-Os", shared_flag: "--enable-shared --with-lto=yes" } | |
| - { optimization: "Os", link_type: "static", cflag: "-Os", shared_flag: "--with-static-libpython" } | |
| include: | |
| - msystem: MINGW64 | |
| prefix: mingw-w64-x86_64 | |
| runner: windows-2022 | |
| - msystem: MINGW32 | |
| prefix: mingw-w64-i686 | |
| runner: windows-2022 | |
| - msystem: CLANGARM64 | |
| prefix: mingw-w64-clang-aarch64 | |
| runner: windows-11-arm | |
| steps: | |
| - name: 设置git | |
| run: | | |
| git config --global core.autocrlf false | |
| git config --global core.eol lf | |
| - name: 克隆python存储库 | |
| run: | | |
| git clone https://github.com/msys2-contrib/cpython-mingw.git --depth 1 | |
| - name: 安装MSYS2 | |
| uses: msys2/setup-msys2@v2 | |
| with: | |
| msystem: ${{ matrix.msystem }} | |
| release: ${{ matrix.msystem == 'CLANGARM64' }} | |
| update: true | |
| install: >- | |
| make | |
| git | |
| dos2unix | |
| binutils | |
| autoconf | |
| autoconf-archive | |
| automake-wrapper | |
| ${{ matrix.prefix }}-7zip | |
| ${{ matrix.prefix }}-toolchain | |
| ${{ matrix.prefix }}-expat | |
| ${{ matrix.prefix }}-bzip2 | |
| ${{ matrix.prefix }}-libffi | |
| ${{ matrix.prefix }}-mpdecimal | |
| ${{ matrix.prefix }}-ncurses | |
| ${{ matrix.prefix }}-openssl | |
| ${{ matrix.prefix }}-sqlite3 | |
| ${{ matrix.prefix }}-tcl | |
| ${{ matrix.prefix }}-tk | |
| ${{ matrix.prefix }}-zlib | |
| ${{ matrix.prefix }}-xz | |
| ${{ matrix.prefix }}-tzdata | |
| - name: 缓存MSYS2包 | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| C:/msys64/var/cache/pacman/pkg/ | |
| key: ${{ runner.os }}-msys2-pkg-${{ hashFiles('**/install-pacman-packages.sh') }} | |
| - name: 缓存编译结果 | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| cpython-mingw/_build/** | |
| key: ${{ runner.os }}-pybuild-${{ hashFiles('**/*.c', '**/*.h', '**/configure', '**/Makefile*') }} | |
| - name: 编译 | |
| shell: msys2 {0} | |
| run: | | |
| cd cpython-mingw | |
| set -ex | |
| if [[ ! -d _build ]]; then | |
| autoreconf -vfi | |
| mkdir -p _build && cd _build | |
| ../configure \ | |
| --prefix=/ \ | |
| --bindir=/ \ | |
| --sbindir=/ \ | |
| --docdir=/doc \ | |
| --mandir=/doc/man \ | |
| --host=${MINGW_CHOST} \ | |
| --build=${MINGW_CHOST} \ | |
| ${{ matrix.build_type.shared_flag }} \ | |
| --without-ensurepip \ | |
| --with-system-expat \ | |
| --with-system-libmpdec \ | |
| --enable-optimizations \ | |
| --disable-test-modules \ | |
| --with-nt-threads \ | |
| --enable-loadable-sqlite-extensions \ | |
| CFLAGS="${{ matrix.build_type.cflag }} -pipe -D__USE_MINGW_ANSI_STDIO=1" \ | |
| LDFLAGS="-Wl,--strip-all,--gc-sections,-s" | |
| else | |
| cd _build | |
| fi | |
| make -j8 | |
| - name: 安装 | |
| shell: msys2 {0} | |
| run: | | |
| cd cpython-mingw | |
| set -ex | |
| cd _build | |
| # 获取分支名称 (示例:mingw-v3.12.10) | |
| _branch_name=$(git rev-parse --abbrev-ref HEAD) | |
| # 构建目录名称 | |
| _pkg_suffix="${{ matrix.msystem }}-${{ matrix.build_type.optimization }}" | |
| [[ "${{ matrix.build_type.link_type }}" == "static" ]] && _pkg_suffix+="-static" | |
| pkgdir="python-${_branch_name}-${_pkg_suffix}" | |
| make -j8 install DESTDIR="${pkgdir}" | |
| # Fix shebangs | |
| _pybasever=$(./python.exe -c "import sys; print(f'{sys.version_info[0]}.{sys.version_info[1]}');") | |
| for fscripts in 2to3 2to3-${_pybasever} idle3 idle${_pybasever} pydoc3 pydoc${_pybasever}; do | |
| sed -i "s|$(cygpath -w / | sed 's|\\|\\\\|g')/python${_pybasever}.exe|/usr/bin/env python${_pybasever}.exe|g" "${pkgdir}/"/${fscripts} | |
| done | |
| sed -i "s|#!//python${_pybasever}.exe|#!/usr/bin/env python${_pybasever}.exe|" "${pkgdir}/"/lib/python${_pybasever}/config-${_pybasever}/python-config.py | |
| # Create version-less aliases | |
| cp "${pkgdir}/"/python3.exe "${pkgdir}/"/python.exe | |
| cp "${pkgdir}/"/python3w.exe "${pkgdir}/"/pythonw.exe | |
| cp "${pkgdir}/"/python3-config "${pkgdir}/"/python-config | |
| cp "${pkgdir}/"/idle3 "${pkgdir}/"/idle | |
| cp "${pkgdir}/"/pydoc3 "${pkgdir}/"/pydoc | |
| # 转换配置文件为 Windows 格式 | |
| for config in python3-config python3.12-config python-config; do | |
| unix2dos -n "${pkgdir}/${config}" "${pkgdir}/${config}.bat" | |
| done | |
| # 创建 VBS 启动脚本 | |
| for script in idle3 pydoc3 2to3; do | |
| cat << EOF > "${pkgdir}/${script}.vbs" | |
| Set WshShell = CreateObject("WScript.Shell") | |
| WshShell.Run "python3w -m ${script} " & WScript.Arguments(0), 0 | |
| EOF | |
| unix2dos "${pkgdir}/${script}.vbs" | |
| done | |
| # copy to / | |
| cp -rf "${pkgdir}"/* / | |
| - name: 压缩构建产物 | |
| if: always() | |
| shell: msys2 {0} | |
| run: | | |
| cd cpython-mingw | |
| cd _build | |
| 7z a -t7z -mx=9 python-${_branch_name}-${{ matrix.msystem }}-${{ matrix.build_type.optimization }}-${{ matrix.build_type.link_type }}.7z ${pkgdir}/ | |
| - name: 上传 | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: build-${{ matrix.msystem }}-${{ matrix.build_type.optimization }}-${{ matrix.build_type.link_type }} | |
| path: | | |
| cpython-mingw/_build/python-*-${{ matrix.msystem }}-${{ matrix.build_type.optimization }}-${{ matrix.build_type.link_type }}.7z |