Skip to content

feat: add submission ID and URL as action outputs #115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,17 @@ jobs:
- run: npm run all
- name: Run sbt-dependency-submission
uses: ./
id: dependency-submission
with:
working-directory: sbt-plugin
sbt-plugin-version: 2.2.0-SNAPSHOT
- name: Check outputs
run: |
echo ${{ steps.dependency-submission.outputs.submission-id }}
echo ${{ steps.dependency-submission.outputs.submission-api-url }}
echo ${{ steps.dependency-submission.outputs.snapshot-json-path }}
- name: Log snapshot JSON
run: |
cat ${{ steps.dependency-submission.outputs.snapshot-json-path }} | jq


6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,9 @@ Thumbs.db
# Ignore built ts files
__tests__/runner/*
lib/**/*

# Scala
.bloop/
.metals/
metals.sbt
target/
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ GitHub Personal Access Token (PAT). Defaults to PAT provided by Action runner.

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

### Outputs

#### `submission-id`

Once the snapshot of the dependencies has been submitted, GitHub responds with an ID of this snapshot.

#### `submission-api-url`

The API URL of the submission created by the action. It can be queried to get the submitted snapshot.

#### `snapshot-json-path`

Path to the temporary JSON file with the dependency snapshot that has been submitted.

#### Example

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

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.




7 changes: 7 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ 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
snapshot-json-path:
description: The path of the snapshot JSON file created by the action
runs:
using: 'node16'
main: 'dist/index.js'
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ object SubmitDependencyGraph {
val snapshotUrl = s"${githubApiUrl()}/repos/${githubRepository()}/dependency-graph/snapshots"

val snapshotJson = CompactPrinter(Converter.toJsonUnsafe(snapshot))

val snapshotJsonFile = IO.withTemporaryFile("dependency-snapshot-", ".json", keepFile = true) { file =>
IO.write(file, snapshotJson)
state.log.info(s"Dependency snapshot written to ${file.getAbsolutePath}")
file
}

val request = Gigahorse
.url(snapshotUrl)
.post(snapshotJson, StandardCharsets.UTF_8)
Expand All @@ -96,12 +103,24 @@ 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}",
"snapshot-json-path" -> snapshotJsonFile.getAbsolutePath
)
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 +187,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