-
Notifications
You must be signed in to change notification settings - Fork 2
230 lines (189 loc) · 8.16 KB
/
build-and-publish.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
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: start ./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 }}