diff --git a/README.md b/README.md index 3fd5e32..59c4658 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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. diff --git a/action.yml b/action.yml index 16854fc..832db63 100644 --- a/action.yml +++ b/action.yml @@ -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. diff --git a/package-lock.json b/package-lock.json index 88cc680..4e15dc1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,7 +8,7 @@ "version": "0.0.0", "license": "Apache-2.0", "dependencies": { - "@actions/core": "^1.9.0" + "@actions/core": "^1.10.0" }, "devDependencies": { "@types/jest": "^27.0.1", @@ -28,11 +28,12 @@ } }, "node_modules/@actions/core": { - "version": "1.9.0", - "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.9.0.tgz", - "integrity": "sha512-5pbM693Ih59ZdUhgk+fts+bUWTnIdHV3kwOSr+QIoFHMLg7Gzhwm0cifDY/AG68ekEJAkHnQVpcy4f6GjmzBCA==", + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.10.0.tgz", + "integrity": "sha512-2aZDDa3zrrZbP5ZYg159sNoLRb61nQ7awl5pSvIq5Qpj81vwDzdMRKzkWJGJuwVvWpvZKx7vspJALyvaaIQyug==", "dependencies": { - "@actions/http-client": "^2.0.1" + "@actions/http-client": "^2.0.1", + "uuid": "^8.3.2" } }, "node_modules/@actions/http-client": { @@ -6519,6 +6520,14 @@ "punycode": "^2.1.0" } }, + "node_modules/uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/v8-compile-cache": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz", @@ -6871,11 +6880,12 @@ }, "dependencies": { "@actions/core": { - "version": "1.9.0", - "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.9.0.tgz", - "integrity": "sha512-5pbM693Ih59ZdUhgk+fts+bUWTnIdHV3kwOSr+QIoFHMLg7Gzhwm0cifDY/AG68ekEJAkHnQVpcy4f6GjmzBCA==", + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.10.0.tgz", + "integrity": "sha512-2aZDDa3zrrZbP5ZYg159sNoLRb61nQ7awl5pSvIq5Qpj81vwDzdMRKzkWJGJuwVvWpvZKx7vspJALyvaaIQyug==", "requires": { - "@actions/http-client": "^2.0.1" + "@actions/http-client": "^2.0.1", + "uuid": "^8.3.2" } }, "@actions/http-client": { @@ -11806,6 +11816,11 @@ "punycode": "^2.1.0" } }, + "uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==" + }, "v8-compile-cache": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz", diff --git a/package.json b/package.json index 202fe84..9c83c97 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/main.ts b/src/main.ts index 218aaa0..88b7483 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,7 +3,7 @@ import {scalafmt} from './scalafmt' async function run(): Promise { 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) diff --git a/src/scalafmt.ts b/src/scalafmt.ts index 07f4bae..9749fcf 100644 --- a/src/scalafmt.ts +++ b/src/scalafmt.ts @@ -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' @@ -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 { 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) }