Skip to content

Commit 023267d

Browse files
committed
Add token input
1 parent 9a48255 commit 023267d

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ jobs:
3434
working-directory: sbt-plugin
3535
env:
3636
GITHUB_TOKEN: ${{ github.token }}
37-
permissions:
38-
contents: write
3937
steps:
4038
- uses: actions/checkout@v3
4139
- uses: coursier/[email protected]
@@ -52,10 +50,6 @@ jobs:
5250
fail-fast: false
5351
name: Test Github action on ${{ matrix.os }}
5452
runs-on: ${{ matrix.os }}
55-
env:
56-
GITHUB_TOKEN: ${{ github.token }}
57-
permissions:
58-
contents: write
5953
steps:
6054
- uses: actions/checkout@v3
6155
- run: sbt publishLocal

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Sbt Dependency Graph Action
22

3-
A Github action to submit the dependency graphs of an [sbt](https://www.scala-sbt.org/) build to the Github Dependency submission API.
3+
A Github action to submit the dependency graphs of an [sbt](https://www.scala-sbt.org/) build to the Github [Dependency submission API](https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/using-the-dependency-submission-api).
44

55
After the workflow has been successfully run, the graph of the sbt build is visible in the [Dependency Graph](https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/exploring-the-dependencies-of-a-repository) page of the Insights tab.
66

@@ -25,8 +25,6 @@ jobs:
2525
submit-graph:
2626
name: Submit Dependency Graph
2727
runs-on: ubuntu-latest # or windows-latest, or macOS-latest
28-
env:
29-
GITHUB_TOKEN: ${{ github.token }}
3028
permissions:
3129
contents: write # this permission is needed to submit the dependency graph
3230
steps:

action.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@ inputs:
1010
required: false
1111
default: ''
1212
projects:
13-
description: "A list of space-separated names of projects from your build. The action will publish the graph of these projects only. Default is the empty string and it means all projects."
13+
description: "A list of space-separated names of projects from your build. The action will publish the graph of these projects only. If unspecified, the action will detect all the projects of the build."
1414
required: false
1515
default: ''
1616
scala-versions:
17-
description: "A list of space-separated versions of Scala, that are declared in your build. The action will publish the graph on these Scala versions only. Defaulat is the empty string and it means all Scala versions."
17+
description: "A list of space-separated versions of Scala, that are declared in your build. The action will publish the graph on these Scala versions only. If unspecified, the action will detect all the Scala versions of the build."
1818
required: false
1919
default: ''
20+
token:
21+
description: "GitHub Personal Access Token (PAT). Defaults to PAT provided by Action runner."
22+
required: false
23+
default: ${{ github.token }}
2024
sbt-plugin-version:
2125
description: "Override the version of the sbt-github-dependency-graph plugin that is used internally."
2226
required: false

src/main.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,24 @@ async function commandExists(cmd: string): Promise<boolean> {
1818

1919
async function run(): Promise<void> {
2020
try {
21+
const token = core.getInput('token')
22+
core.setSecret(token)
23+
2124
const baseDirInput = core.getInput('base-dir')
2225
const baseDir = baseDirInput.length === 0 ? '.' : baseDirInput
2326
const projectDir = path.join(baseDir, 'project')
27+
if (!fs.existsSync(projectDir)) {
28+
core.setFailed(`${baseDir} is not a valid sbt project: missing folder '${projectDir}'.`)
29+
return
30+
}
31+
2432
const uuid = crypto.randomUUID()
33+
const pluginFile = path.join(projectDir, `github-dependency-graph-${uuid}.sbt`)
34+
2535
const pluginVersionInput = core.getInput('sbt-plugin-version')
2636
const pluginVersion =
2737
pluginVersionInput.length === 0 ? defaultPluginVersion : pluginVersionInput
28-
const pluginFile = path.join(projectDir, `github-dependency-graph-${uuid}.sbt`)
2938
const pluginDep = `addSbtPlugin("ch.epfl.scala" % "sbt-github-dependency-graph" % "${pluginVersion}")`
30-
if (!fs.existsSync(projectDir)) {
31-
core.setFailed(`${baseDir} is not a valid sbt project: missing folder '${projectDir}'.`)
32-
return
33-
}
3439
await fsPromises.writeFile(pluginFile, pluginDep)
3540
const sbtExists = await commandExists('sbt')
3641
if (!sbtExists) {
@@ -51,6 +56,7 @@ async function run(): Promise<void> {
5156

5257
await cli.exec('sbt', [`githubSubmitDependencyGraph ${JSON.stringify(input)}`], {
5358
cwd: baseDir,
59+
env: {GITHUB_TOKEN: token}
5460
})
5561
} catch (error) {
5662
if (error instanceof Error) {

0 commit comments

Comments
 (0)