Skip to content

Commit de7a32e

Browse files
committed
CI: Require TOML to be formatted
tombi is a pretty good TOML formatter/LSP with support for TOML in general, and Rust Cargo.toml in particular. Using a unified format is nice. In particular, tombi sorts not just properties within a section, but also sections and tables. Apparently some TOML parsers may fail if tables are not correctly sorted.
1 parent dfb2602 commit de7a32e

File tree

5 files changed

+43
-0
lines changed

5 files changed

+43
-0
lines changed

.github/actions/setup/action.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ inputs:
1919
rustfmt:
2020
description: Install Rustfmt if `true`. Defaults to `false`.
2121
required: false
22+
tombi:
23+
description: Install tombi if `true`. Defaults to `false`.
24+
required: false
2225
solana:
2326
description: Install Solana if `true`. Defaults to `false`.
2427
required: false
@@ -95,6 +98,10 @@ runs:
9598
toolchain: ${{ env.TOOLCHAIN_LINT }}
9699
components: clippy
97100

101+
- name: Install tombi
102+
if: ${{ inputs.tombi == 'true' }}
103+
uses: tombi-toml/setup-tombi@v1
104+
98105
- name: Install Solana
99106
if: ${{ inputs.solana == 'true' }}
100107
uses: solana-program/actions/install-solana@v1

.github/workflows/main.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,21 @@ jobs:
2222
- name: Lint Client JS
2323
run: pnpm clients:js:lint
2424

25+
lint_workspace_toml:
26+
name: Lint workspace level Toml
27+
runs-on: ubuntu-latest
28+
steps:
29+
- name: Git Checkout
30+
uses: actions/checkout@v4
31+
32+
- name: Setup Environment
33+
uses: ./.github/actions/setup
34+
with:
35+
tombi: true
36+
37+
- name: Lint workspace level Toml
38+
run: pnpm workspace:toml:lint
39+
2540
format_and_lint_client_rust:
2641
if: false # Disabled until we have a Rust client
2742
name: Format & Lint Client Rust
@@ -35,6 +50,7 @@ jobs:
3550
with:
3651
clippy: true
3752
rustfmt: true
53+
tombi: true
3854

3955
- name: Format Client Rust
4056
run: pnpm clients:rust:format
@@ -54,6 +70,7 @@ jobs:
5470
with:
5571
clippy: true
5672
rustfmt: true
73+
tombi: true
5774

5875
- name: Format
5976
run: pnpm programs:format
@@ -73,6 +90,7 @@ jobs:
7390
with:
7491
clippy: true
7592
rustfmt: true
93+
tombi: true
7694

7795
- name: Format
7896
run: pnpm p-interface:format
@@ -92,6 +110,7 @@ jobs:
92110
with:
93111
clippy: true
94112
rustfmt: true
113+
tombi: true
95114

96115
- name: Format
97116
run: pnpm p-token:format
@@ -111,6 +130,7 @@ jobs:
111130
with:
112131
clippy: true
113132
rustfmt: true
133+
tombi: true
114134

115135
- name: Format
116136
run: pnpm interface:format

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"private": true,
33
"scripts": {
4+
"workspace:toml:lint": "zx ./scripts/toml/lint.mjs Cargo.toml rust-toolchain.toml rustfmt.toml scripts/spellcheck.toml",
45
"programs:build": "zx ./scripts/rust/build-sbf.mjs program",
56
"programs:format": "zx ./scripts/rust/format.mjs program",
67
"programs:lint": "zx ./scripts/rust/lint.mjs program",

scripts/rust/format.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ const manifestPath = path.join(workingDirectory, folder, 'Cargo.toml');
1818

1919
// Format the client.
2020
if (fix) {
21+
await $`tombi format ${formatArgs} ${folder}`;
2122
await $`cargo ${toolchain} fmt --manifest-path ${manifestPath} ${cargoArgs} -- ${fmtArgs}`;
2223
} else {
24+
await $`tombi lint ${formatArgs} ${folder}`;
2325
await $`cargo ${toolchain} fmt --manifest-path ${manifestPath} ${cargoArgs} -- --check ${fmtArgs}`;
2426
}

scripts/toml/format.mjs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env zx
2+
import 'zx/globals';
3+
import { cliArguments, popArgument } from '../utils.mjs';
4+
5+
const args = cliArguments();
6+
7+
const fix = popArgument(args, '--fix');
8+
9+
if (fix) {
10+
await $`tombi format ${args}`;
11+
} else {
12+
await $`tombi lint ${args}`;
13+
}

0 commit comments

Comments
 (0)