Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/json5-1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jrouly authored Jan 1, 2024
2 parents 445a648 + 94519da commit 0441a6b
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 13 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ By using the native scalafmt image, this action typically completes in two to th
- uses: jrouly/scalafmt-native-action@v2
with:
# Optional: Which version of scalafmt-native to use.
# Default: 3.5.8
# Default: read from .scalafmt.conf, otherwise '3.5.8'
version: '3.5.8'

# Optional: Arguments to be passed to scalafmt-native.
Expand Down Expand Up @@ -47,3 +47,9 @@ Inspired by the design and usage patterns of [olafurpg/setup-scala](https://gith
Similar to [openlawteam/scalafmt-ci](https://github.com/openlawteam/scalafmt-ci) but does not pin the version of the action to a specific version of scalafmt.

Similar to [AvaPL/scalafmt-native-formatter](https://github.com/AvaPL/scalafmt-native-formatter) but leverages the GitHub actions TypeScript SDK for logging and testing.

## Releasing

Merging a branch to `main` triggers the release job from the CI workflow.
This job builds a release candidate and force pushes a commit to the `release` branch.
Once ready to be released, a GitHub release can be created off that branch.
1 change: 0 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ author: jrouly
inputs:
version:
description: The scalafmt-native version to run.
default: 3.5.8
required: false
arguments:
description: Arguments to pass to scalafmt-native.
Expand Down
33 changes: 24 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"author": "jrouly",
"license": "Apache-2.0",
"dependencies": {
"@actions/core": "^1.9.0"
"@actions/core": "^1.10.0"
},
"devDependencies": {
"@types/jest": "^27.0.1",
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {scalafmt} from './scalafmt'

async function run(): Promise<void> {
try {
const version: string = core.getInput('version', {required: true})
const version: string = core.getInput('version')
const args: string = core.getInput('arguments', {required: true})

await scalafmt(version, args)
Expand Down
14 changes: 14 additions & 0 deletions src/scalafmt.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as core from '@actions/core'
import * as fs from 'fs'
import * as os from 'os'
import * as path from 'path'
import * as process from 'child_process'
Expand All @@ -10,8 +11,21 @@ const homedir = os.homedir()
const bin = path.join(homedir, 'bin')
const scalafmtPath = path.join(bin, 'scalafmt-native')

const defaultVersion = '3.5.8'

export async function scalafmt(version: string, args: string): Promise<string> {
await setup()
if (!version && fs.existsSync('./.scalafmt.conf')) {
// If version is unspecified, read it from .scalafmt.conf (if present).
const conf = fs.readFileSync('./.scalafmt.conf', 'utf8')
const v = conf.match('version\\s+=\\s+(\\S+)')
if (v && v.length >= 2) {
version = v[1]
}
}
if (!version) {
version = defaultVersion
}
await install(version)
return await execute(args)
}
Expand Down

0 comments on commit 0441a6b

Please sign in to comment.