Skip to content

Commit

Permalink
feat: add submission ID and URL as action outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
laughedelic committed Jul 5, 2023
1 parent 79d6b42 commit 081e243
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ inputs:
description: Version of the sbt plugin to use.
required: false
default: '2.1.2'
outputs:
submission-id:
description: The ID of the submission created by the action
submission-api-url:
description: The URL of the submission created by the action
runs:
using: 'node16'
main: 'dist/index.js'
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,23 @@ object SubmitDependencyGraph {
snapshot <- getSnapshot(httpResp)
} yield {
state.log.info(s"Submitted successfully as $snapshotUrl/${snapshot.id}")
setGithubOutputs(
"submission-id" -> s"${snapshot.id}",
"submission-api-url" -> s"${snapshotUrl}/${snapshot.id}"
)
state
}

result.get
}

// https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter
private def setGithubOutputs(outputs: (String, String)*): Unit = IO.writeLines(
file(githubOutput),
outputs.toSeq.map { case (name, value) => s"${name}=${value}" },
append = true
)

private def getSnapshot(httpResp: FullResponse): Try[SnapshotResponse] =
httpResp.status match {
case status if status / 100 == 2 =>
Expand Down Expand Up @@ -168,6 +179,7 @@ object SubmitDependencyGraph {
private def githubApiUrl(): String = githubCIEnv("GITHUB_API_URL")
private def githubRepository(): String = githubCIEnv("GITHUB_REPOSITORY")
private def githubToken(): String = githubCIEnv("GITHUB_TOKEN")
private def githubOutput(): String = githubCIEnv("GITHUB_OUTPUT")

private def githubCIEnv(name: String): String =
Properties.envOrNone(name).getOrElse {
Expand Down

0 comments on commit 081e243

Please sign in to comment.