Skip to content

Commit 081e243

Browse files
committed
feat: add submission ID and URL as action outputs
1 parent 79d6b42 commit 081e243

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ inputs:
3737
description: Version of the sbt plugin to use.
3838
required: false
3939
default: '2.1.2'
40+
outputs:
41+
submission-id:
42+
description: The ID of the submission created by the action
43+
submission-api-url:
44+
description: The URL of the submission created by the action
4045
runs:
4146
using: 'node16'
4247
main: 'dist/index.js'

sbt-plugin/src/main/scala/ch/epfl/scala/SubmitDependencyGraph.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,23 @@ object SubmitDependencyGraph {
9696
snapshot <- getSnapshot(httpResp)
9797
} yield {
9898
state.log.info(s"Submitted successfully as $snapshotUrl/${snapshot.id}")
99+
setGithubOutputs(
100+
"submission-id" -> s"${snapshot.id}",
101+
"submission-api-url" -> s"${snapshotUrl}/${snapshot.id}"
102+
)
99103
state
100104
}
101105

102106
result.get
103107
}
104108

109+
// https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter
110+
private def setGithubOutputs(outputs: (String, String)*): Unit = IO.writeLines(
111+
file(githubOutput),
112+
outputs.toSeq.map { case (name, value) => s"${name}=${value}" },
113+
append = true
114+
)
115+
105116
private def getSnapshot(httpResp: FullResponse): Try[SnapshotResponse] =
106117
httpResp.status match {
107118
case status if status / 100 == 2 =>
@@ -168,6 +179,7 @@ object SubmitDependencyGraph {
168179
private def githubApiUrl(): String = githubCIEnv("GITHUB_API_URL")
169180
private def githubRepository(): String = githubCIEnv("GITHUB_REPOSITORY")
170181
private def githubToken(): String = githubCIEnv("GITHUB_TOKEN")
182+
private def githubOutput(): String = githubCIEnv("GITHUB_OUTPUT")
171183

172184
private def githubCIEnv(name: String): String =
173185
Properties.envOrNone(name).getOrElse {

0 commit comments

Comments
 (0)