Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 55 additions & 55 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
name: "CI"

on:
push:
branches: [main]
pull_request:
push:
branches: [main]
pull_request:

jobs:
check-linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6

- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v21

- name: Setup Nix cache
uses: DeterminateSystems/magic-nix-cache-action@v13
with:
use-flakehub: false

- name: Cache Spago dependencies
uses: actions/cache@v4
with:
path: |
generate/.spago
generate/output
~/.cache/spago
key: spago-${{ runner.os }}-${{ hashFiles('generate/spago.lock') }}
restore-keys: |
spago-${{ runner.os }}-

- name: Run spago tests
run: |
cd generate
nix develop ..# --command bash -c "npm ci && spago test"

- name: Verify manifests
run: |
cd generate
nix develop ..# --command spago run -p bin -m Bin.Main -- verify ../manifests

- name: Run flake checks
run: nix flake check --print-build-logs

check-darwin:
runs-on: macos-latest
steps:
- uses: actions/checkout@v6

- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v21

- name: Setup Nix cache
uses: DeterminateSystems/magic-nix-cache-action@v13
with:
use-flakehub: false

- name: Run flake check
run: nix flake check --print-build-logs
check-linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6

- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v21

- name: Setup Nix cache
uses: DeterminateSystems/magic-nix-cache-action@v13
with:
use-flakehub: false

- name: Cache Spago dependencies
uses: actions/cache@v4
with:
path: |
generate/.spago
generate/output
~/.cache/spago
key: spago-${{ runner.os }}-${{ hashFiles('generate/spago.lock') }}
restore-keys: |
spago-${{ runner.os }}-

- name: Run spago tests
run: |
cd generate
nix develop ..# --command bash -c "npm ci && spago test"

- name: Verify manifests
run: |
cd generate
nix develop ..# --command spago run -p bin -- --verbose verify ../manifests

- name: Run flake checks
run: nix flake check --print-build-logs

check-darwin:
runs-on: macos-latest
steps:
- uses: actions/checkout@v6

- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v21

- name: Setup Nix cache
uses: DeterminateSystems/magic-nix-cache-action@v13
with:
use-flakehub: false

- name: Run flake check
run: nix flake check --print-build-logs
40 changes: 20 additions & 20 deletions .github/workflows/daily-update.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@ name: "daily-update"
# The importer is run every day at 07:00 UTC and can also be run manually from
# the 'Actions' tab.
on:
workflow_dispatch:
schedule:
- cron: "0 7 * * *"
workflow_dispatch:
schedule:
- cron: "0 7 * * *"

jobs:
build:
runs-on: ubuntu-latest
build:
runs-on: ubuntu-latest

env:
REPO_TOKEN: ${{ secrets.REPO_TOKEN }}
env:
REPO_TOKEN: ${{ secrets.REPO_TOKEN }}

steps:
- uses: actions/checkout@v6
steps:
- uses: actions/checkout@v6

- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v21
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v21

- name: Setup Nix cache
uses: DeterminateSystems/magic-nix-cache-action@v13
with:
use-flakehub: false
- name: Setup Nix cache
uses: DeterminateSystems/magic-nix-cache-action@v13
with:
use-flakehub: false

- name: Run the generate script
run: |
cd generate
npm ci
nix develop --command spago run -p bin -m Bin.Main -- update ../manifests --commit
- name: Run the generate script
run: |
cd generate
npm ci
nix develop --command spago run -p bin -- --verbose update ../manifests --commit
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ spago test
# Verify manifests can be read correctly
spago run -p bin -- verify ../manifests

# Use --verbose for detailed output (shows GitHub API calls, hashes, etc.)
spago run -p bin -- --verbose verify ../manifests

# Check Nix formatting and package derivations
cd ..
nix flake check
Expand Down
2 changes: 2 additions & 0 deletions generate/bin/spago.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package:
name: bin
run:
main: Bin.Main
dependencies:
- aff
- argparse-basic
Expand Down
105 changes: 37 additions & 68 deletions generate/bin/src/AppM.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Bin.AppM where

import Prelude

import Bin.CLI (Verbosity(..))
import Control.Monad.Except (runExceptT)
import Control.Monad.Reader (class MonadAsk, class MonadReader, ReaderT, ask, runReaderT)
import Control.Monad.Reader as ReaderT
Expand All @@ -10,13 +11,12 @@ import Data.Newtype (class Newtype)
import Effect.Aff (Aff)
import Effect.Aff.Class (class MonadAff, liftAff)
import Effect.Class (class MonadEffect)
import Effect.Class.Console as Console
import Lib.Foreign.Octokit (GitHubError, Octokit)
import Lib.Git (GitM(..))
import Lib.GitHub (GitHubM(..))
import Lib.Nix.Manifest (CombinedManifest, GitHubBinaryManifest, NamedManifest, NPMRegistryManifest)
import Lib.Nix.Manifest (ManifestCodec, NamedManifest)
import Lib.Nix.Manifest as Nix.Manifest
import Lib.Nix.Manifest as Tool
import Lib.Tool (Tool(..))
import Lib.Utils as Utils
import Node.Path (FilePath)
import Node.Path as Path
Expand All @@ -31,6 +31,7 @@ type Env =
, tmpDir :: FilePath
, gitBranch :: String
, manifestDir :: FilePath
, verbosity :: Verbosity
}

newtype AppM a = AppM (ReaderT Env Aff a)
Expand All @@ -48,82 +49,50 @@ derive newtype instance MonadReader Env AppM

instance MonadApp AppM where
runGitHubM (GitHubM run) = do
{ octokit } <- ask
liftAff $ runReaderT (runExceptT run) octokit
{ octokit, verbosity } <- ask
let debugFn msg = when (verbosity >= Verbose) $ Console.log $ "[DEBUG] " <> msg
liftAff $ runReaderT (runExceptT run) { octokit, debug: debugFn }

runGitM (GitM run) = do
{ tmpDir, gitBranch } <- ask
liftAff $ runReaderT (runExceptT run) { cwd: tmpDir, branch: gitBranch }
{ tmpDir, gitBranch, verbosity } <- ask
let debugFn msg = when (verbosity >= Verbose) $ Console.log $ "[DEBUG] " <> msg
liftAff $ runReaderT (runExceptT run) { cwd: tmpDir, branch: gitBranch, debug: debugFn }

runAppM :: forall a. Env -> AppM a -> Aff a
runAppM env (AppM run) = runReaderT run env

getNamedManifestPath :: AppM FilePath
getNamedManifestPath = do
{ manifestDir } <- ask
pure $ Path.concat [ manifestDir, Nix.Manifest.namedPath ]

-- | Read the named manifest (tool channel -> version mappings)
readNamedManifest :: AppM NamedManifest
readNamedManifest = do
path <- getNamedManifestPath
Utils.readJsonFile path Nix.Manifest.namedManifestCodec
{ manifestDir } <- ask
Utils.readJsonFile (Path.concat [ manifestDir, Nix.Manifest.namedPath ]) Nix.Manifest.namedManifestCodec

-- | Write the named manifest
writeNamedManifest :: NamedManifest -> AppM Unit
writeNamedManifest manifest = do
path <- getNamedManifestPath
Utils.writeJsonFile path Nix.Manifest.namedManifestCodec manifest

getToolManifestPath :: Tool -> AppM FilePath
getToolManifestPath tool = do
{ manifestDir } <- ask
pure $ Path.concat [ manifestDir, Tool.filename tool ]

readPursManifest :: AppM GitHubBinaryManifest
readPursManifest = do
path <- getToolManifestPath Purs
Utils.readJsonFile path Nix.Manifest.githubBinaryManifestCodec

writePursManifest :: GitHubBinaryManifest -> AppM Unit
writePursManifest manifest = do
path <- getToolManifestPath Purs
Utils.writeJsonFile path Nix.Manifest.githubBinaryManifestCodec manifest

readSpagoManifest :: AppM CombinedManifest
readSpagoManifest = do
path <- getToolManifestPath Spago
Utils.readJsonFile path Nix.Manifest.combinedManifestCodec
Utils.writeJsonFile (Path.concat [ manifestDir, Nix.Manifest.namedPath ]) Nix.Manifest.namedManifestCodec manifest

writeSpagoManifest :: CombinedManifest -> AppM Unit
writeSpagoManifest manifest = do
path <- getToolManifestPath Spago
Utils.writeJsonFile path Nix.Manifest.combinedManifestCodec manifest

readPursTidyManifest :: AppM NPMRegistryManifest
readPursTidyManifest = do
path <- getToolManifestPath PursTidy
Utils.readJsonFile path Nix.Manifest.npmRegistryManifestCodec

writePursTidyManifest :: NPMRegistryManifest -> AppM Unit
writePursTidyManifest manifest = do
path <- getToolManifestPath PursTidy
Utils.writeJsonFile path Nix.Manifest.npmRegistryManifestCodec manifest

readPursBackendEsManifest :: AppM NPMRegistryManifest
readPursBackendEsManifest = do
path <- getToolManifestPath PursBackendEs
Utils.readJsonFile path Nix.Manifest.npmRegistryManifestCodec

writePursBackendEsManifest :: NPMRegistryManifest -> AppM Unit
writePursBackendEsManifest manifest = do
path <- getToolManifestPath PursBackendEs
Utils.writeJsonFile path Nix.Manifest.npmRegistryManifestCodec manifest

readPursLanguageServerManifest :: AppM NPMRegistryManifest
readPursLanguageServerManifest = do
path <- getToolManifestPath PursLanguageServer
Utils.readJsonFile path Nix.Manifest.npmRegistryManifestCodec
-- | Read a tool's manifest using its codec
readManifest :: forall a. ManifestCodec a -> AppM a
readManifest { codec, tool } = do
{ manifestDir } <- ask
Utils.readJsonFile (Path.concat [ manifestDir, Nix.Manifest.filename tool ]) codec

writePursLanguageServerManifest :: NPMRegistryManifest -> AppM Unit
writePursLanguageServerManifest manifest = do
path <- getToolManifestPath PursLanguageServer
Utils.writeJsonFile path Nix.Manifest.npmRegistryManifestCodec manifest
-- | Write a tool's manifest using its codec
writeManifest :: forall a. ManifestCodec a -> a -> AppM Unit
writeManifest { codec, tool } manifest = do
{ manifestDir } <- ask
Utils.writeJsonFile (Path.concat [ manifestDir, Nix.Manifest.filename tool ]) codec manifest

-- | Log a message (always shown unless Quiet)
log :: String -> AppM Unit
log msg = do
{ verbosity } <- ask
when (verbosity > Quiet) $ Console.log $ "[INFO] " <> msg

-- | Log a message only in Verbose mode
debug :: String -> AppM Unit
debug msg = do
{ verbosity } <- ask
when (verbosity >= Verbose) $ Console.log $ "[DEBUG] " <> msg
Loading