Package me.julb.sdk.github.actions.kit
Class GitHubActionsKit
java.lang.Object
me.julb.sdk.github.actions.kit.GitHubActionsKit
Kit methods for GitHub actions.
- Author:
- Julb.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Prints aDEBUG
message to user log.void
endGroup()
Ends a group.void
Prints aERROR
message to user log.void
error
(@NonNull String message, @NonNull Optional<AnnotationProperties> properties) Prints aERROR
message to user log with given annotation properties.void
Fails the process with the given message.getBooleanInput
(@NonNull String name) Gets the boolean input with the given name.getEnumInput
(@NonNull String name, Class<T> enumClass) Gets the input value with the given name as anEnum
.Gets the environment variable value.Returns the commit abbreviated SHA that triggered the workflow.Returns the GitHub API url.Returns the branch or tag ref that triggered the workflow run.Returns the branch or tag name that triggered the workflow run.Returns the type of ref that triggered the workflow run.Returns the owner and repository name.Returns the workflow run identifier.Returns the commit SHA that triggered the workflow.Gets the input with the given name.Gets the input with the given name, with the option to trim the value.getMultilineInput
(@NonNull String name) Gets the multiline input with the given name.
Each value is trimmed and blank values are not returned.getMultilineInput
(@NonNull String name, boolean trimValue) Gets the multiline input with the given name.
Blank values are not returned.getRequiredBooleanInput
(@NonNull String name) Gets the boolean input with the given name.
This method throws a NoSuchElementException if the input does not exist.<T extends Enum<T>>
TgetRequiredEnumInput
(@NonNull String name, Class<T> enumClass) Gets the enum input value with the given name as anEnum
.
This method throws a NoSuchElementException if the input does not exist.getRequiredEnv
(@NonNull String name) Gets an environment variable value.getRequiredInput
(@NonNull String name) Gets the input with the given name.
This method throws a NoSuchElementException if the input does not exist.getRequiredInput
(@NonNull String name, boolean trimValue) Gets the input with the given name.
This method throws a NoSuchElementException if the input does not exist.String[]
getRequiredMultilineInput
(@NonNull String name) Gets the multiline input with the given name.
This method throws a NoSuchElementException if the input does not exist.
Each value is trimmed and blank values are not returned.String[]
getRequiredMultilineInput
(@NonNull String name, boolean trimValue) Gets the multiline input with the given name.
This method throws a NoSuchElementException if the input does not exist.
Blank values are not returned.Gets the value of an state set by this action's main execution.void
Executes the givenRunnable
in a group.<T> T
Executes the given callable in a group.boolean
isDebug()
Returnstrue
if DEBUG mode is enabled in the runner,false
otherwise.boolean
Returnstrue
if the type of ref that triggered the workflow run isbranch
.boolean
Returnstrue
if the type of ref that triggered the workflow run istag
.void
Prints aNOTICE
message to user log.void
notice
(@NonNull String message, @NonNull Optional<AnnotationProperties> properties) Prints aNOTICE
message to user log.<T> void
Saves the state for current action, the state can only be retrieved by this action's post job execution.void
setCommandEcho
(boolean enabled) Enables or disables the echoing of commands into STDOUT for the rest of the step.
Echoing is disabled by default if ACTIONS_STEP_DEBUG is not set.void
setEmptyOutput
(@NonNull String name) Sets the given output variable with an empty value.<T> void
setOptionalOutput
(@NonNull String name, @NonNull Optional<T> value) Sets the given output variable.<T> void
Sets the given output variable.<T> void
setSecret
(T value) Registers a secret which will get masked from logs.void
startGroup
(@NonNull String name) Starts a group with the given name.
Output until the call toendGroup()
will be foldable.void
Prints aWARNING
message to user log.void
warning
(@NonNull String message, @NonNull Optional<AnnotationProperties> properties) Prints aWARNING
message to user log.
-
Field Details
-
INSTANCE
The public instance to use.
-
-
Constructor Details
-
GitHubActionsKit
public GitHubActionsKit()
-
-
Method Details
-
getInput
Gets the input with the given name.- Parameters:
name
- the input name.- Returns:
- the input value trimmed, or empty if input is not provided.
-
getInput
Gets the input with the given name, with the option to trim the value.- Parameters:
name
- the input name.trimValue
-true
to trim the input value,false
to let as-is.- Returns:
- the input value or empty if input is not provided.
-
getRequiredInput
Gets the input with the given name.
This method throws a NoSuchElementException if the input does not exist.- Parameters:
name
- the input name.- Returns:
- the input value.
- Throws:
NoSuchElementException
- if the object does not exist.
-
getRequiredInput
Gets the input with the given name.
This method throws a NoSuchElementException if the input does not exist.- Parameters:
name
- the input name.trimValue
-true
to trim the input value,false
to let as-is.- Returns:
- the input value or empty if input is not provided.
- Throws:
NoSuchElementException
- if the object does not exist.
-
getBooleanInput
Gets the boolean input with the given name.- Parameters:
name
- the input name.- Returns:
- the input value trimmed, or empty if input is not provided.
- Throws:
IllegalArgumentException
- if the value is not a valid boolean value.
-
getRequiredBooleanInput
Gets the boolean input with the given name.
This method throws a NoSuchElementException if the input does not exist.- Parameters:
name
- the input name.- Returns:
- the input value.
- Throws:
NoSuchElementException
- if the object does not exist.IllegalArgumentException
- if the value is not a valid boolean value.
-
getEnumInput
public <T extends Enum<T>> Optional<T> getEnumInput(@NonNull @NonNull String name, Class<T> enumClass) Gets the input value with the given name as anEnum
.- Type Parameters:
T
- the enum object type.- Parameters:
name
- the input name.enumClass
- the enum class.- Returns:
- the input value as an enum, or empty if input is not provided.
- Throws:
IllegalArgumentException
- if the value is not a valid enum value.
-
getRequiredEnumInput
public <T extends Enum<T>> T getRequiredEnumInput(@NonNull @NonNull String name, Class<T> enumClass) Gets the enum input value with the given name as anEnum
.
This method throws a NoSuchElementException if the input does not exist.- Type Parameters:
T
- the enum object type.- Parameters:
name
- the input name.enumClass
- the enum class.- Returns:
- the input value as an enum, or empty if input is not provided.
- Throws:
NoSuchElementException
- if the object does not exist.IllegalArgumentException
- if the value is not a valid enum value.
-
getMultilineInput
Gets the multiline input with the given name.
Each value is trimmed and blank values are not returned.- Parameters:
name
- the input name.- Returns:
- the multiline input value as an array, or empty if input is not provided.
-
getMultilineInput
Gets the multiline input with the given name.
Blank values are not returned.- Parameters:
name
- the input name.trimValue
-true
to trim the input value,false
to let as-is.- Returns:
- the multiline input value as an array, or empty if input is not provided.
-
getRequiredMultilineInput
Gets the multiline input with the given name.
This method throws a NoSuchElementException if the input does not exist.
Each value is trimmed and blank values are not returned.- Parameters:
name
- the input name.- Returns:
- the multiline input value as an array.
- Throws:
NoSuchElementException
- if the object does not exist.
-
getRequiredMultilineInput
Gets the multiline input with the given name.
This method throws a NoSuchElementException if the input does not exist.
Blank values are not returned.- Parameters:
name
- the input name.trimValue
-true
to trim the input value,false
to let as-is.- Returns:
- the multiline input value as an array.
- Throws:
NoSuchElementException
- if the object does not exist.
-
setOutput
Sets the given output variable.- Type Parameters:
T
- the output object type.- Parameters:
name
- the output variable name.value
- the output variable value.
-
setOptionalOutput
public <T> void setOptionalOutput(@NonNull @NonNull String name, @NonNull @NonNull Optional<T> value) Sets the given output variable.- Type Parameters:
T
- the output object type.- Parameters:
name
- the output variable name.value
- the output variable value.
-
setEmptyOutput
Sets the given output variable with an empty value.- Parameters:
name
- the output variable name.
-
setCommandEcho
public void setCommandEcho(boolean enabled) Enables or disables the echoing of commands into STDOUT for the rest of the step.
Echoing is disabled by default if ACTIONS_STEP_DEBUG is not set.- Parameters:
enabled
-true
to enable,false
otherwise.
-
startGroup
Starts a group with the given name.
Output until the call toendGroup()
will be foldable.- Parameters:
name
- the name of the group.
-
group
Executes the givenRunnable
in a group.- Parameters:
name
- the group name.exec
- theRunnable
to execute within the group.
-
group
public <T> T group(@NonNull @NonNull String name, @NonNull @NonNull Callable<T> exec) throws Exception Executes the given callable in a group. -
endGroup
public void endGroup()Ends a group. -
saveState
Saves the state for current action, the state can only be retrieved by this action's post job execution.- Type Parameters:
T
- the state value object type.- Parameters:
name
- the state variable name.value
- the state variable value.
-
getState
Gets the value of an state set by this action's main execution.- Parameters:
name
- the state variable name.- Returns:
- the state value or empty if state is not set.
-
setSecret
public <T> void setSecret(@NonNull T value) Registers a secret which will get masked from logs.- Type Parameters:
T
- the secret value object type.- Parameters:
value
- the secret value.
-
isDebug
public boolean isDebug()Returnstrue
if DEBUG mode is enabled in the runner,false
otherwise.- Returns:
true
if DEBUG mode is enabled in the runner,false
otherwise.
-
debug
Prints aDEBUG
message to user log.- Parameters:
message
- the message.
-
notice
Prints aNOTICE
message to user log.- Parameters:
message
- the message.
-
notice
public void notice(@NonNull @NonNull String message, @NonNull @NonNull Optional<AnnotationProperties> properties) Prints aNOTICE
message to user log.- Parameters:
message
- the message.properties
- the annotations to add to the message.
-
warning
Prints aWARNING
message to user log.- Parameters:
message
- the message.
-
warning
public void warning(@NonNull @NonNull String message, @NonNull @NonNull Optional<AnnotationProperties> properties) Prints aWARNING
message to user log.- Parameters:
message
- the message.properties
- the annotations to add to the message.
-
error
Prints aERROR
message to user log.- Parameters:
message
- the message.
-
error
public void error(@NonNull @NonNull String message, @NonNull @NonNull Optional<AnnotationProperties> properties) Prints aERROR
message to user log with given annotation properties.- Parameters:
message
- the message.properties
- the annotations to add to the message.
-
fail
Fails the process with the given message.- Parameters:
message
- the error message.
-
getGitHubRepository
Returns the owner and repository name. For example,octocat/Hello-World
. SeeGITHUB_REPOSITORY
.- Returns:
- the owner and repository name. For example,
octocat/Hello-World
. SeeGITHUB_REPOSITORY
. - Throws:
NoSuchElementException
- if the object does not exist.
-
getGitHubRefType
Returns the type of ref that triggered the workflow run. Valid values arebranch
ortag
. SeeGITHUB_REF_TYPE
.- Returns:
- the type of ref that triggered the workflow run. Valid values are
branch
ortag
. SeeGITHUB_REF_TYPE
. - Throws:
NoSuchElementException
- if the object does not exist.
-
isGitHubRefTypeBranch
public boolean isGitHubRefTypeBranch()Returnstrue
if the type of ref that triggered the workflow run isbranch
. SeeGITHUB_REF_TYPE
.- Returns:
true
if the type of ref that triggered the workflow run isbranch
. SeeGITHUB_REF_TYPE
.- Throws:
NoSuchElementException
- if the object does not exist.
-
isGitHubRefTypeTag
public boolean isGitHubRefTypeTag()Returnstrue
if the type of ref that triggered the workflow run istag
. SeeGITHUB_REF_TYPE
.- Returns:
true
if the type of ref that triggered the workflow run istag
. SeeGITHUB_REF_TYPE
.- Throws:
NoSuchElementException
- if the object does not exist.
-
getGitHubRef
Returns the branch or tag ref that triggered the workflow run. SeeGITHUB_REF
.- Returns:
- the branch or tag ref that triggered the workflow run. See
GITHUB_REF
. - Throws:
NoSuchElementException
- if the object does not exist.
-
getGitHubRefName
Returns the branch or tag name that triggered the workflow run. SeeGITHUB_REF_NAME
.- Returns:
- the branch or tag name that triggered the workflow run. See
GITHUB_REF_NAME
. - Throws:
NoSuchElementException
- if the object does not exist.
-
getGitHubSha
Returns the commit SHA that triggered the workflow. SeeGITHUB_SHA
.- Returns:
- the commit SHA that triggered the workflow. See
GITHUB_SHA
. - Throws:
NoSuchElementException
- if the object does not exist.
-
getGitHubAbbreviatedSha
Returns the commit abbreviated SHA that triggered the workflow. SeeGITHUB_SHA
.- Returns:
- the commit abbreviated SHA that triggered the workflow. See
GITHUB_SHA
. - Throws:
NoSuchElementException
- if the object does not exist.
-
getGitHubRunId
Returns the workflow run identifier. SeeGITHUB_RUN_ID
.- Returns:
- the workflow run identifier. See
GITHUB_RUN_ID
. - Throws:
NoSuchElementException
- if the object does not exist.
-
getGitHubApiUrl
Returns the GitHub API url. SeeGITHUB_API_URL
.- Returns:
- the GitHub API url. See
GITHUB_API_URL
. - Throws:
NoSuchElementException
- if the object does not exist.
-
getEnv
Gets the environment variable value.- Parameters:
name
- the environment variable name.- Returns:
- the value if the environment variable exists, or
Optional.empty()
.
-
getRequiredEnv
Gets an environment variable value.- Parameters:
name
- the environment variable name.- Returns:
- the value if the environment variable exists, or
Optional.empty()
.
-