nixpkgs-update/src/Main.hs

73 lines
1.8 KiB
Haskell
Raw Normal View History

2018-03-31 06:07:46 +03:00
{-# LANGUAGE ExtendedDefaultRules #-}
{-# LANGUAGE NamedFieldPuns #-}
2018-04-04 12:24:55 +03:00
{-# LANGUAGE OverloadedStrings #-}
2018-03-31 06:07:46 +03:00
{-# OPTIONS_GHC -fno-warn-type-defaults #-}
2018-04-04 12:24:55 +03:00
module Main where
import OurPrelude
import Control.Applicative ((<**>))
2018-03-31 06:07:46 +03:00
import qualified Data.Text as T
2018-07-11 05:30:34 +03:00
import qualified Data.Text.IO as T
2018-09-06 16:47:09 +03:00
import DeleteMerged (deleteDone)
2018-04-04 02:03:46 +03:00
import qualified Options.Applicative as Opt
import System.Posix.Env (setEnv)
2018-04-04 12:24:55 +03:00
import Update (updateAll)
2018-12-02 06:59:55 +03:00
import Utils (Options(..), setupNixpkgs)
2018-04-04 02:03:46 +03:00
2018-03-31 06:07:46 +03:00
default (T.Text)
2018-04-04 12:24:55 +03:00
data Mode
2018-04-06 18:17:22 +03:00
= Update
2018-09-06 16:47:09 +03:00
| DeleteDone
2018-04-04 02:03:46 +03:00
data Arguments =
Arguments
{ mode :: Mode
, dry :: Bool
}
2018-04-04 02:03:46 +03:00
modeParser :: Opt.Parser Mode
modeParser =
2018-04-06 18:17:22 +03:00
Opt.flag'
Update
(Opt.long "update" <> Opt.help "Update packages (default mode)") <|>
Opt.flag'
2018-09-06 16:47:09 +03:00
DeleteDone
(Opt.long "delete-done" <>
Opt.help "Delete branches from PRs that were merged or closed")
2018-04-04 02:03:46 +03:00
argumentParser :: Opt.Parser Arguments
argumentParser =
Arguments <$> modeParser <*>
Opt.switch
(Opt.long "dry-run" <>
Opt.help
"Do everything except actually pushing the updates to the remote repository")
programInfo :: Opt.ParserInfo Arguments
2018-04-06 18:17:22 +03:00
programInfo =
Opt.info
(argumentParser <**> Opt.helper)
2018-04-06 18:17:22 +03:00
(Opt.fullDesc <> Opt.progDesc "Update packages in nixpkgs repository" <>
Opt.header "nixpkgs-update")
2018-03-31 06:07:46 +03:00
makeOptions :: Arguments -> IO Options
2019-01-27 18:51:55 +03:00
makeOptions Arguments {dry} = do
2018-12-24 03:14:33 +03:00
token <- T.strip <$> T.readFile "github_token.txt"
return $ Options dry token
2018-03-31 06:07:46 +03:00
main :: IO ()
2018-07-11 05:30:34 +03:00
main = do
arguments@Arguments {mode} <- Opt.execParser programInfo
options <- makeOptions arguments
2019-01-18 10:52:45 +03:00
updates <- T.readFile "packages-to-update.txt"
setupNixpkgs options
setEnv "PAGER" "" True
setEnv "GITHUB_TOKEN" (T.unpack (githubToken options)) True
setEnv "GC_INITIAL_HEAP_SIZE" "10g" True
2018-07-11 05:30:34 +03:00
case mode of
2018-09-06 16:47:09 +03:00
DeleteDone -> deleteDone options
2018-12-25 02:23:52 +03:00
Update -> updateAll options updates