-
Notifications
You must be signed in to change notification settings - Fork 1
263 lines (221 loc) · 9.51 KB
/
main.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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
name: MetricsHub Sanity Check
on:
push:
branches:
- main
workflow_dispatch:
inputs:
version:
description: 'Enter the version to compare'
required: true
build_number:
description: 'Enter the build number to compare'
required: true
run_id:
description: 'Enter the GitHub build run ID, example: 9496848962'
required: false
jobs:
sanity-check-ubuntu:
runs-on: ubuntu-latest
steps:
- name: Download artifact from MetricsHub
shell: bash
env:
# Define variables
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OWNER: ${{ github.repository_owner }}
REPO: metricshub
BRANCH: main
RUN_ID: ${{ github.event.inputs.run_id }}
run: |
# Debug - Print variables
echo "Owner: $OWNER"
echo "Repo: $REPO"
echo "Branch: $BRANCH"
if [ -z "$RUN_ID" ]; then
# Get the latest successful workflow run ID
WORKFLOW_RUNS=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" "https://api.github.com/repos/$OWNER/$REPO/actions/runs?branch=$BRANCH&status=completed&per_page=5")
echo "Workflow runs fetched:"
echo $WORKFLOW_RUNS | jq .
RUN_ID=$(echo $WORKFLOW_RUNS | jq -r '.workflow_runs[] | select(.conclusion == "success") | .id' | head -n 1)
fi
if [ -z "$RUN_ID" ]; then
echo "No successful run ID found."
exit 1
fi
echo "Latest successful run ID: $RUN_ID"
# Get the artifact download URL
ARTIFACTS_URL="https://api.github.com/repos/$OWNER/$REPO/actions/runs/$RUN_ID/artifacts"
ARTIFACTS=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" $ARTIFACTS_URL)
echo "Artifacts fetched:"
echo $ARTIFACTS | jq .
DOWNLOAD_URL=$(echo $ARTIFACTS | jq -r '.artifacts[] | select(.name | startswith("metricshub-linux")) | .archive_download_url')
if [ -z "$DOWNLOAD_URL" ]; then
echo "No artifact ID found."
exit 1
fi
echo "Artifact download URL: $DOWNLOAD_URL"
# Download the artifact
curl -L -H "Authorization: Bearer $GITHUB_TOKEN" -o artifact.zip $DOWNLOAD_URL
# Unzip the artifact and extract tarball
mkdir -p artifacts
unzip artifact.zip -d artifacts
cd artifacts
# Debug - List files in artifacts directory
echo "Files in artifacts directory:"
ls -l
# Extract tarball (assuming the correct filename is known)
TAR_FILE=$(ls metricshub-linux-*.tar.gz)
if [ -z "$TAR_FILE" ]; then
echo "No tarball found in artifacts."
exit 1
fi
tar -xzf $TAR_FILE
- name: Run MetricsHub and get version
id: get_version
run: |
cd artifacts/metricshub/bin
VERSION_OUTPUT=$(./metricshub --version)
echo "$VERSION_OUTPUT"
# Extract the version and build number using grep and regex
AGENT_VERSION=$(echo "$VERSION_OUTPUT" | grep -oP 'MetricsHub Agent version \K[\d.]+(?:-[\w]+)?')
BUILD_NUMBER=$(echo "$VERSION_OUTPUT" | grep -oP '(?<=Build Number: )\w+')
echo "AGENT_VERSION=$AGENT_VERSION" >> $GITHUB_ENV
echo "BUILD_NUMBER=$BUILD_NUMBER" >> $GITHUB_ENV
- name: Compare version
run: |
INPUT_VERSION="${{ github.event.inputs.version }}"
AGENT_VERSION="${{ env.AGENT_VERSION }}"
if [ "$INPUT_VERSION" = "$AGENT_VERSION" ]; then
echo "The input version matches the current MetricsHub Agent version."
else
echo "The input version does not match the current MetricsHub Agent version. Version found: $AGENT_VERSION"
exit 1
fi
- name: Compare build number
run: |
expected_build_number="${{ github.event.inputs.build_number }}"
actual_build_number="${{ env.BUILD_NUMBER }}"
if [ "$actual_build_number" != "$expected_build_number" ]; then
echo "Build number mismatch: expected $expected_build_number, got $actual_build_number"
exit 1
else
echo "Build number match: $actual_build_number"
fi
sanity-check-windows:
runs-on: windows-latest
steps:
- name: Download artifact from MetricsHub
shell: pwsh
env:
# Define variables
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OWNER: ${{ github.repository_owner }}
REPO: metricshub
BRANCH: main
RUN_ID: ${{ github.event.inputs.run_id }}
run: |
# Debug - Print variables
Write-Host "Owner: ${env:OWNER}"
Write-Host "Repo: ${env:REPO}"
Write-Host "Branch: ${env:BRANCH}"
if (-not $env:RUN_ID) {
# Get the latest successful workflow run ID
$workflow_runs = Invoke-RestMethod -Headers @{ Authorization = "Bearer $env:GITHUB_TOKEN" } -Uri "https://api.github.com/repos/${env:OWNER}/${env:REPO}/actions/runs?branch=${env:BRANCH}&status=completed&per_page=5"
Write-Host "Workflow runs: $($workflow_runs | ConvertTo-Json -Depth 3)"
$run_id = ($workflow_runs.workflow_runs | Where-Object { $_.conclusion -eq "success" })[0].id
} else {
$run_id = $env:RUN_ID
}
if (-not $run_id) {
Write-Error "No successful run ID found."
exit 1
}
# Debug - Print run_id
Write-Host "Latest successful run ID: $run_id"
# Get the artifact download URL
$artifacts_url = "https://api.github.com/repos/${env:OWNER}/${env:REPO}/actions/runs/$run_id/artifacts"
$artifacts = Invoke-RestMethod -Headers @{ Authorization = "Bearer $env:GITHUB_TOKEN" } -Uri $artifacts_url
# Debug - Print artifacts
Write-Host "Artifacts: $($artifacts | ConvertTo-Json -Depth 3)"
# Extract artifact information
$artifact = $artifacts.artifacts | Where-Object { $_.name -like "metricshub-windows*" } | Select-Object -First 1
if (-not $artifact) {
Write-Error "No artifact found with name starting with 'metricshub-windows'"
exit 1
}
$download_url = $artifact.archive_download_url
# Debug - Print download URL
Write-Host "Download URL: $download_url"
# Download the artifact
Invoke-WebRequest -Headers @{ Authorization = "Bearer $env:GITHUB_TOKEN" } -Uri $download_url -OutFile artifact.zip
# Unzip the artifact
mkdir artifacts
Expand-Archive artifact.zip -DestinationPath artifacts
Expand-Archive artifacts\metricshub-windows*.zip -DestinationPath artifacts
- name: List extracted files
shell: pwsh
run: Get-ChildItem -Path artifacts -Recurse
- name: MetricsHub version
id: get_version
shell: pwsh
run: |
Write-Host "Attempting to find and run metricshub.exe"
# Define output encoding
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
# Find metricshub.exe and run it
$exe_path = Get-ChildItem -Path artifacts -Recurse -Filter MetricsHub.exe | Select-Object -First 1
if ($exe_path) {
Write-Host "Found metricshub.exe at $($exe_path.FullName)"
$version_output = & $exe_path.FullName --version
Write-Output "Raw version output:"
Write-Output "$version_output"
# Extract the version and build number using regex
$version_regex = [regex]::new("MetricsHub Agent version ([\d.]+(?:-[\w]+)?)")
$build_number_regex = [regex]::new("Build Number: ([\w]+)")
$version_matches = $version_regex.Match($version_output)
$build_number_matches = $build_number_regex.Match($version_output)
if ($version_matches.Success) {
$agent_version = $version_matches.Groups[1].Value
Write-Host "AGENT_VERSION=$agent_version"
echo "AGENT_VERSION=$agent_version" >> $env:GITHUB_ENV
} else {
Write-Host "No version number found in the output"
Write-Host "Version output: $version_output"
exit 1
}
if ($build_number_matches.Success) {
$build_number = $build_number_matches.Groups[1].Value
Write-Host "BUILD_NUMBER=$build_number"
echo "BUILD_NUMBER=$build_number" >> $env:GITHUB_ENV
} else {
Write-Host "No build number found in the output"
Write-Host "Build number output: $version_output"
exit 1
}
} else {
Write-Host "metricshub.exe not found"
exit 1
}
- name: Compare version
shell: pwsh
run: |
$input_version = "${{ github.event.inputs.version }}"
$agent_version = $env:AGENT_VERSION
if ($agent_version -ne $input_version) {
Write-Error "Version mismatch: expected $input_version, got $agent_version"
exit 1
} else {
Write-Host "Version match: $agent_version"
}
- name: Compare build number
shell: pwsh
run: |
$expected_build_number = "${{ github.event.inputs.build_number }}"
$actual_build_number = $env:BUILD_NUMBER
if ($actual_build_number -ne $expected_build_number) {
Write-Error "Build number mismatch: expected $expected_build_number, got $actual_build_number"
exit 1
} else {
Write-Host "Build number match: $actual_build_number"
}