Skip to content

Commit

Permalink
[#395] Add TUI button for GitHub Actions (#396)
Browse files Browse the repository at this point in the history
* [#395] Add TUI button for GitHub Actions

Resolves #395

* Update README.md

Co-Authored-By: Dmitrii Kovanikov <kovanikov@gmail.com>

* Renew TUI when cabal checkbox changes

Co-authored-by: Dmitrii Kovanikov <kovanikov@gmail.com>
  • Loading branch information
vrom911 and chshersh committed Jan 4, 2020
1 parent c22a243 commit 8b2131e
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 55 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@
`summoner` uses [PVP Versioning][1].
The changelog is available [on GitHub][2].

## 2.0.0.0 – Unreleased

* [#351](https://github.com/kowainik/summoner/issues/351)
[#395](https://github.com/kowainik/summoner/issues/395):
__#CLI__ __#TUI__
Add GitHub Actions CI check as an option for the generated
project.

Add `-a` or `--actions` CLI option for GitHub actions.
Add `GitHub Actions` entry into interactive CLI mode.
Add `GitHub Actions` button into TUI.
Add `githubActions` to the TOML configs.
(by [patrickt](https://github.com/patrickt), [@vrom911](https://github.com/vrom911))

## 1.4.0.0 – Dec 25, 2019 🎅

* [#339](https://github.com/kowainik/summoner/issues/339):
Expand Down
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
Summoner is a tool for scaffolding fully configured batteries-included production-level Haskell projects.

Do you want to create a library that is to be uploaded to Hackage/Stackage, that builds with both Cabal and Stack and supports the latest three major GHC versions?
Or are you building a production application which uses a custom prelude and has CI with Travis Linux and AppVeyors Windows checks?
Or are you building a production application which uses a custom prelude and has CI with GitHub Actions or Travis Linux and AppVeyors Windows checks?
Maybe do you want to play with your idea in a single module without introducing the whole complexity of the Haskell projects?
Summoner can help you do all that with minimal effort from you - it can even upload the project to GitHub if you wish!

Expand Down Expand Up @@ -134,6 +134,8 @@ Features related to the structure and content of the generated projects.
+ Generation of the `.travis.yml` file that runs build and tests on CI under Linux using
[Dead simple Haskell Travis Settings for Cabal and Stack](https://chshersh.github.io/posts/2019-02-25-haskell-travis).
+ Generation of the `appveyor.yaml` file which runs build and tests on CI under Windows.
+ Generation of the `.github/workflows/ci.yml` file that runs build and tests on
GitHub ACtuions CI under Linux using Cabal.
+ Configuration matrix on CI to build with multiple GHC versions and various build tools.
+ `-Werror` is enabled on CI not to miss any warnings.
+ Run HLint checks on CI.
Expand Down Expand Up @@ -363,6 +365,7 @@ Here is the list of the options that can be configured to suit your needs. If op
| `gitignore` | [Text] | List of files you want added to the default `.gitignore`. (Ignored if `github = false`) |
| `noUpload` | Bool | Do not upload to GitHub, but create all GitHub related files if specified (Ignored if `github = false`) |
| `private` | Bool | Create private repository by default? (Ignored if `github = false`) |
| `githubActions` | Bool | Turn on `GitHub Actions` integration by default? (Currently working with `Cabal` only. Ignored if `github = false`) |
| `travis` | Bool | Turn on `Travis` integration by default? (Ignored if `github = false`) |
| `appveyor` | Bool | Turn on `AppVeyor` integration by default? (Ignored if `github = false`) |
| `lib` | Bool | Create `src` folder with simple `ProjectName.hs` file and library target? |
Expand Down Expand Up @@ -437,6 +440,7 @@ Available command options:
-h, --help Show this help text
-g, --github Github integration
-p, --private Create private GitHub repository
-a, --actions GitHub Actions CI integration
-c, --travis Travis CI integration
-w, --app-veyor AppVeyor CI integration
-l, --library Library target
Expand Down Expand Up @@ -474,10 +478,13 @@ Available options:
-h, --help Show this help text
```

For example, the following command preconfigures the project settings with the custom prelude `relude`, included library, executable, test stanzas (but without benchmarks), creates a private repository on GitHub with the Travis CI and AppVeyor CI integrated.
For example, the following command preconfigures the project settings with the
custom prelude `relude`, included library, executable, test stanzas (but without
benchmarks), creates a private repository on GitHub with the GitHub Actions CI,
Travis CI and AppVeyor CI integrated.

```shell
summon new my-project with -letgcpw without -b --prelude-package relude --prelude-module Relude
summon new my-project with -letgcpwa without -b --prelude-package relude --prelude-module Relude
```

### TUI [](#structure)
Expand Down
6 changes: 3 additions & 3 deletions summoner-cli/src/Summoner/CLI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import Development.GitRev (gitCommitDate, gitDirty, gitHash)
import NeatInterpolation (text)
import Options.Applicative (Parser, ParserInfo, ParserPrefs, argument, command, customExecParser,
flag, fullDesc, help, helpLongEquals, helper, info, infoFooter,
infoHeader, infoOption, long, maybeReader, metavar, option, optional,
prefs, progDesc, short, showHelpOnEmpty, strArgument, strOption,
subparser, subparserInline, switch, value)
infoHeader, infoOption, long, maybeReader, metavar, option, prefs,
progDesc, short, showHelpOnEmpty, strArgument, strOption, subparser,
subparserInline, switch, value)
import Options.Applicative.Help.Chunk (stringChunk)
import Relude.Extra.Enum (universe)
import Relude.Extra.Validation (Validation (..))
Expand Down
92 changes: 48 additions & 44 deletions summoner-cli/src/Summoner/Template/Doc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,58 +40,62 @@ docFiles Settings{..} =
[ "# " <> settingsRepo
, ""
]
++ [travisBadge | settingsTravis]
++ [appVeyorBadge | settingsAppVeyor]
++ [hackage]
++ [stackLtsBadge | settingsStack]
++ [stackNightlyBadge | settingsStack]
++ [licenseBadge | hasLicense]
++ [githubActionsBadge | settingsGhActions]
++ [travisBadge | settingsTravis]
++ [appVeyorBadge | settingsAppVeyor]
++ [hackageBadge]
++ [stackLtsBadge | settingsStack]
++ [stackNightlyBadge | settingsStack]
++ [licenseBadge | hasLicense]
++ [""
, settingsDescription
]
where
hackageShield :: Text =
"https://img.shields.io/hackage/v/" <> settingsRepo <> ".svg?logo=haskell"
hackageLink :: Text =
"https://hackage.haskell.org/package/" <> settingsRepo
hackage :: Text = makeBadge "Hackage" hackageShield hackageLink

licenseShield :: Text =
"https://img.shields.io/badge/license-" <> T.replace "-" "--" licenseName <> "-blue.svg"
licenseBadge :: Text =
makeBadge (licenseName <> " license") licenseShield "LICENSE"

stackShieldLts :: Text =
"http://stackage.org/package/" <> settingsRepo <> "/badge/lts"
stackLinkLts :: Text =
"http://stackage.org/lts/package/" <> settingsRepo

stackShieldNightly :: Text =
"http://stackage.org/package/" <> settingsRepo <> "/badge/nightly"
stackLinkNightly :: Text =
"http://stackage.org/nightly/package/" <> settingsRepo
stackLtsBadge :: Text =
makeBadge "Stackage Lts" stackShieldLts stackLinkLts
stackNightlyBadge :: Text =
makeBadge "Stackage Nightly" stackShieldNightly stackLinkNightly

travisShield :: Text =
"https://img.shields.io/travis/" <> settingsOwner <> "/" <> settingsRepo <> ".svg?logo=travis"
travisLink :: Text =
"https://travis-ci.org/" <> settingsOwner <> "/" <> settingsRepo
travisBadge :: Text =
makeBadge "Build status" travisShield travisLink

appVeyorShield :: Text =
"https://ci.appveyor.com/api/projects/status/github/" <> settingsOwner <> "/" <> settingsRepo <> "?branch=master&svg=true"
appVeyorLink :: Text =
"https://ci.appveyor.com/project/" <> settingsOwner <> "/" <> settingsRepo
appVeyorBadge :: Text =
makeBadge "Windows build status" appVeyorShield appVeyorLink
shieldsIo :: Text
shieldsIo = "https://img.shields.io/"

hackageShield, hackageLink, hackageBadge :: Text
hackageShield = shieldsIo <> "hackage/v/" <> settingsRepo <> ".svg?logo=haskell"
hackageLink = "https://hackage.haskell.org/package/" <> settingsRepo
hackageBadge = makeBadge "Hackage" hackageShield hackageLink

licenseShield, licenseBadge :: Text
licenseShield = shieldsIo <> "badge/license-" <> T.replace "-" "--" licenseName <> "-blue.svg"
licenseBadge = makeBadge (licenseName <> " license") licenseShield "LICENSE"

stackOrg, stackLtsShield, stackLtsLink, stackLtsBadge :: Text
stackOrg = "http://stackage.org/"
stackLtsShield = stackOrg <> "package/" <> settingsRepo <> "/badge/lts"
stackLtsLink = stackOrg <> "lts/package/" <> settingsRepo
stackLtsBadge = makeBadge "Stackage Lts" stackLtsShield stackLtsLink

stackNightlyShield, stackNightlyLink, stackNightlyBadge :: Text
stackNightlyShield = stackOrg <> "package/" <> settingsRepo <> "/badge/nightly"
stackNightlyLink = stackOrg <> "nightly/package/" <> settingsRepo
stackNightlyBadge = makeBadge "Stackage Nightly" stackNightlyShield stackNightlyLink

githubActionsShield, githubActionsLink, githubActionsBadge :: Text
githubActionsShield = "https://github.com/" <> ownerRepo <> "/workflows/CI/badge.svg"
githubActionsLink = "https://github.com/" <> ownerRepo <> "/actions"
githubActionsBadge = makeBadge "GitHub CI" githubActionsShield githubActionsLink

travisShield, travisLink, travisBadge :: Text
travisShield = shieldsIo <> "travis/" <> ownerRepo <> ".svg?logo=travis"
travisLink = "https://travis-ci.org/" <> ownerRepo
travisBadge = makeBadge "Build status" travisShield travisLink

appVeyorCom, appVeyorShield, appVeyorLink, appVeyorBadge :: Text
appVeyorCom = "https://ci.appveyor.com/"
appVeyorShield = appVeyorCom <> "api/projects/status/github/" <> ownerRepo <> "?branch=master&svg=true"
appVeyorLink = appVeyorCom <> "project/" <> ownerRepo
appVeyorBadge = makeBadge "Windows build status" appVeyorShield appVeyorLink

makeBadge :: Text -> Text -> Text -> Text
makeBadge title shield link = "[![" <> title <> "](" <> shield <> ")](" <> link <> ")"

ownerRepo :: Text
ownerRepo = settingsOwner <> "/" <> settingsRepo

changelog :: Text
changelog = unlines $
[ "# Changelog"
Expand Down
1 change: 1 addition & 0 deletions summoner-cli/test/golden/fullProject/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# fullProject

[![GitHub CI](https://github.com/kowainik/fullProject/workflows/CI/badge.svg)](https://github.com/kowainik/fullProject/actions)
[![Build status](https://img.shields.io/travis/kowainik/fullProject.svg?logo=travis)](https://travis-ci.org/kowainik/fullProject)
[![Windows build status](https://ci.appveyor.com/api/projects/status/github/kowainik/fullProject?branch=master&svg=true)](https://ci.appveyor.com/project/kowainik/fullProject)
[![Hackage](https://img.shields.io/hackage/v/fullProject.svg?logo=haskell)](https://hackage.haskell.org/package/fullProject)
Expand Down
3 changes: 2 additions & 1 deletion summoner-tui/src/Summoner/Tui.hs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ appNew dirs = App
-> SummonForm
-> EventM SummonForm (Next (KitForm e))
handleCheckboxActivation ev form = \case
CabalField -> withForm ev form mkNewForm
StackField -> withForm ev form mkNewForm
GitHubEnable -> withForm ev form mkNewForm
GitHubDisable -> withForm ev form mkNewForm
Expand Down Expand Up @@ -221,7 +222,7 @@ drawNew dirs kitForm = case kit ^. shouldSummon of
form = borderLabel "Summon new project" (renderForm kitForm)

tree :: Widget SummonForm
tree = hLimitPercent 25 $ vLimit 21 $ borderLabel "Project Structure" $ vBox
tree = hLimitPercent 25 $ vLimit 22 $ borderLabel "Project Structure" $ vBox
[ withAttr "tree" $ txt $ renderWidgetTree kit
-- to fill all the space that widget should take.
, fill ' '
Expand Down
3 changes: 3 additions & 0 deletions summoner-tui/src/Summoner/Tui/Form.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ data SummonForm
| GitHubDisable
| GitHubNoUpload
| GitHubPrivate
| GitHubActions
| GitHubTravis
| GitHubAppVeyor
deriving stock (Show, Eq, Ord, Enum, Bounded)
Expand Down Expand Up @@ -121,6 +122,7 @@ mkForm sk = setFormConcat arrangeColumns $ newForm
]
, 1 |> activeCheckboxField (gitHub . noUpload) isActive GitHubNoUpload "No upload"
, 1 |> activeCheckboxField (gitHub . private) isActive GitHubPrivate "Private"
, 1 |> activeCheckboxField (gitHub . actions) isActive GitHubActions "GitHub Actions"
, 1 |> activeCheckboxField (gitHub . travis) isActive GitHubTravis "Travis"
, 2 |> activeCheckboxField (gitHub . appVeyor) isActive GitHubAppVeyor "AppVeyor"
]
Expand All @@ -142,6 +144,7 @@ isActive :: SummonKit -> SummonForm -> Bool
isActive kit = \case
GitHubNoUpload -> isGitHubEnabled
GitHubPrivate -> isGitHubEnabled && isUploadEnabled
GitHubActions -> isGitHubEnabled && (kit ^. cabal)
GitHubTravis -> isGitHubEnabled
GitHubAppVeyor -> isGitHubEnabled
_ -> True
Expand Down
9 changes: 5 additions & 4 deletions summoner-tui/src/Summoner/Tui/Kit.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ module Summoner.Tui.Kit
, enabled
, noUpload
, private
, actions
, travis
, appVeyor
) where
Expand Down Expand Up @@ -172,10 +173,10 @@ summonKitToSettings sk = Settings
, settingsLicenseName = sk ^. project . license
, settingsLicenseText = ""
, settingsGitHub = isGitHub
, settingsGhActions = isGitHub && sk ^. gitHub . actions
, settingsGhActions = isGitHub && sk ^. gitHub . actions && sk ^. cabal
, settingsPrivate = isGitHub && sk ^. gitHub . private
, settingsTravis = isGitHub && sk ^. gitHub . travis
, settingsAppVeyor = isGitHub && sk ^. gitHub . appVeyor && sk ^. stack
, settingsAppVeyor = isGitHub && sk ^. gitHub . appVeyor
, settingsIsLib = sk ^. projectMeta . lib
, settingsIsExe = sk ^. projectMeta . exe
, settingsTest = sk ^. projectMeta . test
Expand Down Expand Up @@ -264,9 +265,9 @@ configToSummonKit cRepo cOffline cConfigFile files Config{..} = SummonKit
{ gitHubEnabled = cGitHub /= Nop
, gitHubNoUpload = getAny cNoUpload || cOffline
, gitHubPrivate = toBool cPrivate
, gitHubActions = (cGitHub /= Nop) && (cGhActions /= Nop)
, gitHubActions = (cGitHub /= Nop) && (cGhActions /= Nop) && kitCabal
, gitHubTravis = (cGitHub /= Nop) && (cTravis /= Nop)
, gitHubAppVeyor = toBool cAppVey && kitStack
, gitHubAppVeyor = toBool cAppVey
}
, summonKitExtensions = cExtensions
, summonKitGhcOptions = cGhcOptions
Expand Down

0 comments on commit 8b2131e

Please sign in to comment.