Update CI

This commit is contained in:
Matei Adriel 2023-10-29 05:46:53 +01:00
parent 243360dd70
commit d090a37560
No known key found for this signature in database
7 changed files with 91 additions and 42 deletions

22
.github/workflows/build.yaml vendored Normal file
View file

@ -0,0 +1,22 @@
name: Build
on:
push:
pull_request:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- name: Build project
run: nix build
- name: Upload artifact
uses: actions/upload-pages-artifact@v2
with:
path: ./result/www

View file

@ -1,25 +1,24 @@
name: "Deploy" # Inspired by https://github.com/actions/starter-workflows/blob/main/pages/mdbook.yml
name: Deploy
on: on:
pull_request:
push: push:
branches: [$default-branch]
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
jobs: jobs:
tests: deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: build
steps: steps:
- uses: actions/checkout@v3 - name: Deploy to GitHub Pages
- uses: cachix/install-nix-action@v19 id: deployment
with: uses: actions/deploy-pages@v2
github_access_token: ${{ secrets.GITHUB_TOKEN }}
- uses: cachix/cachix-action@v12
with:
name: erratic-gate
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- run: nix build
- run: nix flake check
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./dist

1
.gitignore vendored
View file

@ -3,3 +3,4 @@ dist
coverege coverege
idea idea
.direnv .direnv
result

View file

@ -3,5 +3,5 @@
"trailingComma": "none", "trailingComma": "none",
"singleQuote": true, "singleQuote": true,
"printWidth": 80, "printWidth": 80,
"tabWidth": 4 "tabWidth": 2
} }

View file

@ -1,19 +1,20 @@
import * as esbuild from 'esbuild' import * as esbuild from 'esbuild'
import { htmlPlugin } from '@craftamap/esbuild-plugin-html' import { htmlPlugin } from '@craftamap/esbuild-plugin-html'
import { sassPlugin } from 'esbuild-sass-plugin' import { sassPlugin } from 'esbuild-sass-plugin'
import * as fs from 'fs'
const production = process.env.NODE_ENV === 'production'
const serve = process.env.ESBUILD_SERVE === '1' const serve = process.env.ESBUILD_SERVE === '1'
const ctx = await esbuild.context({ const ctx = await esbuild.context({
entryPoints: ['src/index.ts'], entryPoints: ['src/index.ts'],
bundle: production, minify: !serve,
// minify: production, bundle: true,
outdir: 'dist',
metafile: true, metafile: true,
splitting: true, splitting: true,
outdir: 'dist',
format: 'esm', format: 'esm',
target: ['chrome100', 'firefox100'], target: ['es2020'],
assetNames: 'assets/[name]-[hash]',
loader: { loader: {
'.svg': 'file' '.svg': 'file'
}, },
@ -26,7 +27,6 @@ const ctx = await esbuild.context({
favicon: 'public/favicon.ico', favicon: 'public/favicon.ico',
htmlTemplate: 'public/index.html', htmlTemplate: 'public/index.html',
scriptLoading: 'module' scriptLoading: 'module'
// inline: { js: true }
} }
] ]
}), }),
@ -37,4 +37,8 @@ const ctx = await esbuild.context({
if (serve) { if (serve) {
const { port, host } = await ctx.serve({ servedir: 'dist' }) const { port, host } = await ctx.serve({ servedir: 'dist' })
console.log(`Serving on ${host}:${port}`) console.log(`Serving on ${host}:${port}`)
} else {
await ctx.rebuild()
await ctx.dispose()
fs.cpSync('./dist/index.html', './dist/404.html') // Needed to please github pages
} }

View file

@ -3,17 +3,43 @@
inputs.flake-utils.url = "github:numtide/flake-utils"; inputs.flake-utils.url = "github:numtide/flake-utils";
outputs = { nixpkgs, flake-utils, ... }: outputs = { nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem flake-utils.lib.eachDefaultSystem (system:
(system:
let pkgs = nixpkgs.legacyPackages.${system}; let pkgs = nixpkgs.legacyPackages.${system};
in in
{ rec {
packages.erratic-gate = pkgs.buildNpmPackage {
name = "erratic-gate";
buildInputs = [ pkgs.nodejs_18 ];
src = pkgs.lib.cleanSource ./.;
npmDepsHash = "sha256-f5mw6IjkhZgsIuzCz9d7DvoAdceY1y+yWXn1BOonsVI=";
npmBuild = "npm run build";
installPhase = ''
mkdir $out
cp -r dist $out/www
'';
};
packages.default = packages.erratic-gate;
devShells.default = devShells.default =
pkgs.mkShell { pkgs.mkShell {
buildInputs = with pkgs; with nodePackages_latest; [ buildInputs = with pkgs;
with nodePackages_latest; [
nodejs nodejs
]; ];
}; };
apps.compute-npm-dep-hash = {
type = "app";
program = pkgs.lib.getExe (pkgs.writeShellApplication {
name = "generate-layout-previes";
runtimeInputs = [ pkgs.prefetch-npm-deps ];
text = "prefetch-npm-deps ./package-lock.json";
});
};
} }
); );
@ -29,3 +55,4 @@
}; };
# }}} # }}}
} }

View file

@ -1,4 +0,0 @@
User-agent: *
Disallow: /server.js
Disallow: /js
Disallow: /css