Skip to content

Commit 40a43b5

Browse files
committed
Initial version
1 parent 1414709 commit 40a43b5

8 files changed

+169
-0
lines changed

Diff for: Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM node:12
2+
3+
COPY . .

Diff for: action.js

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
'use strict'
2+
3+
const fs = require('fs')
4+
const yaml = require('yaml')
5+
6+
const formatters = {
7+
txt: txtFormatter,
8+
json: jsonFormatter,
9+
shell: (data) => txtFormatter(data, { colors: true}),
10+
}
11+
12+
main()
13+
14+
function main() {
15+
const format = process.argv[2]
16+
17+
const formatter = formatters[format]
18+
if (!formatter) {
19+
invalidFormat(format)
20+
return
21+
}
22+
23+
const data = yaml.parse(fs.readFileSync("./humans.txt.yaml", {encoding: "utf8"}))
24+
25+
formatter(data)
26+
}
27+
28+
function invalidFormat(format) {
29+
const list = Object.keys(formatters).sort().join(",")
30+
console.error(`'${format}' is not one of the accepted formats ${list}`)
31+
process.statusCode = 1
32+
return
33+
}
34+
35+
function jsonFormatter({humans}) {
36+
console.log(JSON.stringify(humans, null, 4))
37+
}
38+
39+
function txtFormatter({humans}, {colors = false} = {}) {
40+
let active = humans.filter(h => !h.alum).map(h => h.name)
41+
let alum = humans.filter(h => h.alum).map(h => h.name)
42+
43+
if(colors) {
44+
const chalk = require('chalk')
45+
const total = active.length + alum.length
46+
active = active.map((n, i) => chalk.hsl((i / total) * 360, 100, 50)(n))
47+
alum = alum.map((n, i) => chalk.hsl(((i + active.length) / total) * 360, 100, 50)(n))
48+
}
49+
50+
console.log("Current humans")
51+
console.log("==============\n")
52+
console.log(active.join("\n"))
53+
console.log("\n")
54+
55+
console.log("Human alumni")
56+
console.log("============\n")
57+
console.log(alum.join("\n"))
58+
}
59+
60+

Diff for: actions.test.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const assert = require('assert')
2+

Diff for: actions.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: 'GitHub Actions humans.txt'
2+
description: 'List out the humans who help feed and tend the robots of GitHub Actions'
3+
inputs:
4+
format:
5+
description: 'How to output the people of actions - txt, json or ascii'
6+
default: 'ascii'
7+
runs:
8+
using: 'docker'
9+
image: 'Dockerfile'
10+
args:
11+
- ${{ inputs.format }}

Diff for: humans.txt.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
humans:
2+

Diff for: package-lock.json

+76
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"private": true,
3+
"dependencies": {
4+
"chalk": "3.0.0",
5+
"yaml": "1.7.2"
6+
}
7+
}

Diff for: test.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!bin/bash
2+
3+
set -xeuo pipefail
4+
5+
node action.js txt >/tmp/t1
6+
node action.js json >/tmp/t2
7+
node action.js shell >/tmp/t3
8+

0 commit comments

Comments
 (0)