Skip to content

Commit

Permalink
Move JS logic to the external NPM package https://www.npmjs.com/packa…
Browse files Browse the repository at this point in the history
…ge/github-badge-action , with tests, prettier, eslint, etc
  • Loading branch information
emibcn committed May 22, 2021
1 parent cdf45ad commit 3f67c23
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 60 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# 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).
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) and [Github Badge Action](https://www.npmjs.com/package/github-badge-action) to read and write the GitHub Actions inputs and outputs.

## Inputs

Expand Down Expand Up @@ -83,5 +83,6 @@ And then, [follow the example](https://github.com/emibcn/badge-action/blob/6af28
### Commit the changes to same branch

See a [workflow example](https://github.com/emibcn/badge-action/blob/88b8f35d4c9fbd776e921f3eea831d4fdb8d4387/.github/workflows/test.yml).
Or another [more complex example](https://github.com/emibcn/pywisp/blob/master/.github/workflows/test.yml#L178).

Note: You will need to pull auto-generated commits with this technique, or your repo will mess up.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

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


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);
}
createBadgeFromInputs();
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "badge-action",
"version": "1.0.1",
"version": "1.0.2",
"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",
Expand All @@ -12,8 +12,7 @@
"deploy": "yarn build && yarn pack"
},
"dependencies": {
"@actions/core": "^1.2.7",
"gradient-badge": "^1.3.1"
"github-badge-action": "^0.0.3"
},
"devDependencies": {
"@zeit/ncc": "^0.22.3"
Expand Down
16 changes: 12 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# yarn lockfile v1


"@actions/core@^1.2.7":
version "1.2.7"
resolved "https://registry.yarnpkg.com/@actions/core/-/core-1.2.7.tgz#594f8c45b213f0146e4be7eda8ae5cf4e198e5ab"
integrity sha512-kzLFD5BgEvq6ubcxdgPbRKGD2Qrgya/5j+wh4LZzqT915I0V3rED+MvjH6NXghbvk1MXknpNNQ3uKjXSEN00Ig==
"@actions/core@^1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@actions/core/-/core-1.3.0.tgz#f5e4b24c889e7f2e58b466cc8c7481292284eba0"
integrity sha512-xxtX0Cwdhb8LcgatfJkokqT8KzPvcIbwL9xpLU09nOwBzaStbfm0dNncsP0M4us+EpoPdWy7vbzU5vSOH7K6pg==

"@zeit/ncc@^0.22.3":
version "0.22.3"
Expand All @@ -17,6 +17,14 @@ badgen@^3.2.1:
resolved "https://registry.yarnpkg.com/badgen/-/badgen-3.2.1.tgz#71d09113a091796e74540d0ca8ebc45f89e0f55a"
integrity sha512-XibyDQHM/7l809dJBp1GEvPmHY3BLgO164f6DuHyLP0OTHDm9EAmHjN7hEyiGQATEpn4G3EVGH8x+M4UFfhkHw==

github-badge-action@^0.0.3:
version "0.0.3"
resolved "https://registry.yarnpkg.com/github-badge-action/-/github-badge-action-0.0.3.tgz#ec8ccfcce345f4f5b5a079bd6cb47961811d4ad6"
integrity sha512-DBLOEnwhlXpz0FbpmospB81WHbK7kPOd8hPtI9vnew2dvux1oBACECoCVENu0uQGl5Oa6vSJZLCJLeWA3xL6kA==
dependencies:
"@actions/core" "^1.3.0"
gradient-badge "^1.3.1"

gradient-badge@^1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/gradient-badge/-/gradient-badge-1.3.1.tgz#2564adea865ea6afbfbbcc315b7348eae666d160"
Expand Down

0 comments on commit 3f67c23

Please sign in to comment.