Right now, if you want to track the evolution of some metrics for your project
over time, you need an external tool to store those metrics. But these metrics
could be stored withing the git repository. Git provides a mechanism of notes
that git-metrics simplifies.
cargo install --git https://github.com/jdrouet/git-metrics# fetch the remote metrics
$ git metrics pull
# add a new metric
$ git metrics add binary-size \
--tag "platform.os: linux" \
--tag "platform.arch: amd64" \
1024.0
# push the metrics to remote
$ git metrics push
# log all the metrics for the past commits
$ git metrics log --filter-empty
# display the metrics on current commit
$ git metrics show
binary-size{platform.os="linux", platform.arch="amd64"} 1024.0
# display the metrics difference between commits
$ git metrics diff HEAD~2..HEAD
- binary-size{platform.os="linux", platform.arch="amd64"} 512.0
+ binary-size{platform.os="linux", platform.arch="amd64"} 1024.0 (+200.00 %)
# check the metrics against the defined rules
$ git metrics check --show-success-rules --show-skipped-rules HEAD~2..HEAD
[SUCCESS] binary-size{platform.os="linux", platform.arch="amd64"} 3.44 MiB => 3.53 MiB Δ +96.01 kiB (+2.72 %)
increase should be less than 10.00 % ... check
should be lower than 10.00 MiB ... check
[SUCCESS] binary-size{platform.os="linux", platform.arch="aarch64"} 3.14 MiB => 3.14 MiB
increase should be less than 10.00 % ... check
should be lower than 10.00 MiB ... checkWith git-metrics, using the GitHub actions, you can even add a check to every pull request that opens on your project.
name: monitoring metrics
on:
pull_request:
branches:
- main
push:
branches:
- main
# this is required to be able to post the result of the check command
# in a comment of the pull request
permissions:
pull-requests: write
jobs:
building:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
# this is needed for reporting metrics
fetch-depth: 0
# set the git identity to be able to save and push the metrics
- uses: jdrouet/action-git-identity@main
- uses: jdrouet/action-git-metrics@install
- uses: jdrouet/action-git-metrics@execute
with:
pull: 'true'
# set that to true when not a pull request
push: ${{ github.event_name != 'pull_request' }}
script: |
add binary-size --tag "platform: linux" 1024
# add a comment message to your pull request reporting the evolution
- uses: jdrouet/action-git-metrics@check
if: ${{ github.event_name == 'pull_request' }}- GitHub action to install
git-metrics: https://github.com/jdrouet/action-git-metrics/tree/install - GitHub action to execute
git-metrics: https://github.com/jdrouet/action-git-metrics/tree/execute - GitHub action to report
git-metricschecks: https://github.com/jdrouet/action-git-metrics/tree/check - GitHub action to report
git-metricsdiff: https://github.com/jdrouet/action-git-metrics/tree/diff
-
git-metrics showdisplays the metrics to the current commit -
git-metrics addadds a metric to the current commit -
git-metrics removeremoves a metric from the current commit -
git-metrics fetchfetches the metrics -
git-metrics pushpushes the metrics -
git-metrics logdisplays the metrics for the last commits -
git-metrics diffcomputes the diff of the metrics between 2 commits -
git-metrics checkcompares the metrics against the defined budget -
git-metrics pagegenerates a web page with charts for every metrics -
git-metrics importto add metrics based on some apps output- from lcov file
