Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build on GHA #9

Merged
merged 14 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
256 changes: 256 additions & 0 deletions .github/workflows/build-and-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
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/OSPSuite.FuncParser/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-macos-arm64:
runs-on: macos-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}}" >> $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: CVODES.MacOS.Arm64
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-macos-x64:
runs-on: macos-13
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: CVODES.MacOS.x64
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-linux-x64:
runs-on: ubuntu-22.04
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: CVODES.Ubuntu22
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
Comment on lines +212 to +238
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use build_Windows.bat 🙂

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, let's merge AS IS for now.
Created an issue: #10


- 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 }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# CVODES

[![Build status](https://ci.appveyor.com/api/projects/status/4mh7psxcwyhyjohi?svg=true)](https://ci.appveyor.com/project/open-systems-pharmacology-ci/cvodes)
[![Build status](https://img.shields.io/github/actions/workflow/status/Open-Systems-Pharmacology/CVODES/build-and-publish.yml?logo=nuget)](https://github.com/Open-Systems-Pharmacology/CVODES/actions/workflows/build-and-publish.yml)

36 changes: 0 additions & 36 deletions appveyor.yml

This file was deleted.

Loading