Skip to content

Commit

Permalink
Simplify scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
febo committed Dec 17, 2024
1 parent 6de27e9 commit d240c5f
Show file tree
Hide file tree
Showing 23 changed files with 186 additions and 128 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ jobs:
toolchain: format, lint

- name: Format
run: pnpm rust:format client
run: pnpm rust:format

- name: Lint / Clippy
run: pnpm tsx ./scripts/helpers/rust/lint-clippy.mjs client
run: pnpm rust:lint:clippy

- name: Lint / Docs
run: pnpm tsx ./scripts/helpers/rust/lint-docs.mjs client
run: pnpm rust:lint:docs

- name: Lint / Features
run: pnpm tsx ./scripts/helpers/rust/lint-features.mjs client
run: pnpm rust:lint:features

format_and_lint_interface:
name: Format & Lint Interface
Expand All @@ -59,16 +59,16 @@ jobs:
toolchain: format, lint

- name: Format
run: pnpm rust:format interface
run: pnpm interface:format

- name: Lint / Clippy
run: pnpm tsx ./scripts/helpers/rust/lint-clippy.mjs interface
run: pnpm interface:lint:clippy

- name: Lint / Docs
run: pnpm tsx ./scripts/helpers/rust/lint-docs.mjs interface
run: pnpm interface:lint:docs

- name: Lint / Features
run: pnpm tsx ./scripts/helpers/rust/lint-features.mjs interface
run: pnpm interface:lint:features

wasm_interface:
name: Build Interface in WASM
Expand All @@ -90,7 +90,7 @@ jobs:
tool: wasm-pack

- name: Build Interface with wasm-pack
run: pnpm rust:wasm interface
run: pnpm interface:wasm

test_interface:
name: Test Interface
Expand All @@ -108,7 +108,7 @@ jobs:
solana: true

- name: Test Interface
run: pnpm rust:test interface
run: pnpm interface:test

generate_clients:
name: Check Client Generation
Expand Down Expand Up @@ -162,4 +162,4 @@ jobs:
solana: true

- name: Test Client Rust
run: pnpm rust:test client
run: pnpm rust:test
8 changes: 4 additions & 4 deletions .github/workflows/publish-rust-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ jobs:
solana: true

- name: Format
run: pnpm rust:format client
run: pnpm rust:format

- name: Lint
run: pnpm rust:lint client
run: pnpm rust:lint

- name: Test
run: pnpm rust:test client
run: pnpm rust:test

publish_rust:
name: Publish Rust Client
Expand Down Expand Up @@ -109,7 +109,7 @@ jobs:
OPTIONS=""
fi
pnpm clients:rust:publish $LEVEL $OPTIONS
pnpm rust:publish $LEVEL $OPTIONS
- name: Push Commit and Tag
if: github.event.inputs.dry_run != 'true'
Expand Down
28 changes: 19 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,25 @@
"validator:start": "tsx ./scripts/helpers/start-validator.mts",
"validator:restart": "pnpm validator:start --restart",
"validator:stop": "tsx ./scripts/helpers/stop-validator.mts",
"js:format": "tsx ./scripts/helpers/js/format.mts",
"js:lint": "tsx ./scripts/helpers/js/lint.mts",
"js:publish": "tsx ./scripts/helpers/js/publish.mts",
"js:test": "tsx ./scripts/helpers/js/test.mts",
"rust:format": "tsx ./scripts/helpers/rust/format.mts",
"rust:lint": "tsx ./scripts/helpers/rust/lint.mts",
"rust:publish": "tsx ./scripts/helpers/rust/publish.mts",
"rust:test": "tsx ./scripts/helpers/rust/test.mts",
"rust:wasm": "tsx ./scripts/helpers/rust/wasm.mts",
"js:format": "tsx ./scripts/js/format.mts",
"js:lint": "tsx ./scripts/js/lint.mts",
"js:publish": "tsx ./scripts/js/publish.mts",
"js:test": "tsx ./scripts/js/test.mts",
"rust:format": "tsx ./scripts/rust/format.mts clients/rust",
"rust:lint": "tsx ./scripts/rust/lint.mts clients/rust",
"rust:lint:clippy": "tsx ./scripts/rust/lint-clippy.mts clients/rust",
"rust:lint:docs": "tsx ./scripts/rust/lint-docs.mts clients/rust",
"rust:lint:features": "tsx ./scripts/rust/lint-features.mts clients/rust",
"rust:publish": "tsx ./scripts/rust/publish.mts clients/rust",
"rust:test": "tsx ./scripts/rust/test.mts clients/rust",
"interface:format": "tsx ./scripts/rust/format.mts interface",
"interface:lint": "tsx ./scripts/rust/lint.mts interface",
"interface:lint:clippy": "tsx ./scripts/rust/lint-clippy.mts interface",
"interface:lint:docs": "tsx ./scripts/rust/lint-docs.mts interface",
"interface:lint:features": "tsx ./scripts/rust/lint-features.mts interface",
"interface:publish": "tsx ./scripts/rust/publish.mts interface",
"interface:test": "tsx ./scripts/rust/test.mts interface",
"interface:wasm": "tsx ./scripts/rust/wasm.mts interface",
"template:upgrade": "tsx ./scripts/helpers/upgrade-template.ts"
},
"devDependencies": {
Expand Down
17 changes: 0 additions & 17 deletions scripts/helpers/rust/format.mts

This file was deleted.

16 changes: 0 additions & 16 deletions scripts/helpers/rust/lint-clippy.mts

This file was deleted.

10 changes: 0 additions & 10 deletions scripts/helpers/rust/lint-docs.mts

This file was deleted.

11 changes: 0 additions & 11 deletions scripts/helpers/rust/lint-features.mts

This file was deleted.

17 changes: 0 additions & 17 deletions scripts/helpers/rust/lint.mts

This file was deleted.

18 changes: 0 additions & 18 deletions scripts/helpers/rust/test.mts

This file was deleted.

8 changes: 0 additions & 8 deletions scripts/helpers/rust/wasm.mts

This file was deleted.

23 changes: 20 additions & 3 deletions scripts/helpers/utils.mts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'zx/globals';
import { parse as parseToml } from '@iarna/toml';
import { JsonMap, parse as parseToml } from '@iarna/toml';

process.env.FORCE_COLOR = '3';
process.env.CARGO_TERM_COLOR = 'always';
Expand Down Expand Up @@ -70,7 +70,7 @@ export function getAllProgramFolders(): string[] {
);
}

export function getCargo(folder?: string) {
export function getCargo(folder?: string): JsonMap {
return parseToml(
fs.readFileSync(
path.join(workingDirectory, folder ? folder : '.', 'Cargo.toml'),
Expand Down Expand Up @@ -98,7 +98,7 @@ export function getToolchainArgument(operation): string {
}

export function cliArguments(): string[] {
return process.argv.slice(3);
return process.argv.slice(2);
}

export function popArgument(args: string[], arg: string) {
Expand Down Expand Up @@ -127,3 +127,20 @@ export async function getInstalledSolanaVersion(): Promise<string | undefined> {
return '';
}
}

export function parseCliArguments(): { manifestPath: string; args: string[] } {
// Command-line arguments.
const args = cliArguments();
// Extract the relative crate directory from the command-line arguments. This
// is the only required argument.
const relativePath = args.shift();

if (!relativePath) {
throw new Error('Missing relative manifest path');
}

return {
manifestPath: path.join(workingDirectory, relativePath, 'Cargo.toml'),
args,
};
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions scripts/rust/format.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env zx
import 'zx/globals';
import {
getToolchainArgument,
parseCliArguments,
partitionArguments,
popArgument,
} from '../helpers/utils.mts';

// Extract the crate directory from the command-line arguments.
const { manifestPath, args } = parseCliArguments();
// Configure additional arguments here, e.g.:
// ['--arg1', '--arg2', ...args]
const formatArgs = args;

const fix = popArgument(args, '--fix');
const [cargoArgs, fmtArgs] = partitionArguments(formatArgs, '--');
const toolchain = getToolchainArgument('format');

await $`cargo ${toolchain} fmt --manifest-path ${manifestPath} ${cargoArgs} -- ${fix ? '' : '--check'} ${fmtArgs}`;
22 changes: 22 additions & 0 deletions scripts/rust/lint-clippy.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env zx
import 'zx/globals';
import {
getToolchainArgument,
parseCliArguments,
popArgument,
} from '../helpers/utils.mts';

// Extract the crate directory from the command-line arguments.
const { manifestPath, args } = parseCliArguments();
// Configure additional arguments here, e.g.:
// ['--arg1', '--arg2', ...args]
const clippyArgs = args;
// Note: need to use nightly clippy as frozen-abi proc-macro generates
// a lot of code (frozen-abi is enabled only under nightly due to the
// use of unstable rust feature). Likewise, frozen-abi(-macro) crates'
// unit tests are only compiled under nightly.
const toolchain = getToolchainArgument('lint');
// Check if the `--fix` argument is present.
const fix = popArgument(clippyArgs, '--fix');

await $`cargo ${toolchain} clippy --manifest-path ${manifestPath} ${fix ? '--fix' : ''} ${clippyArgs}`;
12 changes: 12 additions & 0 deletions scripts/rust/lint-docs.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env zx
import 'zx/globals';
import { getToolchainArgument, parseCliArguments } from '../helpers/utils.mts';

// Extract the crate directory from the command-line arguments.
const { manifestPath, args } = parseCliArguments();
// Configure additional arguments here, e.g.:
// ['--arg1', '--arg2', ...args]
const docArgs = args;
const toolchain = getToolchainArgument('lint');

await $`RUSTDOCFLAGS="--cfg docsrs -D warnings" cargo ${toolchain} doc --manifest-path ${manifestPath} --all-features --no-deps ${docArgs}`;
13 changes: 13 additions & 0 deletions scripts/rust/lint-features.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env zx
import 'zx/globals';
import { getToolchainArgument, parseCliArguments } from '../helpers/utils.mts';

// Extract the crate directory from the command-line arguments.
const { manifestPath, args } = parseCliArguments();
// Configure additional arguments here, e.g.:
// ['--arg1', '--arg2', ...args]
const featuresArgs = ['--exclude-features', 'frozen-abi', ...args];
const toolchain = getToolchainArgument('lint');

// Check feature powerset.
await $`cargo ${toolchain} hack check --manifest-path ${manifestPath} --feature-powerset --all-targets ${featuresArgs}`;
17 changes: 17 additions & 0 deletions scripts/rust/lint.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Script to lint a crate.
//
// This script runs the following sub-scripts:
// - lint-clippy.mjs
// - lint-docs.mjs
// - lint-features.mjs

import { cliArguments, workingDirectory } from '../helpers/utils.mts';

const scripts = path.join(workingDirectory, 'scripts', 'rust');

// clippy
await $`tsx ${path.join(scripts, 'lint-clippy.mjs')} ${cliArguments()}`;
// rustdoc
await $`tsx ${path.join(scripts, 'lint-docs.mjs')} ${cliArguments()}`;
// features
await $`tsx ${path.join(scripts, 'lint-features.mjs')} ${cliArguments()}`;
Loading

0 comments on commit d240c5f

Please sign in to comment.