Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
emibcn committed Sep 6, 2020
0 parents commit 2f70f25
Show file tree
Hide file tree
Showing 7 changed files with 874 additions and 0 deletions.
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Badge action

This action generates a SVG badge using GitHub Actions and GitHub Workflow CPU time (no 3rd parties servers). The badge is generated using the NPM package [gradient-badge](https://github.com/bokub/gradient-badge).

## Inputs

### `label`

**Required** The left label of the badge, usually static.

### `label-color`

**Required** Hex or named color for the label. Default: `555`

### `status`

**Required** The right status as the badge, usually based on results.

### `color`

**Required** An array (comma separated) with hex or named colors of the badge value background. More than one creates gradient background. Default: `blue`.

### `style`

**Required** Badge style: flat or classic. Default: `classic`

### `icon`

Use icon.

### `icon-width`

Set this if icon is not square. Default: `13`

### `scale`

Set badge scale. Default: `1`

### `path`

The file path to store the badge image file. Only output to `badge` action output if not defined.

## Outputs

### `badge`

The badge SVG contents.

## Example usage

uses: emibcn/clover-coverage-badges-action@v1
with:
label: 'Test coverage'
status: '53.4%'
color: 'blue,555,daf'
path: '.github/badges/coverage.svg'
46 changes: 46 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# action.yml
name: 'Badge Action'
author: 'emibcn'
description: 'Create a SVG badge using GitHub Actions and GitHub Workflow CPU time (no 3rd parties servers)'
branding:
icon: award
color: blue
inputs:
label:
description: 'The left label of the badge, usually static.'
required: true
label-color:
description: 'Hex or named color for the label'
required: true
default: '555'
status:
description: 'The right status as the badge, usually based on results.'
required: true
color:
description: 'An array (comma separated) with hex or named colors of the badge value background. More than one creates gradient background.'
required: true
default: 'blue'
style:
description: 'Badge style: flat or classic'
required: true
default: 'classic'
icon:
description: 'Use icon'
required: false
icon-width:
description: 'Set this if icon is not square'
required: false
default: 13
scale:
description: 'Set badge scale'
required: true
default: 1
path:
description: 'The file path to store the badge image file. Only output to `badge` action output if undefined.'
required: false
outputs:
badge:
description: 'The badge SVG contents'
runs:
using: 'node12'
main: 'dist/index.js'
1 change: 1 addition & 0 deletions dist/index.js

Large diffs are not rendered by default.

52 changes: 52 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const core = require('@actions/core');
const gradientBadge = require('gradient-badge');
const fs = require('fs');


try {

// Get action inputs
const label = core.getInput('label' );
const labelColor = core.getInput('label-color');
const status = `${core.getInput('status' )}`; // Ensure string
const gradient = core.getInput('color' )
.split(',') // Color gradient as Array
.map( color => color.trim(' ') ) // Clean spaces;
const style = core.getInput('style' );
const icon = core.getInput('icon' );
const iconWidth = core.getInput('icon-width ');
const scale = core.getInput('scale' );
const path = core.getInput('path' );

const inputs = {
label,
labelColor,
status,
gradient,
style,
icon: (icon && icon.length ? icon : null),
iconWidth,
scale,
};

console.log("Generate badge using the given inputs and defaults: ", inputs);

// Generate the badge
const svgString = gradientBadge( inputs );

// Output badge contents to Action output
core.setOutput("badge", svgString);

// If path is defined, save SVG data to that file
if ( path && path.length ) {
console.log(`Write data to file ${path}...`);

// In case an error occurred writing file,
// exception is thrown and success messsage is not printed
fs.writeFileSync(path, svgString);
console.log("Data saved succesfully.");
}

} catch (error) {
core.setFailed(error.message);
}
20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "badge-action",
"version": "1.0.0",
"description": "Create a badge using GitHub Actions and GitHub Workflow CPU time (no 3rd parties servers)",
"main": "index.js",
"repository": "https://github.com/emibcn/badge-action",
"author": "github.com/emibcn",
"license": "GPL-3.0-or-later",
"private": false,
"scripts": {
"pack": "ncc build index.js -m"
},
"dependencies": {
"@actions/core": "^1.2.5",
"gradient-badge": "^1.3.0"
},
"devDependencies": {
"@zeit/ncc": "^0.22.3"
}
}
25 changes: 25 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


"@actions/core@^1.2.5":
version "1.2.5"
resolved "https://registry.yarnpkg.com/@actions/core/-/core-1.2.5.tgz#fa57bf8c07a38191e243beb9ea9d8368c1cb02c8"
integrity sha512-mwpoNjHSWWh0IiALdDEQi3tru124JKn0yVNziIBzTME8QRv7thwoghVuT1jBRjFvdtoHsqD58IRHy1nf86paRg==

"@zeit/ncc@^0.22.3":
version "0.22.3"
resolved "https://registry.yarnpkg.com/@zeit/ncc/-/ncc-0.22.3.tgz#fca6b86b4454ce7a7e1e7e755165ec06457f16cd"
integrity sha512-jnCLpLXWuw/PAiJiVbLjA8WBC0IJQbFeUwF4I9M+23MvIxTxk5pD4Q8byQBSPmHQjz5aBoA7AKAElQxMpjrCLQ==

badgen@^3.2.1:
version "3.2.1"
resolved "https://registry.yarnpkg.com/badgen/-/badgen-3.2.1.tgz#71d09113a091796e74540d0ca8ebc45f89e0f55a"
integrity sha512-XibyDQHM/7l809dJBp1GEvPmHY3BLgO164f6DuHyLP0OTHDm9EAmHjN7hEyiGQATEpn4G3EVGH8x+M4UFfhkHw==

gradient-badge@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/gradient-badge/-/gradient-badge-1.3.0.tgz#ec481fe6c0f315333128065c3d4834f9888f64cd"
integrity sha512-7xkyviql+50//za77UBaq5BdmtyBtjsd3Q+ACx0iByQVmFe1AX6bUZiK3olqWUo95UCIlkDrQYI0VCci4wXp8w==
dependencies:
badgen "^3.2.1"

0 comments on commit 2f70f25

Please sign in to comment.