Skip to content

Commit

Permalink
feat: adds zk linkcheck to zk tool and updates zk env for `zk linkc…
Browse files Browse the repository at this point in the history
…heck` ci usage (matter-labs#868)

Related PRs:
- matter-labs#869
- matter-labs#870

## What ❔
- Adds `zk linkcheck` to zk tool
- Adds required dependencies to make use of `zk linkcheck` in zk env
- Adds `zk linkcheck` docs 
- Updates `spellcheck` dir to be general `checks-config` dir to include
spellcheck and link configuration files
- Fixes issue with `zk spellcheck` exit code
<!-- What are the changes this PR brings about? -->
<!-- Example: This PR adds a PR template to the repo. -->
<!-- (For bigger PRs adding more context is appreciated) -->

## Why ❔
- `zk linkcheck` will ensure no dead links exist in repo and prevent
unnecessary PRs
- Required to install dependencies, similar to `zk spellcheck` 
- Relevant docs to outline `zk linkcheck` usage 

<!-- Why are these changes done? What goal do they contribute to? What
are the principles behind them? -->
<!-- Example: PR templates ensure PR reviewers, observers, and future
iterators are in context about the evolution of repos. -->

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [x] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [x] Documentation comments have been added / updated.
- [x] Code has been formatted via `zk fmt` and `zk lint`.
- [x] Spellcheck has been run via `zk spellcheck`.
  • Loading branch information
dutterbutter authored Jan 15, 2024
1 parent c7d4c24 commit d64f584
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 13 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
29 changes: 29 additions & 0 deletions checks-config/links.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"ignorePatterns": [
{
"pattern": "^https://github\\.com/matter-labs/zksync-2-dev/"
},
{
"pattern": "^https://www\\.notion\\.so/"
},
{
"pattern": "^https://github\\.com/matter-labs/zksync-era/compare/"
},
{
"pattern": "^https://twitter\\.com/zksync"
},
{
"pattern": "^https://twitter\\.com/zkSyncDevs"
},
{
"pattern": "^https://github\\.com/matter-labs/zk_evm"
},
{
"pattern": "^https://sepolia\\.etherscan\\.io/tx/0x18c2a113d18c53237a4056403047ff9fafbf772cb83ccd44bb5b607f8108a64c"
},
{
"pattern": "^https://github\\.com/matter-labs/zksync-era/commit/"
}
],
"aliveStatusCodes": [0, 200, 206, 304]
}
2 changes: 1 addition & 1 deletion core/lib/dal/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub struct ConnectionPool {
impl fmt::Debug for ConnectionPool {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
// We don't print the `database_url`, as is may contain
// sensistive information (e.g. database password).
// sensitive information (e.g. database password).
formatter
.debug_struct("ConnectionPool")
.field("max_size", &self.max_size)
Expand Down
2 changes: 1 addition & 1 deletion core/lib/zksync_core/src/consensus/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ impl PersistentBlockStore for BlockStore {
ctx: &ctx::Ctx,
block: &validator::FinalBlock,
) -> ctx::Result<()> {
// This mutex prevents concurrent store_next_block calls.
// This mutex prevents concurrent `store_next_block` calls.
let mut guard = ctx.wait(self.store_next_block_mutex.lock()).await?;
if let Some(cursor) = &mut *guard {
cursor.advance(block).await.context("cursor.advance()")?;
Expand Down
2 changes: 1 addition & 1 deletion core/lib/zksync_core/src/consensus/testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl MainNodeClient for MockMainNodeClient {

/// Fake StateKeeper for tests.
pub(super) struct StateKeeper {
// Batch of the last_block.
// Batch of the `last_block`.
last_batch: L1BatchNumber,
last_block: MiniblockNumber,
// timestamp of the last block.
Expand Down
4 changes: 2 additions & 2 deletions core/lib/zksync_core/src/consensus/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async fn test_validator_block_store() {

// In the current implementation, consensus certificates are created asynchronously
// for the miniblocks constructed by the StateKeeper. This means that consensus actor
// is effectively just backfilling the consensus certificates for the miniblocks in storage.
// is effectively just back filling the consensus certificates for the miniblocks in storage.
#[tokio::test(flavor = "multi_thread")]
async fn test_validator() {
zksync_concurrency::testonly::abort_on_panic();
Expand Down Expand Up @@ -253,7 +253,7 @@ async fn test_fetcher() {
.unwrap();
}

// Test fetcher backfilling missing certs.
// Test fetcher back filling missing certs.
#[tokio::test(flavor = "multi_thread")]
async fn test_fetcher_backfill_certs() {
zksync_concurrency::testonly::abort_on_panic();
Expand Down
2 changes: 1 addition & 1 deletion docker/local-node/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUN mkdir -p /etc/apt/keyrings && \
wget -c -O - https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list && \
apt-get update && apt-get install nodejs npm -y && \
npm install -g yarn
npm install -g yarn && npm install -g cspell && npm install -g markdown-link-check

# Copy compiler (both solc and zksolc) binaries
# Obtain `solc` 0.8.12.
Expand Down
2 changes: 1 addition & 1 deletion docker/zk-environment/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ RUN mkdir -p /etc/apt/keyrings && \
wget -c -O - https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list && \
apt-get update && apt-get install nodejs npm -y && \
npm install -g yarn && npm install -g cspell@latest
npm install -g yarn && npm install -g cspell && npm install -g markdown-link-check

# Install Rust and required cargo packages
ENV RUSTUP_HOME=/usr/local/rustup \
Expand Down
18 changes: 17 additions & 1 deletion docs/guides/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,27 @@ the spell check, use the following command:
zk spellcheck
Options:
--pattern <pattern>: Specifies the glob pattern for files to check. Default is docs/**/*.
--config <config>: Path to the configuration file. Default is ./spellcheck/cspell.json.
--use-cargo: Utilize cargo spellcheck.
--use-cspell: Utilize cspell.
```

## Link Checking

To maintain the integrity and reliability of our documentation, we make use of a link checking process using the
`markdown-link-check` tool. This ensures that all links in our markdown files are valid and accessible. The following
section describes how to use this tool and configure it for specific needs.

### Using the Link Check Command

The link check command `zk linkcheck` is designed to verify the integrity of links in our markdown files. To execute the
link check, use the following command:

```
zk linkcheck
Options:
--config <config>: Path to the markdown-link-check configuration file. Default is './checks-config/links.json'.
```

### General Rules

**Code References in Comments**: When referring to code elements within development comments, they should be wrapped in
Expand Down
5 changes: 3 additions & 2 deletions infrastructure/zk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"@types/tabtab": "^3.0.1",
"hardhat": "=2.16.0",
"typescript": "^4.3.5",
"cspell": "*",
"sql-formatter": "^13.1.0"
"cspell": "^8.3.2",
"sql-formatter": "^13.1.0",
"markdown-link-check": "^3.11.2"
}
}
2 changes: 2 additions & 0 deletions infrastructure/zk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { command as verifyUpgrade } from './verify-upgrade';
import { proverCommand } from './prover_setup';
import { command as status } from './status';
import { command as spellcheck } from './spellcheck';
import { command as linkcheck } from './linkcheck';
import * as env from './env';

const COMMANDS = [
Expand Down Expand Up @@ -50,6 +51,7 @@ const COMMANDS = [
env.command,
status,
spellcheck,
linkcheck,
completion(program as Command)
];

Expand Down
25 changes: 25 additions & 0 deletions infrastructure/zk/src/linkcheck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Command } from 'commander';
import * as utils from './utils';

export async function runMarkdownLinkCheck(configPath: string) {
// Command line usage for markdown-link-check suggests using find and xargs for
// recursive checks. See: `https://github.com/tcort/markdown-link-check?tab=readme-ov-file#check-links-from-a-local-markdown-folder-recursive`
const findCommand = `find . -name "*.md" ! -path "*/node_modules/*" ! -path "*/target/release/*" ! -path "*/build/*" ! -path "*/contracts/*" -print0`;
const markdownLinkCheckCommand = `xargs -0 -n1 markdown-link-check --config ${configPath}`;
const fullCommand = `${findCommand} | ${markdownLinkCheckCommand}`;

try {
await utils.spawn(fullCommand);
console.log('Markdown link check completed successfully');
} catch (error) {
console.error('Error occurred during markdown link checking:', error);
process.exit(1);
}
}

export const command = new Command('linkcheck')
.option('--config <config>', 'Path to configuration file', './checks-config/links.json')
.description('Run markdown link check on specified files')
.action((cmd) => {
runMarkdownLinkCheck(cmd.config);
});
6 changes: 3 additions & 3 deletions infrastructure/zk/src/spellcheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import * as utils from './utils';

export async function runSpellCheck(pattern: string, useCargo: boolean, useCSpell: boolean) {
// Default commands for cSpell and cargo spellcheck
const cSpellCommand = `cspell "${pattern}" --config=./spellcheck/cspell.json`;
const cargoCommand = `cargo spellcheck --cfg=./spellcheck/era.cfg`;
const cSpellCommand = `cspell "${pattern}" --config=./checks-config/cspell.json`;
const cargoCommand = `cargo spellcheck --cfg=./checks-config/era.cfg --code 1`;
// Necessary to run cargo spellcheck in the prover directory explicitly as
// it is not included in the root cargo.toml file
const cargoCommandForProver = `cargo spellcheck --cfg=../spellcheck/era.cfg`;
const cargoCommandForProver = `cargo spellcheck --cfg=../checks-config/era.cfg --code 1`;

try {
let results = [];
Expand Down

0 comments on commit d64f584

Please sign in to comment.