Skip to content

Commit

Permalink
upload binaries to GitHub Releases from Travis-CI
Browse files Browse the repository at this point in the history
  • Loading branch information
msakai committed Feb 16, 2018
1 parent b9cc5a6 commit 189c492
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
1 change: 1 addition & 0 deletions CPL.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
53 changes: 53 additions & 0 deletions misc/build_zip.hs
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 ()

0 comments on commit 189c492

Please sign in to comment.