Merge pull request #16 from dogged/ethomson/ci #92
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 | |
on: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
release: | |
types: [ published ] | |
workflow_dispatch: | |
jobs: | |
build: | |
strategy: | |
matrix: | |
platform: | |
- name: Linux (amd64) | |
os: ubuntu-latest | |
- name: macOS (amd64, arm64) | |
os: macos-latest | |
cmake_options: -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" | |
- name: Windows (amd64) | |
os: windows-latest | |
name: "Build: ${{ matrix.platform.name }}" | |
runs-on: ${{ matrix.platform.os }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
submodules: true | |
- name: Build | |
id: build | |
run: | | |
mkdir build | |
cd build | |
BUILD_TYPE="${{env.BUILD_TYPE}}" | |
BUILD_TYPE="${BUILD_TYPE:-RelWithDebInfo}" | |
LIBGIT2_SRC="${GITHUB_WORKSPACE}/libgit2" | |
SHA=${SHA:-$(git --git-dir="${LIBGIT2_SRC}/.git" rev-parse --short=7 HEAD)} | |
LIBGIT2_BASENAME="git2-${SHA}" | |
case $(uname -s) in | |
Darwin) | |
PLATFORM="osx" | |
LIBGIT2_FILENAME="lib${LIBGIT2_BASENAME}.dylib" | |
;; | |
MINGW*) | |
PLATFORM="win-x64" | |
LIBGIT2_FILENAME="${BUILD_TYPE}/${LIBGIT2_BASENAME}.dll" | |
;; | |
Linux) | |
PLATFORM="linux-x64" | |
LIBGIT2_FILENAME="lib${LIBGIT2_BASENAME}.so" | |
;; | |
*) | |
echo "Unknown platform" 1>&2 | |
false | |
;; | |
esac | |
cmake "${LIBGIT2_SRC}" \ | |
-DCMAKE_BUILD_TYPE="${BUILD_TYPE}" \ | |
-DBUILD_SHARED_LIBS=ON \ | |
-DBUILD_TESTS=OFF \ | |
-DUSE_SSH=OFF \ | |
-DUSE_BUNDLED_ZLIB=ON \ | |
-DLIBGIT2_FILENAME="${LIBGIT2_BASENAME}" \ | |
${{ matrix.platform.cmake_options }} | |
cmake --build . --config ${BUILD_TYPE} | |
echo "platform=${PLATFORM}" >> $GITHUB_OUTPUT | |
echo "path=build/${LIBGIT2_FILENAME}" >> $GITHUB_OUTPUT | |
shell: bash | |
- name: Upload Library | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{steps.build.outputs.platform}} | |
path: ${{steps.build.outputs.path}} | |
package: | |
needs: build | |
runs-on: windows-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Setup | |
run: | | |
mkdir -p tmp | |
mkdir -p build/runtimes/linux-x64/native | |
mkdir -p build/runtimes/osx/native | |
mkdir -p build/runtimes/win-x64/native | |
choco install nuget.commandline | |
- name: Download Artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
path: tmp | |
- name: Set up Artifacts | |
run: | | |
mv tmp/linux-x64/* build/runtimes/linux-x64/native | |
mv tmp/osx/* build/runtimes/osx/native | |
mv tmp/win-x64/* build/runtimes/win-x64/native | |
- name: Calculate Version | |
id: version | |
run: | | |
if [ "$GITHUB_EVENT_NAME" = "pull_request" ]; then | |
SHA=$(git rev-parse --short HEAD) | |
VERSION="$(git describe --tags | \ | |
sed -e "s/^v//" | \ | |
sed -e "s/-g[0-9a-f]*$//" | \ | |
sed -e "s/-[0-9]*$//")-pr${{ github.event.number }}-${SHA}" | |
else | |
VERSION=$(git describe --tags | \ | |
sed -e "s/^v//" | \ | |
sed -e "s/-g[0-9a-f]*$//" | \ | |
sed -e "s/-\([0-9]*\)$/\.\1/") | |
fi | |
echo "Version ${VERSION}" | |
echo "version=${VERSION}" >> $GITHUB_OUTPUT | |
shell: bash | |
- name: Build Package | |
id: build | |
run: | | |
cd build | |
mkdir images | |
cp -R ../images/* ./images/ | |
. ..\generate_props.ps1 | |
nuget pack -version ${{steps.version.outputs.version}} -basepath . ..\dogged.native.binaries.nuspec | |
Write-Host "package=dogged.native.binaries.${{steps.version.outputs.version}}.nupkg" >> $Env:GITHUB_OUTPUT | |
- name: Upload Package | |
uses: actions/upload-artifact@v4 | |
with: | |
name: nuget | |
path: build/${{steps.build.outputs.package}}/Dogged.Native.Binaries.${{steps.version.outputs.version}}.nupkg |