Add integration test to CI/CD #34
Workflow file for this run
This file contains 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: CI/CD | |
on: | |
workflow_dispatch: | |
pull_request: | |
branches: | |
- rust | |
push: | |
tags: | |
- 'v*' | |
jobs: | |
unit_test_integration_test: | |
name: "Unit test and integration test for ${{ matrix.vim.dist }} @ ${{ matrix.vim.version }}" | |
runs-on: ubuntu-22.04 | |
strategy: | |
fail-fast: false | |
matrix: | |
vim: | |
- dist: vim | |
version: v8.2.0 | |
- dist: vim | |
version: v9.1.0 | |
- dist: nvim | |
version: v0.10.2 | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
path: jieba_vim | |
- uses: dtolnay/rust-toolchain@stable | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: '3.11' | |
cache: 'pip' | |
- name: Cache vim/nvim and vader.vim | |
id: cache-vim | |
uses: actions/cache@v4 | |
with: | |
path: | | |
vim | |
vim_bundle/vader.vim | |
key: vim-distro-${{ matrix.vim.dist }}-${{ matrix.vim.version }} | |
- name: Install vim/nvim | |
if: steps.cache-vim.outputs.cache-hit != 'true' | |
run: | | |
case ${{ matrix.vim.dist }} in | |
vim) | |
sudo apt-get update | |
sudo apt-get install -y git make clang libtool-bin | |
git clone https://github.com/vim/vim.git && cd vim | |
git checkout ${{ matrix.vim.version }} | |
# References: | |
# - https://allanchain.github.io/blog/post/compile-vim-python3/ | |
case ${{ matrix.vim.version }} in | |
v9.1.0) | |
LDFLAGS=-rdynamic ./configure \ | |
--with-features=huge \ | |
--enable-fail-if-missing \ | |
--enable-largefile \ | |
--enable-multibyte \ | |
--enable-python3interp \ | |
--with-python3-command=python3.11 \ | |
--with-python3-stable-abi=3.11 \ | |
--enable-gui=no \ | |
--prefix="$GITHUB_WORKSPACE/vim/prefix" | |
;; | |
v8.2.0) | |
env \ | |
vi_cv_path_python3_plibs="-L$(python3.11-config --configdir) -lpython3.11 -ldl -lm" \ | |
vi_cv_var_python3_version=3.11 \ | |
LDFLAGS=-rdynamic \ | |
./configure \ | |
--with-features=huge \ | |
--enable-fail-if-missing \ | |
--enable-largefile \ | |
--enable-multibyte \ | |
--enable-python3interp \ | |
--with-python3-command=python3.11 \ | |
--with-python3-config-dir="$(python3.11-config --configdir)" \ | |
--prefix="$GITHUB_WORKSPACE/vim/prefix" | |
;; | |
esac | |
make -j4 && make install | |
echo "$GITHUB_WORKSPACE/vim/prefix/bin" >> $GITHUB_PATH | |
;; | |
nvim) | |
sudo apt-get update | |
sudo apt-get install -y curl tar | |
cd "$GITHUB_WORKSPACE" | |
mkdir vim | |
# Extract nvim to "vim", so that it's easier to cache the result. | |
curl -fsSL https://github.com/neovim/neovim/releases/download/${{ matrix.vim.version }}/nvim-linux64.tar.gz | tar xzf - --strip-components=1 -C vim | |
echo "$GITHUB_WORKSPACE/vim/bin" >> $GITHUB_PATH | |
;; | |
esac | |
- name: Add vim/nvim to PATH | |
if: steps.cache-vim.outputs.cache-hit == 'true' | |
run: | | |
case ${{ matrix.vim.dist }} in | |
vim) | |
echo "$GITHUB_WORKSPACE/vim/prefix/bin" >> $GITHUB_PATH | |
;; | |
nvim) | |
echo "$GITHUB_WORKSPACE/vim/bin" >> $GITHUB_PATH | |
;; | |
esac | |
- name: Ensure vim/nvim version | |
run: | | |
${{ matrix.vim.dist }} --version | |
- name: Install vader.vim | |
if: steps.cache-vim.outputs.cache-hit != 'true' | |
run: | | |
mkdir "$GITHUB_WORKSPACE/vim_bundle" | |
git clone https://github.com/junegunn/vader.vim.git "$GITHUB_WORKSPACE/vim_bundle/vader.vim" | |
- name: Verify and run unit tests | |
run: | | |
export VIM_BUNDLE_PATH="$GITHUB_WORKSPACE/vim_bundle" | |
export VIM_BIN_NAME=${{ matrix.vim.dist }} | |
cd "$GITHUB_WORKSPACE/jieba_vim/pythonx/jieba_vim_rs_core" | |
cargo test -F verifiable_case | |
- name: Build | |
run: | | |
cd "$GITHUB_WORKSPACE/jieba_vim/pythonx" | |
cargo build --locked --release | |
- name: Install integration test dependencies | |
run: | | |
cd "$GITHUB_WORKSPACE/jieba_vim/test" | |
pip install . | |
- name: Run integration tests | |
run: | | |
cd "$GITHUB_WORKSPACE/jieba_vim/test" | |
export VIM_BUNDLE_PATH="$GITHUB_WORKSPACE/vim_bundle" | |
export VIM_BIN_NAME=${{ matrix.vim.dist }} | |
pytest | |
# Reference: https://github.com/sharkdp/fd/blob/master/.github/workflows/CICD.yml | |
build: | |
name: Build for ${{ matrix.job.target }} | |
runs-on: ${{ matrix.job.os }} | |
needs: unit_test_integration_test | |
strategy: | |
fail-fast: false | |
matrix: | |
job: | |
# This should be re-enabled after issue #8 is resolved. See more at | |
# https://github.com/kkew3/jieba.vim/issues/8. | |
# | |
# - target: aarch64-unknown-linux-gnu | |
# os: ubuntu-22.04 | |
# use-cross: true | |
- target: x86_64-unknown-linux-gnu | |
os: ubuntu-22.04 | |
use-cross: true | |
- target: aarch64-apple-darwin | |
os: macos-14 | |
- target: x86_64-pc-windows-msvc | |
os: windows-2022 | |
env: | |
BUILD_CMD: cargo | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
path: jieba_vim | |
- name: Install prerequisites | |
shell: bash | |
run: | | |
case ${{ matrix.job.target }} in | |
aarch64-unknown-linux-gnu) | |
sudo apt-get update | |
sudo apt-get install -y gcc-aarch64-linux-gnu | |
;; | |
esac | |
- name: Install Rust toolchain | |
uses: dtolnay/rust-toolchain@stable | |
with: | |
targets: ${{ matrix.job.target }} | |
toolchain: "${{ contains(matrix.job.target, 'windows-') && '1.77.2' || 'stable' }}" | |
# Somehow dtolnay/rust-toolchain does not install non-host targets | |
- name: Patch rust toolchain | |
shell: bash | |
run: | | |
case ${{ matrix.job.target }} in | |
aarch64-unknown-linux-gnu) | |
rustup install --force-non-host stable-aarch64-unknown-linux-gnu | |
;; | |
esac | |
- name: Install cross | |
if: matrix.job.use-cross | |
uses: taiki-e/install-action@v2 | |
with: | |
tool: cross | |
- name: Overwrite build command env variable | |
if: matrix.job.use-cross | |
shell: bash | |
run: echo "BUILD_CMD=cross" >> $GITHUB_ENV | |
- name: Show version information (Rust, cargo, gcc) | |
shell: bash | |
run: | | |
gcc --version || true | |
rustup -V | |
rustup toolchain list | |
rustup default | |
cargo -V | |
rustc -V | |
- name: Test and build | |
shell: bash | |
run: | | |
cd "$GITHUB_WORKSPACE/jieba_vim/pythonx/jieba_vim_rs_test" && $BUILD_CMD test --release --target=${{ matrix.job.target }} | |
cd "$GITHUB_WORKSPACE/jieba_vim/pythonx/jieba_vim_rs_core" && $BUILD_CMD test --release --target=${{ matrix.job.target }} | |
cd "$GITHUB_WORKSPACE/jieba_vim/pythonx" && $BUILD_CMD build --locked --release --target=${{ matrix.job.target }} | |
- name: Set cdylib name and path | |
id: cdylib | |
shell: bash | |
run: | | |
LIB_NAME=jieba_vim_rs | |
case ${{ matrix.job.target }} in | |
*-linux-*) CDYLIB_SUFFIX=".so"; CDYLIB_PREFIX="lib"; ;; | |
*-apple-darwin) CDYLIB_SUFFIX=".dylib"; CDYLIB_PREFIX="lib"; ;; | |
*-pc-windows-*) CDYLIB_SUFFIX=".dll"; CDYLIB_PREFIX=""; ;; | |
esac | |
CDYLIB_NAME=${CDYLIB_PREFIX}${LIB_NAME}${CDYLIB_SUFFIX} | |
LIB_PATH="$GITHUB_WORKSPACE/jieba_vim/pythonx/target/${{ matrix.job.target }}/release/${CDYLIB_NAME}" | |
test -f "$LIB_PATH" | |
echo "CDYLIB_SUFFIX=$CDYLIB_SUFFIX" >> $GITHUB_OUTPUT | |
echo "LIB_PATH=$LIB_PATH" >> $GITHUB_OUTPUT | |
- name: Rename dylib | |
id: package | |
shell: bash | |
run: | | |
LIB_NAME=jieba_vim_rs | |
PKG_BASEDIR="$GITHUB_WORKSPACE/packages" | |
mkdir -p "$PKG_BASEDIR" && cd "$PKG_BASEDIR" | |
TO_NAME="${LIB_NAME}-${{ matrix.job.target }}${{ steps.cdylib.outputs.CDYLIB_SUFFIX }}" | |
cp "${{ steps.cdylib.outputs.LIB_PATH }}" "$TO_NAME" | |
echo "PKG_PATH=${PKG_BASEDIR}/${TO_NAME}" >> $GITHUB_OUTPUT | |
- name: Check for release | |
id: is-release | |
shell: bash | |
run: | | |
unset IS_RELEASE | |
if [[ ${{ github.ref }} =~ ^refs/tags/v[0-9].* ]]; then IS_RELEASE='true'; fi | |
echo "IS_RELEASE=${IS_RELEASE}" >> $GITHUB_OUTPUT | |
- name: Publish cdylib | |
uses: softprops/action-gh-release@v2 | |
if: steps.is-release.outputs.IS_RELEASE | |
with: | |
files: | | |
${{ steps.package.outputs.PKG_PATH }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |