|
| 1 | +import * as cli from '@actions/exec' |
1 | 2 | import * as core from '@actions/core'
|
| 3 | +import * as crypto from 'crypto' |
| 4 | +import * as fs from 'fs' |
| 5 | +import * as fsPromises from 'fs/promises' |
| 6 | +import * as os from 'os' |
| 7 | +import * as path from 'path' |
| 8 | + |
| 9 | +// Version of the sbt-dependency-graph-plugin |
| 10 | +const pluginVersion = '0.1.0-M5' |
| 11 | +const baseDir = '.' |
| 12 | + |
| 13 | +async function commandExists(cmd: string): Promise<boolean> { |
| 14 | + const isWin = os.platform() === 'win32' |
| 15 | + const where = isWin ? 'where.exe' : 'which' |
| 16 | + const code = await cli.exec(where, [cmd], { silent: true }) |
| 17 | + return code === 0 |
| 18 | +} |
2 | 19 |
|
3 | 20 | async function run(): Promise<void> {
|
4 | 21 | try {
|
5 |
| - core.info('Hello, World!') |
| 22 | + const projectDir = path.join(baseDir, 'project') |
| 23 | + const uuid = crypto.randomUUID() |
| 24 | + const pluginFile = path.join(projectDir, `github-dependency-graph-${uuid}.sbt`) |
| 25 | + const pluginDep = `addSbtPlugin("ch.epfl.scala" % "sbt-github-dependency-graph" % "${pluginVersion}")` |
| 26 | + const isProject = fs.existsSync(projectDir) |
| 27 | + if (!isProject) { |
| 28 | + core.setFailed(`${baseDir} is not a valid sbt project: missing folder '${projectDir}'.`) |
| 29 | + return |
| 30 | + } |
| 31 | + await fsPromises.writeFile(pluginFile, pluginDep) |
| 32 | + const sbtExists = await commandExists('sbt') |
| 33 | + if (!sbtExists) { |
| 34 | + core.setFailed('Not found sbt command') |
| 35 | + return |
| 36 | + } |
| 37 | + await cli.exec('sbt', ['submitGithubDependencyGraph']) |
6 | 38 | } catch (error) {
|
7 | 39 | if (error instanceof Error) {
|
8 | 40 | core.setFailed(error)
|
|
0 commit comments