Skip to content

Commit 78075c7

Browse files
Clean up duplication in AppM, add debug logging (#133)
1 parent 52223e0 commit 78075c7

File tree

12 files changed

+332
-489
lines changed

12 files changed

+332
-489
lines changed

.github/workflows/ci.yaml

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,60 @@
11
name: "CI"
22

33
on:
4-
push:
5-
branches: [main]
6-
pull_request:
4+
push:
5+
branches: [main]
6+
pull_request:
77

88
jobs:
9-
check-linux:
10-
runs-on: ubuntu-latest
11-
steps:
12-
- uses: actions/checkout@v6
13-
14-
- name: Install Nix
15-
uses: DeterminateSystems/nix-installer-action@v21
16-
17-
- name: Setup Nix cache
18-
uses: DeterminateSystems/magic-nix-cache-action@v13
19-
with:
20-
use-flakehub: false
21-
22-
- name: Cache Spago dependencies
23-
uses: actions/cache@v4
24-
with:
25-
path: |
26-
generate/.spago
27-
generate/output
28-
~/.cache/spago
29-
key: spago-${{ runner.os }}-${{ hashFiles('generate/spago.lock') }}
30-
restore-keys: |
31-
spago-${{ runner.os }}-
32-
33-
- name: Run spago tests
34-
run: |
35-
cd generate
36-
nix develop ..# --command bash -c "npm ci && spago test"
37-
38-
- name: Verify manifests
39-
run: |
40-
cd generate
41-
nix develop ..# --command spago run -p bin -m Bin.Main -- verify ../manifests
42-
43-
- name: Run flake checks
44-
run: nix flake check --print-build-logs
45-
46-
check-darwin:
47-
runs-on: macos-latest
48-
steps:
49-
- uses: actions/checkout@v6
50-
51-
- name: Install Nix
52-
uses: DeterminateSystems/nix-installer-action@v21
53-
54-
- name: Setup Nix cache
55-
uses: DeterminateSystems/magic-nix-cache-action@v13
56-
with:
57-
use-flakehub: false
58-
59-
- name: Run flake check
60-
run: nix flake check --print-build-logs
9+
check-linux:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v6
13+
14+
- name: Install Nix
15+
uses: DeterminateSystems/nix-installer-action@v21
16+
17+
- name: Setup Nix cache
18+
uses: DeterminateSystems/magic-nix-cache-action@v13
19+
with:
20+
use-flakehub: false
21+
22+
- name: Cache Spago dependencies
23+
uses: actions/cache@v4
24+
with:
25+
path: |
26+
generate/.spago
27+
generate/output
28+
~/.cache/spago
29+
key: spago-${{ runner.os }}-${{ hashFiles('generate/spago.lock') }}
30+
restore-keys: |
31+
spago-${{ runner.os }}-
32+
33+
- name: Run spago tests
34+
run: |
35+
cd generate
36+
nix develop ..# --command bash -c "npm ci && spago test"
37+
38+
- name: Verify manifests
39+
run: |
40+
cd generate
41+
nix develop ..# --command spago run -p bin -- --verbose verify ../manifests
42+
43+
- name: Run flake checks
44+
run: nix flake check --print-build-logs
45+
46+
check-darwin:
47+
runs-on: macos-latest
48+
steps:
49+
- uses: actions/checkout@v6
50+
51+
- name: Install Nix
52+
uses: DeterminateSystems/nix-installer-action@v21
53+
54+
- name: Setup Nix cache
55+
uses: DeterminateSystems/magic-nix-cache-action@v13
56+
with:
57+
use-flakehub: false
58+
59+
- name: Run flake check
60+
run: nix flake check --print-build-logs

.github/workflows/daily-update.yaml

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,30 @@ name: "daily-update"
44
# The importer is run every day at 07:00 UTC and can also be run manually from
55
# the 'Actions' tab.
66
on:
7-
workflow_dispatch:
8-
schedule:
9-
- cron: "0 7 * * *"
7+
workflow_dispatch:
8+
schedule:
9+
- cron: "0 7 * * *"
1010

1111
jobs:
12-
build:
13-
runs-on: ubuntu-latest
12+
build:
13+
runs-on: ubuntu-latest
1414

15-
env:
16-
REPO_TOKEN: ${{ secrets.REPO_TOKEN }}
15+
env:
16+
REPO_TOKEN: ${{ secrets.REPO_TOKEN }}
1717

18-
steps:
19-
- uses: actions/checkout@v6
18+
steps:
19+
- uses: actions/checkout@v6
2020

21-
- name: Install Nix
22-
uses: DeterminateSystems/nix-installer-action@v21
21+
- name: Install Nix
22+
uses: DeterminateSystems/nix-installer-action@v21
2323

24-
- name: Setup Nix cache
25-
uses: DeterminateSystems/magic-nix-cache-action@v13
26-
with:
27-
use-flakehub: false
24+
- name: Setup Nix cache
25+
uses: DeterminateSystems/magic-nix-cache-action@v13
26+
with:
27+
use-flakehub: false
2828

29-
- name: Run the generate script
30-
run: |
31-
cd generate
32-
npm ci
33-
nix develop --command spago run -p bin -m Bin.Main -- update ../manifests --commit
29+
- name: Run the generate script
30+
run: |
31+
cd generate
32+
npm ci
33+
nix develop --command spago run -p bin -- --verbose update ../manifests --commit

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ spago test
111111
# Verify manifests can be read correctly
112112
spago run -p bin -- verify ../manifests
113113

114+
# Use --verbose for detailed output (shows GitHub API calls, hashes, etc.)
115+
spago run -p bin -- --verbose verify ../manifests
116+
114117
# Check Nix formatting and package derivations
115118
cd ..
116119
nix flake check

generate/bin/spago.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package:
22
name: bin
3+
run:
4+
main: Bin.Main
35
dependencies:
46
- aff
57
- argparse-basic

generate/bin/src/AppM.purs

Lines changed: 37 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module Bin.AppM where
22

33
import Prelude
44

5+
import Bin.CLI (Verbosity(..))
56
import Control.Monad.Except (runExceptT)
67
import Control.Monad.Reader (class MonadAsk, class MonadReader, ReaderT, ask, runReaderT)
78
import Control.Monad.Reader as ReaderT
@@ -10,13 +11,12 @@ import Data.Newtype (class Newtype)
1011
import Effect.Aff (Aff)
1112
import Effect.Aff.Class (class MonadAff, liftAff)
1213
import Effect.Class (class MonadEffect)
14+
import Effect.Class.Console as Console
1315
import Lib.Foreign.Octokit (GitHubError, Octokit)
1416
import Lib.Git (GitM(..))
1517
import Lib.GitHub (GitHubM(..))
16-
import Lib.Nix.Manifest (CombinedManifest, GitHubBinaryManifest, NamedManifest, NPMRegistryManifest)
18+
import Lib.Nix.Manifest (ManifestCodec, NamedManifest)
1719
import Lib.Nix.Manifest as Nix.Manifest
18-
import Lib.Nix.Manifest as Tool
19-
import Lib.Tool (Tool(..))
2020
import Lib.Utils as Utils
2121
import Node.Path (FilePath)
2222
import Node.Path as Path
@@ -31,6 +31,7 @@ type Env =
3131
, tmpDir :: FilePath
3232
, gitBranch :: String
3333
, manifestDir :: FilePath
34+
, verbosity :: Verbosity
3435
}
3536

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

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

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

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

61-
getNamedManifestPath :: AppM FilePath
62-
getNamedManifestPath = do
63-
{ manifestDir } <- ask
64-
pure $ Path.concat [ manifestDir, Nix.Manifest.namedPath ]
65-
64+
-- | Read the named manifest (tool channel -> version mappings)
6665
readNamedManifest :: AppM NamedManifest
6766
readNamedManifest = do
68-
path <- getNamedManifestPath
69-
Utils.readJsonFile path Nix.Manifest.namedManifestCodec
67+
{ manifestDir } <- ask
68+
Utils.readJsonFile (Path.concat [ manifestDir, Nix.Manifest.namedPath ]) Nix.Manifest.namedManifestCodec
7069

70+
-- | Write the named manifest
7171
writeNamedManifest :: NamedManifest -> AppM Unit
7272
writeNamedManifest manifest = do
73-
path <- getNamedManifestPath
74-
Utils.writeJsonFile path Nix.Manifest.namedManifestCodec manifest
75-
76-
getToolManifestPath :: Tool -> AppM FilePath
77-
getToolManifestPath tool = do
7873
{ manifestDir } <- ask
79-
pure $ Path.concat [ manifestDir, Tool.filename tool ]
80-
81-
readPursManifest :: AppM GitHubBinaryManifest
82-
readPursManifest = do
83-
path <- getToolManifestPath Purs
84-
Utils.readJsonFile path Nix.Manifest.githubBinaryManifestCodec
85-
86-
writePursManifest :: GitHubBinaryManifest -> AppM Unit
87-
writePursManifest manifest = do
88-
path <- getToolManifestPath Purs
89-
Utils.writeJsonFile path Nix.Manifest.githubBinaryManifestCodec manifest
90-
91-
readSpagoManifest :: AppM CombinedManifest
92-
readSpagoManifest = do
93-
path <- getToolManifestPath Spago
94-
Utils.readJsonFile path Nix.Manifest.combinedManifestCodec
74+
Utils.writeJsonFile (Path.concat [ manifestDir, Nix.Manifest.namedPath ]) Nix.Manifest.namedManifestCodec manifest
9575

96-
writeSpagoManifest :: CombinedManifest -> AppM Unit
97-
writeSpagoManifest manifest = do
98-
path <- getToolManifestPath Spago
99-
Utils.writeJsonFile path Nix.Manifest.combinedManifestCodec manifest
100-
101-
readPursTidyManifest :: AppM NPMRegistryManifest
102-
readPursTidyManifest = do
103-
path <- getToolManifestPath PursTidy
104-
Utils.readJsonFile path Nix.Manifest.npmRegistryManifestCodec
105-
106-
writePursTidyManifest :: NPMRegistryManifest -> AppM Unit
107-
writePursTidyManifest manifest = do
108-
path <- getToolManifestPath PursTidy
109-
Utils.writeJsonFile path Nix.Manifest.npmRegistryManifestCodec manifest
110-
111-
readPursBackendEsManifest :: AppM NPMRegistryManifest
112-
readPursBackendEsManifest = do
113-
path <- getToolManifestPath PursBackendEs
114-
Utils.readJsonFile path Nix.Manifest.npmRegistryManifestCodec
115-
116-
writePursBackendEsManifest :: NPMRegistryManifest -> AppM Unit
117-
writePursBackendEsManifest manifest = do
118-
path <- getToolManifestPath PursBackendEs
119-
Utils.writeJsonFile path Nix.Manifest.npmRegistryManifestCodec manifest
120-
121-
readPursLanguageServerManifest :: AppM NPMRegistryManifest
122-
readPursLanguageServerManifest = do
123-
path <- getToolManifestPath PursLanguageServer
124-
Utils.readJsonFile path Nix.Manifest.npmRegistryManifestCodec
76+
-- | Read a tool's manifest using its codec
77+
readManifest :: forall a. ManifestCodec a -> AppM a
78+
readManifest { codec, tool } = do
79+
{ manifestDir } <- ask
80+
Utils.readJsonFile (Path.concat [ manifestDir, Nix.Manifest.filename tool ]) codec
12581

126-
writePursLanguageServerManifest :: NPMRegistryManifest -> AppM Unit
127-
writePursLanguageServerManifest manifest = do
128-
path <- getToolManifestPath PursLanguageServer
129-
Utils.writeJsonFile path Nix.Manifest.npmRegistryManifestCodec manifest
82+
-- | Write a tool's manifest using its codec
83+
writeManifest :: forall a. ManifestCodec a -> a -> AppM Unit
84+
writeManifest { codec, tool } manifest = do
85+
{ manifestDir } <- ask
86+
Utils.writeJsonFile (Path.concat [ manifestDir, Nix.Manifest.filename tool ]) codec manifest
87+
88+
-- | Log a message (always shown unless Quiet)
89+
log :: String -> AppM Unit
90+
log msg = do
91+
{ verbosity } <- ask
92+
when (verbosity > Quiet) $ Console.log $ "[INFO] " <> msg
93+
94+
-- | Log a message only in Verbose mode
95+
debug :: String -> AppM Unit
96+
debug msg = do
97+
{ verbosity } <- ask
98+
when (verbosity >= Verbose) $ Console.log $ "[DEBUG] " <> msg

0 commit comments

Comments
 (0)