Skip to content

Commit 479972f

Browse files
Allow running stylua as an optional step (#58)
* feat(run): `args: false` will install+cache but not run * Extend smoketest to show stylua can be run * Tweak readme slightly * Commit compiled output --------- Co-authored-by: JohnnyMorganz <johnnymorganz@outlook.com>
1 parent b666182 commit 479972f

File tree

6 files changed

+51
-6
lines changed

6 files changed

+51
-6
lines changed

.github/workflows/test.yml

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
with:
3636
version: ^0.17
3737
token: ${{ secrets.GITHUB_TOKEN }}
38-
args: --check ./test
38+
args: --check ./test/sample.lua
3939
smoketest_latest_version_provided:
4040
runs-on: ubuntu-latest
4141
steps:
@@ -44,4 +44,27 @@ jobs:
4444
with:
4545
version: latest
4646
token: ${{ secrets.GITHUB_TOKEN }}
47-
args: --check ./test
47+
args: --check ./test/sample.lua
48+
# only install / cache the StyLua install, don't run it
49+
smoketest_args_false:
50+
runs-on: ubuntu-latest
51+
steps:
52+
- uses: actions/checkout@v4
53+
54+
- name: Copy Test File
55+
run: |
56+
cp ./test/needs_spaces.lua{,.copy}
57+
58+
- uses: ./
59+
with:
60+
version: latest
61+
token: ${{ secrets.GITHUB_TOKEN }}
62+
args: false
63+
64+
- name: Confirm test file was not changed
65+
run: |
66+
cmp ./test/needs_spaces.lua{,.copy}
67+
68+
- name: Can run stylua independently
69+
run: |
70+
stylua --version

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@ Installs the StyLua binary (from GitHub releases), and caches it. Any StyLua com
1818
args: --check .
1919
```
2020
21+
If you would just like to install `stylua`, but not run it (e.g., since it is used as part of a wider CI script), then
22+
you can set `args: false`:
23+
24+
```yaml
25+
- uses: actions/checkout@v4
26+
- uses: JohnnyMorganz/stylua-action@v4
27+
with:
28+
token: ${{ secrets.GITHUB_TOKEN }}
29+
version: latest # NOTE: we recommend pinning to a specific version in case of formatting changes
30+
# This disables running `stylua`
31+
args: false
32+
# Run stylua independently
33+
- run: |
34+
stylua --version
35+
```
36+
2137
### Parameters
2238
2339
#### `token` (Required)
@@ -26,7 +42,7 @@ GitHub token. Required since the binary is downloaded from GitHub releases (to s
2642

2743
#### `args` (Required)
2844

29-
The arguments to pass to the StyLua binary
45+
The arguments to pass to the StyLua binary. If you don't want to run the binary, set `args: false`.
3046

3147
#### `version` (Required)
3248

dist/index.js

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ async function run(): Promise<void> {
5656
const args = core.getInput('args')
5757
core.debug(`Running stylua with arguments: ${args}`)
5858

59-
await exec(`stylua ${args}`)
59+
if (args !== 'false') {
60+
await exec(`stylua ${args}`)
61+
}
62+
6063
// eslint-disable-next-line @typescript-eslint/no-explicit-any
6164
} catch (error: any) {
6265
core.setFailed(error.message)

test/needs_spaces.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
local x=1

0 commit comments

Comments
 (0)