From f3609953f3213def85179d4ae55fb3497d4b6981 Mon Sep 17 00:00:00 2001 From: 0rphee <0rph3e@proton.me> Date: Fri, 17 Jan 2025 10:31:10 -0600 Subject: [PATCH] Try to build github pages --- .github/workflows/linting.yml | 6 ++++- .github/workflows/web.yml | 50 +++++++++++++++++++++++++++++++++++ flake.nix | 1 + web/build.sh | 30 ++++++++++++++++++--- web/package.json | 4 +-- 5 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/web.yml diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index 7eaee7d..d1a86b7 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -4,7 +4,11 @@ on: pull_request: push: branches: ["main"] - + paths: + - "app/**" + - "Setup.hs" + - "src/**" + - "test/**" jobs: fourmolu: runs-on: ubuntu-latest diff --git a/.github/workflows/web.yml b/.github/workflows/web.yml new file mode 100644 index 0000000..3880d0d --- /dev/null +++ b/.github/workflows/web.yml @@ -0,0 +1,50 @@ +name: Web + +# Trigger the workflow on push or pull request, but only for the main branch +on: + pull_request: + paths: + - "app/**" + - "asmh.cabal" + - "cabal.project" + - "Setup.hs" + - "src/**" + - "test/**" + - "web/**" + push: + paths: + - "app/**" + - "asmh.cabal" + - "cabal.project" + - "Setup.hs" + - "src/**" + - "test/**" + - "web/**" + workflow_dispatch: + +jobs: + build: + name: "Build website" + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - uses: nixbuild/nix-quick-install-action@v29 + - uses: DeterminateSystems/magic-nix-cache-action@main + + - name: Build site + run: | + nix develop -command bash -c "cd web && echo hello world ls -la" + # nix develop -command bash -c "cd web && ./build.sh && ls dist/" + + - name: Setup Pages + uses: actions/configure-pages@v5 + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + with: + path: './web/dist/' + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 diff --git a/flake.nix b/flake.nix index 98e1373..067b9f1 100644 --- a/flake.nix +++ b/flake.nix @@ -42,6 +42,7 @@ ''; mkShell = pkgs.callPackage inputs.clean-devshell.lib.mkDevShell { }; packages = [ + pkgs.bash pkgs.gnumake pkgs.dartpkgs."2.19.6" jlox-test diff --git a/web/build.sh b/web/build.sh index 88f5c93..041aec2 100755 --- a/web/build.sh +++ b/web/build.sh @@ -5,9 +5,33 @@ if [[ $PWD != */web ]]; then exit 1 fi +outdir="" +case $1 in + dev) + echo "dev run" + outdir="./static/" + ;; + prod) + echo "prod run" + npm install + outdir="./dist/" + cp -R static/ $outdir/ + ;; + *) + echo "This script should be invoked with 'dev' or 'prod' as arguments." + exit 1 + ;; +esac + wasm32-wasi-cabal build xolsh-exe && wasmpath=$(wasm32-wasi-cabal list-bin xolsh-exe) -cp -f $wasmpath dist/xolsh-exe.wasm -cp -R static/ dist/ +cp -f $wasmpath $outdir/xolsh-exe.wasm -esbuild ./src/index.js --bundle --serve=127.0.0.1:9000 --servedir=./dist --outfile=./dist/index.js --global-name=Main --format=esm --platform=browser "--external:node:timers" \ No newline at end of file +case $1 in + dev) + esbuild ./src/index.js --bundle --serve=127.0.0.1:9000 --servedir=./static --outfile=./static/index.js --format=esm --platform=browser "--external:node:timers" + ;; + prod) + esbuild ./src/index.js --bundle --outfile=./dist/index.js --format=esm --platform=browser "--external:node:timers" + ;; +esac diff --git a/web/package.json b/web/package.json index e921cc1..2053c1f 100644 --- a/web/package.json +++ b/web/package.json @@ -3,7 +3,7 @@ "version": "1.0.0", "main": "index.js", "scripts": { - "start": "./build.sh" + "start": "./build.sh dev" }, "repository": { "type": "git", @@ -24,4 +24,4 @@ "codemirror": "^6.0.1", "thememirror": "^2.0.1" } -} +} \ No newline at end of file