Attempt to fix issue #7 #19
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: | |
branches: | |
- rust | |
jobs: | |
unit_test: | |
name: "Unit 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: dtolnay/rust-toolchain@stable | |
- uses: actions/checkout@v4 | |
with: | |
path: jieba_vim | |
- name: Install vim/nvim | |
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 }} | |
./configure --prefix="$GITHUB_WORKSPACE/vim/prefix" && make -j4 && make install | |
echo "$GITHUB_WORKSPACE/vim/prefix/bin" >> $GITHUB_PATH | |
;; | |
nvim) | |
sudo apt-get update | |
sudo apt-get install -y curl tar | |
curl -fsSL https://github.com/neovim/neovim/releases/download/${{ matrix.vim.version }}/nvim-linux64.tar.gz | tar xzf - | |
echo "$GITHUB_WORKSPACE/nvim-linux64/bin" >> $GITHUB_PATH | |
;; | |
esac | |
- name: Ensure vim/nvim version | |
run: | | |
${{ matrix.vim.dist }} --version | |
- name: Install vader.vim | |
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 | |
# 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 | |
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 }} |