This repository was archived by the owner on Apr 17, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
156 lines (128 loc) · 4.52 KB
/
get-telemetry-data.yaml
File metadata and controls
156 lines (128 loc) · 4.52 KB
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
name: Get Telemetry Data
on:
workflow_dispatch:
schedule:
- cron: "0 22 * * 0" # Weekly on Sunday 22:00 UTC
permissions:
contents: write
jobs:
fetch-telemetry:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Restore Telemetry Cache
id: cache-restore
uses: actions/cache/restore@v4
with:
path: ${{ runner.temp }}/telemetry_cache
key: telemetry-${{ github.ref_name }}
restore-keys: |
telemetry-${{ github.ref_name }}-
telemetry-
- name: Fetch and validate remote Telemetry JSON
id: fetch-validate
run: |
set -euo pipefail
JSON_FILE="chart_data_raw.json"
CACHE_DIR="${{ runner.temp }}/telemetry_cache"
HASH_FILE="$CACHE_DIR/hash.txt"
mkdir -p "$CACHE_DIR"
echo "Fetching JSON..."
curl -sSL --fail https://www.freecad.org/chart_data.json -o "$JSON_FILE"
if [ ! -s "$JSON_FILE" ]; then
echo "❌ $JSON_FILE missing or empty"
exit 1
fi
NEW_HASH=$(sha256sum "$JSON_FILE" | awk '{print $1}')
echo "New hash: $NEW_HASH"
if [ -f "$HASH_FILE" ] && [ "$(cat "$HASH_FILE")" = "$NEW_HASH" ]; then
echo "No change detected."
echo "changed=false" >> "$GITHUB_OUTPUT"
else
echo "$NEW_HASH" > "$HASH_FILE"
echo "Change detected."
echo "changed=true" >> "$GITHUB_OUTPUT"
fi
if ! jq empty "$JSON_FILE"; then
echo "❌ Invalid $JSON_FILE format"
exit 1
fi
echo "✅ $JSON_FILE is valid and non-empty"
- name: Extract most common totalUsers
if: steps.fetch-validate.outputs.changed == 'true'
id: extract_total
run: |
set -euo pipefail
TOTAL_USERS=$(jq -r '
to_entries
| map(select(.value.totalUsers != null) | .value.totalUsers)
| sort
| group_by(.)
| last | .[0] // "No totalUsers found"
' chart_data_raw.json)
echo "totalUsers=$TOTAL_USERS"
echo "totalUsers=$TOTAL_USERS" >> "$GITHUB_OUTPUT"
- name: Log invalid keys
if: steps.fetch-validate.outputs.changed == 'true'
run: |
set -euo pipefail
INVALID=$(jq -r '
to_entries
| map(select(.key != "totalUsers"))
| map(select(
(.value.labels == null)
or (.value.data == null)
or ((.value.labels | length) != (.value.data | length))
))
| .[].key
' chart_data_raw.json)
if [[ -n "$INVALID" ]]; then
echo "⚠️ Invalid keys (due to missing or mismatched labels/data):"
echo "$INVALID"
else
echo "✅ No invalid keys found."
fi
- name: Clean and transform Telemetry JSON
if: steps.fetch-validate.outputs.changed == 'true'
run: |
set -euo pipefail
mkdir -p data
jq --argjson totalUsers "${{ steps.extract_total.outputs.totalUsers }}" '
with_entries(
if (.value.labels and .value.data) then
. as {key: $k, value: $v} |
{
key: $k,
value: (
[range(0; ($v.labels | length))]
| map({ ("\($v.labels[.])"): $v.data[.] })
| add
)
}
else
.
end
)
| . + { totalUsers: $totalUsers }
' chart_data_raw.json > data/telemetry_data.json
- name: Commit and push cleaned Telemetry Data
if: steps.fetch-validate.outputs.changed == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add data/telemetry_data.json
if git diff --cached --quiet; then
echo "No changes to commit."
exit 0
fi
DATE=$(date -u +"%Y-%m-%d")
git commit -m "Action: Update Telemetry Data - $DATE"
git push
- name: Save Telemetry Cache
id: cache-save
if: steps.fetch-validate.outputs.changed == 'true'
uses: actions/cache/save@v4
with:
path: ${{ runner.temp }}/telemetry_cache
key: telemetry-${{ github.ref_name }}