Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ecb3f52

Browse filesBrowse files
author
Massimiliano Pippi
authored
[skip changelog] Gather downloads stats from GitHub releases (#665)
* add stats script * send metrics * add failure event and comments * confusing languages * testing failures * revert, failures reporting works ok * rename file, remove test clause
1 parent 0c1f41b commit ecb3f52
Copy full SHA for ecb3f52

File tree

Expand file treeCollapse file tree

1 file changed

+90
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+90
-0
lines changed

‎.github/workflows/github-stats.yaml

Copy file name to clipboard
+90Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: download-stats
2+
3+
on:
4+
schedule:
5+
# run every 5 minutes
6+
- cron: '*/5 * * * *'
7+
8+
jobs:
9+
push-stats:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Fetch downloads count
14+
id: fetch
15+
uses: actions/github-script@0.2.0
16+
with:
17+
github-token: ${{github.token}}
18+
script: |
19+
let metrics = []
20+
21+
// Get a list of releases
22+
const opts = github.repos.listReleases.endpoint.merge({
23+
...context.repo
24+
})
25+
const releases = await github.paginate(opts)
26+
27+
// Get download stats for every release
28+
for (const rel of releases) {
29+
// Names for assets are like `arduino-cli_0.4.0_Linux_32bit.tar.gz`,
30+
// we'll use this later to split the asset file name more easily
31+
const baseName = `arduino-cli_${rel.name}_`
32+
33+
// Get a list of assets for this release
34+
const opts = github.repos.listAssetsForRelease.endpoint.merge({
35+
...context.repo,
36+
release_id: rel.id
37+
})
38+
const assets = await github.paginate(opts)
39+
40+
for (const asset of assets) {
41+
// Ignore files that are not arduino-cli packages
42+
if (!asset.name.startsWith(baseName)) {
43+
continue
44+
}
45+
46+
// Strip the base and remove file extension to get `Linux_32bit`
47+
systemArch = asset.name.replace(baseName, "").split(".")[0].split("_")
48+
49+
// Add a metric object to the list of gathered metrics
50+
metrics.push({
51+
"type": "gauge",
52+
"name": "arduino.downloads.total",
53+
"value": asset.download_count,
54+
"host": "${{ github.repository }}",
55+
"tags": [
56+
`version:${rel.name}`,
57+
`os:${systemArch[0]}`,
58+
`arch:${systemArch[1]}`,
59+
"cdn:github.com",
60+
"project:arduino-cli"
61+
]
62+
})
63+
}
64+
}
65+
66+
// The action will put whatever we return from this function in
67+
// `outputs.result`, JSON encoded. So we just return the array
68+
// of objects and GitHub will do the rest.
69+
return metrics
70+
71+
- name: Send metrics
72+
uses: masci/datadog@v1
73+
with:
74+
api-key: ${{ secrets.DD_API_KEY }}
75+
# Metrics input expects YAML but JSON will work just right.
76+
metrics: ${{steps.fetch.outputs.result}}
77+
78+
- name: Report failure
79+
if: failure()
80+
uses: masci/datadog@v1
81+
with:
82+
api-key: ${{ secrets.DD_API_KEY }}
83+
events: |
84+
- title: "Arduino CLI stats failing"
85+
text: "Stats collection failed"
86+
alert_type: "error"
87+
host: ${{ github.repository }}
88+
tags:
89+
- "project:arduino-cli"
90+
- "cdn:github.com"

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.