Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
292 changes: 292 additions & 0 deletions .github/workflows/testbuild.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,292 @@
name: Just test

# 触发机制为“非主分支的提交”
on:
push:
branches-ignore:
- main # 排除主分支
- master # 如果有 master 分支,也可以排除

jobs:
build: # 编译C程序和C库
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: windows-2022
arch: x86_64 # windows x86_6
- os: ubuntu-22.04
arch: x86_64 # Ubuntu x86_64
- os: macos-13
arch: x86_64 # macOS Intel
- os: macos-14
arch: arm64 # macOS Apple Silicon

fail-fast: true

defaults:
run:
shell: bash

steps:
- name: Set MSYS2 (Windows) # windows平台使用MSYS2工具编译程序
if: contains(matrix.os, 'windows')
uses: msys2/setup-msys2@v2
with:
msystem: UCRT64
install: >-
git
mingw-w64-ucrt-x86_64-gcc
make
mingw-w64-ucrt-x86_64-fftw

- name: Configured git attributes for line endings (Windows) # 防止接下来在windows平台checkout代码时,文本文件的换行符发生变化,导致MSYS2工作出错
if: contains(matrix.os, 'windows')
run: git config --global core.autocrlf input

- name: Checkout code # 下载库代码
uses: actions/checkout@v3
with:
fetch-depth: 1

# --------------------------- 安装依赖 ------------------------------------------
- name: Install dependencies (Ubuntu)
if: contains(matrix.os, 'ubuntu')
run: |
sudo apt update
sudo apt install -y libfftw3-dev

- name: Install dependencies (macOS)
# 匹配包含 "macos" 的操作系统
if: contains(matrix.os, 'macos')
run: |
brew install libomp
brew install fftw

FFTW_PREFIX=$(brew --prefix fftw)
echo "FFT_INC_PATH=$FFTW_PREFIX/include" >> $GITHUB_ENV
echo "FFT_LIB_PATH=$FFTW_PREFIX/lib" >> $GITHUB_ENV

# ----------------- 编译C库和C程序 ----------------------------------
- name: Build the project (macOS)
if: contains(matrix.os, 'macos')
working-directory: ./pygrt/C_extension
run: |

# Mac系统需要显式设置头文件路径和库路径
export C_INCLUDE_PATH=$FFT_INC_PATH:$C_INCLUDE_PATH
export LIBRARY_PATH=$FFT_LIB_PATH:${LIBRARY_PATH}
export LD_LIBRARY_PATH=$FFT_LIB_PATH:${LD_LIBRARY_PATH}
export DYLD_LIBRARY_PATH=$FFT_LIB_PATH:${DYLD_LIBRARY_PATH}

make ARCH="-arch ${{ matrix.arch }}" \
CC=gcc-14 \
LFFT_FLAGS="$FFT_LIB_PATH/libfftw3.a $FFT_LIB_PATH/libfftw3f.a"
make cleanbuild
otool -L lib/libgrt.so
otool -L bin/*

- name: Build the project (Ubuntu)
if: contains(matrix.os, 'ubuntu')
working-directory: ./pygrt/C_extension
run: |
make
make cleanbuild
ldd lib/libgrt.so
ldd bin/*

- name: Build the project (Windows)
if: contains(matrix.os, 'windows')
shell: msys2 {0}
working-directory: ./pygrt/C_extension
run: |
make
make cleanbuild
ldd lib/libgrt.so
ldd bin/*


# ------------------------ 定义接下来打包程序命名时的系统名后缀 ---------------
- name: Define the package OS suffix
run: |
# 符合pypi命名规范,否则上传失败
if [[ "${{ matrix.os }}" == *"ubuntu"* ]]; then
SUFFIX_PLAT_NAME="manylinux2014_x86_64"
elif [[ "${{ matrix.os }}" == *"macos"* && "${{ matrix.arch }}" == *"x86_64"* ]]; then
SUFFIX_PLAT_NAME="macosx_10_9_x86_64"
elif [[ "${{ matrix.os }}" == *"macos"* && "${{ matrix.arch }}" == *"arm64"* ]]; then
SUFFIX_PLAT_NAME="macosx_11_0_arm64"
elif [[ "${{ matrix.os }}" == *"windows"* ]]; then
SUFFIX_PLAT_NAME="win_amd64"
else
echo " Unsupported OS: ${{ matrix.os }} (${{ matrix.arch }})"
exit 1
fi

echo "SUFFIX_PLAT_NAME=$SUFFIX_PLAT_NAME" >> $GITHUB_ENV

# --------------------------- 打包整个程序 ---------------------
- name: Package the binary
run: |
PACK_NAME=pygrt_kit-${{ github.ref_name }}-${{ env.SUFFIX_PLAT_NAME }}
echo "PACK_NAME=$PACK_NAME" >> $GITHUB_ENV
FILE_CONTENT=$(ls)
mkdir -p $PACK_NAME
cp -r ${FILE_CONTENT} $PACK_NAME/
tar -czvf $PACK_NAME.tar.gz $PACK_NAME
rm -rf $PACK_NAME

# -------------------- upload artifacts -----------------------
- name: Upload artifact (*.tar.gz)
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.os }}-${{ matrix.arch }}_tar
path: ${{ env.PACK_NAME }}.tar.gz


# =======================================================================================
test_project: # 在全新系统上测试程序,不安装其它依赖,看能否运行
runs-on: ${{ matrix.os }}
needs: build
strategy:
matrix:
include:
- os: windows-2022
arch: x86_64 # windows x86_6
- os: ubuntu-22.04
arch: x86_64 # Ubuntu x86_64
- os: macos-13
arch: x86_64 # macOS Intel
- os: macos-14
arch: arm64 # macOS Apple Silicon

fail-fast: true

defaults:
run:
shell: bash

steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: ${{ matrix.os }}-${{ matrix.arch }}_tar
path: artifacts

- name: Display structure of downloaded files, and Uncompress
run: |
ls -R artifacts
echo "------------------- tar output -----------------------------"
tar -xzvf artifacts/*.tar.gz
echo "------------------------------------------------------------"

# 获得压缩包解压出来的文件夹名
PACK_NAME=$(ls | grep pygrt_kit)
echo "PACK_NAME=$PACK_NAME" >> $GITHUB_ENV

# 从解压出的文件夹命名来推断${{ env.SUFFIX_PLAT_NAME }}
SUFFIX_PLAT_NAME=$(echo $PACK_NAME | sed 's/.*-\(.*\)/\1/')
echo "SUFFIX_PLAT_NAME=$SUFFIX_PLAT_NAME" >> $GITHUB_ENV

echo $PACK_NAME
echo $SUFFIX_PLAT_NAME

# --------------------------- 安装依赖 ------------------------------------------
# 实际使用时可能需要安装libomp
# - name: Install libomp (Ubuntu)
# if: contains(matrix.os, 'ubuntu')
# run: |
# sudo apt install -y libomp-dev

- name: Set alias (MacOS)
if: contains(matrix.os, 'macos')
run: |
brew install coreutils
echo "alias timeout=gtimeout" >> ~/.bashrc

# --------------------搭建python环境,开始测试,并制作wheel文件 ------------------------------
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Install dependencies
working-directory: ${{ env.PACK_NAME }}
run: |
python -m pip install --upgrade pip
pip install --upgrade setuptools wheel build
pip install -v .

- name: Clean up build and egg-info directories
working-directory: ${{ env.PACK_NAME }}
run: |
# 清理临时文件
rm -rf build/
rm -rf pygrt_kit.egg-info/

- name: Add the C library path to the environment
working-directory: ${{ env.PACK_NAME }}
run: |
echo "$(pwd)/pygrt/C_extension/bin" >> "$GITHUB_PATH"

- name: Copy the test files
working-directory: ${{ env.PACK_NAME }}
run: |
cp -r example test_tmp
# don't use $(pwd) to get abspath, not valid on Windows
echo "EXAMPLE_COPY_PATH=${{ env.PACK_NAME }}/test_tmp" >> $GITHUB_ENV

- name: Test 1 compare_results
working-directory: ${{ env.EXAMPLE_COPY_PATH }}/compare_results
run: |
chmod +x *.sh
./run_milrow_grt.sh
python plot_cps_pygrt.py

- name: Test 2 site_effect
working-directory: ${{ env.EXAMPLE_COPY_PATH }}/site_effect
run: |
chmod +x *.sh
./run1.sh
python run2.py

- name: Test 3 multi_traces
working-directory: ${{ env.EXAMPLE_COPY_PATH }}/multi_traces
timeout-minutes: 1
run: |
chmod +x *.sh
./run1.sh
continue-on-error: true # 即使失败,仍然标记为成功

- name: Test 4 lamb_problem
working-directory: ${{ env.EXAMPLE_COPY_PATH }}/lamb_problem
run: |
chmod +x *.sh
./run1.sh
python run2.py

- name: Test 5 far_field
working-directory: ${{ env.EXAMPLE_COPY_PATH }}/far_field
timeout-minutes: 1
run: |
chmod +x *.sh
./run_milrow_grt.sh
python plot_compare_pygrt.py
continue-on-error: true # 即使失败,仍然标记为成功

- name: Remove the test files
run: |
rm -rf ${{ env.EXAMPLE_COPY_PATH }}

# --------------------------- 制作wheels ---------------------
# - name: Build the Python Wheel
# working-directory: ${{ env.PACK_NAME }}
# run: |
# python setup.py bdist_wheel --plat-name=${{ env.SUFFIX_PLAT_NAME }} # 只制作wheel,这里不打包源码

# - name: Upload artifact (*.whl)
# uses: actions/upload-artifact@v4
# with:
# name: ${{ env.PACK_NAME }}_whl
# path: ${{ env.PACK_NAME }}/dist/*.whl

Loading
Loading