Skip to content

remove unused switches #26

remove unused switches

remove unused switches #26

name: Build and Publish
on:
push:
pull_request:
branches:
- develop
env:
MAJOR: 12
MINOR: 1
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.Core/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 15 if no package is found or response is invalid (since the last build was 12.1.14)
new_build_id=15
else
latest_version=$(echo "$response" | jq -r '.[0].name // empty')
# Extract MAJOR, MINOR from the latest version
IFS='.' read -r last_major last_minor last_build <<< "$latest_version"
# Compare with the current MAJOR, MINOR
if [[ "$last_major" -eq "${{ env.MAJOR }}" && "$last_minor" -eq "${{ env.MINOR }}" ]]; 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="9${{ env.RUN }}"
fi
echo "New Build ID: ${build_id}"
echo "BUILD_ID=${build_id}" >> $GITHUB_ENV
echo "BUILD_ID=${build_id}" >> $GITHUB_OUTPUT
- name: Get App Version
id: get_app_version
shell: bash
run: |
app_version="${{ env.MAJOR }}.${{ env.MINOR }}.${{ env.BUILD_ID }}"
echo "App Version: ${app_version}"
echo "APP_VERSION=${app_version}" >> $GITHUB_ENV
echo "APP_VERSION=${app_version}" >> $GITHUB_OUTPUT
build:
runs-on: windows-latest
needs: get-version
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: 'true'
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v2
- name: Restore dependencies
run: |
nuget sources add -username Open-Systems-Pharmacology -password ${{ secrets.GITHUB_TOKEN }} -name OSP-GitHub-Packages -source "https://nuget.pkg.github.com/Open-Systems-Pharmacology/index.json"
nuget sources add -name bddhelper -source https://ci.appveyor.com/nuget/ospsuite-bddhelper
nuget sources add -name utility -source https://ci.appveyor.com/nuget/ospsuite-utility
nuget sources add -name serializer -source https://ci.appveyor.com/nuget/ospsuite-serializer
nuget sources add -name databinding -source https://ci.appveyor.com/nuget/ospsuite-databinding
nuget sources add -name texreporting -source https://ci.appveyor.com/nuget/ospsuite-texreporting
nuget sources add -name databinding-devexpress -source https://ci.appveyor.com/nuget/ospsuite-databinding-devexpress
dotnet restore
- 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: Build
run: msbuild OSPSuite.Core.sln /p:Version=${{env.APP_VERSION}}
- name : Test
run: dotnet test .\tests\**\bin\Debug\net472\OSPSuite*Tests.dll -v normal --no-build --logger:"html;LogFileName=../testLog_Windows.html"
- name: Pack the project
run: dotnet pack .\OSPSuite.Core.sln --no-build --no-restore -o ./ -p:PackageVersion=${{env.APP_VERSION}} --configuration=Debug --include-symbols --no-build
- 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: OSPSuite.Core
path: ./*.nupkg
- name: Push test log as artifact
uses: actions/upload-artifact@v4
with:
name: testLog_Windows
path: ./testLog*.html
- 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 }}