Skip to content

fix build with remote config and update ci #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 4, 2025
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
55 changes: 44 additions & 11 deletions .github/workflows/cabal-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,29 @@ jobs:
strategy:
fail-fast: false
matrix:
ghc: ['8.10.7', '9.0.1', '9.2', '9.4', '9.6']
cabal: ['3.10']
os: ['ubuntu-22.04', 'ubuntu-20.04', 'macOS-latest']
ghc: ['9.4', '9.6', '9.8', '9.10', '9.12']
cabal: ['latest']
os: ['ubuntu-22.04', 'ubuntu-24.04', 'macOS-latest']
remoteConfigs: ['-remote-configs', '+remote-configs']
include:
- ghc: '9.2'
cabal: '3.6'
- ghc: '9.6'
cabal: '3.8'
os: 'ubuntu-22.04'
remoteConfigs: '+remote-configs'
remoteConfigs: '-remote-configs'


steps:

# Setup
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install GHC and Cabal
uses: haskell/actions/setup@v2
uses: haskell-actions/setup@v2
with:
ghc-version: ${{ matrix.ghc }}
cabal-version: ${{ matrix.cabal }}

- name: Configure project
run: |
cat > cabal.project.local <<EOF
Expand All @@ -41,24 +44,54 @@ jobs:
EOF

# Restore Packages from Caches
- uses: actions/cache@v3
name: Cache cabal packages
- name: Restore cache ~/.cabal/packages and ~/.cabal/store
id: deps-cache-restore
uses: actions/cache/restore@v4
with:
path: |
~/.cabal/packages
~/.cabal/store
key: deps-${{ matrix.os }}-${{ matrix.ghc }}-${{ hashFiles('**/*.cabal', '**/cabal.project', '**/cabal.project.local') }}
restore-keys: |
deps-${{ matrix.os }}-${{ matrix.ghc }}-

# Restore dist-newstyle
- name: Cache dist-newstyle
uses: actions/cache@v4
with:
path: |
dist-newstyle
key: ${{ matrix.os }}-${{ matrix.ghc }}-cabal
key: dist-${{ matrix.os }}-${{ matrix.ghc }}-${{ hashFiles('**/*.cabal', '**/cabal.project', '**/cabal.project.local') }}
restore-keys: |
dist-${{ matrix.os }}-${{ matrix.ghc }}-
save-always: true

# Build
- name: Update package database
run: cabal update

- name: Configure build
run: |
cabal build all --dry-run
cabal freeze
cat cabal.project.freeze

- name: Show outdated packages
run: cabal outdated

- name: Install build dependencies
run: cabal build --only-dependencies

# Save packages
- name: Save cache for ~/.cabal/packages and ~/.cabal/store
uses: actions/cache/save@v4
if: always()
with:
path: |
~/.cabal/packages
~/.cabal/store
key: ${{ steps.deps-cache-restore.outputs.cache-primary-key }}

- name: Build library
run: cabal build

Expand Down
49 changes: 35 additions & 14 deletions Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ import Distribution.Simple.BuildPaths
import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.PackageIndex
import Distribution.Simple.Setup
import Distribution.Simple.Utils (createDirectoryIfMissingVerbose)
import Distribution.Text
import Distribution.Utils.Path
import Distribution.Utils.ShortText
Expand All @@ -128,10 +129,17 @@ import Data.Monoid
import Prelude hiding (readFile, writeFile)

import System.Directory
(canonicalizePath, createDirectoryIfMissing, doesDirectoryExist,
doesFileExist, getCurrentDirectory)
( canonicalizePath
, doesDirectoryExist
, doesFileExist
, getCurrentDirectory
)
import System.Exit (ExitCode(ExitSuccess))
#if MIN_VERSION_Cabal(3,14,0)
import System.FilePath (isDrive, takeDirectory)
#else
import System.FilePath (isDrive, takeDirectory, (</>))
#endif

-- | Include this function when your setup doesn't contain any
-- extra functionality.
Expand Down Expand Up @@ -162,6 +170,11 @@ mkPkgInfoModules hooks = hooks
prettyLicense :: I.InstalledPackageInfo -> String
prettyLicense = either prettyShow prettyShow . I.license

#if !MIN_VERSION_Cabal(3,14,0)
interpretSymbolicPath :: Maybe () -> FilePath -> FilePath
interpretSymbolicPath _ p = p
#endif

-- -------------------------------------------------------------------------- --
-- Cabal 2.0

Expand All @@ -173,28 +186,31 @@ mkPkgInfoModulesPostConf
-> LocalBuildInfo
-> IO ()
mkPkgInfoModulesPostConf hook args flags pkgDesc bInfo = do
mapM_ (updatePkgInfoModule pkgDesc bInfo) $ Graph.toList $ componentGraph bInfo
mapM_ (updatePkgInfoModule pkgDesc bInfo flags) $ Graph.toList $ componentGraph bInfo
hook args flags pkgDesc bInfo

updatePkgInfoModule :: PackageDescription -> LocalBuildInfo -> ComponentLocalBuildInfo -> IO ()
updatePkgInfoModule pkgDesc bInfo clbInfo = do
createDirectoryIfMissing True dirName
updatePkgInfoModule
:: PackageDescription
-> LocalBuildInfo
-> ConfigFlags
-> ComponentLocalBuildInfo
-> IO ()
updatePkgInfoModule pkgDesc bInfo flags clbInfo = do
createDirectoryIfMissingVerbose verbosity True dirName
moduleBytes <- pkgInfoModule moduleName cName pkgDesc bInfo
updateFile fileName moduleBytes

-- legacy module
legacyModuleBytes <- pkgInfoModule legacyModuleName cName pkgDesc bInfo
updateFile legacyFileName legacyModuleBytes

where
dirName = autogenComponentModulesDir bInfo clbInfo
verbosity = fromFlag $ configVerbosity flags
dirName = interpretSymbolicPath Nothing $ autogenComponentModulesDir bInfo clbInfo
cName = unUnqualComponentName <$> componentNameString (componentLocalName clbInfo)

moduleName = pkgInfoModuleName
fileName = dirName ++ "/" ++ moduleName ++ ".hs"

fileName = dirName </> moduleName <> ".hs"
legacyModuleName = legacyPkgInfoModuleName cName
legacyFileName = dirName ++ "/" ++ legacyModuleName ++ ".hs"
legacyFileName = dirName </> legacyModuleName <> ".hs"

-- -------------------------------------------------------------------------- --
-- Generate PkgInfo Module
Expand All @@ -214,7 +230,7 @@ updateFile fileName content = do

legacyPkgInfoModuleName :: Maybe String -> String
legacyPkgInfoModuleName Nothing = "PkgInfo"
legacyPkgInfoModuleName (Just cn) = "PkgInfo_" ++ map tr cn
legacyPkgInfoModuleName (Just cn) = "PkgInfo_" <> map tr cn
where
tr '-' = '_'
tr c = c
Expand All @@ -236,7 +252,12 @@ getVCS = getCurrentDirectory >>= getVcsOfDir
then return Nothing
else getVcsOfDir (takeDirectory canonicDir)

pkgInfoModule :: String -> Maybe String -> PackageDescription -> LocalBuildInfo -> IO B.ByteString
pkgInfoModule
:: String
-> Maybe String
-> PackageDescription
-> LocalBuildInfo
-> IO B.ByteString
pkgInfoModule moduleName cName pkgDesc bInfo = do
(tag, revision, branch) <- getVCS >>= \case
Just Mercurial -> hgInfo
Expand Down
5 changes: 2 additions & 3 deletions src/Configuration/Utils/ConfigFile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ import Data.Maybe
import Data.Monoid.Unicode
import Data.String
import qualified Data.Text as T
import Data.Typeable

import Prelude hiding (any, concatMap, mapM_)

Expand Down Expand Up @@ -254,7 +253,7 @@ infix 6 %.:
data ConfigFile
= ConfigFileRequired { getConfigFile ∷ !T.Text }
| ConfigFileOptional { getConfigFile ∷ !T.Text }
deriving (Show, Read, Eq, Ord, Typeable)
deriving (Show, Read, Eq, Ord)

-- | An /internal/ type for the meta configuration that specifies how the
-- configuration files are loaded and parsed.
Expand All @@ -263,7 +262,7 @@ data ConfigFile
data ConfigFilesConfig = ConfigFilesConfig
{ _cfcHttpsPolicy ∷ !HttpsCertPolicy
}
deriving (Show, Eq, Typeable)
deriving (Show, Eq)

cfcHttpsPolicy ∷ Lens' ConfigFilesConfig HttpsCertPolicy
cfcHttpsPolicy = lens _cfcHttpsPolicy $ \a b → a { _cfcHttpsPolicy = b }
Expand Down
3 changes: 1 addition & 2 deletions src/Configuration/Utils/Internal/ConfigFileReader.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import Data.Bifunctor
import qualified Data.ByteString.Char8 as B8
import Data.Monoid.Unicode
import qualified Data.Text as T
import Data.Typeable
import qualified Data.Yaml as Yaml

import GHC.Generics
Expand Down Expand Up @@ -155,7 +154,7 @@ data ConfigFileFormat
= Yaml
| Json
| Other
deriving (Show, Read, Eq, Ord, Enum, Bounded, Typeable, Generic)
deriving (Show, Read, Eq, Ord, Enum, Bounded, Generic)

instance NFData ConfigFileFormat

Expand Down
7 changes: 3 additions & 4 deletions src/Configuration/Utils/Internal/HttpsCertPolicy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import Data.Monoid.Unicode
import Data.String
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import Data.Typeable
import qualified Data.X509 as TLS
import qualified Data.X509.Validation as TLS

Expand Down Expand Up @@ -80,7 +79,7 @@ data HttpsCertPolicy = HttpsCertPolicy
, _certPolicyHostFingerprints ∷ !(HM.HashMap TLS.ServiceID TLS.Fingerprint)
-- ^ a whitelist for services with trusted certificates
}
deriving (Show, Eq, Typeable)
deriving (Show, Eq)

certPolicyInsecure ∷ Lens' HttpsCertPolicy Bool
certPolicyInsecure = lens _certPolicyInsecure $ \s a → s { _certPolicyInsecure = a }
Expand Down Expand Up @@ -177,7 +176,7 @@ httpWithValidationPolicy request policy = do
-- In particular exceptions should include rejected certificates.
--
newtype VerboseTlsException = VerboseTlsException T.Text
deriving (Eq, Ord, Typeable)
deriving (Eq, Ord)

instance Show VerboseTlsException where
show (VerboseTlsException msg) = "TLS exception: " ⊕ T.unpack msg
Expand All @@ -189,7 +188,7 @@ handleTlsException
→ Maybe (TLS.SignedExact TLS.Certificate)
→ TLS.TLSException
→ IO a
handleTlsException request cert e@(TLS.HandshakeFailed (TLS.Error_Protocol (msg, _b, _alert)))
handleTlsException request cert e@(TLS.HandshakeFailed (TLS.Error_Protocol msg _))
| "certificate rejected: [SelfSigned]" `L.isPrefixOf` msg = throwIO ∘ VerboseTlsException
$ "The server uses a self-signed certificate. If you are sure that no-one"
⊕ " is intercepting the connection and this is the correct certificate you"
Expand Down
Loading
Loading