-
-
Notifications
You must be signed in to change notification settings - Fork 405
[skip changelog] Gather downloads stats from GitHub releases #665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9009b87
add stats script
42b9d31
send metrics
0474f0d
add failure event and comments
e651897
confusing languages
104f2f0
testing failures
8feff8f
revert, failures reporting works ok
5a71dd3
rename file, remove test clause
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
name: download-stats | ||
|
||
on: | ||
push: | ||
branches: | ||
- massi/stats | ||
schedule: | ||
# run every 5 minutes | ||
- cron: '*/5 * * * *' | ||
|
||
jobs: | ||
push-stats: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Fetch downloads count | ||
id: fetch | ||
uses: actions/github-script@0.2.0 | ||
with: | ||
github-token: ${{github.token}} | ||
script: | | ||
let metrics = [] | ||
|
||
// Get a list of releases | ||
const opts = github.repos.listReleases.endpoint.merge({ | ||
...context.repo | ||
}) | ||
const releases = await github.paginate(opts) | ||
|
||
// Get download stats for every release | ||
for (const rel of releases) { | ||
// Names for assets are like `arduino-cli_0.4.0_Linux_32bit.tar.gz`, | ||
// we'll use this later to split the asset file name more easily | ||
const baseName = `arduino-cli_${rel.name}_` | ||
|
||
// Get a list of assets for this release | ||
const opts = github.repos.listAssetsForRelease.endpoint.merge({ | ||
...context.repo, | ||
release_id: rel.id | ||
}) | ||
const assets = await github.paginate(opts) | ||
|
||
for (const asset of assets) { | ||
// Ignore files that are not arduino-cli packages | ||
if (!asset.name.startsWith(baseName)) { | ||
continue | ||
} | ||
|
||
// Strip the base and remove file extension to get `Linux_32bit` | ||
systemArch = asset.name.replace(baseName, "").split(".")[0].split("_") | ||
|
||
// Add a metric object to the list of gathered metrics | ||
metrics.push({ | ||
"type": "gauge", | ||
"name": "arduino.downloads.total", | ||
"value": asset.download_count, | ||
"host": "${{ github.repository }}", | ||
"tags": [ | ||
`version:${rel.name}`, | ||
`os:${systemArch[0]}`, | ||
`arch:${systemArch[1]}`, | ||
"cdn:github.com", | ||
"project:arduino-cli" | ||
] | ||
}) | ||
} | ||
} | ||
|
||
// The action will put whatever we return from this function in | ||
// `outputs.result`, JSON encoded. So we just return the array | ||
// of objects and GitHub will do the rest. | ||
return metrics | ||
|
||
- name: Send metrics | ||
uses: masci/datadog@v1 | ||
with: | ||
api-key: ${{ secrets.DD_API_KEY }} | ||
# Metrics input expects YAML but JSON will work just right. | ||
metrics: ${{steps.fetch.outputs.result}} | ||
|
||
- name: Report failure | ||
if: failure() | ||
uses: masci/datadog@v1 | ||
with: | ||
api-key: ${{ secrets.DD_API_KEY }} | ||
events: | | ||
- title: "Arduino CLI stats failing" | ||
text: "Stats collection failed" | ||
alert_type: "error" | ||
host: ${{ github.repository }} | ||
tags: | ||
- "project:arduino-cli" | ||
- "cdn:github.com" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for testing, I'll remove it before merging