nixpkgs-update/src/Main.hs

64 lines
1.6 KiB
Haskell
Raw Normal View History

2018-03-31 06:07:46 +03:00
{-# LANGUAGE ExtendedDefaultRules #-}
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
2018-09-06 16:47:09 +03:00
import System.Directory (getHomeDirectory)
2018-07-11 05:30:34 +03:00
import System.Posix.Env (getEnv)
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
| UpdateMergeBase
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") <|>
Opt.flag'
UpdateMergeBase
(Opt.long "update-merge-base" <>
Opt.help "Updates the branch to use for updates")
2018-04-04 02:03:46 +03:00
programInfo :: Opt.ParserInfo Mode
2018-04-06 18:17:22 +03:00
programInfo =
Opt.info
(modeParser <**> Opt.helper)
(Opt.fullDesc <> Opt.progDesc "Update packages in nixpkgs repository" <>
Opt.header "nixpkgs-update")
2018-03-31 06:07:46 +03:00
2018-07-11 05:30:34 +03:00
makeOptions :: IO Options
2018-03-31 06:07:46 +03:00
makeOptions = do
2018-12-24 03:14:33 +03:00
dry <- isJust <$> getEnv "DRY_RUN"
homeDir <- T.pack <$> getHomeDirectory
2018-12-24 03:14:33 +03:00
token <- T.strip <$> T.readFile "github_token.txt"
return $ Options dry (homeDir <> "/.nixpkgs-update") token
2018-03-31 06:07:46 +03:00
main :: IO ()
2018-07-11 05:30:34 +03:00
main = do
mode <- Opt.execParser programInfo
options <- makeOptions
2018-12-25 02:23:52 +03:00
updates <- T.pack <$> readFile "packages-to-update.txt"
2018-12-02 06:59:55 +03:00
setupNixpkgs
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
UpdateMergeBase -> return ()