Skip to content
This repository was archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Merge branch 'release/0.6.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
smallhadroncollider committed Jan 24, 2020
2 parents 6066d15 + 76c4508 commit b1bebb6
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 28 deletions.
55 changes: 42 additions & 13 deletions .bin/build
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
resolver="lts-13.13"
ghcv="8.6.4"
# stop on any errors
set -e

workDir=".stack-build"
branch=$(git rev-parse --abbrev-ref HEAD)

if [ $branch != "master" ]; then
echo "\033[0;31mMust be on master branch\033[0m"
exit
fi

if [ ! -d ".stack-work" ]; then
if [ ! -d "$workDir" ]; then
echo "\033[0;31mMust be run in project root\033[0m"
exit
fi
Expand All @@ -18,40 +19,58 @@ if [ -z "$1" ]; then
exit
fi

# stash any changes
git stash

# check cabal build works
cabal build

if [ $? -ne 0 ]
then
git stash pop
echo "\033[0;31mCabal build failed\033[0m"
exit
fi

# make sure latest changes pushed to github
git push --all && git push --tags

# clean out previous build attempts
rm -rf .stack-work/install
rm -rf "$workDir/install"

# sort out releases directory
rm -rf "releases/$1/cmt"
mkdir -p "releases/$1/cmt"

# Mac
stack build --ghc-options -O3
stack build --work-dir "$workDir" --ghc-options -O3

strip "$(stack path --local-install-root --work-dir $workDir)/bin/cmt" # remove tokens

tar -czvf "releases/$1/cmt-$1_x86-64-mac.tar.gz" --directory=".stack-work/install/x86_64-osx/$resolver/$ghcv/bin" "cmt"
tar -czvf "releases/$1/cmt-$1_x86-64-mac.tar.gz" --directory="$(stack path --local-install-root --work-dir $workDir)/bin" "cmt"


# Linux
stack docker pull
stack build --docker --ghc-options -O3
stack build --work-dir "$workDir" --docker --ghc-options -O3

LINUX_DIR=$(ls .stack-work/install | grep linux)
LINUX_FULL_PATH=$(find "$workDir" -path "*linux*" -and -path "*bin/cmt")
LINUX_PATH=${LINUX_FULL_PATH%"cmt"}

tar -czvf "releases/$1/cmt-$1_x86-64-linux.tar.gz" --directory=".stack-work/install/$LINUX_DIR/$resolver/$ghcv/bin" "cmt"
strip "$LINUX_FULL_PATH" # remove tokens

tar -czvf "releases/$1/cmt-$1_x86-64-linux.tar.gz" --directory="$LINUX_PATH" "cmt"

mkdir -p "releases/$1/cmt/DEBIAN"
mkdir -p "releases/$1/cmt/usr/local/bin"

cp ".stack-work/install/$LINUX_DIR/$resolver/$ghcv/bin/cmt" "releases/$1/cmt/usr/local/bin"
cp "$LINUX_PATH/cmt" "releases/$1/cmt/usr/local/bin"

echo "Package: cmt
Version: $1
Maintainer: Mark Wales
Architecture: amd64
Description: Finds cmten links in text files" > "releases/$1/cmt/DEBIAN/control"
Description: Find cmten links in text documents" > "releases/$1/cmt/DEBIAN/control"

docker run -v "$PWD/releases/$1":/usr/src/app -w /usr/src/app debian dpkg-deb --build cmt

Expand All @@ -63,11 +82,21 @@ rm -rf "releases/$1/cmt"
open "releases/$1"
open "https://github.com/smallhadroncollider/cmt/releases/new"

echo "-
echo "
-

### Installation

- Mac/Linux: download binary and place it in a directory in your \`\$PATH\` (e.g. \`/usr/local/bin\`)
- Debian (including Ubuntu): download the \`.deb\` file and run \`dpkg -i cmt-$1_x86-64-linux.deb\`" | pbcopy
- Debian (including Ubuntu): download the \`.deb\` file and run \`dpkg -i cmt-$1_x86-64-linux.deb\`. You may also need to install the \`libtinfo5\` package (\`sudo apt install libtinfo5\`)
- Fedora: Run \`sudo dnf install ncurses-compat-libs\` then download and run binary as described above" | pbcopy

echo "Release info copied to clipboard"


# add to Hackage
stack upload .


# unstash
git stash pop
1 change: 1 addition & 0 deletions .bin/cmt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
stack build --test && stack install > /dev/null && ~/.local/bin/cmt $@
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: cmt
version: 0.5.0.0
version: 0.6.0.0
github: "smallhadroncollider/cmt"
license: BSD3
author: "Small Hadron Collider / Mark Wales"
Expand Down
11 changes: 7 additions & 4 deletions src/Cmt.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import ClassyPrelude

import Data.Text (stripEnd)
import System.Directory (removeFile)
import System.Exit (exitFailure, exitSuccess)
import System.Exit (ExitCode (..), exitFailure, exitSuccess)

import Cmt.IO.Config (checkFormat, load, readCfg)
import Cmt.IO.Git (commit)
Expand All @@ -24,6 +24,7 @@ data Next
| PreDefined Text
Outputs
| Continue Outputs
| Version

backup :: FilePath
backup = ".cmt.bkp"
Expand All @@ -35,10 +36,10 @@ send :: Text -> IO ()
send txt = do
commited <- commit $ stripEnd txt
case commited of
Right msg -> putStrLn msg >> exitSuccess
Left msg -> do
ExitSuccess -> exitSuccess
ExitFailure _ -> do
writeFile backup (encodeUtf8 txt)
failure msg
exitFailure

display :: Either Text (Config, Outputs) -> IO ()
display (Left err) = putStrLn err
Expand All @@ -63,6 +64,7 @@ predef name output = do
Just cf -> display $ checkFormat output cf

parseArgs :: [Text] -> Next
parseArgs ["-v"] = Version
parseArgs ["--prev"] = Previous
parseArgs ["-p", name] = PreDefined name []
parseArgs ["-p", name, msg] = PreDefined name [("*", msg)]
Expand All @@ -78,3 +80,4 @@ go = do
Continue output -> readCfg output >>= display
Previous -> previous
PreDefined name output -> predef name output
Version -> putStrLn "0.6.0"
13 changes: 4 additions & 9 deletions src/Cmt/IO/Git.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ module Cmt.IO.Git

import ClassyPrelude

import System.Exit (ExitCode (ExitFailure))
import System.Process (readCreateProcessWithExitCode, shell)
import System.Exit (ExitCode)
import System.Process (readCreateProcessWithExitCode, shell, spawnCommand, waitForProcess)

-- copied from https://hackage.haskell.org/package/posix-escape
escape :: String -> String
Expand All @@ -19,15 +19,10 @@ escape xs = "'" ++ concatMap f xs ++ "'"
f '\'' = "'\"'\"'"
f x = [x]

commit :: Text -> IO (Either Text Text)
commit :: Text -> IO ExitCode
commit message = do
let msg = "git commit -m" <> escape (unpack message)
(code, out, err) <- readCreateProcessWithExitCode (shell msg) ""
let output = unlines (pack <$> filter (not . null) [out, err])
pure $
case code of
ExitFailure _ -> Left output
_ -> Right output
waitForProcess =<< spawnCommand msg

changed :: IO [Text]
changed = do
Expand Down
2 changes: 1 addition & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resolver: lts-13.13
resolver: lts-14.21
pvp-bounds: both
packages:
- .
12 changes: 12 additions & 0 deletions stack.yaml.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file was autogenerated by Stack.
# You should not edit this file by hand.
# For more information, please see the documentation at:
# https://docs.haskellstack.org/en/stable/lock_files

packages: []
snapshots:
- completed:
size: 524162
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/14/21.yaml
sha256: 9a55dd75853718f2bbbe951872b36a3b7802fcd71796e0f25b8664f24e34c666
original: lts-14.21

0 comments on commit b1bebb6

Please sign in to comment.