2018-03-31 06:07:46 +03:00
|
|
|
{-# LANGUAGE ExtendedDefaultRules #-}
|
2019-01-18 11:20:47 +03:00
|
|
|
{-# 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
|
|
|
|
2018-12-24 02:02:54 +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
|
2019-03-21 08:27:20 +03:00
|
|
|
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
|
|
|
|
2019-08-25 00:03:30 +03:00
|
|
|
data Arguments =
|
|
|
|
Arguments
|
|
|
|
{ mode :: Mode
|
|
|
|
, dry :: Bool
|
|
|
|
}
|
2019-01-18 11:20:47 +03:00
|
|
|
|
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" <>
|
2019-08-25 00:03:30 +03:00
|
|
|
Opt.help "Delete branches from PRs that were merged or closed")
|
2018-04-04 02:03:46 +03:00
|
|
|
|
2019-01-18 11:20:47 +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
|
2019-01-18 11:20:47 +03:00
|
|
|
(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
|
|
|
|
2019-01-18 11:20:47 +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"
|
2019-02-05 08:30:59 +03:00
|
|
|
return $ Options dry token
|
2018-03-31 06:07:46 +03:00
|
|
|
|
|
|
|
main :: IO ()
|
2018-07-11 05:30:34 +03:00
|
|
|
main = do
|
2019-01-18 11:20:47 +03:00
|
|
|
arguments@Arguments {mode} <- Opt.execParser programInfo
|
|
|
|
options <- makeOptions arguments
|
2019-01-18 10:52:45 +03:00
|
|
|
updates <- T.readFile "packages-to-update.txt"
|
2019-01-18 10:57:42 +03:00
|
|
|
setupNixpkgs options
|
2019-03-21 08:27:20 +03:00
|
|
|
setEnv "PAGER" "" True
|
|
|
|
setEnv "GITHUB_TOKEN" (T.unpack (githubToken options)) True
|
2019-03-26 00:17:24 +03:00
|
|
|
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
|