Skip to content

Commit 05f501c

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 05f501c

File tree

7 files changed

+61
-0
lines changed

7 files changed

+61
-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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,24 @@ jobs:
2222
- name: Lint Client JS
2323
run: pnpm clients:js:lint
2424

25+
format_and_lint_workspace_toml:
26+
name: Format & 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: Format workspace level Toml
38+
run: pnpm workspace:toml:format
39+
40+
- name: Lint workspace level Toml
41+
run: pnpm workspace:toml:lint
42+
2543
format_and_lint_client_rust:
2644
if: false # Disabled until we have a Rust client
2745
name: Format & Lint Client Rust
@@ -35,6 +53,7 @@ jobs:
3553
with:
3654
clippy: true
3755
rustfmt: true
56+
tombi: true
3857

3958
- name: Format Client Rust
4059
run: pnpm clients:rust:format
@@ -54,6 +73,7 @@ jobs:
5473
with:
5574
clippy: true
5675
rustfmt: true
76+
tombi: true
5777

5878
- name: Format
5979
run: pnpm programs:format
@@ -73,6 +93,7 @@ jobs:
7393
with:
7494
clippy: true
7595
rustfmt: true
96+
tombi: true
7697

7798
- name: Format
7899
run: pnpm p-interface:format
@@ -92,6 +113,7 @@ jobs:
92113
with:
93114
clippy: true
94115
rustfmt: true
116+
tombi: true
95117

96118
- name: Format
97119
run: pnpm p-token:format
@@ -111,6 +133,7 @@ jobs:
111133
with:
112134
clippy: true
113135
rustfmt: true
136+
tombi: true
114137

115138
- name: Format
116139
run: pnpm interface:format

.github/workflows/publish-rust.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ jobs:
5656
with:
5757
clippy: true
5858
rustfmt: true
59+
tombi: true
5960
solana: true
6061
cargo-cache-key: cargo-test-publish-${{ inputs.package_path }}
6162
cargo-cache-fallback-key: cargo-test-publish
@@ -66,6 +67,12 @@ jobs:
6667
- name: Lint
6768
run: pnpm zx ./scripts/rust/lint.mjs "${{ inputs.package_path }}"
6869

70+
- name: Format Toml
71+
run: pnpm zx ./scripts/toml/format.mjs "${{ inputs.package_path }}"
72+
73+
- name: Lint Toml
74+
run: pnpm zx ./scripts/toml/lint.mjs "${{ inputs.package_path }}"
75+
6976
- name: Build programs
7077
run: pnpm programs:build
7178

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"private": true,
33
"scripts": {
4+
"workspace:toml:format": "zx ./scripts/toml/format.mjs Cargo.toml rust-toolchain.toml rustfmt.toml scripts/spellcheck.toml",
5+
"workspace:toml:lint": "zx ./scripts/toml/lint.mjs Cargo.toml rust-toolchain.toml rustfmt.toml scripts/spellcheck.toml",
46
"programs:build": "zx ./scripts/rust/build-sbf.mjs program",
57
"programs:format": "zx ./scripts/rust/format.mjs program",
68
"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 format --check ${args}`;
13+
}

scripts/toml/lint.mjs

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

0 commit comments

Comments
 (0)