Skip to content

use build matrix strategy (#14) #22

use build matrix strategy (#14)

use build matrix strategy (#14) #22

name: Build and Publish NuGet Package for all supported platforms
on:
push:
pull_request:
branches:
- master
env:
MAJOR: 5
MINOR: 8
RELEASE: 0
RUN: ${{ github.run_number }}
jobs:
get-version:
runs-on: ubuntu-latest
outputs:
BUILD_ID: ${{ steps.get_build_id.outputs.BUILD_ID}}
APP_VERSION: ${{ steps.get_app_version.outputs.APP_VERSION}}
steps:
- name: Get New Build Number
id: get_build_id
shell: bash
run: |
# Get the build ID
if [[ "${{ github.event_name }}" == 'push' && "${{ github.ref_name }}" == "${{ github.event.repository.default_branch }}" ]]; then
# Fetch the latest version from the organization NuGet package
response=$(curl -s -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/orgs/Open-Systems-Pharmacology/packages/nuget/CVODES/versions)
# Log the raw response for debugging
echo "API Response: $response"
# Check if the response indicates a package not found error or is not valid JSON
if echo "$response" | jq -e '.message == "Package not found." or (.[0].name // empty | length == 0)' >/dev/null 2>&1; then
# Set the build number to 9 if no package is found or response is invalid (since the last released was 5.8.0.8)
new_build_id=9
else
latest_version=$(echo "$response" | jq -r '.[0].name // empty')
# Extract MAJOR, MINOR, and RELEASE from the latest version
IFS='.' read -r last_major last_minor last_release last_build <<< "$latest_version"
# Compare with the current MAJOR, MINOR, and RELEASE
if [[ "$last_major" -eq "${{ env.MAJOR }}" && "$last_minor" -eq "${{ env.MINOR }}" && "$last_release" -eq "${{ env.RELEASE }}" ]]; then
# Increment the last number if they match
new_build_id=$((last_build + 1))
else
# Reset build number to 0 if the current version is different
new_build_id=0
fi
fi
echo "latest build number: ${latest_version:-'None found'}"
echo "new build number: ${new_build_id}"
build_id="${new_build_id}"
else
build_id="999${{ env.RUN }}"
fi
echo "New Build ID: ${build_id}"
echo "BUILD_ID=${build_id}" >> $GITHUB_ENV
echo "::set-output name=BUILD_ID::${build_id}"
- name: Get App Version
id: get_app_version
shell: bash
run: |
app_version="${{ env.MAJOR }}.${{ env.MINOR }}.${{ env.RELEASE }}.${{ env.BUILD_ID }}"
echo "App Version: ${app_version}"
echo "APP_VERSION=${app_version}" >> $GITHUB_ENV
echo "::set-output name=APP_VERSION::${app_version}"
build-nix:
strategy:
matrix:
include:
- os: macos-latest
nuget_package: CVODES.MacOS.Arm64
- os: macos-13
nuget_package: CVODES.MacOS.x64
- os: ubuntu-22.04
nuget_package: CVODES.Ubuntu22
runs-on: ${{ matrix.os }}
needs: get-version
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: 'true'
- name: define env variables
run: |
echo "APP_VERSION=${{needs.get-version.outputs.APP_VERSION}}" >> $GITHUB_ENV
echo "BUILD_ID=${{needs.get-version.outputs.BUILD_ID}}" >> $GITHUB_ENV
- name: Build native libraries
run: |
chmod ugo+x buildNix.sh
./buildNix.sh
- name: Pack the project
run: |
chmod ugo+x createNugetPackage_Nix.sh
./createNugetPackage_Nix.sh ${{env.APP_VERSION}}
- name: Push nupkg as artifact
# if it is a push to a branch
if: github.event_name == 'push' && github.ref_name != github.event.repository.default_branch
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.nuget_package }}
path: ./*.nupkg
- name: Publish to GitHub registry
# if it is a merge to default branch
if: github.event_name == 'push' && github.ref_name == github.event.repository.default_branch
run: dotnet nuget push ./*.nupkg --source https://nuget.pkg.github.com/${{github.repository_owner}}/index.json --api-key ${{ secrets.GITHUB_TOKEN }}
build-windows-x64:
runs-on: windows-latest
needs: get-version
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: 'true'
- name: define env variables
run: |
echo "APP_VERSION=${{needs.get-version.outputs.APP_VERSION}}" | Out-File -FilePath $env:GITHUB_ENV -Append
echo "BUILD_ID=${{needs.get-version.outputs.BUILD_ID}}" | Out-File -FilePath $env:GITHUB_ENV -Append
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v2
- name: build debug
run: |
if not exist BuildCVODES_Windows mkdir BuildCVODES_Windows
echo Compiling for build type = Debug
cmake -BBuildCVODES_Windows/Debug/x64/ -Hsrc/CVODES/ -DCMAKE_BUILD_TYPE=Debug -DEXAMPLES_ENABLE_C=OFF -DBUILD_SHARED_LIBS=OFF -DBUILD_STATIC_LIBS=ON -DENABLE_KLU=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DKLU_INCLUDE_DIR=BuildSuiteSparse/include/ -DKLU_LIBRARY_DIR=BuildSuiteSparse/lib64/ -DCMAKE_C_FLAGS_RELEASE="/O2 /Ob2 /DNDEBUG /Oi"
IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL%
msbuild BuildCVODES_Windows/Debug/x64/ALL_BUILD.vcxproj /property:Configuration=Debug
IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL%
if exist Dist\Windows\Debug\x64 rmdir /S /Q Dist\Windows\Debug\x64
IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL%
mkdir Dist\Windows\Debug\x64
IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL%
shell: cmd
- name: build release
run: |
if not exist BuildCVODES_Windows mkdir BuildCVODES_Windows
echo Compiling for build type = Release
cmake -BBuildCVODES_Windows/Release/x64/ -Hsrc/CVODES/ -DCMAKE_BUILD_TYPE=Release -DEXAMPLES_ENABLE_C=OFF -DBUILD_SHARED_LIBS=OFF -DBUILD_STATIC_LIBS=ON -DENABLE_KLU=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DKLU_INCLUDE_DIR=BuildSuiteSparse/include/ -DKLU_LIBRARY_DIR=BuildSuiteSparse/lib64/ -DCMAKE_C_FLAGS_RELEASE="/O2 /Ob2 /DNDEBUG /Oi"
IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL%
msbuild BuildCVODES_Windows/Release/x64/ALL_BUILD.vcxproj /property:Configuration=Release
IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL%
if exist Dist\Windows\Release\x64 rmdir /S /Q Dist\Windows\Release\x64
IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL%
mkdir Dist\Windows\Release\x64
IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL%
shell: cmd
- name: Pack the project
run: ./createNugetPackage_Windows.bat ${{env.APP_VERSION}}
shell: cmd
- name: Push nupkg as artifact
# if it is a push to a branch
if: github.event_name == 'push' && github.ref_name != github.event.repository.default_branch
uses: actions/upload-artifact@v4
with:
name: CVODES
path: ./*.nupkg
- name: Publish to GitHub registry
# if it is a merge to default branch
if: github.event_name == 'push' && github.ref_name == github.event.repository.default_branch
shell: pwsh
run: dotnet nuget push .\CVODES*.nupkg --source https://nuget.pkg.github.com/${{github.repository_owner}}/index.json --api-key ${{ secrets.GITHUB_TOKEN }}