use bun as package manager and runner for the docke rcontainer, plus some tweak on the github action

This commit is contained in:
Platane
2025-02-20 19:34:18 +07:00
committed by GitHub
parent 74bc4f0651
commit 85da3901f5
29 changed files with 25796 additions and 10209 deletions

View File

@@ -8,15 +8,13 @@ jobs:
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions/setup-node@v3 - uses: oven-sh/setup-bun@v1
with:
cache: yarn - run: bun install --frozen-lockfile
node-version: 20
- run: yarn install --frozen-lockfile
- run: npm run type - run: npm run type
- run: npm run lint - run: npm run lint
- run: npm run test --ci - run: bun test
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -46,7 +44,7 @@ jobs:
test -f dist/github-contribution-grid-snake-dark.svg test -f dist/github-contribution-grid-snake-dark.svg
test -f dist/github-contribution-grid-snake.gif test -f dist/github-contribution-grid-snake.gif
- uses: crazy-max/ghaction-github-pages@v3.1.0 - uses: crazy-max/ghaction-github-pages@v4.1.0
with: with:
target_branch: output target_branch: output
build_dir: dist build_dir: dist
@@ -57,11 +55,9 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions/setup-node@v3 - uses: oven-sh/setup-bun@v1
with:
cache: yarn - run: bun install --frozen-lockfile
node-version: 20
- run: yarn install --frozen-lockfile
- name: build svg-only action - name: build svg-only action
run: | run: |
@@ -84,7 +80,7 @@ jobs:
test -f dist/github-contribution-grid-snake.svg test -f dist/github-contribution-grid-snake.svg
test -f dist/github-contribution-grid-snake-dark.svg test -f dist/github-contribution-grid-snake-dark.svg
- uses: crazy-max/ghaction-github-pages@v3.1.0 - uses: crazy-max/ghaction-github-pages@v4.1.0
with: with:
target_branch: output-svg-only target_branch: output-svg-only
build_dir: dist build_dir: dist
@@ -93,22 +89,22 @@ jobs:
deploy-ghpages: deploy-ghpages:
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions:
pages: write
id-token: write
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions/setup-node@v3 - uses: oven-sh/setup-bun@v1
with:
cache: yarn - run: bun install --frozen-lockfile
node-version: 20
- run: yarn install --frozen-lockfile
- run: npm run build:demo - run: npm run build:demo
env: env:
GITHUB_USER_CONTRIBUTION_API_ENDPOINT: https://snk-one.vercel.app/api/github-user-contribution/ GITHUB_USER_CONTRIBUTION_API_ENDPOINT: https://snk-one.vercel.app/api/github-user-contribution/
- uses: crazy-max/ghaction-github-pages@v3.1.0 - uses: actions/upload-pages-artifact@v3
if: success() && github.ref == 'refs/heads/main'
with: with:
target_branch: gh-pages path: packages/demo/dist
build_dir: packages/demo/dist
env: - uses: actions/deploy-pages@v4
GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN_GH_PAGES }} if: success() && github.ref == 'refs/heads/main'

View File

@@ -37,9 +37,7 @@ jobs:
test -f dist/docker/github-contribution-grid-snake.gif test -f dist/docker/github-contribution-grid-snake.gif
- name: push github-contribution-grid-snake.svg to the output branch - name: push github-contribution-grid-snake.svg to the output branch
uses: crazy-max/ghaction-github-pages@v3.1.0 uses: crazy-max/ghaction-github-pages@v4.1.0
with: with:
target_branch: manual-run-output target_branch: manual-run-output
build_dir: dist build_dir: dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -45,20 +45,18 @@ jobs:
run: | run: |
sed -i "s/image: .*/image: docker:\/\/platane\/snk@${{ steps.docker-build.outputs.digest }}/" action.yml sed -i "s/image: .*/image: docker:\/\/platane\/snk@${{ steps.docker-build.outputs.digest }}/" action.yml
- uses: actions/setup-node@v3 - uses: oven-sh/setup-bun@v1
with:
cache: yarn - run: bun install --frozen-lockfile
node-version: 20
- name: build svg-only action - name: build svg-only action
run: | run: |
yarn install --frozen-lockfile
npm run build:action npm run build:action
rm -r svg-only/dist rm -r svg-only/dist
mv packages/action/dist svg-only/dist mv packages/action/dist svg-only/dist
- name: bump package version - name: bump package version
run: yarn version --no-git-tag-version --new-version ${{ github.event.inputs.version }} run: npm version --no-git-tag-version --new-version ${{ github.event.inputs.version }}
- name: push new build, tag version and push - name: push new build, tag version and push
id: push-tags id: push-tags
@@ -77,13 +75,11 @@ jobs:
git tag v$( echo $VERSION | cut -d. -f 1-2 ) git tag v$( echo $VERSION | cut -d. -f 1-2 )
git push origin --tags --force git push origin --tags --force
echo "prerelease=false" >> $GITHUB_OUTPUT echo "prerelease=false" >> $GITHUB_OUTPUT
else else
echo "prerelease=true" >> $GITHUB_OUTPUT echo "prerelease=true" >> $GITHUB_OUTPUT
fi fi
- uses: ncipollo/release-action@v1.12.0 - uses: ncipollo/release-action@v1.15.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with: with:
tag: v${{ github.event.inputs.version }} tag: v${{ github.event.inputs.version }}
body: ${{ github.event.inputs.description }} body: ${{ github.event.inputs.description }}

3
.gitignore vendored
View File

@@ -1,7 +1,6 @@
node_modules node_modules
npm-debug.log* npm-debug.log*
yarn-error.log*
dist dist
!svg-only/dist !svg-only/dist
build build
.env .env

View File

@@ -1,32 +1,27 @@
FROM node:20-slim as builder FROM oven/bun:1.2.2-slim as builder
WORKDIR /app WORKDIR /app
COPY package.json yarn.lock ./ COPY package.json bun.lock ./
COPY tsconfig.json ./ COPY tsconfig.json ./
COPY packages packages COPY packages packages
RUN export YARN_CACHE_FOLDER="$(mktemp -d)" \ RUN bun install --no-cache
&& yarn install --frozen-lockfile \
&& rm -r "$YARN_CACHE_FOLDER"
RUN yarn build:action RUN bun run build:action
FROM node:20-slim FROM oven/bun:1.2.2-slim
WORKDIR /action-release WORKDIR /action-release
RUN export YARN_CACHE_FOLDER="$(mktemp -d)" \ RUN bun add canvas@3.1.0 gifsicle@5.3.0 --no-lockfile --no-cache
&& yarn add canvas@3.1.0 gifsicle@5.3.0 --no-lockfile \
&& rm -r "$YARN_CACHE_FOLDER"
COPY --from=builder /app/packages/action/dist/ /action-release/ COPY --from=builder /app/packages/action/dist/ /action-release/
CMD ["node", "/action-release/index.js"] CMD ["bun", "/action-release/index.js"]

1639
bun.lock Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -5,30 +5,16 @@
"private": true, "private": true,
"repository": "github:platane/snk", "repository": "github:platane/snk",
"devDependencies": { "devDependencies": {
"@sucrase/jest-plugin": "3.0.0", "@types/bun": "1.2.2",
"@types/jest": "29.5.12",
"@types/node": "20.14.10",
"jest": "29.7.0",
"prettier": "2.8.8", "prettier": "2.8.8",
"sucrase": "3.35.0",
"typescript": "5.5.3" "typescript": "5.5.3"
}, },
"workspaces": [ "workspaces": [
"packages/*" "packages/*"
], ],
"jest": {
"testEnvironment": "node",
"testMatch": [
"**/__tests__/**/?(*.)+(spec|test).ts"
],
"transform": {
"\\.(ts|tsx)$": "@sucrase/jest-plugin"
}
},
"scripts": { "scripts": {
"type": "tsc --noEmit", "type": "tsc --noEmit",
"lint": "prettier -c '**/*.{ts,js,json,md,yml,yaml}' '!packages/*/dist/**' '!svg-only/dist/**'", "lint": "prettier -c '**/*.{ts,js,json,md,yml,yaml}' '!packages/*/dist/**' '!svg-only/dist/**'",
"test": "jest --verbose --no-cache",
"dev:demo": "( cd packages/demo ; npm run dev )", "dev:demo": "( cd packages/demo ; npm run dev )",
"build:demo": "( cd packages/demo ; npm run build )", "build:demo": "( cd packages/demo ; npm run build )",
"build:action": "( cd packages/action ; npm run build )" "build:action": "( cd packages/action ; npm run build )"

View File

@@ -1,11 +1,8 @@
import * as fs from "fs"; import * as fs from "fs";
import * as path from "path"; import * as path from "path";
import { it, expect } from "bun:test";
import { generateContributionSnake } from "../generateContributionSnake"; import { generateContributionSnake } from "../generateContributionSnake";
import { parseOutputsOption } from "../outputsOptions"; import { parseOutputsOption } from "../outputsOptions";
import { config } from "dotenv";
config({ path: __dirname + "/../../../.env" });
jest.setTimeout(2 * 60 * 1000);
const silent = (handler: () => void | Promise<void>) => async () => { const silent = (handler: () => void | Promise<void>) => async () => {
const originalConsoleLog = console.log; const originalConsoleLog = console.log;
@@ -43,5 +40,6 @@ it(
fs.writeFileSync(outputs[0]!.filename, results[0]!); fs.writeFileSync(outputs[0]!.filename, results[0]!);
fs.writeFileSync(outputs[1]!.filename, results[1]!); fs.writeFileSync(outputs[1]!.filename, results[1]!);
fs.writeFileSync(outputs[2]!.filename, results[2]!); fs.writeFileSync(outputs[2]!.filename, results[2]!);
}) }),
{ timeout: 2 * 60 * 1000 }
); );

View File

@@ -1,4 +1,5 @@
import { parseEntry } from "../outputsOptions"; import { parseEntry } from "../outputsOptions";
import { it, expect } from "bun:test";
it("should parse options as json", () => { it("should parse options as json", () => {
expect( expect(

View File

@@ -10,11 +10,9 @@
"@snk/types": "1.0.0" "@snk/types": "1.0.0"
}, },
"devDependencies": { "devDependencies": {
"@vercel/ncc": "0.38.1", "@vercel/ncc": "0.38.1"
"dotenv": "16.4.5"
}, },
"scripts": { "scripts": {
"build": "ncc build --external canvas --external gifsicle --out dist ./index.ts", "build": "ncc build --external canvas --external gifsicle --out dist ./index.ts"
"run:build": "INPUT_GITHUB_USER_NAME=platane INPUT_OUTPUTS='dist/out.svg' node dist/index.js"
} }
} }

View File

@@ -10,7 +10,6 @@
"@snk/types": "1.0.0" "@snk/types": "1.0.0"
}, },
"devDependencies": { "devDependencies": {
"dotenv": "16.4.5",
"@types/dat.gui": "0.7.13", "@types/dat.gui": "0.7.13",
"dat.gui": "0.7.9", "dat.gui": "0.7.9",
"html-webpack-plugin": "5.6.0", "html-webpack-plugin": "5.6.0",

View File

@@ -2,13 +2,11 @@ import path from "path";
import HtmlWebpackPlugin from "html-webpack-plugin"; import HtmlWebpackPlugin from "html-webpack-plugin";
import webpack from "webpack"; import webpack from "webpack";
import { getGithubUserContribution } from "@snk/github-user-contribution"; import { getGithubUserContribution } from "@snk/github-user-contribution";
import { config } from "dotenv";
import type { Configuration as WebpackConfiguration } from "webpack"; import type { Configuration as WebpackConfiguration } from "webpack";
import { import {
ExpressRequestHandler, ExpressRequestHandler,
type Configuration as WebpackDevServerConfiguration, type Configuration as WebpackDevServerConfiguration,
} from "webpack-dev-server"; } from "webpack-dev-server";
config({ path: __dirname + "/../../.env" });
const demos: string[] = require("./demo.json"); const demos: string[] = require("./demo.json");

View File

@@ -1,5 +1,6 @@
import * as fs from "fs"; import * as fs from "fs";
import * as path from "path"; import * as path from "path";
import { it, expect } from "bun:test";
import { AnimationOptions, createGif } from ".."; import { AnimationOptions, createGif } from "..";
import * as grids from "@snk/types/__fixtures__/grid"; import * as grids from "@snk/types/__fixtures__/grid";
import { snake3 as snake } from "@snk/types/__fixtures__/snake"; import { snake3 as snake } from "@snk/types/__fixtures__/snake";
@@ -7,8 +8,6 @@ import { createSnakeFromCells, nextSnake } from "@snk/types/snake";
import { getBestRoute } from "@snk/solver/getBestRoute"; import { getBestRoute } from "@snk/solver/getBestRoute";
import type { Options as DrawOptions } from "@snk/draw/drawWorld"; import type { Options as DrawOptions } from "@snk/draw/drawWorld";
jest.setTimeout(20 * 1000);
const upscale = 1; const upscale = 1;
const drawOptions: DrawOptions = { const drawOptions: DrawOptions = {
sizeDotBorderRadius: 2 * upscale, sizeDotBorderRadius: 2 * upscale,
@@ -35,10 +34,46 @@ for (const key of [
"small", "small",
"smallPacked", "smallPacked",
] as const) ] as const)
it(`should generate ${key} gif`, async () => { it(
const grid = grids[key]; `should generate ${key} gif`,
async () => {
const grid = grids[key];
const chain = [snake, ...getBestRoute(grid, snake)!]; const chain = [snake, ...getBestRoute(grid, snake)!];
const gif = await createGif(
grid,
null,
chain,
drawOptions,
animationOptions
);
expect(gif).toBeDefined();
fs.writeFileSync(path.resolve(dir, key + ".gif"), gif);
},
{ timeout: 20 * 1000 }
);
it(
`should generate swipper`,
async () => {
const grid = grids.smallFull;
let snk = createSnakeFromCells(
Array.from({ length: 6 }, (_, i) => ({ x: i, y: -1 }))
);
const chain = [snk];
for (let y = -1; y < grid.height; y++) {
snk = nextSnake(snk, 0, 1);
chain.push(snk);
for (let x = grid.width - 1; x--; ) {
snk = nextSnake(snk, (y + 100) % 2 ? 1 : -1, 0);
chain.push(snk);
}
}
const gif = await createGif( const gif = await createGif(
grid, grid,
@@ -50,29 +85,7 @@ for (const key of [
expect(gif).toBeDefined(); expect(gif).toBeDefined();
fs.writeFileSync(path.resolve(dir, key + ".gif"), gif); fs.writeFileSync(path.resolve(dir, "swipper.gif"), gif);
}); },
{ timeout: 20 * 1000 }
it(`should generate swipper`, async () => { );
const grid = grids.smallFull;
let snk = createSnakeFromCells(
Array.from({ length: 6 }, (_, i) => ({ x: i, y: -1 }))
);
const chain = [snk];
for (let y = -1; y < grid.height; y++) {
snk = nextSnake(snk, 0, 1);
chain.push(snk);
for (let x = grid.width - 1; x--; ) {
snk = nextSnake(snk, (y + 100) % 2 ? 1 : -1, 0);
chain.push(snk);
}
}
const gif = await createGif(grid, null, chain, drawOptions, animationOptions);
expect(gif).toBeDefined();
fs.writeFileSync(path.resolve(dir, "swipper.gif"), gif);
});

View File

@@ -11,10 +11,9 @@
}, },
"devDependencies": { "devDependencies": {
"@types/gifsicle": "5.2.2", "@types/gifsicle": "5.2.2",
"@types/tmp": "0.2.6", "@types/tmp": "0.2.6"
"@vercel/ncc": "0.38.1"
}, },
"scripts": { "scripts": {
"benchmark": "ncc run __tests__/benchmark.ts --quiet" "benchmark": "bun __tests__/benchmark.ts"
} }
} }

View File

@@ -1,6 +1,5 @@
import { getGithubUserContribution } from ".."; import { getGithubUserContribution } from "..";
import { config } from "dotenv"; import { describe, it, expect } from "bun:test";
config({ path: __dirname + "/../../../.env" });
describe("getGithubUserContribution", () => { describe("getGithubUserContribution", () => {
const promise = getGithubUserContribution("platane", { const promise = getGithubUserContribution("platane", {

View File

@@ -1,7 +1,4 @@
{ {
"name": "@snk/github-user-contribution", "name": "@snk/github-user-contribution",
"version": "1.0.0", "version": "1.0.0"
"devDependencies": {
"dotenv": "16.4.5"
}
} }

View File

@@ -1,3 +1,4 @@
import { it, expect } from "bun:test";
import { getBestRoute } from "../getBestRoute"; import { getBestRoute } from "../getBestRoute";
import { snake3, snake4 } from "@snk/types/__fixtures__/snake"; import { snake3, snake4 } from "@snk/types/__fixtures__/snake";
import { import {

View File

@@ -1,3 +1,4 @@
import { it, expect } from "bun:test";
import { getBestRoute } from "../getBestRoute"; import { getBestRoute } from "../getBestRoute";
import { Color, createEmptyGrid, setColor } from "@snk/types/grid"; import { Color, createEmptyGrid, setColor } from "@snk/types/grid";
import { createSnakeFromCells, snakeToCells } from "@snk/types/snake"; import { createSnakeFromCells, snakeToCells } from "@snk/types/snake";

View File

@@ -1,3 +1,4 @@
import { it, expect } from "bun:test";
import { createEmptyGrid } from "@snk/types/grid"; import { createEmptyGrid } from "@snk/types/grid";
import { getHeadX, getHeadY } from "@snk/types/snake"; import { getHeadX, getHeadY } from "@snk/types/snake";
import { snake3 } from "@snk/types/__fixtures__/snake"; import { snake3 } from "@snk/types/__fixtures__/snake";

View File

@@ -1,3 +1,4 @@
import { it, expect } from "bun:test";
import { createSnakeFromCells } from "@snk/types/snake"; import { createSnakeFromCells } from "@snk/types/snake";
import { getPathToPose } from "../getPathToPose"; import { getPathToPose } from "../getPathToPose";

View File

@@ -1,3 +1,4 @@
import { it, expect, describe } from "bun:test";
import { sortPush } from "../utils/sortPush"; import { sortPush } from "../utils/sortPush";
const sortFn = (a: number, b: number) => a - b; const sortFn = (a: number, b: number) => a - b;

View File

@@ -1,3 +1,4 @@
import { it, expect } from "bun:test";
import * as fs from "fs"; import * as fs from "fs";
import * as path from "path"; import * as path from "path";
import { createSvg, DrawOptions as DrawOptions } from ".."; import { createSvg, DrawOptions as DrawOptions } from "..";

View File

@@ -1,3 +1,4 @@
import { it, expect } from "bun:test";
import { minifyCss } from "../css-utils"; import { minifyCss } from "../css-utils";
it("should minify css", () => { it("should minify css", () => {
@@ -6,7 +7,7 @@ it("should minify css", () => {
.c { .c {
color : red ; color : red ;
} }
`) `)
).toBe(".c{color:red}"); ).toBe(".c{color:red}");
@@ -17,10 +18,10 @@ it("should minify css", () => {
color : red ; color : red ;
} }
# { # {
animation: linear 10; animation: linear 10;
} }
`) `)
).toBe(".c{top:0;color:red}#{animation:linear 10}"); ).toBe(".c{top:0;color:red}#{animation:linear 10}");
}); });

View File

@@ -1,13 +1,14 @@
import { it, expect, test } from "bun:test";
import { createEmptyGrid, setColor, getColor, isInside, Color } from "../grid"; import { createEmptyGrid, setColor, getColor, isInside, Color } from "../grid";
it("should set / get cell", () => { it("should set / get cell", () => {
const grid = createEmptyGrid(2, 3); const grid = createEmptyGrid(2, 3);
expect(getColor(grid, 0, 1)).toBe(0); expect(getColor(grid, 0, 1)).toBe(0 as any);
setColor(grid, 0, 1, 1 as Color); setColor(grid, 0, 1, 1 as Color);
expect(getColor(grid, 0, 1)).toBe(1); expect(getColor(grid, 0, 1)).toBe(1 as any);
}); });
test.each([ test.each([

View File

@@ -1,3 +1,4 @@
import { it, expect } from "bun:test";
import { import {
createSnakeFromCells, createSnakeFromCells,
nextSnake, nextSnake,

View File

@@ -23,7 +23,7 @@ var external_path_default = /*#__PURE__*/__webpack_require__.n(external_path_);
// EXTERNAL MODULE: external "child_process" // EXTERNAL MODULE: external "child_process"
var external_child_process_ = __webpack_require__(2081); var external_child_process_ = __webpack_require__(2081);
// EXTERNAL MODULE: external "canvas" // EXTERNAL MODULE: external "canvas"
var external_canvas_ = __webpack_require__(1576); var external_canvas_ = __webpack_require__(1813);
// EXTERNAL MODULE: ../types/grid.ts // EXTERNAL MODULE: ../types/grid.ts
var types_grid = __webpack_require__(2881); var types_grid = __webpack_require__(2881);
;// CONCATENATED MODULE: ../draw/pathRoundedRect.ts ;// CONCATENATED MODULE: ../draw/pathRoundedRect.ts

File diff suppressed because it is too large Load Diff

24040
svg-only/dist/index.js vendored

File diff suppressed because one or more lines are too long

6307
yarn.lock

File diff suppressed because it is too large Load Diff