-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upload binaries to GitHub Releases from Travis-CI
- Loading branch information
Showing
3 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 () |