Skip to content

Commit 7b72de4

Browse files
committed
Updated CI workflows and supporting scripts/tools.
1 parent 4dbaabf commit 7b72de4

File tree

2 files changed

+71
-93
lines changed

2 files changed

+71
-93
lines changed

.github/workflows/Biohazrd.yml

Lines changed: 20 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ env:
2121
ContinuousIntegrationBuild: true
2222
# This URL will be added to the restore sources if it isn't the official NuGet.org
2323
# (This is mainly intended to allow using the NuGet.org test servers to test CI in forks.)
24-
CiNuGetApiUrl: ${{secrets.NUGET_API_URL}}
24+
CiNuGetApiUrl: ${{vars.NUGET_API_URL}}
2525
jobs:
2626
# =====================================================================================================================================================================
2727
# Build and Test Biohazrd
@@ -38,11 +38,10 @@ jobs:
3838
os: ubuntu-latest
3939
rid: linux-x64
4040
- name: Linux ARM64
41-
os: ubuntu-arm64-latest
41+
os: ubuntu-24.04-arm
4242
rid: linux-arm64
43-
skip-tool-install: true
4443
- name: macOS x64
45-
os: macos-10.15
44+
os: macos-13
4645
rid: osx-x64
4746
configuration: ['Debug', 'Release']
4847
include:
@@ -58,32 +57,30 @@ jobs:
5857
steps:
5958
# ----------------------------------------------------------------------- Checkout
6059
- name: Checkout
61-
uses: actions/checkout@v2
60+
uses: actions/checkout@v4
6261
with:
6362
submodules: recursive
6463

6564
# ----------------------------------------------------------------------- Setup Python
66-
- name: Setup Python 3.8
67-
if: matrix.platform.skip-tool-install != true
68-
uses: actions/setup-python@v2
65+
- name: Setup Python
66+
uses: actions/setup-python@v5
6967
with:
70-
python-version: '3.8'
68+
python-version: '3.11'
7169

7270
# ----------------------------------------------------------------------- Setup .NET
7371
- name: Setup .NET
74-
if: matrix.platform.skip-tool-install != true
75-
uses: actions/setup-dotnet@v1
72+
uses: actions/setup-dotnet@v4
7673
with:
77-
dotnet-version: 6.0.x
74+
dotnet-version: 8.x
7875

7976
# ----------------------------------------------------------------------- Setup other dependencies
8077
- name: Setup other dependencies (Linux)
81-
if: matrix.platform.skip-tool-install != true && runner.os == 'Linux'
78+
if: runner.os == 'Linux'
8279
# This installs lld and llvm-ar, which are used by LinkImportsTransformationElfTests
8380
run: sudo apt-get install --yes lld llvm
8481

8582
- name: Setup other dependencies (macOS)
86-
if: matrix.platform.skip-tool-install != true && runner.os == 'macOS'
83+
if: runner.os == 'macOS'
8784
# The LLVM toolchain provided by Xcode is stripped down and doesn't include things like lld or llvm-ar
8885
# However, the runners do have a full LLVM toolchian installed via brew, so we use that for tests which require these tools
8986
run: python .github/workflows/gha.py set_environment_variable BIOHAZRD_FULL_LLVM_TOOLCHAIN_PATH "$(brew --prefix llvm)"
@@ -117,7 +114,7 @@ jobs:
117114

118115
# ----------------------------------------------------------------------- Collect Artifacts
119116
- name: Collect NuGet Packages
120-
uses: actions/upload-artifact@v2
117+
uses: actions/upload-artifact@v4
121118
# We always want to collect packages when they were produced
122119
if: steps.pack.outcome == 'success' && always()
123120
with:
@@ -139,50 +136,20 @@ jobs:
139136
steps:
140137
# ----------------------------------------------------------------------- Setup .NET
141138
- name: Setup .NET
142-
uses: actions/setup-dotnet@v1
139+
uses: actions/setup-dotnet@v4
143140
with:
144-
dotnet-version: 6.0.x
141+
dotnet-version: 8.x
145142

146143
# ----------------------------------------------------------------------- Download built packages
147144
- name: Download built packages
148-
uses: actions/download-artifact@v2
145+
uses: actions/download-artifact@v4
149146
with:
150147
name: Packages
151148

152149
# ----------------------------------------------------------------------- Upload release assets
153150
- name: Upload release assets
154151
if: github.event_name == 'release'
155-
uses: actions/github-script@v4
156-
with:
157-
user-agent: actions/github-script for ${{github.repository}}
158-
script: |
159-
const fs = require('fs').promises;
160-
const path = require('path');
161-
const upload_url = context.payload.release.upload_url;
162-
163-
if (!upload_url) {
164-
throw "Missing release asset upload URL!";
165-
}
166-
167-
for (let filePath of await fs.readdir('.')) {
168-
const fileExtension = path.extname(filePath);
169-
if (fileExtension != '.nupkg' && fileExtension != '.snupkg') {
170-
continue;
171-
}
172-
173-
console.log(`Uploading '${filePath}'`);
174-
const contentLength = (await fs.stat(filePath)).size;
175-
const fileContents = await fs.readFile(filePath);
176-
await github.repos.uploadReleaseAsset({
177-
url: upload_url,
178-
headers: {
179-
'content-type': 'application/octet-stream',
180-
'content-length': contentLength
181-
},
182-
name: path.basename(filePath),
183-
data: fileContents
184-
});
185-
}
152+
run: gh release upload ${{github.event.release.tag_name}} *.nupkg *.snupkg --clobber
186153

187154
# ----------------------------------------------------------------------- Push to GitHub Packages
188155
- name: Push to GitHub Packages
@@ -206,49 +173,19 @@ jobs:
206173
steps:
207174
# ----------------------------------------------------------------------- Setup .NET
208175
- name: Setup .NET
209-
uses: actions/setup-dotnet@v1
176+
uses: actions/setup-dotnet@v4
210177
with:
211-
dotnet-version: 6.0.x
178+
dotnet-version: 8.x
212179

213180
# ----------------------------------------------------------------------- Download built packages
214181
- name: Download built packages
215-
uses: actions/download-artifact@v2
182+
uses: actions/download-artifact@v4
216183
with:
217184
name: Packages
218185

219186
# ----------------------------------------------------------------------- Push to NuGet.org
220187
- name: Push to NuGet.org
221-
run: dotnet nuget push "*.nupkg" --api-key ${{secrets.NUGET_API_KEY}} --source ${{secrets.NUGET_API_URL}}
188+
run: dotnet nuget push "*.nupkg" --api-key ${{secrets.NUGET_API_KEY}} --source ${{vars.NUGET_API_URL}}
222189
env:
223190
# This is a workaround for https://github.com/NuGet/Home/issues/9775
224191
DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER: 0
225-
226-
# =====================================================================================================================================================================
227-
# Send CI Failure Notification
228-
# =====================================================================================================================================================================
229-
send-ci-failure-notification:
230-
name: Send CI Failure Notification
231-
needs: [build-and-test, publish-packages-github, publish-packages-nuget-org]
232-
if: failure() && github.event_name != 'pull_request'
233-
continue-on-error: true
234-
runs-on: ubuntu-latest
235-
steps:
236-
# ----------------------------------------------------------------------- Checkout
237-
- name: Checkout
238-
uses: actions/checkout@v2
239-
240-
# ----------------------------------------------------------------------- Setup Python
241-
- name: Setup Python 3.8
242-
uses: actions/setup-python@v2
243-
with:
244-
python-version: '3.8'
245-
246-
# ----------------------------------------------------------------------- Send CI Failure Notification
247-
- name: Send Notification
248-
run: python .github/workflows/send-ci-failure-notification.py
249-
env:
250-
webhook_url: ${{secrets.TEAMS_WEBHOOK_URL}}
251-
github_organization: ${{github.repository_owner}}
252-
github_repo: ${{github.repository}}
253-
github_workflow_name: ${{github.workflow}}
254-
github_run_number: ${{github.run_id}}

.github/workflows/gha.py

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
#!/usr/bin/env python3
12
# GitHub Actions Utility Functions
23
# https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions
4+
import io
35
import os
46
import sys
57

@@ -13,15 +15,16 @@ def fail_if_errors():
1315
def print_error(message):
1416
global errors_were_printed
1517
errors_were_printed = True
16-
print(f"::error::{message}", file=sys.stderr)
18+
print(f"::error::{message}")
1719

1820
def print_warning(message):
19-
print(f"::warning::{message}", file=sys.stderr)
21+
print(f"::warning::{message}")
2022

21-
def set_output(name, value):
22-
if isinstance(value, bool):
23-
value = "true" if value else "false"
24-
print(f"::set-output name={name}::{value}")
23+
def print_notice(message):
24+
print(f"::notice::{message}")
25+
26+
def print_debug(message):
27+
print(f"::debug::{message}")
2528

2629
def github_file_command(command, message):
2730
command = f"GITHUB_{command}"
@@ -34,17 +37,51 @@ def github_file_command(command, message):
3437
if not os.path.exists(command_file):
3538
print_error(f"'{command}' points to non-existent file '{command_file}')")
3639
sys.exit(1)
37-
40+
3841
with open(command_file, 'a') as command_file_handle:
3942
command_file_handle.write(message)
4043
command_file_handle.write('\n')
4144

45+
def set_output(name, value):
46+
if isinstance(value, bool):
47+
value = "true" if value else "false"
48+
github_file_command("OUTPUT", f"{name}<<GHA_PY_EOF\n{value}\nGHA_PY_EOF")
49+
4250
def set_environment_variable(name, value):
4351
github_file_command("ENV", f"{name}={value}")
4452

4553
def add_path(path):
4654
github_file_command("PATH", path)
4755

56+
class JobSummary:
57+
def __init__(self):
58+
self.file: io.TextIOBase | None = None
59+
60+
summary_file_path_var = "GITHUB_STEP_SUMMARY"
61+
summary_file_path = os.getenv(summary_file_path_var)
62+
if summary_file_path is None:
63+
print_warning(f"Failed to open step summary file, {summary_file_path_var} is not set.")
64+
return
65+
66+
try:
67+
self.file = open(summary_file_path, 'a')
68+
except Exception as ex:
69+
print_warning(f"Failed to open step summary file '{summary_file_path}': {ex}")
70+
71+
def __enter__(self):
72+
return self
73+
74+
def write_line(self, line: str = '') -> None:
75+
if self.file is None:
76+
return
77+
78+
self.file.write(line)
79+
self.file.write('\n')
80+
81+
def __exit__(self, exc_type, exc_val, exc_tb) -> None:
82+
if self.file is not None:
83+
self.file.__exit__(exc_type, exc_val, exc_tb)
84+
4885
if __name__ == "__main__":
4986
args = sys.argv
5087

@@ -56,12 +93,12 @@ def pop_arg():
5693
result = args[0]
5794
args = args[1:]
5895
return result
59-
96+
6097
def done_parsing():
6198
if len(args) > 0:
6299
print_error("Bad command line, too many arguments specified.")
63100
sys.exit(1)
64-
101+
65102
pop_arg() # Skip script name
66103
command = pop_arg()
67104
if command == "print_error":
@@ -72,6 +109,10 @@ def done_parsing():
72109
message = pop_arg()
73110
done_parsing()
74111
print_warning(message)
112+
elif command == "print_notice":
113+
message = pop_arg()
114+
done_parsing()
115+
print_notice(message)
75116
elif command == "set_output":
76117
name = pop_arg()
77118
value = pop_arg()
@@ -89,5 +130,5 @@ def done_parsing():
89130
else:
90131
print_error(f"Unknown command '{command}'")
91132
sys.exit(1)
92-
133+
93134
fail_if_errors()

0 commit comments

Comments
 (0)