Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
047c7191f3 | ||
|
|
10d162247f | ||
|
|
13f9f66ae0 | ||
|
|
7e80be60db | ||
|
|
16eb314428 | ||
|
|
72507d3b16 | ||
|
|
a7ffc4959e | ||
|
|
8271057335 | ||
|
|
6d9d6bd0f7 | ||
|
|
ae451ddb81 | ||
|
|
aa304de936 | ||
|
|
49260a4367 | ||
|
|
d23468549b | ||
|
|
75496b6100 |
9
.github/workflows/deploy.yml
vendored
9
.github/workflows/deploy.yml
vendored
@@ -1,9 +1,12 @@
|
||||
name: deploy
|
||||
|
||||
on: [push]
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
test:
|
||||
deploy-demo:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
@@ -15,6 +18,8 @@ jobs:
|
||||
- uses: bahmutov/npm-install@v1
|
||||
|
||||
- run: yarn build:demo
|
||||
env:
|
||||
BASE_PATHNAME: "snk"
|
||||
|
||||
- uses: crazy-max/ghaction-github-pages@068e494
|
||||
with:
|
||||
|
||||
15
.github/workflows/main.yml
vendored
15
.github/workflows/main.yml
vendored
@@ -7,7 +7,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- run: sudo apt-get install gifsicle graphicsmagick
|
||||
# - run: sudo apt-get install gifsicle graphicsmagick
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions/setup-node@v1
|
||||
with:
|
||||
@@ -15,6 +15,13 @@ jobs:
|
||||
|
||||
- uses: bahmutov/npm-install@v1
|
||||
|
||||
- run: yarn type
|
||||
- run: yarn lint
|
||||
- run: yarn test --ci
|
||||
# - run: yarn type
|
||||
# - run: yarn lint
|
||||
# - run: yarn test --ci
|
||||
# - run: yarn build:lib
|
||||
|
||||
- uses: actions/github-contribution-grid-snake@v1
|
||||
with:
|
||||
github_user_name: platane
|
||||
|
||||
- run: ls
|
||||
|
||||
3
README.md
Normal file
3
README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# snk
|
||||
|
||||
Generates a snake game from a github user contributions grid and output a screen capture as gif
|
||||
10
action.yml
10
action.yml
@@ -1,10 +1,10 @@
|
||||
name: "github-contribution-grid-snake"
|
||||
description: ""
|
||||
name: "generate-snake-game-from-github-contribution-grid"
|
||||
description: "Generates a snake game from a github user contributions grid and output a screen capture as gif"
|
||||
author: "platane"
|
||||
|
||||
outputs:
|
||||
gif_out_path:
|
||||
description: ""
|
||||
description: "path of the generated gif"
|
||||
|
||||
runs:
|
||||
using: "docker"
|
||||
@@ -15,9 +15,9 @@ runs:
|
||||
|
||||
inputs:
|
||||
github_user_name:
|
||||
description: ""
|
||||
description: "github user name"
|
||||
required: true
|
||||
gif_out_path:
|
||||
description: ""
|
||||
description: "path of the generated gif"
|
||||
required: false
|
||||
default: "./github-contribution-grid-snake.gif"
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"name": "snk",
|
||||
"description": "Generates a snake game from a github user contributions grid and output a screen capture as gif",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"repository": "github:platane/snk",
|
||||
|
||||
1
packages/action/.gitignore
vendored
1
packages/action/.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
!dist
|
||||
!dist/build
|
||||
out.gif
|
||||
5
packages/action/__tests__/dev.ts
Normal file
5
packages/action/__tests__/dev.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { generateContributionSnake } from "../generateContributionSnake";
|
||||
|
||||
generateContributionSnake("platane").then((buffer) => {
|
||||
process.stdout.write(buffer);
|
||||
});
|
||||
BIN
packages/action/dist/build/Release/canvas.node
vendored
Executable file
BIN
packages/action/dist/build/Release/canvas.node
vendored
Executable file
Binary file not shown.
BIN
packages/action/dist/build/Release/libcairo.so.2
vendored
Normal file
BIN
packages/action/dist/build/Release/libcairo.so.2
vendored
Normal file
Binary file not shown.
BIN
packages/action/dist/build/Release/libcroco-0.6.so.3
vendored
Normal file
BIN
packages/action/dist/build/Release/libcroco-0.6.so.3
vendored
Normal file
Binary file not shown.
BIN
packages/action/dist/build/Release/libexpat.so.1
vendored
Normal file
BIN
packages/action/dist/build/Release/libexpat.so.1
vendored
Normal file
Binary file not shown.
BIN
packages/action/dist/build/Release/libffi.so.6
vendored
Normal file
BIN
packages/action/dist/build/Release/libffi.so.6
vendored
Normal file
Binary file not shown.
BIN
packages/action/dist/build/Release/libfontconfig.so.1
vendored
Normal file
BIN
packages/action/dist/build/Release/libfontconfig.so.1
vendored
Normal file
Binary file not shown.
BIN
packages/action/dist/build/Release/libfreetype.so.6
vendored
Normal file
BIN
packages/action/dist/build/Release/libfreetype.so.6
vendored
Normal file
Binary file not shown.
BIN
packages/action/dist/build/Release/libfribidi.so.0
vendored
Normal file
BIN
packages/action/dist/build/Release/libfribidi.so.0
vendored
Normal file
Binary file not shown.
BIN
packages/action/dist/build/Release/libgdk_pixbuf-2.0.so.0
vendored
Normal file
BIN
packages/action/dist/build/Release/libgdk_pixbuf-2.0.so.0
vendored
Normal file
Binary file not shown.
BIN
packages/action/dist/build/Release/libgif.so.7
vendored
Normal file
BIN
packages/action/dist/build/Release/libgif.so.7
vendored
Normal file
Binary file not shown.
BIN
packages/action/dist/build/Release/libgio-2.0.so.0
vendored
Normal file
BIN
packages/action/dist/build/Release/libgio-2.0.so.0
vendored
Normal file
Binary file not shown.
BIN
packages/action/dist/build/Release/libglib-2.0.so.0
vendored
Normal file
BIN
packages/action/dist/build/Release/libglib-2.0.so.0
vendored
Normal file
Binary file not shown.
BIN
packages/action/dist/build/Release/libgmodule-2.0.so.0
vendored
Normal file
BIN
packages/action/dist/build/Release/libgmodule-2.0.so.0
vendored
Normal file
Binary file not shown.
BIN
packages/action/dist/build/Release/libgobject-2.0.so.0
vendored
Normal file
BIN
packages/action/dist/build/Release/libgobject-2.0.so.0
vendored
Normal file
Binary file not shown.
BIN
packages/action/dist/build/Release/libgthread-2.0.so.0
vendored
Normal file
BIN
packages/action/dist/build/Release/libgthread-2.0.so.0
vendored
Normal file
Binary file not shown.
BIN
packages/action/dist/build/Release/libharfbuzz.so.0
vendored
Normal file
BIN
packages/action/dist/build/Release/libharfbuzz.so.0
vendored
Normal file
Binary file not shown.
BIN
packages/action/dist/build/Release/libjpeg.so.62
vendored
Normal file
BIN
packages/action/dist/build/Release/libjpeg.so.62
vendored
Normal file
Binary file not shown.
BIN
packages/action/dist/build/Release/libpango-1.0.so.0
vendored
Normal file
BIN
packages/action/dist/build/Release/libpango-1.0.so.0
vendored
Normal file
Binary file not shown.
BIN
packages/action/dist/build/Release/libpangocairo-1.0.so.0
vendored
Normal file
BIN
packages/action/dist/build/Release/libpangocairo-1.0.so.0
vendored
Normal file
Binary file not shown.
BIN
packages/action/dist/build/Release/libpangoft2-1.0.so.0
vendored
Normal file
BIN
packages/action/dist/build/Release/libpangoft2-1.0.so.0
vendored
Normal file
Binary file not shown.
BIN
packages/action/dist/build/Release/libpcre.so.1
vendored
Normal file
BIN
packages/action/dist/build/Release/libpcre.so.1
vendored
Normal file
Binary file not shown.
BIN
packages/action/dist/build/Release/libpixman-1.so.0
vendored
Normal file
BIN
packages/action/dist/build/Release/libpixman-1.so.0
vendored
Normal file
Binary file not shown.
BIN
packages/action/dist/build/Release/libpng16.so.16
vendored
Normal file
BIN
packages/action/dist/build/Release/libpng16.so.16
vendored
Normal file
Binary file not shown.
BIN
packages/action/dist/build/Release/librsvg-2.so.2
vendored
Normal file
BIN
packages/action/dist/build/Release/librsvg-2.so.2
vendored
Normal file
Binary file not shown.
BIN
packages/action/dist/build/Release/libstdc++.so.6
vendored
Normal file
BIN
packages/action/dist/build/Release/libstdc++.so.6
vendored
Normal file
Binary file not shown.
BIN
packages/action/dist/build/Release/libxml2.so.2
vendored
Normal file
BIN
packages/action/dist/build/Release/libxml2.so.2
vendored
Normal file
Binary file not shown.
BIN
packages/action/dist/build/Release/libz.so.1
vendored
Normal file
BIN
packages/action/dist/build/Release/libz.so.1
vendored
Normal file
Binary file not shown.
174125
packages/action/dist/index.js
vendored
Normal file
174125
packages/action/dist/index.js
vendored
Normal file
File diff suppressed because one or more lines are too long
84
packages/action/dist/index1.js
vendored
Normal file
84
packages/action/dist/index1.js
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
const Canvas = require('./lib/canvas')
|
||||
const Image = require('./lib/image')
|
||||
const CanvasRenderingContext2D = require('./lib/context2d')
|
||||
const parseFont = require('./lib/parse-font')
|
||||
const packageJson = require('./package.json')
|
||||
const bindings = require('./lib/bindings')
|
||||
const fs = require('fs')
|
||||
const PNGStream = require('./lib/pngstream')
|
||||
const PDFStream = require('./lib/pdfstream')
|
||||
const JPEGStream = require('./lib/jpegstream')
|
||||
const DOMMatrix = require('./lib/DOMMatrix').DOMMatrix
|
||||
const DOMPoint = require('./lib/DOMMatrix').DOMPoint
|
||||
|
||||
function createCanvas (width, height, type) {
|
||||
return new Canvas(width, height, type)
|
||||
}
|
||||
|
||||
function createImageData (array, width, height) {
|
||||
return new bindings.ImageData(array, width, height)
|
||||
}
|
||||
|
||||
function loadImage (src) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const image = new Image()
|
||||
|
||||
function cleanup () {
|
||||
image.onload = null
|
||||
image.onerror = null
|
||||
}
|
||||
|
||||
image.onload = () => { cleanup(); resolve(image) }
|
||||
image.onerror = (err) => { cleanup(); reject(err) }
|
||||
|
||||
image.src = src
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve paths for registerFont. Must be called *before* creating a Canvas
|
||||
* instance.
|
||||
* @param src {string} Path to font file.
|
||||
* @param fontFace {{family: string, weight?: string, style?: string}} Object
|
||||
* specifying font information. `weight` and `style` default to `"normal"`.
|
||||
*/
|
||||
function registerFont (src, fontFace) {
|
||||
// TODO this doesn't need to be on Canvas; it should just be a static method
|
||||
// of `bindings`.
|
||||
return Canvas._registerFont(fs.realpathSync(src), fontFace)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
Canvas,
|
||||
Context2d: CanvasRenderingContext2D, // Legacy/compat export
|
||||
CanvasRenderingContext2D,
|
||||
CanvasGradient: bindings.CanvasGradient,
|
||||
CanvasPattern: bindings.CanvasPattern,
|
||||
Image,
|
||||
ImageData: bindings.ImageData,
|
||||
PNGStream,
|
||||
PDFStream,
|
||||
JPEGStream,
|
||||
DOMMatrix,
|
||||
DOMPoint,
|
||||
|
||||
registerFont,
|
||||
parseFont,
|
||||
|
||||
createCanvas,
|
||||
createImageData,
|
||||
loadImage,
|
||||
|
||||
backends: bindings.Backends,
|
||||
|
||||
/** Library version. */
|
||||
version: packageJson.version,
|
||||
/** Cairo version. */
|
||||
cairoVersion: bindings.cairoVersion,
|
||||
/** jpeglib version. */
|
||||
jpegVersion: bindings.jpegVersion,
|
||||
/** gif_lib version. */
|
||||
gifVersion: bindings.gifVersion ? bindings.gifVersion.replace(/[^.\d]/g, '') : undefined,
|
||||
/** freetype version. */
|
||||
freetypeVersion: bindings.freetypeVersion
|
||||
}
|
||||
60
packages/action/dist/xhr-sync-worker.js
vendored
Normal file
60
packages/action/dist/xhr-sync-worker.js
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
"use strict";
|
||||
/* eslint-disable no-process-exit */
|
||||
const util = require("util");
|
||||
const { JSDOM } = require("../../../..");
|
||||
const { READY_STATES } = require("./xhr-utils");
|
||||
const idlUtils = require("../generated/utils");
|
||||
const tough = require("tough-cookie");
|
||||
|
||||
const dom = new JSDOM();
|
||||
const xhr = new dom.window.XMLHttpRequest();
|
||||
const xhrImpl = idlUtils.implForWrapper(xhr);
|
||||
|
||||
const chunks = [];
|
||||
|
||||
process.stdin.on("data", chunk => {
|
||||
chunks.push(chunk);
|
||||
});
|
||||
|
||||
process.stdin.on("end", () => {
|
||||
const buffer = Buffer.concat(chunks);
|
||||
|
||||
const flag = JSON.parse(buffer.toString());
|
||||
if (flag.body && flag.body.type === "Buffer" && flag.body.data) {
|
||||
flag.body = Buffer.from(flag.body.data);
|
||||
}
|
||||
if (flag.cookieJar) {
|
||||
flag.cookieJar = tough.CookieJar.fromJSON(flag.cookieJar);
|
||||
}
|
||||
|
||||
flag.synchronous = false;
|
||||
Object.assign(xhrImpl.flag, flag);
|
||||
const { properties } = xhrImpl;
|
||||
xhrImpl.readyState = READY_STATES.OPENED;
|
||||
try {
|
||||
xhr.addEventListener("loadend", () => {
|
||||
if (properties.error) {
|
||||
properties.error = properties.error.stack || util.inspect(properties.error);
|
||||
}
|
||||
process.stdout.write(JSON.stringify({
|
||||
responseURL: xhrImpl.responseURL,
|
||||
status: xhrImpl.status,
|
||||
statusText: xhrImpl.statusText,
|
||||
properties
|
||||
}), () => {
|
||||
process.exit(0);
|
||||
});
|
||||
}, false);
|
||||
xhr.send(flag.body);
|
||||
} catch (error) {
|
||||
properties.error += error.stack || util.inspect(error);
|
||||
process.stdout.write(JSON.stringify({
|
||||
responseURL: xhrImpl.responseURL,
|
||||
status: xhrImpl.status,
|
||||
statusText: xhrImpl.statusText,
|
||||
properties
|
||||
}), () => {
|
||||
process.exit(0);
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -5,8 +5,8 @@ import { computeBestRun } from "@snk/compute";
|
||||
import { createGif } from "../gif-creator";
|
||||
|
||||
export const userContributionToGrid = (cells: Cell[]) => {
|
||||
const width = Math.max(...cells.map((c) => c.x));
|
||||
const height = Math.max(...cells.map((c) => c.y));
|
||||
const width = Math.max(0, ...cells.map((c) => c.x)) + 1;
|
||||
const height = Math.max(0, ...cells.map((c) => c.y)) + 1;
|
||||
|
||||
const grid = generateEmptyGrid(width, height);
|
||||
for (const c of cells) setColor(grid, c.x, c.y, c.k === 0 ? null : c.k);
|
||||
@@ -39,9 +39,9 @@ export const generateContributionSnake = async (userName: string) => {
|
||||
|
||||
const gameOptions = { maxSnakeLength: 5 };
|
||||
|
||||
const gifOptions = { delay: 20 };
|
||||
const gifOptions = { delay: 10 };
|
||||
|
||||
const commands = computeBestRun(grid0, snake0, gameOptions).slice(0, 50);
|
||||
const commands = computeBestRun(grid0, snake0, gameOptions);
|
||||
|
||||
const buffer = await createGif(
|
||||
grid0,
|
||||
|
||||
@@ -7,9 +7,15 @@ import { generateContributionSnake } from "./generateContributionSnake";
|
||||
console.log(core.getInput("user_name"));
|
||||
console.log(core.getInput("gif_out_path"));
|
||||
console.log("--");
|
||||
console.log("--");
|
||||
console.log(process.cwd());
|
||||
console.log("--");
|
||||
console.log(fs.readdirSync(process.cwd()));
|
||||
console.log("--");
|
||||
console.log("--");
|
||||
console.log(process.env.GITHUB_WORKSPACE);
|
||||
console.log("--");
|
||||
console.log(fs.readdirSync(process.cwd()));
|
||||
|
||||
const buffer = await generateContributionSnake(core.getInput("user_name"));
|
||||
fs.writeFileSync(core.getInput("gif_out_path"), buffer);
|
||||
|
||||
@@ -2,14 +2,15 @@
|
||||
"name": "@snk/action",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"@actions/core": "1.2.4",
|
||||
"@snk/gif-creator": "1.0.0",
|
||||
"@snk/github-user-contribution": "1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@actions/core": "1.2.4",
|
||||
"@zeit/ncc": "0.22.3"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "ncc build ./index.ts --out dist"
|
||||
"build": "ncc build ./index.ts --out dist",
|
||||
"dev": "ncc run __tests__/dev.ts --quiet | tail -n +2 > out.gif "
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ export const computeBestRun = (
|
||||
|
||||
const commands: Point[] = [];
|
||||
|
||||
let u = 100;
|
||||
let u = 500;
|
||||
|
||||
while (!isGridEmpty(g) && u-- > 0) {
|
||||
let direction;
|
||||
|
||||
@@ -22,7 +22,7 @@ export const run = async () => {
|
||||
|
||||
const gameOptions = { maxSnakeLength: 5 };
|
||||
|
||||
const grid0 = generateGrid(14, 7, { colors: [1, 2, 3, 4], emptyP: 3 });
|
||||
const grid0 = generateGrid(42, 7, { colors: [1, 2, 3, 4], emptyP: 3 });
|
||||
|
||||
const snake0 = [
|
||||
{ x: 4, y: -1 },
|
||||
|
||||
@@ -13,7 +13,7 @@ const config: Configuration = {
|
||||
entry: "./index",
|
||||
resolve: { extensions: [".ts", ".js"] },
|
||||
output: {
|
||||
path: path.join(__dirname, "dist", "demo"),
|
||||
path: path.join(__dirname, "dist"),
|
||||
filename: "[contenthash].js",
|
||||
publicPath: "/" + basePathname.map((x) => x + "/").join(""),
|
||||
},
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"jsx": "preserve",
|
||||
"lib": ["dom", "ES2020"],
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
|
||||
Reference in New Issue
Block a user