From 40a43b5e9826823a3871de0755af9d5200d90665 Mon Sep 17 00:00:00 2001 From: Tim Ruffles Date: Thu, 19 Dec 2019 14:53:51 +0000 Subject: [PATCH 1/3] Initial version --- Dockerfile | 3 ++ action.js | 60 +++++++++++++++++++++++++++++++++++++ actions.test.js | 2 ++ actions.yml | 11 +++++++ humans.txt.yaml | 2 ++ package-lock.json | 76 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 7 +++++ test.sh | 8 +++++ 8 files changed, 169 insertions(+) create mode 100644 Dockerfile create mode 100644 action.js create mode 100644 actions.test.js create mode 100644 actions.yml create mode 100644 humans.txt.yaml create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 test.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3f2817f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,3 @@ +FROM node:12 + +COPY . . diff --git a/action.js b/action.js new file mode 100644 index 0000000..88e52b9 --- /dev/null +++ b/action.js @@ -0,0 +1,60 @@ +'use strict' + +const fs = require('fs') +const yaml = require('yaml') + +const formatters = { + txt: txtFormatter, + json: jsonFormatter, + shell: (data) => txtFormatter(data, { colors: true}), +} + +main() + +function main() { + const format = process.argv[2] + + const formatter = formatters[format] + if (!formatter) { + invalidFormat(format) + return + } + + const data = yaml.parse(fs.readFileSync("./humans.txt.yaml", {encoding: "utf8"})) + + formatter(data) +} + +function invalidFormat(format) { + const list = Object.keys(formatters).sort().join(",") + console.error(`'${format}' is not one of the accepted formats ${list}`) + process.statusCode = 1 + return +} + +function jsonFormatter({humans}) { + console.log(JSON.stringify(humans, null, 4)) +} + +function txtFormatter({humans}, {colors = false} = {}) { + let active = humans.filter(h => !h.alum).map(h => h.name) + let alum = humans.filter(h => h.alum).map(h => h.name) + + if(colors) { + const chalk = require('chalk') + const total = active.length + alum.length + active = active.map((n, i) => chalk.hsl((i / total) * 360, 100, 50)(n)) + alum = alum.map((n, i) => chalk.hsl(((i + active.length) / total) * 360, 100, 50)(n)) + } + + console.log("Current humans") + console.log("==============\n") + console.log(active.join("\n")) + console.log("\n") + + console.log("Human alumni") + console.log("============\n") + console.log(alum.join("\n")) +} + + diff --git a/actions.test.js b/actions.test.js new file mode 100644 index 0000000..b25c065 --- /dev/null +++ b/actions.test.js @@ -0,0 +1,2 @@ +const assert = require('assert') + diff --git a/actions.yml b/actions.yml new file mode 100644 index 0000000..229990a --- /dev/null +++ b/actions.yml @@ -0,0 +1,11 @@ +name: 'GitHub Actions humans.txt' +description: 'List out the humans who help feed and tend the robots of GitHub Actions' +inputs: + format: + description: 'How to output the people of actions - txt, json or ascii' + default: 'ascii' +runs: + using: 'docker' + image: 'Dockerfile' + args: + - ${{ inputs.format }} diff --git a/humans.txt.yaml b/humans.txt.yaml new file mode 100644 index 0000000..a08ed76 --- /dev/null +++ b/humans.txt.yaml @@ -0,0 +1,2 @@ +humans: + diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..62d2acb --- /dev/null +++ b/package-lock.json @@ -0,0 +1,76 @@ +{ + "requires": true, + "lockfileVersion": 1, + "dependencies": { + "@babel/runtime": { + "version": "7.7.7", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.7.7.tgz", + "integrity": "sha512-uCnC2JEVAu8AKB5do1WRIsvrdJ0flYx/A/9f/6chdacnEZ7LmavjdsDXr5ksYBegxtuTPR5Va9/+13QF/kFkCA==", + "requires": { + "regenerator-runtime": "^0.13.2" + } + }, + "@types/color-name": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz", + "integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==" + }, + "ansi-styles": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.0.tgz", + "integrity": "sha512-7kFQgnEaMdRtwf6uSfUnVr9gSGC7faurn+J/Mv90/W+iTtN0405/nLdopfMWwchyxhbGYl6TC4Sccn9TUkGAgg==", + "requires": { + "@types/color-name": "^1.1.1", + "color-convert": "^2.0.1" + } + }, + "chalk": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", + "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==", + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + }, + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" + }, + "has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==" + }, + "regenerator-runtime": { + "version": "0.13.3", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.3.tgz", + "integrity": "sha512-naKIZz2GQ8JWh///G7L3X6LaQUAMp2lvb1rvwwsURe/VXwD6VMfr+/1NuNw3ag8v2kY1aQ/go5SNn79O9JU7yw==" + }, + "supports-color": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.1.0.tgz", + "integrity": "sha512-oRSIpR8pxT1Wr2FquTNnGet79b3BWljqOuoW/h4oBhxJ/HUbX5nX6JSruTkvXDCFMwDPvsaTTbvMLKZWSy0R5g==", + "requires": { + "has-flag": "^4.0.0" + } + }, + "yaml": { + "version": "1.7.2", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-1.7.2.tgz", + "integrity": "sha512-qXROVp90sb83XtAoqE8bP9RwAkTTZbugRUTm5YeFCBfNRPEp2YzTeqWiz7m5OORHzEvrA/qcGS8hp/E+MMROYw==", + "requires": { + "@babel/runtime": "^7.6.3" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..afa6d5f --- /dev/null +++ b/package.json @@ -0,0 +1,7 @@ +{ + "private": true, + "dependencies": { + "chalk": "3.0.0", + "yaml": "1.7.2" + } +} diff --git a/test.sh b/test.sh new file mode 100644 index 0000000..9eec1de --- /dev/null +++ b/test.sh @@ -0,0 +1,8 @@ +#!bin/bash + +set -xeuo pipefail + +node action.js txt >/tmp/t1 +node action.js json >/tmp/t2 +node action.js shell >/tmp/t3 + From 1454285019484626b65f827417ef0376177d3896 Mon Sep 17 00:00:00 2001 From: Tim Ruffles Date: Thu, 19 Dec 2019 15:05:06 +0000 Subject: [PATCH 2/3] Add dockerfile --- Dockerfile | 4 ++++ action.js | 11 +++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3f2817f..0a29ca3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,7 @@ FROM node:12 COPY . . + +RUN npm i --production + +ENTRYPOINT ["node" , "action.js"] diff --git a/action.js b/action.js index 88e52b9..ce5b66f 100644 --- a/action.js +++ b/action.js @@ -2,6 +2,7 @@ const fs = require('fs') const yaml = require('yaml') +const chalk = require('chalk') const formatters = { txt: txtFormatter, @@ -12,7 +13,7 @@ const formatters = { main() function main() { - const format = process.argv[2] + const format = process.argv[2] || (process.stdout.isTTY ? "shell" : "txt") const formatter = formatters[format] if (!formatter) { @@ -41,10 +42,9 @@ function txtFormatter({humans}, {colors = false} = {}) { let alum = humans.filter(h => h.alum).map(h => h.name) if(colors) { - const chalk = require('chalk') const total = active.length + alum.length - active = active.map((n, i) => chalk.hsl((i / total) * 360, 100, 50)(n)) - alum = alum.map((n, i) => chalk.hsl(((i + active.length) / total) * 360, 100, 50)(n)) + active = mapColorRange(active, 0, total) + alum = mapColorRange(alum, active.length, total) } console.log("Current humans") @@ -57,4 +57,7 @@ function txtFormatter({humans}, {colors = false} = {}) { console.log(alum.join("\n")) } +function mapColorRange(strings, base, total) { + return strings.map((n, i) => chalk.hsl(((i + base) / total) * 360, 100, 50)(n)) +} From 872bad546e56a447ff1be3bac1d9440b1fe8a846 Mon Sep 17 00:00:00 2001 From: Tim Ruffles Date: Thu, 19 Dec 2019 15:43:45 +0000 Subject: [PATCH 3/3] Add CI --- .github/workflows/ci.yml | 13 +++++++++++++ actions.test.js | 2 -- humans.txt.yaml | 2 +- test.sh | 10 ++++++---- 4 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 actions.test.js mode change 100644 => 100755 test.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..42ef490 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,13 @@ +on: + push: + branches: ["**"] + + +jobs: + ci: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: npm install --production + - run: "./test.sh" + diff --git a/actions.test.js b/actions.test.js deleted file mode 100644 index b25c065..0000000 --- a/actions.test.js +++ /dev/null @@ -1,2 +0,0 @@ -const assert = require('assert') - diff --git a/humans.txt.yaml b/humans.txt.yaml index a08ed76..b48fa17 100644 --- a/humans.txt.yaml +++ b/humans.txt.yaml @@ -1,2 +1,2 @@ -humans: +humans: [] diff --git a/test.sh b/test.sh old mode 100644 new mode 100755 index 9eec1de..22f7736 --- a/test.sh +++ b/test.sh @@ -1,8 +1,10 @@ -#!bin/bash +#!/bin/bash set -xeuo pipefail -node action.js txt >/tmp/t1 -node action.js json >/tmp/t2 -node action.js shell >/tmp/t3 +node action.js json >/dev/null +node action.js txt +# check default arg +node action.js >/dev/null +node action.js shell