2022-03-16 18:00:18 +03:00
|
|
|
#!/usr/bin/env cabal
|
|
|
|
{- cabal:
|
|
|
|
build-depends:
|
|
|
|
base == 4.*
|
|
|
|
, turtle == 1.5.*
|
|
|
|
, regex-tdfa == 1.3.*
|
|
|
|
, text == 1.2.*
|
2020-10-31 13:08:33 +03:00
|
|
|
-}
|
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
|
2022-11-07 15:24:35 +03:00
|
|
|
import Control.Monad (when)
|
|
|
|
import qualified Data.Text as T
|
|
|
|
import qualified Data.Text.IO as T.IO
|
|
|
|
import System.Environment (getArgs)
|
|
|
|
import System.Exit (ExitCode (..))
|
|
|
|
import qualified Text.Regex.TDFA as TR
|
|
|
|
import Turtle (empty, shell, shellStrict)
|
2020-10-31 13:08:33 +03:00
|
|
|
|
|
|
|
main = do
|
2022-11-07 15:24:35 +03:00
|
|
|
args <- getArgs
|
|
|
|
case args of
|
|
|
|
[version] -> makeNewRelease version
|
|
|
|
_ -> putStrLn "Usage: new-release <version>"
|
2020-10-31 13:08:33 +03:00
|
|
|
|
|
|
|
makeNewRelease :: String -> IO ()
|
|
|
|
makeNewRelease newVersion = do
|
2022-11-07 15:24:35 +03:00
|
|
|
(ExitSuccess, branchName) <- shellStrict "git rev-parse --abbrev-ref HEAD" empty
|
|
|
|
when (T.strip branchName /= "release") $ error "You must run this script from the release branch!"
|
2022-02-25 15:40:28 +03:00
|
|
|
|
2022-11-07 15:24:35 +03:00
|
|
|
let cabalFileName = "waspc.cabal"
|
|
|
|
oldCabalFileContents <- T.unpack <$> T.IO.readFile cabalFileName
|
2020-10-31 13:08:33 +03:00
|
|
|
|
2022-11-07 15:24:35 +03:00
|
|
|
(newCabalFileContents, oldVersion) <- updateCabalFile oldCabalFileContents newVersion
|
|
|
|
let tag = "v" ++ newVersion
|
2020-10-31 13:08:33 +03:00
|
|
|
|
2022-11-07 15:24:35 +03:00
|
|
|
when (newVersion == oldVersion) $ error "Version you provided is the current version!"
|
2020-10-31 13:08:33 +03:00
|
|
|
|
2022-11-07 15:24:35 +03:00
|
|
|
putStrLn $
|
|
|
|
unlines
|
|
|
|
[ "This will update wasp version from " ++ oldVersion ++ " to " ++ newVersion,
|
|
|
|
cabalFileName ++ " will be updated, and this change will be commited and pushed.",
|
|
|
|
"Also, tag " ++ tag ++ " will be created and pushed, triggering CI to"
|
|
|
|
++ " create new release on Github.",
|
|
|
|
"Are you sure you want to proceed (y/n)?"
|
|
|
|
]
|
|
|
|
confirmation <- getLine
|
|
|
|
when (confirmation /= "y") $ error "Aborting"
|
2020-10-31 13:08:33 +03:00
|
|
|
|
2022-11-07 15:24:35 +03:00
|
|
|
T.IO.writeFile cabalFileName $ T.pack newCabalFileContents
|
2020-10-31 13:08:33 +03:00
|
|
|
|
2022-11-07 15:24:35 +03:00
|
|
|
-- TODO: Print what I am doing for each step.
|
2020-10-31 13:08:33 +03:00
|
|
|
|
2022-11-07 15:24:35 +03:00
|
|
|
putStrLn $ "\nCreating new commit with updated " ++ cabalFileName ++ " and pushing it.\n"
|
|
|
|
ExitSuccess <- shell (T.pack $ "git add " ++ cabalFileName) empty
|
|
|
|
ExitSuccess <- shell (T.pack $ "git commit -m \"Updated wasp version to " ++ newVersion ++ ".\"") empty
|
|
|
|
gitPushExitCode <- shell "git push" empty
|
|
|
|
case gitPushExitCode of
|
|
|
|
ExitSuccess -> return ()
|
|
|
|
ExitFailure _ -> do
|
|
|
|
ExitSuccess <- shell "git reset --hard HEAD~1" empty
|
|
|
|
error "Failed to do `git push`, reverted changes."
|
2020-10-31 13:08:33 +03:00
|
|
|
|
2022-11-07 15:24:35 +03:00
|
|
|
putStrLn $ "\nCreating tag " ++ tag ++ " and pushing it.\n"
|
|
|
|
ExitSuccess <- shell (T.pack $ "git tag " ++ tag) empty
|
|
|
|
ExitSuccess <- shell (T.pack $ "git push origin " ++ tag) empty
|
2020-10-31 13:08:33 +03:00
|
|
|
|
2022-11-07 15:24:35 +03:00
|
|
|
return ()
|
2020-10-31 13:08:33 +03:00
|
|
|
|
2022-03-16 18:00:18 +03:00
|
|
|
updateCabalFile :: String -> String -> IO (String, String) -- Returns (updated cabal file contents, old version)
|
|
|
|
updateCabalFile cabalFileContents newVersion = do
|
2022-11-07 15:24:35 +03:00
|
|
|
let (beforeMatch, match, afterMatch, submatches) =
|
|
|
|
cabalFileContents TR.=~ ("^(version: *)([0-9]+\\.[0-9]+\\.[0-9]+)" :: String) :: (String, String, String, [String])
|
|
|
|
when (null match) $ error "Couldn't locate version in cabal file!?"
|
|
|
|
let [matchBeforeVersion, oldVersion] = submatches
|
|
|
|
let newContents = beforeMatch ++ matchBeforeVersion ++ newVersion ++ afterMatch
|
|
|
|
return (newContents, oldVersion)
|