Skip to content

Commit 8b31280

Browse files
authored
Merge pull request #115 from laughedelic/feat/output-submission-info
feat: add submission ID and URL as action outputs
2 parents 62a4b3d + d54465a commit 8b31280

File tree

5 files changed

+56
-4
lines changed

5 files changed

+56
-4
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,17 @@ jobs:
6363
- run: npm run all
6464
- name: Run sbt-dependency-submission
6565
uses: ./
66+
id: dependency-submission
6667
with:
6768
working-directory: sbt-plugin
6869
sbt-plugin-version: 2.2.0-SNAPSHOT
70+
- name: Check outputs
71+
run: |
72+
echo ${{ steps.dependency-submission.outputs.submission-id }}
73+
echo ${{ steps.dependency-submission.outputs.submission-api-url }}
74+
echo ${{ steps.dependency-submission.outputs.snapshot-json-path }}
75+
- name: Log snapshot JSON
76+
run: |
77+
cat ${{ steps.dependency-submission.outputs.snapshot-json-path }} | jq
6978
7079

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,9 @@ Thumbs.db
9797
# Ignore built ts files
9898
__tests__/runner/*
9999
lib/**/*
100+
101+
# Scala
102+
.bloop/
103+
.metals/
104+
metals.sbt
105+
target/

README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@ GitHub Personal Access Token (PAT). Defaults to PAT provided by Action runner.
5757

5858
Example: `${{ secrets.USER_TOKEN }}`
5959

60+
### Outputs
61+
62+
#### `submission-id`
63+
64+
Once the snapshot of the dependencies has been submitted, GitHub responds with an ID of this snapshot.
65+
66+
#### `submission-api-url`
67+
68+
The API URL of the submission created by the action. It can be queried to get the submitted snapshot.
69+
70+
#### `snapshot-json-path`
71+
72+
Path to the temporary JSON file with the dependency snapshot that has been submitted.
73+
6074
#### Example
6175

6276
##### Excluding some projects or some Scala versions from the dependency submission.
@@ -133,7 +147,3 @@ permissions:
133147
### sbt.librarymanagement.ResolveException: Error downloading
134148

135149
This error may happen when you try to access artifacts from private GitHub packages with the default GitHub token. You need to pass personal access token which is allowed to access private packages in the `token` input.
136-
137-
138-
139-

action.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ 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
45+
snapshot-json-path:
46+
description: The path of the snapshot JSON file created by the action
4047
runs:
4148
using: 'node16'
4249
main: 'dist/index.js'

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ object SubmitDependencyGraph {
8282
val snapshotUrl = s"${githubApiUrl()}/repos/${githubRepository()}/dependency-graph/snapshots"
8383

8484
val snapshotJson = CompactPrinter(Converter.toJsonUnsafe(snapshot))
85+
86+
val snapshotJsonFile = IO.withTemporaryFile("dependency-snapshot-", ".json", keepFile = true) { file =>
87+
IO.write(file, snapshotJson)
88+
state.log.info(s"Dependency snapshot written to ${file.getAbsolutePath}")
89+
file
90+
}
91+
8592
val request = Gigahorse
8693
.url(snapshotUrl)
8794
.post(snapshotJson, StandardCharsets.UTF_8)
@@ -96,12 +103,24 @@ object SubmitDependencyGraph {
96103
snapshot <- getSnapshot(httpResp)
97104
} yield {
98105
state.log.info(s"Submitted successfully as $snapshotUrl/${snapshot.id}")
106+
setGithubOutputs(
107+
"submission-id" -> s"${snapshot.id}",
108+
"submission-api-url" -> s"${snapshotUrl}/${snapshot.id}",
109+
"snapshot-json-path" -> snapshotJsonFile.getAbsolutePath
110+
)
99111
state
100112
}
101113

102114
result.get
103115
}
104116

117+
// https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter
118+
private def setGithubOutputs(outputs: (String, String)*): Unit = IO.writeLines(
119+
file(githubOutput),
120+
outputs.toSeq.map { case (name, value) => s"${name}=${value}" },
121+
append = true
122+
)
123+
105124
private def getSnapshot(httpResp: FullResponse): Try[SnapshotResponse] =
106125
httpResp.status match {
107126
case status if status / 100 == 2 =>
@@ -168,6 +187,7 @@ object SubmitDependencyGraph {
168187
private def githubApiUrl(): String = githubCIEnv("GITHUB_API_URL")
169188
private def githubRepository(): String = githubCIEnv("GITHUB_REPOSITORY")
170189
private def githubToken(): String = githubCIEnv("GITHUB_TOKEN")
190+
private def githubOutput(): String = githubCIEnv("GITHUB_OUTPUT")
171191

172192
private def githubCIEnv(name: String): String =
173193
Properties.envOrNone(name).getOrElse {

0 commit comments

Comments
 (0)