Skip to content

Commit

Permalink
Create Scala Steward workspace under home dir instead of /opt
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandrohdezma committed May 31, 2020
1 parent 9d2a22b commit 3199096
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
21 changes: 13 additions & 8 deletions src/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as core from '@actions/core'
import * as io from '@actions/io'
import fs from 'fs'
import * as exec from '@actions/exec'
import os from 'os'

/**
* Prepares the Scala Steward workspace that will be used when launching the app.
Expand All @@ -15,26 +16,30 @@ import * as exec from '@actions/exec'
* @param {string | Buffer} repository - The repository to update or a file containing a list of
* repositories in Markdown format.
* @param {string} token - The Github Token used to authenticate into Github.
* @returns {string} The workspace directory path
*/
export async function prepareScalaStewardWorkspace(
repository: Buffer | string,
token: string
): Promise<void> {
): Promise<string> {
try {
await io.mkdirP('/opt/scala-steward')
const stewarddir = `${os.homedir()}/scala-steward`
await io.mkdirP(stewarddir)

if (typeof repository === 'string') {
fs.writeFileSync('/opt/scala-steward/repos.md', `- ${repository}`)
fs.writeFileSync(`${stewarddir}/repos.md`, `- ${repository}`)
} else {
fs.writeFileSync('/opt/scala-steward/repos.md', repository)
fs.writeFileSync(`${stewarddir}/repos.md`, repository)
}

fs.writeFileSync('/opt/scala-steward/askpass.sh', `#!/bin/sh\n\necho '${token}'`)
await exec.exec('chmod', ['+x', '/opt/scala-steward/askpass.sh'], {silent: true})
fs.writeFileSync(`${stewarddir}/askpass.sh`, `#!/bin/sh\n\necho '${token}'`)
await exec.exec('chmod', ['+x', `${stewarddir}/askpass.sh`], {silent: true})

core.info('✓ Scala Steward workspace created')

return stewarddir
} catch (error) {
core.debug(error.message)
throw new Error('Unable to create Scala Steward workspace')
}

core.info('✓ Scala Steward workspace created')
}
8 changes: 4 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ async function run(): Promise<void> {
const repo = check.reposFile() || check.githubRepository()
const user = await github.getAuthUser(token)

await files.prepareScalaStewardWorkspace(repo, token)
const workspace = await files.prepareScalaStewardWorkspace(repo, token)

const version = core.getInput('scala-steward-version')

const signCommits = /true/i.test(core.getInput('sign-commits'))
const ignoreOptsFiles = /true/i.test(core.getInput('ignore-opts-files'))

await coursier.launch('org.scala-steward', 'scala-steward-core_2.13', version, [
['--workspace', '/opt/scala-steward/workspace'],
['--repos-file', '/opt/scala-steward/repos.md'],
['--git-ask-pass', '/opt/scala-steward/askpass.sh'],
['--workspace', `${workspace}/workspace`],
['--repos-file', `${workspace}/repos.md`],
['--git-ask-pass', `${workspace}/askpass.sh`],
['--git-author-email', `${user.email}"`],
['--git-author-name', `${user.name}"`],
['--vcs-login', `${user.login}"`],
Expand Down

0 comments on commit 3199096

Please sign in to comment.