-
Notifications
You must be signed in to change notification settings - Fork 1
163 lines (131 loc) · 5.97 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
name: Download Artifacts from MetricsHub
on:
push:
branches:
- main
workflow_dispatch:
inputs:
version:
description: 'Enter the version to compare'
required: true
default: '0.9.0000-SNAPSHOT'
jobs:
sanity-check-ubuntu:
runs-on: ubuntu-latest
steps:
- name: Checkout this repository
uses: actions/checkout@v4
- name: Download artifacts from MetricsHub
run: |
# Define variables
OWNER="MohammedSentry"
REPO="metricshub"
BRANCH="main"
# Get the latest successful workflow run ID
WORKFLOW_RUNS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/$OWNER/$REPO/actions/runs?branch=$BRANCH&status=completed&per_page=5")
RUN_ID=$(echo $WORKFLOW_RUNS | jq -r '.workflow_runs[] | select(.conclusion == "success") | .id' | head -n 1)
# Get the artifact download URL
ARTIFACTS_URL="https://api.github.com/repos/$OWNER/$REPO/actions/runs/$RUN_ID/artifacts"
ARTIFACTS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" $ARTIFACTS_URL)
# Extract artifact information
ARTIFACT_ID=$(echo $ARTIFACTS | jq -r '.artifacts[0].id')
DOWNLOAD_URL="https://api.github.com/repos/$OWNER/$REPO/actions/artifacts/$ARTIFACT_ID/zip"
# Download the artifact
curl -L -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -o artifact.zip $DOWNLOAD_URL
# Unzip the artifact and extract tarball
mkdir -p artifacts
unzip artifact.zip -d artifacts
cd artifacts
tar -xzf metricshub-linux-*.tar.gz
- name: Run MetricsHub and get version
id: get_version
run: |
cd artifacts/metricshub/bin
VERSION_OUTPUT=$(./metricshub --version)
echo "$VERSION_OUTPUT"
# Extract the version number using grep and regex
AGENT_VERSION=$(echo "$VERSION_OUTPUT" | grep -oP '(?<=MetricsHub Agent version )[\d.-]+-SNAPSHOT')
echo "MetricsHub Agent version: $AGENT_VERSION"
echo "::set-output name=agent_version::$AGENT_VERSION"
shell: bash
- name: Compare versions
run: |
INPUT_VERSION="${{ github.event.inputs.version }}"
AGENT_VERSION="${{ steps.get_version.outputs.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."
exit 1
fi
shell: bash
- name: List downloaded files
run: ls -al artifacts
sanity-check-windows:
runs-on: windows-latest
steps:
- name: Checkout this repository
uses: actions/checkout@v4
- name: Download artifacts from MetricsHub
shell: pwsh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Define variables
$OWNER = "MohammedSentry"
$REPO = "metricshub"
$BRANCH = "main"
# Debug - Print variables
Write-Host "Owner: $OWNER"
Write-Host "Repo: $REPO"
Write-Host "Branch: $BRANCH"
# Get the latest successful workflow run ID
$workflow_runs = Invoke-RestMethod -Headers @{ Authorization = "Bearer $env:GITHUB_TOKEN" } -Uri "https://api.github.com/repos/$OWNER/$REPO/actions/runs?branch=$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
# Debug - Print run_id
Write-Host "Run ID: $run_id"
# Get the artifact download URL
$artifacts_url = "https://api.github.com/repos/$OWNER/$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
}
$artifact_id = $artifact.id
$download_url = "https://api.github.com/repos/$OWNER/$REPO/actions/artifacts/$artifact_id/zip"
# 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
shell: pwsh
run: |
Write-Host "Contents of artifacts directory:"
Write-Host "Attempting to find and run metricshub.exe"
# Find metricshub.exe and run it
$exe_path = Get-ChildItem -Path artifacts -Recurse -Filter metricshub.exe | Select-Object -First 1
Write-Host "Found metricshub.exe at $($exe_path.FullName)"
& $exe_path.FullName --version
- name: MetricsHub localhost collect
shell: pwsh
run: |
Write-Host "Metrics for localhost:"
# Find metricshub.exe and run it
$exe_path = Get-ChildItem -Path artifacts -Recurse -Filter metricshub.exe | Select-Object -First 1
Write-Host "Found metricshub.exe at $($exe_path.FullName)"
& $exe_path.FullName localhost -t win --wmi --connectors Windows
- name: List downloaded files
shell: pwsh
run: Get-ChildItem -Path artifacts