1+ name : Build and Publish
2+
3+ on :
4+ push :
5+ pull_request :
6+ branches :
7+ - develop
8+
9+ env :
10+ MAJOR : 12
11+ MINOR : 1
12+ RUN : ${{ github.run_number }}
13+
14+ jobs :
15+ get-version :
16+ runs-on : ubuntu-latest
17+ outputs :
18+ BUILD_ID : ${{ steps.get_build_id.outputs.BUILD_ID}}
19+ APP_VERSION : ${{ steps.get_app_version.outputs.APP_VERSION}}
20+ steps :
21+ - name : Get New Build Number
22+ id : get_build_id
23+ shell : bash
24+ run : |
25+
26+ # Get the build ID
27+ if [[ "${{ github.event_name }}" == 'push' && "${{ github.ref_name }}" == "${{ github.event.repository.default_branch }}" ]]; then
28+ # Fetch the latest version from the organization NuGet package
29+ response=$(curl -s -L \
30+ -H "Accept: application/vnd.github+json" \
31+ -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
32+ -H "X-GitHub-Api-Version: 2022-11-28" \
33+ https://api.github.com/orgs/Open-Systems-Pharmacology/packages/nuget/OSPSuite.Core/versions)
34+
35+ # Log the raw response for debugging
36+ echo "API Response: $response"
37+
38+ # Check if the response indicates a package not found error or is not valid JSON
39+ if echo "$response" | jq -e '.message == "Package not found." or (.[0].name // empty | length == 0)' >/dev/null 2>&1; then
40+ # Set the build number to 15 if no package is found or response is invalid (since the last build was 12.1.14)
41+ new_build_id=15
42+ else
43+ latest_version=$(echo "$response" | jq -r '.[0].name // empty')
44+
45+ # Extract MAJOR, MINOR from the latest version
46+ IFS='.' read -r last_major last_minor last_build <<< "$latest_version"
47+
48+ # Compare with the current MAJOR, MINOR
49+ if [[ "$last_major" -eq "${{ env.MAJOR }}" && "$last_minor" -eq "${{ env.MINOR }}" ]]; then
50+ # Increment the last number if they match
51+ new_build_id=$((last_build + 1))
52+ else
53+ # Reset build number to 0 if the current version is different
54+ new_build_id=0
55+ fi
56+ fi
57+
58+ echo "latest build number: ${latest_version:-'None found'}"
59+ echo "new build number: ${new_build_id}"
60+ build_id="${new_build_id}"
61+ else
62+ build_id="9${{ env.RUN }}"
63+ fi
64+
65+ echo "New Build ID: ${build_id}"
66+ echo "BUILD_ID=${build_id}" >> $GITHUB_ENV
67+ echo "BUILD_ID=${build_id}" >> $GITHUB_OUTPUT
68+
69+ - name : Get App Version
70+ id : get_app_version
71+ shell : bash
72+ run : |
73+ app_version="${{ env.MAJOR }}.${{ env.MINOR }}.${{ env.BUILD_ID }}"
74+ echo "App Version: ${app_version}"
75+ echo "APP_VERSION=${app_version}" >> $GITHUB_ENV
76+ echo "APP_VERSION=${app_version}" >> $GITHUB_OUTPUT
77+
78+ build :
79+ runs-on : windows-latest
80+ needs : get-version
81+ steps :
82+ - name : Checkout code
83+ uses : actions/checkout@v4
84+ with :
85+ submodules : ' true'
86+
87+ - name : Add msbuild to PATH
88+ uses : microsoft/setup-msbuild@v2
89+
90+ - name : Restore dependencies
91+ run : |
92+ 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"
93+ nuget sources add -name bddhelper -source https://ci.appveyor.com/nuget/ospsuite-bddhelper
94+ nuget sources add -name utility -source https://ci.appveyor.com/nuget/ospsuite-utility
95+ nuget sources add -name serializer -source https://ci.appveyor.com/nuget/ospsuite-serializer
96+ nuget sources add -name databinding -source https://ci.appveyor.com/nuget/ospsuite-databinding
97+ nuget sources add -name texreporting -source https://ci.appveyor.com/nuget/ospsuite-texreporting
98+ nuget sources add -name databinding-devexpress -source https://ci.appveyor.com/nuget/ospsuite-databinding-devexpress
99+ dotnet restore
100+
101+ - name : define env variables
102+ run : |
103+ echo "APP_VERSION=${{needs.get-version.outputs.APP_VERSION}}" | Out-File -FilePath $env:GITHUB_ENV -Append
104+ echo "BUILD_ID=${{needs.get-version.outputs.BUILD_ID}}" | Out-File -FilePath $env:GITHUB_ENV -Append
105+
106+ - name : Build
107+ run : msbuild OSPSuite.Core.sln /p:Version=${{env.APP_VERSION}}
108+
109+ - name : Test
110+ run : dotnet test .\tests\**\bin\Debug\net472\OSPSuite*Tests.dll -v normal --no-build --logger:"html;LogFileName=../testLog_Windows.html"
111+
112+ - name : Pack the project
113+ run : dotnet pack .\OSPSuite.Core.sln --no-build --no-restore -o ./ -p:PackageVersion=${{env.APP_VERSION}} --configuration=Debug --include-symbols --no-build
114+
115+ - name : Push nupkg as artifact
116+ # if it is a push to a branch
117+ if : github.event_name == 'push' && github.ref_name != github.event.repository.default_branch
118+ uses : actions/upload-artifact@v4
119+ with :
120+ name : OSPSuite.Core
121+ path : ./*.nupkg
122+
123+ - name : Push test log as artifact
124+ uses : actions/upload-artifact@v4
125+ with :
126+ name : testLog_Windows
127+ path : ./testLog*.html
128+
129+ - name : Publish to GitHub registry
130+ # if it is a merge to default branch
131+ if : github.event_name == 'push' && github.ref_name == github.event.repository.default_branch
132+ run : dotnet nuget push ./*.nupkg --source https://nuget.pkg.github.com/${{github.repository_owner}}/index.json --api-key ${{ secrets.GITHUB_TOKEN }}
0 commit comments