├── .github └── workflows │ └── haskell.yml ├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── Setup.hs ├── releaser.cabal ├── releaser └── Main.hs ├── src └── Releaser │ └── Primitives.hs └── stack.yaml /.github/workflows/haskell.yml: -------------------------------------------------------------------------------- 1 | name: Haskell CI 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - uses: actions/checkout@v2 12 | - uses: mstksg/setup-stack@v2 13 | - name: Build & Test 14 | run: ~/.local/bin/stack --no-terminal test --fast 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .stack-work 2 | dist/ 3 | dist-newstyle/ 4 | .ghc.environment* 5 | 6 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Revision history for releaser 2 | 3 | ## 0.3.0.0 -- 2020-05-04 4 | 5 | * Upload to haddock support 6 | 7 | * LTS-15 support 8 | 9 | ## 0.2.1.0 -- 2019-12-02 10 | 11 | * Use cabal v2 commands to avoid compatibility issues 12 | 13 | ## 0.2.0.0 -- 2019-09-16 14 | 15 | * Write cabal versions using a regex 16 | 17 | Unfortunately, cabal api can't operate on Cabal AST, 18 | so we just resort to good old perl methods. 19 | 20 | * If any of the primitives fail, wait to retry. 21 | 22 | * Avoid checking out git branch since it's confusing. 23 | 24 | ## 0.1.0.0 -- 2019-09-09 25 | 26 | * First version. Released on an unsuspecting world. 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright 2019 Domen Kožar 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Releaser 2 | 3 | Automation of Haskell package release process. 4 | 5 | ## Example usage 6 | 7 | ``` 8 | $ releaser 9 | >> Assserting there are no uncommitted files 10 | >> Looking for a cabal file in . 11 | >> Found releaser-0.1.0.0 12 | >> Bump cabal version from 0.1.0.0 to: 0.1.0.0 13 | >> Bumped releaser to 0.1.0.0 14 | >> Running $ git checkout -b v0.1.0.0 15 | Switched to a new branch 'v0.1.0.0' 16 | >> Assserting there are no uncommitted files 17 | >> Running $ cabal dist 18 | >> Looking for a cabal file in . 19 | >> Found releaser-0.1.0.0 20 | Warning: The sdist command is a part of the legacy v1 style of cabal usage. 21 | 22 | Please switch to using either the new project style and the new-sdist command 23 | or the legacy v1-sdist alias as new-style projects will become the default in 24 | the next version of cabal-install. Please file a bug if you cannot replicate a 25 | working v1- use case with the new-style commands. 26 | 27 | For more information, see: https://wiki.haskell.org/Cabal/NewBuild 28 | 29 | >> Created dist/releaser-0.1.0.0.tar.gz 30 | >> Running $ git commit 31 | >> Running $ git tag --annotate --sign v0.1.0.0 32 | >> Pushing git to origin 33 | Enumerating objects: 25, done. 34 | Counting objects: 100% (25/25), done. 35 | Delta compression using up to 8 threads 36 | Compressing objects: 100% (13/13), done. 37 | Writing objects: 100% (19/19), 3.37 KiB | 3.37 MiB/s, done. 38 | Total 19 (delta 8), reused 0 (delta 0) 39 | remote: Resolving deltas: 100% (8/8), completed with 3 local objects. 40 | remote: 41 | remote: Create a pull request for 'v0.1.0.0' on GitHub by visiting: 42 | remote: https://github.com/domenkozar/releaser/pull/new/v0.1.0.0 43 | remote: 44 | To https://github.com/domenkozar/releaser.git 45 | * [new branch] HEAD -> v0.1.0.0 46 | >> Pushing git to origin 47 | Enumerating objects: 1, done. 48 | Counting objects: 100% (1/1), done. 49 | Writing objects: 100% (1/1), 540 bytes | 540.00 KiB/s, done. 50 | Total 1 (delta 0), reused 0 (delta 0) 51 | To https://github.com/domenkozar/releaser.git 52 | * [new tag] v0.1.0.0 -> v0.1.0.0 53 | >> Running $ cabal upload 54 | ploading dist/releaser-0.1.0.0.tar.gz... 55 | Package successfully published. You can now view it at 56 | 'https://hackage.haskell.org/package/releaser-0.1.0.0'. 57 | ``` 58 | 59 | ## Features 60 | 61 | - `Releaser.Primitives` module provides a bunch of functions 62 | to help automating release process. 63 | 64 | - `releaser` executable provides interactive automation 65 | for releasing package to Hackage and git. 66 | 67 | ## Design decisions 68 | 69 | - When there's a choice for configuration, prefer a convention and avoid configuration. 70 | 71 | - Log each primitive action 72 | 73 | ## Prior art 74 | 75 | - [bgamari/hs-maintainer-tools](https://github.com/bgamari/hs-maintainer-tools) 76 | -------------------------------------------------------------------------------- /Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /releaser.cabal: -------------------------------------------------------------------------------- 1 | cabal-version: 2.4 2 | name: releaser 3 | synopsis: Automation of Haskell package release process 4 | version: 0.3.0.0 5 | license: Apache-2.0 6 | license-file: LICENSE 7 | maintainer: domen@dev.si 8 | author: Domen Kozar 9 | category: Development 10 | extra-source-files: 11 | CHANGELOG.md 12 | 13 | source-repository head 14 | type: git 15 | location: https://github.com/domenkozar/releaser/ 16 | 17 | library 18 | exposed-modules: 19 | Releaser.Primitives 20 | hs-source-dirs: src 21 | default-language: Haskell2010 22 | default-extensions: OverloadedStrings 23 | build-depends: 24 | base >=4.7 && <5, 25 | Cabal -any, 26 | regex-tdfa -any, 27 | process -any, 28 | pretty-terminal -any, 29 | text -any 30 | 31 | executable releaser 32 | main-is: Main.hs 33 | default-language: Haskell2010 34 | hs-source-dirs: releaser 35 | other-modules: 36 | Paths_releaser 37 | autogen-modules: 38 | Paths_releaser 39 | build-depends: 40 | base -any, 41 | releaser -any 42 | -------------------------------------------------------------------------------- /releaser/Main.hs: -------------------------------------------------------------------------------- 1 | module Main (main) where 2 | 3 | import Releaser.Primitives 4 | import System.IO (hSetBuffering, stdout, stderr, BufferMode(..)) 5 | 6 | main :: IO () 7 | main = do 8 | hSetBuffering stdout LineBuffering 9 | hSetBuffering stderr LineBuffering 10 | 11 | -- prepare release 12 | -- TODO: pass a list directories 13 | gitAssertEmptyStaging 14 | version <- cabalBumpVersion "." 15 | let release = "v" <> version 16 | changelogPrepare 17 | 18 | -- make release 19 | tarball <- cabalSdist "." 20 | gitCommit $ "Bump to " <> release 21 | gitTag release 22 | 23 | -- syncing github/hackage 24 | gitPush "origin" 25 | gitPushTags "origin" 26 | cabalUpload tarball 27 | 28 | -- make haddocks and upload them 29 | docsTarball <- cabalMakeHaddocks "." 30 | cabalUploadDocs docsTarball 31 | -------------------------------------------------------------------------------- /src/Releaser/Primitives.hs: -------------------------------------------------------------------------------- 1 | module Releaser.Primitives ( 2 | -- cabal utilities 3 | CabalInfo(..) 4 | , cabalRead 5 | , cabalWriteVersion 6 | , cabalBumpVersion 7 | , cabalSdist 8 | , cabalUpload 9 | , cabalMakeHaddocks 10 | , cabalUploadDocs 11 | -- git primitives 12 | , gitCheckout 13 | , gitGetTags 14 | , gitTag 15 | , gitCommit 16 | , gitPush 17 | , gitPushTags 18 | , gitAssertEmptyStaging 19 | -- utilities 20 | , prompt 21 | , abort 22 | , logStep 23 | , changelogPrepare 24 | ) where 25 | 26 | import System.IO 27 | import System.Process 28 | import System.Console.Pretty (Color(..), color) 29 | import System.Environment (lookupEnv) 30 | import System.Exit (ExitCode(..), exitFailure) 31 | import Text.Regex.TDFA 32 | import Text.Regex.TDFA.Text 33 | import Data.Functor (void) 34 | import Data.List (intercalate) 35 | import qualified Data.Text as T 36 | import qualified Data.Text.IO as T 37 | import Text.ParserCombinators.ReadP (ReadP, readP_to_S) 38 | import Data.Version (parseVersion) 39 | import Distribution.PackageDescription.Parsec 40 | import Distribution.Verbosity (silent) 41 | import Distribution.Types.PackageId (pkgVersion, pkgName) 42 | import Distribution.Types.PackageDescription (package) 43 | import Distribution.Types.GenericPackageDescription (packageDescription) 44 | import Distribution.Types.Version (versionNumbers, mkVersion') 45 | import Distribution.Simple.Utils (tryFindPackageDesc) 46 | import Distribution.Types.PackageName (unPackageName) 47 | 48 | logStep :: String -> IO () 49 | logStep str = 50 | putStrLn $ color Green ">> " <> str 51 | 52 | prompt :: String -> IO String 53 | prompt str = do 54 | putStr $ color Blue ">> " <> str 55 | hFlush stdout 56 | getLine 57 | 58 | promptRetry :: String -> IO () 59 | promptRetry str = 60 | void $ prompt $ str <> ". Retry? (press enter) " 61 | 62 | abort :: String -> IO a 63 | abort str = do 64 | putStrLnErr $ color Red ">> " <> str 65 | exitFailure 66 | 67 | data CabalInfo = CabalInfo 68 | { name :: String 69 | , version :: String 70 | } 71 | 72 | -- | Given a folder, find a Cabal file and read the package version 73 | cabalRead :: FilePath -> IO CabalInfo 74 | cabalRead dir = do 75 | logStep $ "Looking for a cabal file in " <> dir 76 | cabalFile <- tryFindPackageDesc silent dir 77 | genericPackageDescription <- readGenericPackageDescription silent cabalFile 78 | let pkgversion = pkgVersion $ package $ packageDescription genericPackageDescription 79 | pkgname = pkgName $ package $ packageDescription genericPackageDescription 80 | cabalinfo = CabalInfo 81 | { version = intercalate "." $ show <$> versionNumbers pkgversion 82 | , name = unPackageName pkgname 83 | } 84 | logStep $ "Found " <> name cabalinfo <> "-" <> version cabalinfo 85 | return cabalinfo 86 | 87 | -- | Given a folder, find a Cabal file and update the package version 88 | cabalWriteVersion :: FilePath -> String -> IO () 89 | cabalWriteVersion dir versionStr = do 90 | if validCabalVersion versionStr 91 | then do 92 | cabalFile <- tryFindPackageDesc silent dir 93 | cabalinfo <- cabalRead dir 94 | cabal <- T.readFile cabalFile 95 | let versionPrev :: T.Text 96 | versionPrev = cabal =~ ("version:[ \t]*" ++ version cabalinfo) 97 | if versionPrev == "" 98 | then abort $ "Failed to replace version in " <> cabalFile <> ", please open an issue at https://github.com/domenkozar/releaser/issues" 99 | else do 100 | T.writeFile cabalFile $ T.replace versionPrev ("version: " <> T.pack versionStr) cabal 101 | logStep $ "Bumped " <> name cabalinfo <> " to " <> versionStr 102 | else do 103 | promptRetry "Cabal version does not match /^[0-9]+([.][0-9]+)*$/" 104 | void $ cabalBumpVersion dir 105 | 106 | 107 | validCabalVersion :: String -> Bool 108 | validCabalVersion version = 109 | version =~ ("^[0-9]+([.][0-9]+)*$" :: String) 110 | 111 | putStrLnErr :: String -> IO () 112 | putStrLnErr = hPutStrLn stderr 113 | 114 | cabalBumpVersion :: FilePath -> IO String 115 | cabalBumpVersion dir = do 116 | cabalinfo <- cabalRead dir 117 | version <- prompt $ "Bump cabal version from " <> version cabalinfo <> " to: " 118 | cabalWriteVersion dir version 119 | return version 120 | 121 | cabalSdist :: FilePath -> IO FilePath 122 | cabalSdist dir = do 123 | logStep "Running $ cabal dist" 124 | cabalinfo <- cabalRead dir 125 | void $ readProcess "cabal" ["v2-sdist"] mempty 126 | let sdistTarball = "dist-newstyle/sdist/" <> name cabalinfo <> "-" <> version cabalinfo <> ".tar.gz" 127 | logStep $ "Created " <> sdistTarball 128 | return sdistTarball 129 | 130 | cabalMakeHaddocks :: FilePath -> IO FilePath 131 | cabalMakeHaddocks dir = do 132 | logStep "Running $ cabal haddock" 133 | cabalinfo <- cabalRead dir 134 | void $ readProcess "cabal" ["v2-haddock", "--haddock-for-hackage"] mempty 135 | let docsTarball = "dist-newstyle/" <> name cabalinfo <> "-" <> version cabalinfo <> "-docs.tar.gz" 136 | logStep $ "Created " <> docsTarball 137 | return docsTarball 138 | 139 | cabalUploadDocs :: FilePath -> IO () 140 | cabalUploadDocs docsTarball = do 141 | logStep "Running $ cabal upload -d" 142 | -- TODO: recommend that credentials are configured via ~/cabal/config 143 | interactiveProcess (proc "cabal" ["upload", "-d", "--publish", docsTarball]) $ \_ -> do 144 | promptRetry "cabal upload -d" 145 | cabalUploadDocs docsTarball 146 | 147 | cabalUpload :: FilePath -> IO () 148 | cabalUpload sdistTarball = do 149 | logStep "Running $ cabal upload" 150 | -- TODO: recommend that credentials are configured via ~/cabal/config 151 | interactiveProcess (proc "cabal" ["upload", "--publish", sdistTarball]) $ \_ -> do 152 | promptRetry "cabal upload" 153 | cabalUpload sdistTarball 154 | 155 | gitGetTags :: IO [String] 156 | gitGetTags = do 157 | lines <$> readProcess "git" ["tag"] mempty 158 | 159 | -- TODO: what can we do if previous release process terminated and branch exists? 160 | gitCheckout :: String -> IO () 161 | gitCheckout tag = do 162 | logStep $ "Running $ git checkout -b " <> tag 163 | -- TODO: check for existing branch 164 | interactiveProcess (proc "git" ["checkout", "-b", tag]) $ \i -> do 165 | promptRetry "git checkout failed" 166 | gitCheckout tag 167 | 168 | gitTag :: String -> IO () 169 | gitTag tag = do 170 | logStep $ "Running $ git tag --annotate --sign " <> tag 171 | tags <- gitGetTags 172 | if elem tag tags 173 | then abort "git tag already exists, please delete it and start over" 174 | else interactiveProcess (proc "git" ["tag", "--annotate", "--sign", tag]) $ \i -> do 175 | promptRetry "git tag failed" 176 | gitTag tag 177 | 178 | gitCommit :: String -> IO () 179 | gitCommit message = do 180 | logStep $ "Running $ git commit " 181 | interactiveProcess (proc "git" ["commit", "-a", "-m", message]) $ \i -> do 182 | promptRetry "git commit failed" 183 | gitCommit message 184 | 185 | 186 | gitPush :: String -> IO () 187 | gitPush remote = do 188 | logStep $ "Pushing git to " <> remote 189 | interactiveProcess (proc "git" ["push", remote, "HEAD"]) $ \i -> do 190 | promptRetry "git push" 191 | gitPush remote 192 | 193 | gitPushTags :: String -> IO () 194 | gitPushTags remote = do 195 | logStep $ "Pushing git tags to " <> remote 196 | void $ readProcess "git" ["push", remote, "--tags"] mempty 197 | 198 | gitAssertEmptyStaging :: IO () 199 | gitAssertEmptyStaging = do 200 | logStep "Assserting there are no uncommitted files" 201 | output <- readProcess "git" ["status", "--untracked-files=no", "--porcelain"] mempty 202 | if output == "" 203 | then return () 204 | else abort "git status is not clean" 205 | 206 | changelogPrepare :: IO () 207 | changelogPrepare = do 208 | logStep "Assserting there are no uncommitted files" 209 | editorEnv <- lookupEnv "EDITOR" 210 | case editorEnv of 211 | Nothing -> abort "please make sure $EDITOR is set" 212 | Just editor -> do 213 | -- TODO: prepare the changelog 214 | interactiveProcess (proc editor ["CHANGELOG.md"]) $ \i -> do 215 | logStep $ editor <> " failed with " <> show i <> ", retrying" 216 | changelogPrepare 217 | 218 | -- internal 219 | 220 | interactiveProcess :: CreateProcess -> (Int -> IO ()) -> IO () 221 | interactiveProcess cmd bad = do 222 | (_, _, _, ph) <- createProcess cmd 223 | exitcode <- waitForProcess ph 224 | case exitcode of 225 | ExitSuccess -> return () 226 | ExitFailure i -> bad i -------------------------------------------------------------------------------- /stack.yaml: -------------------------------------------------------------------------------- 1 | resolver: lts-15.11 2 | packages: 3 | - . 4 | extra-deps: 5 | - pretty-terminal-0.1.0.0 6 | nix: 7 | packages: [zlib,pcre] 8 | --------------------------------------------------------------------------------