Skip to content

Update workflow

Update workflow #23

Workflow file for this run

name: CI
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches: [ master ]
tags: [ '*' ]
pull_request:
branches: [ master ]
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
Windows:
runs-on: windows-latest
needs: Linux
strategy:
fail-fast: true
matrix:
include:
- arch: x86
- arch: x64
steps:
- name: "Set Build Type"
id: build_type
run: |
if ("${{ github.ref }}".StartsWith("refs/tags/")) {
echo "BUILD_TYPE::Release";
echo "::set-output name=BUILD_TYPE::Release";
} else {
echo "BUILD_TYPE::Debug";
echo "::set-output name=BUILD_TYPE::Debug";
}
if ("${{ matrix.arch }}" -eq "x64") {
echo "Arch:x64";
echo "::set-output name=BUILD_ARCH::x64";
} else {
echo "Arch:Win32";
echo "::set-output name=BUILD_ARCH::Win32";
}
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
with:
submodules: true
# Install build tools
- name: Install Ninja
uses: seanmiddleditch/gha-setup-ninja@master
# Install latest CMake
- uses: lukka/get-cmake@latest
# Restore from cache the previously built ports
- name: Restore artifacts, or setup vcpkg
uses: lukka/run-vcpkg@v10
with:
vcpkgDirectory: '${{ github.workspace }}/vcpkg'
# Add this to prevent storing partial cache in case of failure
- run: |
echo "RUNVCPKG_NO_CACHE=1" >> $GITHUB_ENV
if: ${{ failure() || cancelled() }}
shell: bash
- name: 'Run CMake'
uses: lukka/run-cmake@v10
with:
configurePreset: 'windows-ninja'
buildPreset: ${{ startsWith(github.ref, 'refs/tags/') && 'windows-ninja-release' || 'windows-ninja-debug' }}
testPreset: ${{ startsWith(github.ref, 'refs/tags/') && 'test-windows-release' || 'test-windows-debug' }}
- name: "Check file existence"
uses: andstor/file-existence-action@v3
with:
allow_failure: true
files: "${{ github.workspace }}/../../_temp/windows/src/${{ steps.build_type.outputs.BUILD_TYPE }}/simple.dll, ${{ github.workspace }}/../../_temp/windows/cppjieba/src/cppjieba/dict/jieba.dict.utf8"
# can't build
# npm run
# - uses: actions/setup-node@v2
# with:
# node-version: '16'
# - name: run node example
# working-directory: ./examples/node/
# run: |
# npm install
# npm run p -- --ext_path="${{ github.workspace }}/../../_temp/windows/src/${{ steps.build_type.outputs.BUILD_TYPE }}/" --dict_path="${{ github.workspace }}/../../_temp/windows/cppjieba/src/cppjieba/dict/"
# - name: 'Run CTest'
# run: ctest -C ${{ env.BUILD_TYPE }}
# working-directory: "${{ github.workspace }}/../../_temp/windows"
# python run
# - uses: actions/setup-python@v4
# with:
# python-version: '3.x' # Version range or exact version of a Python version to use, using SemVer's version range syntax
# - name: run python example
# working-directory: ./examples/python3/
# run: python db_connector.py "${{ github.workspace }}/../../_temp/windows/src/${{ steps.build_type.outputs.BUILD_TYPE }}/simple"
- name: Package
if: startsWith(github.ref, 'refs/tags/')
run: |
mkdir libsimple-windows-${{ matrix.arch }}
Copy-Item -Path src/${{ steps.build_type.outputs.BUILD_TYPE }}/simple.dll,cppjieba/src/cppjieba/dict/ -Destination libsimple-windows-${{ matrix.arch }}/ -Recurse
Compress-Archive -Path libsimple-windows-${{ matrix.arch }} -DestinationPath libsimple-windows-${{ matrix.arch }}.zip
working-directory: "${{ github.workspace }}/../../_temp/windows/"
- name: Release
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v1
with:
draft: true
files: "D:/a/_temp/windows/libsimple-windows-${{ matrix.arch }}.zip"
# files: "${{ github.workspace }}/../../_temp/windows/libsimple-windows-${{ matrix.arch }}.zip"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Linux:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
include:
- os: ubuntu-20.04
- os: ubuntu-22.04-arm
- os: ubuntu-latest
steps:
- name: "Release Build Type"
if: startsWith(github.ref, 'refs/tags/')
run: echo "BUILD_TYPE=Release" >> $GITHUB_ENV
- name: "Debug Build Type"
if: startsWith(github.ref, 'refs/tags/') != true
run: echo "BUILD_TYPE=Debug" >> $GITHUB_ENV
- uses: actions/checkout@v4
with:
submodules: true
- name: Update apt-get
run: sudo apt-get update
- name: Install build tools
run: |
sudo apt-get install -y ninja-build
sudo apt-get install -y build-essential
sudo apt-get install -y gcc g++
# - uses: lukka/get-cmake@latest
- name: Restore artifacts, or setup vcpkg
uses: lukka/run-vcpkg@v10
with:
vcpkgDirectory: '${{ github.workspace }}/vcpkg'
- name: Install lcov
if: startsWith(github.ref, 'refs/tags/') != true
run: sudo apt-get install lcov
- name: Install codecov
if: startsWith(github.ref, 'refs/tags/') != true
shell: bash
run: sudo pip install codecov
- run: |
echo "RUNVCPKG_NO_CACHE=1" >> $GITHUB_ENV
if: ${{ failure() || cancelled() }}
shell: bash
- name: 'Run CMake'
uses: lukka/run-cmake@v10
if: startsWith(github.ref, 'refs/tags/') != true
with:
configurePreset: 'ninja-vcpkg-coverage-no-test'
buildPreset: 'ninja-vcpkg-coverage-no-test'
- name: 'Run CMake without coverage'
if: startsWith(github.ref, 'refs/tags/')
uses: lukka/run-cmake@v10
with:
configurePreset: 'ninja-vcpkg-release'
buildPreset: 'ninja-vcpkg-release-minimal'
testPreset: 'test-release'
- name: 'Run CTest'
if: ${{ startsWith(github.ref, 'refs/tags/') != true && matrix.os == 'ubuntu-latest' }}
run: ctest -V -C ${{ env.BUILD_TYPE }}
working-directory: "${{ github.workspace }}/build"
# CODE COVERAGE
- name: Code coverage - Capture coverage info
if: ${{ startsWith(github.ref, 'refs/tags/') != true && matrix.os == 'ubuntu-latest' }}
run: lcov --directory . --capture --output-file coverage.info --ignore-errors mismatch
- name: Code coverage - Filter out system, external, and unit test source files
if: ${{ startsWith(github.ref, 'refs/tags/') != true && matrix.os == 'ubuntu-latest' }}
run: lcov --remove coverage.info --output-file coverage_filter.info '/Library/*' '/usr/*' '*/test/*' '*/cmrc/*' '*/entry.cc' '*/simple_highlight.*' --ignore-errors unused
- name: Code coverage - Output coverage data for debugging
if: ${{ startsWith(github.ref, 'refs/tags/') != true && matrix.os == 'ubuntu-latest' }}
run: lcov --list coverage_filter.info
- name: Code coverage - Upload to CodeCov
if: ${{ startsWith(github.ref, 'refs/tags/') != true && matrix.os == 'ubuntu-latest' }}
run: bash <(curl -s https://codecov.io/bash) -f coverage_filter.info || echo "Codecov did not collect coverage reports"
- name: "Check file existence"
uses: andstor/file-existence-action@v3
with:
allow_failure: true
files: "${{ github.workspace }}/build/src/libsimple.so, ${{ github.workspace }}/build/test/dict/jieba.dict.utf8"
# npm run
- uses: actions/setup-node@v4
if: startsWith(github.ref, 'refs/tags/') != true
with:
node-version: '20'
- name: run node example
if: startsWith(github.ref, 'refs/tags/') != true
working-directory: ./examples/node/
run: |
npm install
npm run p -- --ext_path="${{ github.workspace }}/build/src/" --dict_path="${{ github.workspace }}/build/test/dict/"
npm run b -- --ext_path="${{ github.workspace }}/build/src/" --dict_path="${{ github.workspace }}/build/test/dict/"
# python run
- uses: actions/setup-python@v5
if: startsWith(github.ref, 'refs/tags/') != true
with:
python-version: '3.13' # Version range or exact version of a Python version to use, using SemVer's version range syntax
- name: run python example
if: startsWith(github.ref, 'refs/tags/') != true
working-directory: ./examples/python3/
run: python db_connector.py "${{ github.workspace }}/build/src/libsimple"
# create release
- name: "Build Changelog"
id: build_changelog
if: ${{ startsWith(github.ref, 'refs/tags/') && matrix.os == 'ubuntu-latest' }}
uses: mikepenz/release-changelog-builder-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Package
if: startsWith(github.ref, 'refs/tags/')
run: |
mkdir libsimple-linux-${{ matrix.os }}
cp -r src/libsimple.so test/dict/ libsimple-linux-${{ matrix.os }}/
zip -r libsimple-linux-${{ matrix.os }}.zip libsimple-linux-${{ matrix.os }}
working-directory: "${{ github.workspace }}/build"
- name: Release without changelog
if: ${{ startsWith(github.ref, 'refs/tags/') && matrix.os != 'ubuntu-latest' }}
uses: softprops/action-gh-release@v1
with:
draft: true
files: ${{ github.workspace }}/build/libsimple-linux-${{ matrix.os }}.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Release
if: ${{ startsWith(github.ref, 'refs/tags/') && matrix.os == 'ubuntu-latest' }}
uses: softprops/action-gh-release@v1
with:
draft: true
files: ${{ github.workspace }}/build/libsimple-linux-${{ matrix.os }}.zip
body: ${{steps.build_changelog.outputs.changelog}}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MacOS:
runs-on: macos-latest
needs: Linux
steps:
- name: "Release Build Type"
if: startsWith(github.ref, 'refs/tags/')
run: echo "BUILD_TYPE=Release" >> $GITHUB_ENV
- name: "Debug Build Type"
if: startsWith(github.ref, 'refs/tags/') != true
run: echo "BUILD_TYPE=Debug" >> $GITHUB_ENV
- uses: actions/checkout@v4
with:
submodules: true
# Install build tools
- name: Install Ninja
run: brew install ninja
# Install latest CMake
# - uses: lukka/get-cmake@latest
# Restore from cache the previously built ports
- name: Restore artifacts, or setup vcpkg
uses: lukka/run-vcpkg@v10
with:
vcpkgDirectory: '${{ github.workspace }}/vcpkg'
# Add this to prevent storing partial cache in case of failure
- run: |
echo "RUNVCPKG_NO_CACHE=1" >> $GITHUB_ENV
if: ${{ failure() || cancelled() }}
shell: bash
- name: 'Run CMake'
uses: lukka/run-cmake@v10
with:
configurePreset: 'macos-ninja'
buildPreset: ${{ startsWith(github.ref, 'refs/tags/') && 'macos-ninja-release' || 'macos-ninja-debug' }}
testPreset: ${{ startsWith(github.ref, 'refs/tags/') && 'test-macos-release' || 'test-macos-debug' }}
- name: 'Run CTest'
run: ctest -C ${{ env.BUILD_TYPE }}
working-directory: "${{ github.workspace }}/../../_temp/macos"
- name: "Check file existence"
uses: andstor/file-existence-action@v3
with:
allow_failure: true
files: "${{ github.workspace }}/../../_temp/macos/src/libsimple.dylib, ${{ github.workspace }}/../../_temp/macos/test/dict/jieba.dict.utf8"
- uses: actions/setup-node@v4
with:
node-version: '20'
# - uses: actions/setup-python@v5
# with:
# python-version: '3.12' # Version range or exact version of a Python version to use, using SemVer's version range syntax
# npm run
- name: run node example
working-directory: ./examples/node/
run: |
brew install python-setuptools
npm install
npm run p -- --ext_path="${{ github.workspace }}/../../_temp/macos/src/" --dict_path="${{ github.workspace }}/../../_temp/macos/test/dict/"
# don't run this as it's toooo slow
# npm run b -- --ext_path="${{ github.workspace }}/../../_temp/macos/src/" --dict_path="${{ github.workspace }}/../../_temp/macos/test/dict/"
# python run
# - name: run python example
# working-directory: ./examples/python3/
# run: |
# python db_connector.py "${{ github.workspace }}/../../_temp/macos/src/libsimple"
- name: Package
if: startsWith(github.ref, 'refs/tags/')
run: |
mkdir libsimple-osx-x64
sudo xattr -r -d com.apple.quarantine src/libsimple.dylib
cp -r src/libsimple.dylib test/dict libsimple-osx-x64/
zip -r libsimple-osx-x64.zip libsimple-osx-x64
working-directory: "${{ github.workspace }}/../../_temp/macos"
- name: Release
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v1
with:
draft: true
files: "${{ github.workspace }}/../../_temp/macos/libsimple-osx-x64.zip"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: build-iOS
run: ./build-ios.sh