diff --git a/.travis.yml b/.travis.yml index f5ce7bc..62b068c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -80,3 +80,19 @@ script: # `cabal install --force-reinstalls dist/*-*.tar.gz` - SRC_TGZ=$(cabal info . | awk '{print $2;exit}').tar.gz && (cd dist && cabal install --force-reinstalls "$SRC_TGZ") + +before_deploy: + - cp dist/build/cpl/cpl ./ + - cabal install turtle + - runghc misc/build_zip.hs + +deploy: + provider: releases + api_key: + secure: "JCuU9VnFu3wdhlUT87jqO3t/dBcfP3UnNL6UVk6wEawje9tEoAcxpHj6aV45qo+noMTSzgNrqI5mkWT1ZDjnLfgBJz9ImbeAf0jeMoITNAc4S9aYNku2hHrJ4kQfnEHeS8++2Y5u9bKbXW1MG6RK4iJXOWD9rdc8IK/687DrC4Q=" + file_glob: true + file: '*.zip' + skip_cleanup: true + on: + tags: true + condition: "$GHCVER = 8.2.2" diff --git a/CPL.cabal b/CPL.cabal index ebbe9b9..2be65be 100644 --- a/CPL.cabal +++ b/CPL.cabal @@ -40,6 +40,7 @@ Extra-Source-Files: windows/CPL.wxs, windows/build_msi.hs, windows/build_zip.hs, + misc/build_zip.hs, build_bdist_linux.sh Build-Type: Simple diff --git a/misc/build_zip.hs b/misc/build_zip.hs new file mode 100644 index 0000000..3632b0f --- /dev/null +++ b/misc/build_zip.hs @@ -0,0 +1,53 @@ +{-# OPTIONS_GHC -Wall #-} +{-# LANGUAGE ScopedTypeVariables, OverloadedStrings #-} +import Control.Exception +import Control.Monad +import Data.String +import Distribution.Package +import Distribution.PackageDescription +import Distribution.PackageDescription.Parse +import Distribution.Verbosity +import Distribution.Version +import qualified System.Info as SysInfo +import System.Process +import Turtle hiding (FilePath) + +getGitHash :: IO (Maybe String) +getGitHash = + liftM (Just . takeWhile (/='\n')) (readProcess "git" ["rev-parse", "--short", "HEAD"] "") + `catch` \(_::SomeException) -> return Nothing + +getVersion :: FilePath -> IO Version +getVersion cabalFile = do + pkg <- readPackageDescription silent cabalFile + return $ pkgVersion $ package $ packageDescription $ pkg + +main :: IO () +main = do + gitHashMaybe <- getGitHash + version <- getVersion "CPL.cabal" + let suffix_githash = + case gitHashMaybe of + Nothing -> "" + Just gitHash -> "_" ++ gitHash + dir :: IsString a => a + dir = fromString $ "CPL-" ++ showVersion version ++ suffix_githash ++ "-" ++ SysInfo.os ++ "-" ++ SysInfo.arch + + let binDir = dir "bin" + samplesDir = dir "samples" + zipFile :: IsString a => a + zipFile = fromString (dir ++ ".zip") + testfile zipFile >>= \b -> when b (rm zipFile) + testfile dir >>= \b -> when b (rmtree dir) + mktree dir + mktree binDir + mktree samplesDir + cp ("cpl") (binDir "cpl") + sh $ do + fpath <- ls "samples" + cp fpath (samplesDir filename fpath) + cp "COPYING" (dir "COPYING") + cp "README.markdown" (dir "README.markdown") + cp "CHANGELOG.markdown" (dir "CHANGELOG.markdown") + procs "zip" ["-r", zipFile, dir] empty + return ()