|
1 | 1 | name: Formatting
|
2 | 2 |
|
3 |
| -on: |
| 3 | +on: |
4 | 4 | push:
|
5 |
| - branches: [ "main" ] |
6 |
| - paths-ignore: |
7 |
| - - ".github/**" |
8 |
| - - "**.md" |
9 |
| - - "**.norg" |
| 5 | + branches: [main] # or any branch you want to watch |
| 6 | + paths: |
| 7 | + - '**.lua' |
| 8 | + pull_request: |
| 9 | + paths: |
| 10 | + - '**.lua' |
10 | 11 |
|
11 | 12 | jobs:
|
12 |
| - format-with-stylua: |
| 13 | + format: |
13 | 14 | runs-on: ubuntu-latest
|
14 |
| - steps: |
15 |
| - - uses: actions/checkout@v2 |
16 |
| - |
17 |
| - - name: Cache cargo modules |
18 |
| - id: cache-cargo |
19 |
| - uses: actions/cache@v2 |
20 |
| - env: |
21 |
| - cache-name: cache-node-modules |
22 |
| - with: |
23 |
| - path: ~/.cargo |
24 |
| - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/Cargo.toml') }} |
25 |
| - restore-keys: | |
26 |
| - ${{ runner.os }}-build-${{ env.cache-name }}- |
27 |
| - ${{ runner.os }}-build- |
28 |
| - ${{ runner.os }}- |
29 |
| -
|
30 |
| - - name: Install cargo |
31 |
| - run: curl https://sh.rustup.rs -sSf | sh -s -- -y |
32 |
| - |
33 |
| - - name: Install stylua |
34 |
| - run: cargo install stylua --features lua52 |
35 | 15 |
|
36 |
| - - name: Run formatting |
37 |
| - run: stylua -v --verify . |
38 |
| - |
39 |
| - - uses: stefanzweifel/git-auto-commit-action@v4 |
40 |
| - with: |
41 |
| - commit_message: "chore: autoformat with stylua" |
42 |
| - branch: ${{ github.ref }} |
43 |
| - |
44 |
| - - name: Push changes |
45 |
| - uses: ad-m/github-push-action@master |
| 16 | + steps: |
| 17 | + - name: Checkout code |
| 18 | + uses: actions/checkout@v3 |
46 | 19 | with:
|
47 |
| - github_token: ${{ secrets.GITHUB_TOKEN }} |
48 |
| - branch: ${{ github.ref }} |
| 20 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 21 | + |
| 22 | + - name: Set up Lua |
| 23 | + uses: leafo/gh-actions-lua@v9 |
| 24 | + |
| 25 | + - name: Install Stylua |
| 26 | + run: | |
| 27 | + curl -L https://github.com/JohnnyMorganz/StyLua/releases/latest/download/stylua-linux-x86_64.zip -o stylua.zip |
| 28 | + unzip stylua.zip -d stylua-bin |
| 29 | + sudo mv stylua-bin/stylua /usr/local/bin/ |
| 30 | + stylua --version |
| 31 | +
|
| 32 | + - name: Run Stylua formatter |
| 33 | + run: | |
| 34 | + stylua . |
| 35 | +
|
| 36 | + - name: Commit formatted code (if changed) |
| 37 | + run: | |
| 38 | + git config user.name "github-actions" |
| 39 | + git config user.email "github-actions@github.com" |
| 40 | + git add . |
| 41 | + git diff --cached --quiet || git commit -m "chore: auto-format Lua code with Stylua" |
| 42 | + git push |
0 commit comments