生成可以嵌入到任何地方的指标,包括你的 GitHub 个人资料自述文件!它适用于用户和组织帐户,甚至适用于存储库!
⚠️ 这是v3.17 -beta(@master分支)的文档,其中包含未发布的功能,请在此处查看v3.16(@latest分支)的文档。
对于用户帐户 | 对于组织帐户 |
---|---|
你可以使用插件、模板和数百个选项对这些进行大量自定义!
|
|
---|---|
查看文档 |
为了获得功能齐全的体验,你应该将指标用作GitHub 操作,但你现在也可以使用你的 GitHub 用户名在metrics.lecoq.io上尝试!
选择
📊 Metrics embed是否要自定义 GitHub 配置文件并
✨ Metrics insights快速概览 GitHub 统计信息:
Embed metrics images on your profile readme or blog! Use GitHub actions for even more features! |
Share your metrics with friends and on social medias! No configuration needed! |
Setup a GitHub Action which runs periodically and pushes your generated metrics image to your repository. See all supported options in action.yml.
Assuming your username is
my-github-user, you can then embed rendered metrics in your readme like below:
<!-- If you're using "master" as default branch -->
![Metrics](https://github.com/my-github-user/my-github-user/blob/master/github-metrics.svg)
<!-- If you're using "main" as default branch -->
![Metrics](https://github.com/my-github-user/my-github-user/blob/main/github-metrics.svg)
Create a repository with the same name as your GitHub login (if it's not already done).
Its
README.mdwill be displayed on your user profile:
From the
Developer settingsof your account settings, select
Personal access tokensto create a new token.
No additional scopes are needed for basic metrics, but you may have to grant additional scope depending on what features you're planning to use:
public_reposcope for some plugins
read:orgscope for all organizations related metrics
reposcope for all private repositories related metrics
read:userscope may also be required for some private repositories related metrics
A scope-less token can still display private contributions by enabling
Include private contributions on my profilein your account settings:
If a plugin has not enough scopes to operate (and
plugins_errors_fatalisn't enabled), it'll be reported in the rendering like below:
Go to the
Settingsof your repository to create a new secret and paste your freshly generated GitHub token there.
Create a new workflow from the
Actionstab of your repository and paste the following:
name: Metrics
on:
# Schedule updates (each hour)
schedule: [{cron: "0 * * * *"}]
# Lines below let you run workflow manually and on each commit (optional)
workflow_dispatch:
push: {branches: ["master", "main"]}
jobs:
github-metrics:
runs-on: ubuntu-latest
steps:
# See action.yml for all options
- uses: lowlighter/metrics@latest
with:
# Your GitHub token
token: ${{ secrets.METRICS_TOKEN }}
See all supported options in action.yml.
Rendered metrics will be committed to your repository on each run.
@latest,
@masteror a fork
If you wish to use new features as they're being released, you can switch from
@latestto
@master. As the latter is used as a development branch, jobs may fail from time to time (although we try to mitigate this).
For convenience, it is possible to use
@maininstead of
@master.
When using a token with additional permissions, it is advised to fork this repository and use it instead to minimize security risks:
- uses: my-github-username/metrics@master
# If you make changes on your fork, be sure not leave @latest as tag!
In this case, please consider watching new releases to stay up-to-date and enjoy latest features!
@latestwill be updated on each release. Metrics doesn't introduce breaking changes from an user point of view (i.e. your workflows will always be valid) so you can follow release cycles without worrying.
Metrics displayed on this page are rendered from this workflow so you can check it out for some code examples about plugins usage.
You can also take a look at this user workflow if you want.
Update your README.md to embed your metrics:
<!-- If you're using "master" as default branch -->
![Metrics](https://github.com/my-github-user/my-github-user/blob/master/github-metrics.svg)
<!-- If you're using "main" as default branch -->
![Metrics](https://github.com/my-github-user/my-github-user/blob/main/github-metrics.svg)
<!-- If you're using the "columns" display mode -->
<img src="https://github.com/my-github-user/my-github-user/blob/master/github-metrics.svg" alt="Metrics" width="100%">
For convenience, you can use the shared instance available at metrics.lecoq.io without any additional setup.
![Metrics](https://metrics.lecoq.io/my-github-user)
This is mostly intended for previews, to enjoy all features consider using GitHub Action instead. Availability is not guaranteed.
To ensure service availability, shared instance has a few limitations:
Service is provided free of charge, so please be gentle with it
Setup a metrics instance on your server if you don't want to use GitHub Actions and metrics.lecoq.io. See all supported options in settings.example.json.
Assuming your username is
my-github-user, you can then embed rendered metrics in your readme like below:
![Metrics](https://my-personal-domain.com/my-github-user)
You'll need a server with a recent version NodeJS (see used version in Dockerfile).
From the
Developer settingsof your account settings, select
Personal access tokensto create a new token.
No additional scopes are needed.
Clone repository, install dependencies and copy configuration example to
settings.json:
git clone https://github.com/lowlighter/metrics.git
cd metrics/
npm install --only=prod
cp settings.example.json settings.json
Edit
settings.jsonto configure your instance.
{
//GitHub API token
"token":"GITHUB_TOKEN",
//Other options...
}
See all supported options in settings.example.json.
If you plan to make your web instance public, it is advised to restrict its access thanks to rate limiter and access list.
Once you've finished configuring metrics, start your instance:
npm start
Access your server with provided port in
setting.jsonfrom your browser to ensure everything is working.
Edit your repository readme and add your metrics image from your server domain:
![Metrics](https://my-personal-domain.com/my-github-user)
To ensure that your instance will restart if it reboots or crashes, you should set it up as a service. This is described below for Linux-like systems which support systemd.
Create a new service file
/etc/systemd/system/github_metrics.serviceand paste the following after editing paths inside:
[Unit]
Description=Metrics
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
WorkingDirectory=/path/to/metrics
ExecStart=/usr/bin/node /path/to/metrics/index.mjs
[Install]
WantedBy=multi-user.target
Reload services, enable it, start it and check if it is up and running:
systemctl daemon-reload
systemctl enable github_metrics
systemctl start github_metrics
systemctl status github_metrics
Most of options from action.yml are actually supported by web instance, though syntax is slightly different. All underscores (
_) must be replaced by dots (
.) and
plugin_prefixes must be dropped.
For example, to configure pagespeed plugin you'd use the following:
https://my-personal-domain.com/my-github-user?pagespeed=1&pagespeed.detailed=1&pagespeed.url=https%3A%2F%2Fexample.com
Note that url parameters must be encoded.
As for
basecontent, which is enabled by default, sections are available through "
base.<section>".
For example, to display only
repositoriessection, use:
https://my-personal-domain.com/my-github-user?base=0&base.repositories=1
Template/Plugin | |||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||
|
✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||||||
Mode/Plugin | |||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||
|
注意:markdown 模板实际上可以使用函数渲染任何类型的 SVG 指标embed
模板可让你更改渲染指标的一般外观。有关如何设置它们的更多信息,请参阅它们各自的文档:
插件是提供额外内容并允许你自定义渲染指标的功能。有关如何设置它们的更多信息,请参阅它们各自的文档:
虽然指标主要针对用户帐户,但也可以呈现组织帐户的指标。
设置与用户帐户相同,但你需要添加
read:org范围,无论你是否是目标组织的成员。
你还需要
user使用你的组织名称设置选项。
如果你遇到错误并且你的组织正在使用单点登录,请尝试授权你的个人令牌。
用户帐户支持的大多数插件都可以与组织帐户一起使用,但请注意,组织的渲染指标会消耗更多 API 请求。
要支持私有存储库,请将完整
repo范围添加到你的个人令牌中。
- uses: lowlighter/metrics@latest
with:
# ... other options
token: ${{ secrets.METRICS_TOKEN }} # A personal token from an user account with read:org scope
user: organization-name # Organization name
Metrics 可以轻松定制。Fork 这个存储库,将使用的操作从
lowlighter/metrics@latest你的 fork切换到你的 fork 并开始编码!
有关代码结构的更多信息,请参见ARCHITECTURE.md。
要报告错误,请填写描述它的问题。要建议新功能或请求帮助设置指标,请查看讨论。
如果你想贡献,提交一个pull request。请务必阅读CONTRIBUTING.md以获取更多信息。
MIT License Copyright (c) 2020-present lowlighter
在LICENSE.md 中查看完整许可证