From afe808c22741247d01d356b1670da535d10d6baa Mon Sep 17 00:00:00 2001 From: Aaron VonderHaar Date: Sat, 11 Mar 2023 12:54:43 -0800 Subject: [PATCH 1/4] Build haddock docs for elm-format-lib --- README.md | 6 +--- Shakefile/build-elm-format.cabal | 4 ++- Shakefile/package.yaml | 2 ++ Shakefile/src/Main.hs | 11 +++++++ Shakefile/src/Shakefiles/Haskell.hs | 46 +++++++++++++++++++++++++++++ dev/Documentation/Build Commands.md | 4 +++ dev/Documentation/README.md | 1 + dev/build.sh | 2 +- shell.nix | 1 + 9 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 dev/Documentation/Build Commands.md diff --git a/README.md b/README.md index 022dc2c6e..5e2fd7c0f 100644 --- a/README.md +++ b/README.md @@ -316,8 +316,4 @@ dev/build.sh -- build ./_build/elm-format ``` -### Running tests - -```bash -dev/build.sh -``` +See [`dev/Documentation`](dev/Documentation/README.md) for more contributor and build command documentation. diff --git a/Shakefile/build-elm-format.cabal b/Shakefile/build-elm-format.cabal index 9ff9e860d..a81aa3bbd 100644 --- a/Shakefile/build-elm-format.cabal +++ b/Shakefile/build-elm-format.cabal @@ -27,7 +27,9 @@ executable build-elm-format LambdaCase ghc-options: -rtsopts -threaded -with-rtsopts=-I0 build-depends: - base >=4.16.2.0 + aeson >=2.0.0.0 + , base >=4.16.2.0 , directory >=1.3.6.2 , shake >=0.19.6 && <0.20 + , yaml default-language: Haskell2010 diff --git a/Shakefile/package.yaml b/Shakefile/package.yaml index 7d8af5332..4cb386498 100644 --- a/Shakefile/package.yaml +++ b/Shakefile/package.yaml @@ -13,9 +13,11 @@ ghc-options: - -with-rtsopts=-I0 dependencies: + aeson: ">= 2.0.0.0" base: ">= 4.16.2.0" directory: ">= 1.3.6.2" shake: ">=0.19.6 && <0.20" + yaml: {} executables: diff --git a/Shakefile/src/Main.hs b/Shakefile/src/Main.hs index 67b94dff5..a19a28df5 100644 --- a/Shakefile/src/Main.hs +++ b/Shakefile/src/Main.hs @@ -50,6 +50,9 @@ rules = do phony "generated" $ need [ "generated/Build_elm_format.hs" ] + phony "docs" $ need + [ "_build/docs/elm-format-lib.ok" + ] phony "unit-tests" $ need [ "_build/cabal/elm-format-lib/test.ok" , "_build/cabal/elm-format-test-lib/test.ok" @@ -142,3 +145,11 @@ rules = do Shakefiles.NestedCheckout.rules Shakefiles.Shellcheck.rules shellcheck + + -- + -- Dev tools + -- + + phony "serve:docs" $ do + need [ "docs" ] + cmd_ "simple-http-server" "--index" "_build/docs/public" diff --git a/Shakefile/src/Shakefiles/Haskell.hs b/Shakefile/src/Shakefiles/Haskell.hs index a54103931..5a82e02a4 100644 --- a/Shakefile/src/Shakefiles/Haskell.hs +++ b/Shakefile/src/Shakefiles/Haskell.hs @@ -10,6 +10,15 @@ import qualified Shakefiles.Platform import Data.Char (isSpace) import Data.List (dropWhileEnd, stripPrefix) import Shakefiles.Extra +import System.Directory (createDirectoryIfMissing) +import Data.Yaml (FromJSON, (.:)) +import Data.Yaml.TH (FromJSON(..)) +import qualified Data.Yaml as Yaml +import qualified Data.Aeson.Key as Key + + +docsDir :: FilePath +docsDir = "_build/docs/public" cabalProject :: String -> [String] -> [String] -> [String] -> [String] -> [String] -> Rules () @@ -33,6 +42,12 @@ cabalProject name sourceFiles sourcePatterns deps testPatterns testDeps = liftIO $ getHashedShakeVersion allFiles in do + "_build/cabal/" name "version" %> \out -> do + let packageYaml = name "package.yaml" + need [ packageYaml ] + (VersionFromYaml version) <- Yaml.decodeFileThrow packageYaml + writeFileChanged out version + "_build/cabal/" name "build.ok" %> \out -> do hash <- needProjectFiles cmd_ "cabal" "v2-build" "-O0" (name ++ ":libs") "--enable-tests" @@ -58,6 +73,29 @@ cabalProject name sourceFiles sourcePatterns deps testPatterns testDeps = cmd_ "cabal" "v2-test" "-O0" (name ++ ":tests") "--test-show-details=streaming" writeFile' out "" + "_build/cabal/" name "haddock.ok" %> \out -> do + hash <- needProjectFiles + cmd_ "cabal" "v2-haddock" + "--haddock-html" + --"--haddock-for-hackage" -- broken in current haddock + name + writeFile' out hash + + "_build/docs/" name <.> "ok" %> \out -> do + let haddockOk = "_build/cabal" name "haddock.ok" + need [ haddockOk ] + buildDir <- cabalBuildDir name + let docsBuildDir = buildDir "doc" "html" name + liftIO $ createDirectoryIfMissing True docsDir + cmd_ "rsync" "-a" "--delete" (docsBuildDir <> "/") (docsDir name <> "/") + copyFileChanged haddockOk out + + +cabalBuildDir :: String -> Action FilePath +cabalBuildDir projectName = do + version <- readFile' ("_build/cabal" projectName "version") + return $ "dist-newstyle" "build" Shakefiles.Platform.cabalInstallOs "ghc-9.2.5" projectName ++ "-" ++ version + cabalBinPath :: String -> String -> FilePath cabalBinPath projectName opt = @@ -169,3 +207,11 @@ executable target projectName gitDescribe = "publish" "*" projectName ++ "-*-" ++ show target <.> zipExt %> \out -> do let source = "_build" "github-ci" "unzipped" takeFileName out copyFileChanged source out + + +newtype VersionFromYaml = + VersionFromYaml String + +instance FromJSON VersionFromYaml where + parseJSON = Yaml.withObject "hpack" $ \o -> VersionFromYaml + <$> o .: Key.fromString "version" diff --git a/dev/Documentation/Build Commands.md b/dev/Documentation/Build Commands.md new file mode 100644 index 000000000..b75c15ae8 --- /dev/null +++ b/dev/Documentation/Build Commands.md @@ -0,0 +1,4 @@ + +- `dev/build.sh`: build and run tests +- `dev/build.sh build`: build a local binary to `./_build/elm-format` +- `dev/build.sh serve:docs`: start a local HTTP server with the public Haskell API docs diff --git a/dev/Documentation/README.md b/dev/Documentation/README.md index 525fb41a7..2ec4d7290 100644 --- a/dev/Documentation/README.md +++ b/dev/Documentation/README.md @@ -1,4 +1,5 @@ Documentation about the development and maintenance of elm-format itself. +- [Build Commands.md](./Build Commands.md): List of useful build and dev commands - [Publishing.md](./Publishing.md): Instructions on how to publish a new release of elm-format diff --git a/dev/build.sh b/dev/build.sh index 3b6b1d7e7..fb445fff5 100755 --- a/dev/build.sh +++ b/dev/build.sh @@ -7,4 +7,4 @@ set -euo pipefail (cd elm-format-lib && hpack) (cd elm-format-test-lib && hpack) hpack -exec cabal run build-elm-format:exe:build-elm-format -- --share "$@" +exec cabal run build-elm-format:exe:build-elm-format -- "$@" diff --git a/shell.nix b/shell.nix index 1a26f0370..1f9e449bc 100644 --- a/shell.nix +++ b/shell.nix @@ -32,5 +32,6 @@ in haskellPackages.shellFor { nix-prefetch nodejs minisign + simple-http-server ]; } From 6c3d08b8439cdccd0dba6505d870c6f18a26e95d Mon Sep 17 00:00:00 2001 From: Aaron VonderHaar Date: Sat, 11 Mar 2023 12:56:30 -0800 Subject: [PATCH 2/4] Build haddock docs on CI (attempt 1) --- .github/workflows/CI.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 585ef357a..67ed20d31 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -36,9 +36,10 @@ jobs: - name: Tests if: runner.os != 'Windows' run: | - ./dev/build.sh + ./dev/build.sh -- test - name: Tests (for Windows) if: runner.os == 'Windows' run: | ./dev/build.sh -- unit-tests echo "##[warning]integration tests are currently disabled on Windows CI" + - run: ./dev/build.sh -- docs From 246536dcac86a9c6b6cb0dc1beea189ab5fb810f Mon Sep 17 00:00:00 2001 From: Aaron VonderHaar Date: Sat, 11 Mar 2023 13:02:28 -0800 Subject: [PATCH 3/4] Add dev/build.sh ci --- Shakefile/src/Main.hs | 6 ++++++ dev/Documentation/Build Commands.md | 1 + 2 files changed, 7 insertions(+) diff --git a/Shakefile/src/Main.hs b/Shakefile/src/Main.hs index a19a28df5..c80db942f 100644 --- a/Shakefile/src/Main.hs +++ b/Shakefile/src/Main.hs @@ -63,6 +63,12 @@ rules = do phonyPrefix "publish-" $ \version -> need [ "elm-format-publish-" ++ version ] + phony "ci" $ need + [ "build" + , "test" + , "docs" + ] + phony "clean" $ do removeFilesAfter "dist-newstyle" [ "//*" ] removeFilesAfter "_build" [ "//*" ] diff --git a/dev/Documentation/Build Commands.md b/dev/Documentation/Build Commands.md index b75c15ae8..3b972cbee 100644 --- a/dev/Documentation/Build Commands.md +++ b/dev/Documentation/Build Commands.md @@ -1,4 +1,5 @@ - `dev/build.sh`: build and run tests - `dev/build.sh build`: build a local binary to `./_build/elm-format` +- `dev/build.sh ci`: run all build targets that are checked on CI - `dev/build.sh serve:docs`: start a local HTTP server with the public Haskell API docs From 837148027e302d2bb102e6200a4ef7dc4ea6b4cc Mon Sep 17 00:00:00 2001 From: Aaron VonderHaar Date: Sat, 11 Mar 2023 13:49:04 -0800 Subject: [PATCH 4/4] Build haddock docs on CI (attempt 2) --- Shakefile/build-elm-format.cabal | 1 + Shakefile/package.yaml | 1 + Shakefile/src/Shakefiles/Haskell.hs | 9 +++++++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Shakefile/build-elm-format.cabal b/Shakefile/build-elm-format.cabal index a81aa3bbd..096f62741 100644 --- a/Shakefile/build-elm-format.cabal +++ b/Shakefile/build-elm-format.cabal @@ -30,6 +30,7 @@ executable build-elm-format aeson >=2.0.0.0 , base >=4.16.2.0 , directory >=1.3.6.2 + , relude , shake >=0.19.6 && <0.20 , yaml default-language: Haskell2010 diff --git a/Shakefile/package.yaml b/Shakefile/package.yaml index 4cb386498..13598e4c5 100644 --- a/Shakefile/package.yaml +++ b/Shakefile/package.yaml @@ -17,6 +17,7 @@ dependencies: base: ">= 4.16.2.0" directory: ">= 1.3.6.2" shake: ">=0.19.6 && <0.20" + relude: {} yaml: {} diff --git a/Shakefile/src/Shakefiles/Haskell.hs b/Shakefile/src/Shakefiles/Haskell.hs index 5a82e02a4..dc98f7c69 100644 --- a/Shakefile/src/Shakefiles/Haskell.hs +++ b/Shakefile/src/Shakefiles/Haskell.hs @@ -10,11 +10,12 @@ import qualified Shakefiles.Platform import Data.Char (isSpace) import Data.List (dropWhileEnd, stripPrefix) import Shakefiles.Extra -import System.Directory (createDirectoryIfMissing) +import System.Directory (createDirectoryIfMissing, removeDirectoryRecursive) import Data.Yaml (FromJSON, (.:)) import Data.Yaml.TH (FromJSON(..)) import qualified Data.Yaml as Yaml import qualified Data.Aeson.Key as Key +import Relude.Bool.Guard (whenM) docsDir :: FilePath @@ -87,7 +88,11 @@ cabalProject name sourceFiles sourcePatterns deps testPatterns testDeps = buildDir <- cabalBuildDir name let docsBuildDir = buildDir "doc" "html" name liftIO $ createDirectoryIfMissing True docsDir - cmd_ "rsync" "-a" "--delete" (docsBuildDir <> "/") (docsDir name <> "/") + let docsOutDir = docsDir name + whenM + (doesDirectoryExist docsOutDir) + (liftIO $ removeDirectoryRecursive docsOutDir) + cmd_ "cp" "-r" (docsBuildDir <> "/") docsOutDir copyFileChanged haddockOk out