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: 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 artefact | |
# 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 artefact | |
# 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 artefact | |
# 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 release and debug | |
run: start ./build_Windows.bat | |
- name: Pack the project | |
run: createNugetPackage_Windows.bat ${{env.APP_VERSION}} | |
- name: Push nupkg as artefact | |
# 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 }} |