You've already forked dynamic-badges-action
Compare commits
29 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a6775a6487 | ||
|
|
7ce4e745e5 | ||
|
|
a3f7e7f029 | ||
|
|
6511e529e9 | ||
|
|
e43bdee88e | ||
|
|
3dd7c22d76 | ||
|
|
ee320739c6 | ||
|
|
9bce11bffe | ||
|
|
53c821a382 | ||
|
|
6363528813 | ||
|
|
f3547450fa | ||
|
|
6d79bf4c0a | ||
|
|
b718050283 | ||
|
|
0ba52741d3 | ||
|
|
a690d6b4cb | ||
|
|
517bd6931a | ||
|
|
3bcfbf7edc | ||
|
|
8da8f7816f | ||
|
|
65787a717d | ||
|
|
cfd1eebb35 | ||
|
|
42207bfa4c | ||
|
|
4c1242cfa4 | ||
|
|
7788d4f27b | ||
|
|
a298000e06 | ||
|
|
5ba090896c | ||
|
|
2f15321252 | ||
|
|
a96c4be21f | ||
|
|
fe55f62a4b | ||
|
|
9ee069bab8 |
10
.github/workflows/badges.yml
vendored
10
.github/workflows/badges.yml
vendored
@@ -8,14 +8,16 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Get the Numbers
|
- name: Get the Numbers
|
||||||
run: echo "::set-env name=ANSWER::42"
|
run: echo "ANSWER=42" >> $GITHUB_ENV
|
||||||
- name: Create the Badge
|
- name: Create the Badge
|
||||||
uses: schneegans/dynamic-badges-action@master
|
uses: schneegans/dynamic-badges-action@master
|
||||||
with:
|
with:
|
||||||
auth: ${{ secrets.GIST_SECRET }}
|
auth: ${{ secrets.GIST_SECRET }}
|
||||||
gistID: 2ab8f1d386f13aaebccbd87dac94068d
|
gistID: 2ab8f1d386f13aaebccbd87dac94068d
|
||||||
filename: answer.json
|
filename: answer.json
|
||||||
label: The Answer is
|
label: The Answer
|
||||||
message: ${{ env.ANSWER }}
|
message: is ${{ env.ANSWER }}
|
||||||
color: green
|
valColorRange: ${{ env.ANSWER }}
|
||||||
|
maxColorRange: 100
|
||||||
|
minColorRange: 0
|
||||||
|
|
||||||
|
|||||||
73
README.md
73
README.md
@@ -8,7 +8,7 @@ This action allows you to create badges for your README.md with [shields.io](htt
|
|||||||
|
|
||||||
This action supports all [configuration options of shields.io/endpoint](https://shields.io/endpoint) and can be used in various ways:
|
This action supports all [configuration options of shields.io/endpoint](https://shields.io/endpoint) and can be used in various ways:
|
||||||
* Show custom CI statistics from GitHub actions, such as code coverage or detailed test results.
|
* Show custom CI statistics from GitHub actions, such as code coverage or detailed test results.
|
||||||
* Show metadata of your repository such as lines of code, comment line percentage, ...
|
* Show metadata of your repository such as [lines of code, comment line percentage](https://schneegans.github.io/tutorials/2020/08/16/badges), ...
|
||||||
* Basically anything which may change from commit to commit!
|
* Basically anything which may change from commit to commit!
|
||||||
|
|
||||||
## How Does It Work?
|
## How Does It Work?
|
||||||
@@ -33,13 +33,13 @@ https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/schneegan
|
|||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
1. Head over to [gist.github.com](https://gist.github.com/) and create a new gist. You will need the ID of the gist (this is the long alphanumerical part of its URL) later.
|
1. Head over to [gist.github.com](https://gist.github.com/) and create a new gist. You can name the file `test.json`, but this can be changed later as well. You will need the ID of the gist (this is the long alphanumerical part of its URL) later.
|
||||||
2. Navigate to [github.com/settings/tokens](https://github.com/settings/tokens) and create a new token with the *gist* scope.
|
2. Navigate to [github.com/settings/tokens](https://github.com/settings/tokens) and create a new token with the *gist* scope.
|
||||||
3. Go to the *Secrets* page of the settings of your repository and add this token as a new secret. You can give it any name, for example `GIST_SECRET`.
|
3. Go to the *Secrets* page of the settings of your repository and add this token as a new secret. You can give it any name, for example `GIST_SECRET`.
|
||||||
4. Add something like the following to your workflow:
|
4. Add something like the following to your workflow:
|
||||||
```yml
|
```yml
|
||||||
- name: Create Awesome Badge
|
- name: Create Awesome Badge
|
||||||
uses: schneegans/dynamic-badges-action@v1.0.0
|
uses: schneegans/dynamic-badges-action@v1.2.0
|
||||||
with:
|
with:
|
||||||
auth: ${{ secrets.GIST_SECRET }}
|
auth: ${{ secrets.GIST_SECRET }}
|
||||||
gistID: <gist-ID>
|
gistID: <gist-ID>
|
||||||
@@ -49,7 +49,7 @@ https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/schneegan
|
|||||||
color: orange
|
color: orange
|
||||||
```
|
```
|
||||||
|
|
||||||
Once the action is executed, got to your gist.
|
Once the action is executed, go to your gist.
|
||||||
There should be a new file called `test.json`.
|
There should be a new file called `test.json`.
|
||||||
You can view the raw content of this file at `https://gist.githubusercontent.com/<user>/<gist-ID>/raw/test.json`.
|
You can view the raw content of this file at `https://gist.githubusercontent.com/<user>/<gist-ID>/raw/test.json`.
|
||||||
Embed the badge with:
|
Embed the badge with:
|
||||||
@@ -58,20 +58,26 @@ Embed the badge with:
|
|||||||

|

|
||||||
```
|
```
|
||||||
|
|
||||||
### Input Parameters
|
### Required Input Parameters
|
||||||
|
|
||||||
The **Badge Parameters** are directly passed to [shields.io](https://shields.io). See the [official documentation](https://shields.io/endpoint) for more detailed explanations.
|
Parameter | Description
|
||||||
|
----------|------------
|
||||||
Gist Parameter | Description
|
`auth` | A secret token with the *gist* scope.
|
||||||
|
`gistID` | The ID of the target gist. Something like `8f6459c2417de7534f64d98360dde866`.
|
||||||
|
`filename` | The target filename - each gist may contain several files. This should have the `.json` extension.
|
||||||
|
|
||||||
|
|
||||||
|
### Shields.io Parameters (optional)
|
||||||
|
|
||||||
|
All these parameters are optional.
|
||||||
|
They are directly passed to [shields.io](https://shields.io). See the [official documentation](https://shields.io/endpoint) for more detailed explanations.
|
||||||
|
|
||||||
|
Parameter | Description
|
||||||
----------|------------
|
----------|------------
|
||||||
`auth` | Required. A secret token with the *gist* scope.
|
|
||||||
`gistID` | Required. The ID of the target gist. Something like `8f6459c2417de7534f64d98360dde866`.
|
|
||||||
`filename` | Required. The target filename - each gist may contain several files. This should have the `.json` extension.
|
|
||||||
**Badge Parameter** | **Description**
|
|
||||||
`label` | Required. The left text of the badge.
|
`label` | Required. The left text of the badge.
|
||||||
`message` | Required. The right text of the badge.
|
`message` | Required. The right text of the badge.
|
||||||
`labelColor` | The left color of the badge.
|
`labelColor` | The left color of the badge.
|
||||||
`color` | The right color of the badge.
|
`color` | The right color of the badge. For custom colors wrap color string in quotes `"#bf155b"`. This parameter is ignored if the `valColorRange`, `maxColorRange`, and `minColorRange` are set.
|
||||||
`isError` | The color will be red and cannot be overridden.
|
`isError` | The color will be red and cannot be overridden.
|
||||||
`namedLogo` | A logo name from [simpleicons.org](http://simpleicons.org/).
|
`namedLogo` | A logo name from [simpleicons.org](http://simpleicons.org/).
|
||||||
`logoSvg` | An svg-string to be used as logo.
|
`logoSvg` | An svg-string to be used as logo.
|
||||||
@@ -81,25 +87,46 @@ Gist Parameter | Description
|
|||||||
`style` | The style like "flat" or "social".
|
`style` | The style like "flat" or "social".
|
||||||
`cacheSeconds` | The cache lifetime in seconds (must be greater than 300).
|
`cacheSeconds` | The cache lifetime in seconds (must be greater than 300).
|
||||||
|
|
||||||
|
### Color Range Parameters (optional)
|
||||||
|
|
||||||
|
Starting with version 1.3.0 of this action, the color of the right side of the badge can be computed automatically on a green-to-red color-scale.
|
||||||
|
For this, the following parameters can be used.
|
||||||
|
|
||||||
|
Parameter | Description
|
||||||
|
----------|------------
|
||||||
|
`valColorRange` | A numerical value used to define the message color. Usually this should be between `maxColorRange` and `minColorRange`. This is required if you want to use the color range feature.
|
||||||
|
`maxColorRange` | If `valColorRange` assumes this value, the badge will be green. This is required if you want to use the color range feature.
|
||||||
|
`minColorRange` | If `valColorRange` assumes this value, the badge will be red. This is required if you want to use the color range feature.
|
||||||
|
`invertColorRange` | If the range should be inverted, causing a smaller value to have green color. Defaults to `false`.
|
||||||
|
`colorRangeSaturation` | Saturation used by the color range feature. Defaults to 100.
|
||||||
|
`colorRangeLightness` | Lightness used by the color range feature. Defaults to 40.
|
||||||
|
|
||||||
|
|
||||||
### Using Environment Variables as Parameters [](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/schneegans/2ab8f1d386f13aaebccbd87dac94068d/raw/answer.json)
|
### Using Environment Variables as Parameters [](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/schneegans/2ab8f1d386f13aaebccbd87dac94068d/raw/answer.json)
|
||||||
|
|
||||||
A common usage pattern of this action is to create environment variables in previous steps of a job and later use them as message in your badge. This can be achieved like this:
|
A common usage pattern of this action is to create environment variables in previous steps of a job and later use them as message in your badge.
|
||||||
|
How this can be done, is shown in the following example.
|
||||||
|
|
||||||
|
This example also shows how to use the automatic color range feature: If the answer is <= 0, the badge will be red, if it's >= 100 it will be green.
|
||||||
|
For all values in between, the color will be interpolated.
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
- name: Get the Numbers
|
- name: Get the Numbers
|
||||||
run: echo "::set-env name=ANSWER::42"
|
run: echo "ANSWER=42" >> $GITHUB_ENV
|
||||||
- name: Create the Badge
|
- name: Create the Badge
|
||||||
uses: schneegans/dynamic-badges-action@v1.0.0
|
uses: schneegans/dynamic-badges-action@v1.2.0
|
||||||
with:
|
with:
|
||||||
auth: ${{ secrets.GIST_SECRET }}
|
auth: ${{ secrets.GIST_SECRET }}
|
||||||
gistID: <gist-ID>
|
gistID: <gist-ID>
|
||||||
filename: answer.json
|
filename: answer.json
|
||||||
label: The Answer is
|
label: The Answer
|
||||||
message: ${{ env.ANSWER }}
|
message: is ${{ env.ANSWER }}
|
||||||
color: green
|
valColorRange: ${{ env.ANSWER }}
|
||||||
|
maxColorRange: 100
|
||||||
|
minColorRange: 0
|
||||||
```
|
```
|
||||||
|
|
||||||
# Contributing to Dynamic Badges Action
|
## Contributing to Dynamic Badges Action
|
||||||
|
|
||||||
Whenever you encounter a :beetle: **bug** or have :tada: **feature request**,
|
Whenever you encounter a :beetle: **bug** or have :tada: **feature request**,
|
||||||
report this via [Github issues](https://github.com/schneegans/dynamic-badges-action/issues).
|
report this via [Github issues](https://github.com/schneegans/dynamic-badges-action/issues).
|
||||||
@@ -107,7 +134,7 @@ report this via [Github issues](https://github.com/schneegans/dynamic-badges-act
|
|||||||
We are happy to receive contributions in the form of **pull requests** via Github.
|
We are happy to receive contributions in the form of **pull requests** via Github.
|
||||||
Feel free to fork the repository, implement your changes and create a merge request to the `master` branch.
|
Feel free to fork the repository, implement your changes and create a merge request to the `master` branch.
|
||||||
|
|
||||||
## Git Commit Messages
|
### Git Commit Messages
|
||||||
|
|
||||||
Commits should start with a Capital letter and should be written in present tense (e.g. __:tada: Add cool new feature__ instead of __:tada: Added cool new feature__).
|
Commits should start with a Capital letter and should be written in present tense (e.g. __:tada: Add cool new feature__ instead of __:tada: Added cool new feature__).
|
||||||
You should also start your commit message with **one** applicable emoji. This does not only look great but also makes you rethink what to add to a commit. Make many but small commits!
|
You should also start your commit message with **one** applicable emoji. This does not only look great but also makes you rethink what to add to a commit. Make many but small commits!
|
||||||
@@ -126,11 +153,11 @@ Emoji | Description
|
|||||||
:fire: `:fire:` | When you removed something.
|
:fire: `:fire:` | When you removed something.
|
||||||
:truck: `:truck:` | When you moved / renamed something.
|
:truck: `:truck:` | When you moved / renamed something.
|
||||||
|
|
||||||
## Version Numbers
|
### Version Numbers
|
||||||
|
|
||||||
Version numbers will be assigned according to the [Semantic Versioning](https://semver.org/) scheme.
|
Version numbers will be assigned according to the [Semantic Versioning](https://semver.org/) scheme.
|
||||||
This means, given a version number MAJOR.MINOR.PATCH, we will increment the:
|
This means, given a version number MAJOR.MINOR.PATCH, we will increment the:
|
||||||
|
|
||||||
1. MAJOR version when we make incompatible API changes,
|
1. MAJOR version when we make incompatible API changes,
|
||||||
2. MINOR version when we add functionality in a backwards compatible manner, and
|
2. MINOR version when we add functionality in a backwards compatible manner, and
|
||||||
3. PATCH version when we make backwards compatible bug fixes.
|
3. PATCH version when we make backwards compatible bug fixes.
|
||||||
|
|||||||
18
action.yml
18
action.yml
@@ -49,6 +49,24 @@ inputs:
|
|||||||
cacheSeconds:
|
cacheSeconds:
|
||||||
description: 'The cache lifetime in seconds (must be greater than 300)'
|
description: 'The cache lifetime in seconds (must be greater than 300)'
|
||||||
required: false
|
required: false
|
||||||
|
valColorRange:
|
||||||
|
description: 'A numerical value used to define the message color. Usually this should be between maxColorRange and minColorRange. This is required if you want to use the color range feature.'
|
||||||
|
required: false
|
||||||
|
maxColorRange:
|
||||||
|
description: 'If valColorRange assumes this value, the badge will be green. This is required if you want to use the color range feature.'
|
||||||
|
required: false
|
||||||
|
minColorRange:
|
||||||
|
description: 'If valColorRange assumes this value, the badge will be red. This is required if you want to use the color range feature.'
|
||||||
|
required: false
|
||||||
|
invertColorRange:
|
||||||
|
description: 'If the range should be inverted, causing a smaller value to have green color. Defaults to false.'
|
||||||
|
required: false
|
||||||
|
colorRangeSaturation:
|
||||||
|
description: 'Saturation used by the color range feature. Defaults to 100.'
|
||||||
|
required: false
|
||||||
|
colorRangeLightness:
|
||||||
|
description: 'Lightness used by the color range feature. Defaults to 40.'
|
||||||
|
required: false
|
||||||
runs:
|
runs:
|
||||||
using: 'node12'
|
using: 'node12'
|
||||||
main: 'index.js'
|
main: 'index.js'
|
||||||
|
|||||||
38
changelog.md
Normal file
38
changelog.md
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
# Changelog of the Dynamic Badges Action
|
||||||
|
|
||||||
|
## [Dynamic Badges Action 1.3.0](https://github.com/Schneegans/dynamic-badges-action/tree/v1.3.0)
|
||||||
|
|
||||||
|
**Release Date:** 2022-04-18
|
||||||
|
|
||||||
|
#### Changes
|
||||||
|
|
||||||
|
* Added the possibility to generate the badge color automatically between red and green based on a numerical value and its bounds. Thanks to [@LucasWolfgang](https://github.com/LucasWolfgang) for this contribution!
|
||||||
|
|
||||||
|
## [Dynamic Badges Action 1.2.0](https://github.com/Schneegans/dynamic-badges-action/tree/v1.2.0)
|
||||||
|
|
||||||
|
**Release Date:** 2022-03-26
|
||||||
|
|
||||||
|
#### Changes
|
||||||
|
|
||||||
|
* The action does not log the response of writing the Gist anymore.
|
||||||
|
* Added this changelog.
|
||||||
|
|
||||||
|
|
||||||
|
## [Dynamic Badges Action 1.1.0](https://github.com/Schneegans/dynamic-badges-action/tree/v1.1.0)
|
||||||
|
|
||||||
|
**Release Date:** 2021-06-16
|
||||||
|
|
||||||
|
#### Changes
|
||||||
|
|
||||||
|
* The action now logs an error message when writing the Gist failed.
|
||||||
|
* Used new API for setting environment variables in the README.md examples.
|
||||||
|
|
||||||
|
|
||||||
|
## [Dynamic Badges Action 1.0.0](https://github.com/Schneegans/dynamic-badges-action/tree/v1.0.0)
|
||||||
|
|
||||||
|
**Release Date:** 2020-08-16
|
||||||
|
|
||||||
|
#### Changes
|
||||||
|
|
||||||
|
* Initial publication on GitHub.
|
||||||
|
|
||||||
58
index.js
58
index.js
@@ -13,9 +13,49 @@ try {
|
|||||||
message: core.getInput('message')
|
message: core.getInput('message')
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Compute the message color based on the given inputs.
|
||||||
|
const color = core.getInput('color');
|
||||||
|
const valColorRange = core.getInput('valColorRange');
|
||||||
|
const minColorRange = core.getInput('minColorRange');
|
||||||
|
const maxColorRange = core.getInput('maxColorRange');
|
||||||
|
const invertColorRange = core.getInput('invertColorRange');
|
||||||
|
const colorRangeSaturation = core.getInput('colorRangeSaturation');
|
||||||
|
const colorRangeLightness = core.getInput('colorRangeLightness');
|
||||||
|
|
||||||
|
if (minColorRange != '' && maxColorRange != '' && valColorRange != '') {
|
||||||
|
const max = parseFloat(maxColorRange);
|
||||||
|
const min = parseFloat(minColorRange);
|
||||||
|
const val = parseFloat(valColorRange);
|
||||||
|
|
||||||
|
if (val < min) val = min;
|
||||||
|
if (val > max) val = max;
|
||||||
|
|
||||||
|
let hue = 0;
|
||||||
|
if (invertColorRange == '') {
|
||||||
|
hue = Math.floor((val - min) / (max - min) * 120);
|
||||||
|
} else {
|
||||||
|
hue = Math.floor((max - val) / (max - min) * 120);
|
||||||
|
}
|
||||||
|
|
||||||
|
let sat = 100;
|
||||||
|
if (colorRangeSaturation != '') {
|
||||||
|
sat = parseFloat(colorRangeSaturation);
|
||||||
|
}
|
||||||
|
|
||||||
|
let lig = 40;
|
||||||
|
if (colorRangeLightness != '') {
|
||||||
|
lig = parseFloat(colorRangeLightness);
|
||||||
|
}
|
||||||
|
|
||||||
|
content.color = 'hsl(' + hue + ', ' + sat + '%, ' + lig + '%)';
|
||||||
|
|
||||||
|
} else if (color != '') {
|
||||||
|
|
||||||
|
content.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
// Get all optional attributes and add them to the content object if given.
|
// Get all optional attributes and add them to the content object if given.
|
||||||
const labelColor = core.getInput('labelColor');
|
const labelColor = core.getInput('labelColor');
|
||||||
const color = core.getInput('color');
|
|
||||||
const isError = core.getInput('isError');
|
const isError = core.getInput('isError');
|
||||||
const namedLogo = core.getInput('namedLogo');
|
const namedLogo = core.getInput('namedLogo');
|
||||||
const logoSvg = core.getInput('logoSvg');
|
const logoSvg = core.getInput('logoSvg');
|
||||||
@@ -29,10 +69,6 @@ try {
|
|||||||
content.labelColor = labelColor;
|
content.labelColor = labelColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (color != '') {
|
|
||||||
content.color = color;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isError != '') {
|
if (isError != '') {
|
||||||
content.isError = isError;
|
content.isError = isError;
|
||||||
}
|
}
|
||||||
@@ -86,9 +122,13 @@ try {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
res => {
|
res => {
|
||||||
let body = '';
|
if (res.statusCode < 200 || res.statusCode >= 400) {
|
||||||
res.on('data', data => body += data);
|
core.setFailed(
|
||||||
res.on('end', () => console.log('result:' + body));
|
'Failed to create gist, response status code: ' + res.statusCode +
|
||||||
|
', status message: ' + res.statusMessage);
|
||||||
|
} else {
|
||||||
|
console.log('Success!');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
req.write(request);
|
req.write(request);
|
||||||
@@ -96,4 +136,4 @@ try {
|
|||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed(error);
|
core.setFailed(error);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user