From 1204822ef68046cffee4082af1290fb33bd0c22f Mon Sep 17 00:00:00 2001 From: Colin Kennedy Date: Thu, 9 Jan 2025 08:06:25 -0800 Subject: [PATCH] feat(run): `args: false` will install+cache but not run --- .github/workflows/test.yml | 23 +++++++++++++++++++++-- README.md | 21 +++++++++++++++++++++ dist/index.js | 10 +++++++--- src/main.ts | 5 ++++- test/needs_spaces.lua | 1 + 5 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 test/needs_spaces.lua diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e0d0a46..913d66c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -35,7 +35,7 @@ jobs: with: version: ^0.17 token: ${{ secrets.GITHUB_TOKEN }} - args: --check ./test + args: --check ./test/sample.lua smoketest_latest_version_provided: runs-on: ubuntu-latest steps: @@ -44,4 +44,23 @@ jobs: with: version: latest token: ${{ secrets.GITHUB_TOKEN }} - args: --check ./test + args: --check ./test/sample.lua + # only install / cache the StyLua install, don't run it + smoketest_args_false: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Copy Test File + run: | + cp ./test/needs_spaces.lua{,.copy} + + - uses: ./ + with: + version: latest + token: ${{ secrets.GITHUB_TOKEN }} + args: false + + - name: Confirm test file was not changed + run: | + cmp ./test/needs_spaces.lua{,.copy} diff --git a/README.md b/README.md index eb2fbf9..0c7163a 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,27 @@ Installs the StyLua binary (from GitHub releases), and caches it. Any StyLua com args: --check . ``` +### Advanced Usage - Skip Running StyLua +This action can be summarized as 2 main steps + +1. Get An Installation Of [StyLua](https://github.com/JohnnyMorganz/StyLua) + 1a. From the cache + 1b. If no cache, install + cache it +2. Run `stylua` with the user-provided `args` + +If you would like to keep step 1 but skip step 2 because you want more manual +control, use `args: false`. + +```yaml +- uses: actions/checkout@v4 +- uses: JohnnyMorganz/stylua-action@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + version: latest # NOTE: we recommend pinning to a specific version in case of formatting changes + # This disables running `stylua` + args: false +``` + ### Parameters #### `token` (Required) diff --git a/dist/index.js b/dist/index.js index 59544de..539bb01 100644 --- a/dist/index.js +++ b/dist/index.js @@ -84,8 +84,12 @@ function run() { } } const args = core.getInput('args'); - core.debug(`Running stylua with arguments: ${args}`); - yield (0, exec_1.exec)(`stylua ${args}`); + + if (args !== 'false') { + core.debug(`Running stylua with arguments: ${args}`); + yield (0, exec_1.exec)(`stylua ${args}`); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (error) { @@ -17028,4 +17032,4 @@ module.exports = JSON.parse('[[[0,44],"disallowed_STD3_valid"],[[45,46],"valid"] /******/ /******/ })() ; -//# sourceMappingURL=index.js.map \ No newline at end of file +//# sourceMappingURL=index.js.map diff --git a/src/main.ts b/src/main.ts index adc8f07..55ed44b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -56,7 +56,10 @@ async function run(): Promise { const args = core.getInput('args') core.debug(`Running stylua with arguments: ${args}`) - await exec(`stylua ${args}`) + if (args !== 'false') { + await exec(`stylua ${args}`) + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (error: any) { core.setFailed(error.message) diff --git a/test/needs_spaces.lua b/test/needs_spaces.lua new file mode 100644 index 0000000..8e14037 --- /dev/null +++ b/test/needs_spaces.lua @@ -0,0 +1 @@ +local x=1