-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add grouping, masking, and stopping (#8)
* remove weeder * add grouping, masking, and stopping * add parent GitHub.Workflow.Command module and docs * release 0.0.1.0
- Loading branch information
1 parent
aed698b
commit a3a5764
Showing
17 changed files
with
346 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
-- | Programs run by GitHub Actions can use workflow commands to communicate with the runner. | ||
-- | ||
-- GitHub documentation: | ||
-- <https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions Workflow commands for GitHub Actions> | ||
module GitHub.Workflow.Command | ||
( -- * Executing commands | ||
MonadCommand (..) | ||
, PrintCommands (..) | ||
|
||
-- * Commands | ||
, ToCommand (..) | ||
|
||
-- ** Setting a debug message | ||
, Debug (..) | ||
, debug | ||
|
||
-- ** Setting a notice message | ||
, Notice (..) | ||
, notice | ||
|
||
-- ** Setting a warning message | ||
, Warning (..) | ||
, warning | ||
|
||
-- ** Setting an error message | ||
, Error (..) | ||
, error | ||
|
||
-- ** Grouping log lines | ||
, group | ||
, GroupStart (..) | ||
, GroupEnd (..) | ||
|
||
-- ** Masking a value in a log | ||
, AddMask (..) | ||
|
||
-- ** Stopping and starting workflow commands | ||
, suspendCommands | ||
, stopCommands | ||
, resumeCommands | ||
, SuspendToken | ||
|
||
-- * Location | ||
, Location (..) | ||
, HasLocationMaybe (..) | ||
|
||
-- ** File | ||
, File (..) | ||
, inFile | ||
, file | ||
|
||
-- ** Position | ||
, Position (..) | ||
, position | ||
, Extent (..) | ||
, extent | ||
, Columns (..) | ||
, line | ||
, startColumn | ||
, endColumn | ||
, Line (..) | ||
, atLine | ||
, Column (..) | ||
, atColumn | ||
|
||
-- * Anatomy of a command | ||
, Command | ||
|
||
-- ** Name | ||
, Name (..) | ||
, HasName (..) | ||
|
||
-- ** Message | ||
, Message (..) | ||
, HasMessage (..) | ||
|
||
-- ** Properties | ||
, Properties | ||
, HasProperties (..) | ||
, Key (..) | ||
, Value (..) | ||
) where | ||
|
||
import GitHub.Workflow.Command.Annotation.Commands.Debug | ||
import GitHub.Workflow.Command.Annotation.Commands.Error | ||
import GitHub.Workflow.Command.Annotation.Commands.Notice | ||
import GitHub.Workflow.Command.Annotation.Commands.Warning | ||
import GitHub.Workflow.Command.Annotation.File | ||
import GitHub.Workflow.Command.Annotation.Location | ||
import GitHub.Workflow.Command.Annotation.Position | ||
import GitHub.Workflow.Command.Annotation.Position.Column | ||
import GitHub.Workflow.Command.Annotation.Position.Columns | ||
import GitHub.Workflow.Command.Annotation.Position.Extent | ||
import GitHub.Workflow.Command.Annotation.Position.Line | ||
import GitHub.Workflow.Command.Execution | ||
import GitHub.Workflow.Command.Grouping | ||
import GitHub.Workflow.Command.Masking | ||
import GitHub.Workflow.Command.Stopping | ||
import GitHub.Workflow.Command.Syntax |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module GitHub.Workflow.Command.Execution | ||
( MonadCommand (..) | ||
, PrintCommands (..) | ||
) where | ||
|
||
import Control.Applicative (Applicative) | ||
import Control.Monad (Monad) | ||
import Control.Monad.IO.Class (MonadIO, liftIO) | ||
import Data.Function ((.)) | ||
import Data.Functor (Functor) | ||
import GitHub.Workflow.Command.Syntax | ||
import System.IO (IO) | ||
|
||
-- | Monadic context in which GitHub workflow commands may be executed | ||
-- | ||
-- * For the most basic uses, use the 'IO' instance, which prints commands to 'System.IO.stdout'. | ||
-- | ||
-- * For custom monads that support 'MonadIO', you may derive 'MonadCommand' via 'PrintCommands' | ||
-- to get the same behavior that 'IO' exhibits. | ||
-- | ||
-- * A program that wishes to accommodate running in both GitHub and non-GitHub contexts | ||
-- may wish to define a more sophisicated 'MonadCommand' instance that prints GitHub | ||
-- workflow commands only when the @GITHUB_ACTIONS@ environment variable is present, | ||
-- and otherwise takes some other more context-appropriate action. | ||
class Monad m => MonadCommand m where | ||
executeCommand :: ToCommand a => a -> m () | ||
|
||
instance MonadCommand IO where | ||
executeCommand = printByteStringLn . toCommand | ||
|
||
newtype PrintCommands m a = PrintCommands (m a) | ||
deriving newtype (Functor, Applicative, Monad, MonadIO) | ||
|
||
instance MonadIO m => MonadCommand (PrintCommands m) where | ||
executeCommand = liftIO . executeCommand |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
module GitHub.Workflow.Command.Grouping | ||
( group | ||
, GroupStart (..) | ||
, GroupEnd (..) | ||
) where | ||
|
||
import Control.Applicative ((*>), (<*)) | ||
import Control.Lens ((.~)) | ||
import Data.Function ((.)) | ||
import Data.Text (Text) | ||
import GitHub.Workflow.Command.Execution | ||
import GitHub.Workflow.Command.Syntax | ||
|
||
-- | Creates an expandable group in the log | ||
-- | ||
-- GitHub documentation: | ||
-- <https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#grouping-log-lines Grouping log lines> | ||
group | ||
:: MonadCommand m | ||
=> Text | ||
-- ^ Group title | ||
-> m a | ||
-- ^ Anything printed within this action will be | ||
-- nested inside an expandable entry in the log | ||
-> m a | ||
group title x = | ||
executeCommand GroupStart {title} | ||
*> x | ||
<* executeCommand GroupEnd | ||
|
||
-- | Starts a 'group' | ||
newtype GroupStart = GroupStart {title :: Text} | ||
|
||
instance ToCommand GroupStart where | ||
addToCommand GroupStart {title} = | ||
(name .~ "group") . (message .~ Message title) | ||
|
||
-- | Ends a 'group' | ||
data GroupEnd = GroupEnd | ||
|
||
instance ToCommand GroupEnd where | ||
addToCommand GroupEnd = name .~ "endgroup" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module GitHub.Workflow.Command.Masking | ||
( AddMask (..) | ||
) where | ||
|
||
import Control.Lens ((.~)) | ||
import Data.Function ((.)) | ||
import Data.Text (Text) | ||
import GitHub.Workflow.Command.Syntax | ||
|
||
-- | Prevents a string or variable from being printed in the log | ||
-- | ||
-- GitHub documentation: | ||
-- <https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#masking-a-value-in-a-log Masking a value in a log> | ||
newtype AddMask = AddMask | ||
{ value :: Text | ||
-- ^ An environment variable or string | ||
} | ||
|
||
instance ToCommand AddMask where | ||
addToCommand AddMask {value} = | ||
(name .~ "add-mask") . (message .~ Message value) |
Oops, something went wrong.