Skip to content

Commit

Permalink
Add Nix builds for the full registry (#619)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomashoneyman committed Jul 6, 2023
1 parent 21f0186 commit 466146b
Show file tree
Hide file tree
Showing 14 changed files with 2,494 additions and 994 deletions.
39 changes: 6 additions & 33 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,13 @@ on:
jobs:
tests:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SPACES_KEY: ${{ secrets.SPACES_KEY }}
SPACES_SECRET: ${{ secrets.SPACES_SECRET }}
steps:
# Setup
- name: Check out source repository
uses: actions/checkout@v2

- name: Cache NPM dependencies
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Cache PureScript dependencies
uses: actions/cache@v2
with:
key: ${{ runner.os }}-spago-${{ hashFiles('**/spago.yaml') }}
path: |
.spago
output
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v4
with:
github-token: ${{ env.GITHUB_TOKEN }}

- name: Setup Nix cache
uses: DeterminateSystems/magic-nix-cache-action@v2
Expand All @@ -45,15 +24,9 @@ jobs:
- name: Initialize Nix
run: nix develop

# Checks for the Registry Draft
- name: "Check that all Dhall compiles, and fixtures correctly conform to a Manifest"
run: nix develop --command 'registry-verify-dhall'

- name: "Build project"
run: nix develop --command 'registry-build'

- name: "Run tests"
run: nix develop --command 'registry-test'

- name: "Verify CI code formats"
run: nix develop --command 'registry-check-format'
# Unfortunately I can't run 'spago test' in a derivation because it doesn't
# have a mode that ignores the cache. So we run it in a script instead.
# Once we can make this a normal derivation then we can delete this
# workflow file altogether.
- name: Run Spago tests
run: nix develop --command run-tests-script
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ result

# Keep it secret, keep it safe.
.env

89 changes: 89 additions & 0 deletions app/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
stdenv,
purix,
slimlock,
purs-backend-es,
esbuild,
writeText,
compilers,
nodejs,
}: let
package-lock = slimlock.buildPackageLock {src = ../.; omit = ["dev" "peer"];};
spago-lock = purix.buildSpagoLock {
src = ../.;
corefn = true;
};

# Since both the importer and the server share the same build process, we
# don't need to build them twice separately and can share an optimized output
# directory.
shared = stdenv.mkDerivation {
name = "registry-app-shared";
src = ./src;
phases = ["buildPhase" "installPhase"];
nativeBuildInputs = [purs-backend-es];
buildPhase = ''
ln -s ${package-lock}/js/node_modules .
cp -r ${spago-lock.registry-app}/output .
echo "Optimizing with purs-backend-es..."
purs-backend-es build
'';
installPhase = ''
mkdir $out
mv output-es $out/output
'';
};
in {
server = stdenv.mkDerivation rec {
name = "registry-server";
src = ./src;
nativeBuildInputs = [esbuild];
buildInputs = [compilers nodejs];
entrypoint = writeText "entrypoint.js" ''
import { main } from "./output/Registry.App.Server";
main();
'';
buildPhase = ''
ln -s ${package-lock}/js/node_modules .
cp -r ${shared}/output .
cp ${entrypoint} entrypoint.js
esbuild entrypoint.js --bundle --outfile=${name}.js --platform=node
'';
installPhase = ''
mkdir -p $out/bin
cp ${name}.js $out/${name}.js
echo '#!/usr/bin/env sh' > $out/bin/${name}
echo 'exec ${nodejs}/bin/node '"$out/${name}.js"' "$@"' >> $out/bin/${name}
chmod +x $out/bin/${name}
cp ${name}.js $out
'';
};

github-importer = stdenv.mkDerivation rec {
name = "registry-github-importer";
src = ./src;
nativeBuildInputs = [esbuild];
buildInputs = [compilers nodejs];
entrypoint = writeText "entrypoint.js" ''
import { main } from "./output/Registry.App.Main";
main();
'';
buildPhase = ''
ln -s ${package-lock}/js/node_modules .
cp -r ${shared}/output .
cp ${entrypoint} entrypoint.js
esbuild entrypoint.js --bundle --outfile=${name}.js --platform=node
'';
checkPhase = ''
'';
installPhase = ''
mkdir -p $out/bin
cp ${name}.js $out/${name}.js
echo '#!/usr/bin/env sh' > $out/bin/${name}
echo 'exec node '"$out/${name}.js"' "$@"' >> $out/bin/${name}
chmod +x $out/bin/${name}
cp ${name}.js $out
'';
};
}
1 change: 1 addition & 0 deletions app/src/App/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ main = launchAff_ $ do

-- Git env
debouncer <- Git.newDebouncer

let
gitEnv :: GitEnv
gitEnv =
Expand Down
90 changes: 58 additions & 32 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 466146b

Please sign in to comment.