Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into eli/release
Browse files Browse the repository at this point in the history
  • Loading branch information
EliSchleifer committed Feb 12, 2024
2 parents b891fdc + bc6aa5d commit 843d2ad
Show file tree
Hide file tree
Showing 24 changed files with 506 additions and 93 deletions.
13 changes: 13 additions & 0 deletions .github/actionlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
self-hosted-runner:
labels:
- mint
- small
- 2xlarge
- prod
- playwright
- monorepo-amd64-large
- monorepo-amd64-xlarge
- monorepo-amd64-2xlarge
- monorepo-arm64-2xlarge
- public-amd64-2xlarge
- ubuntu-x64
20 changes: 7 additions & 13 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,23 @@ concurrency:
jobs:
build_and_test:
name: Cargo Test [linux]
runs-on: ubuntu-latest
runs-on: [self-hosted, ubuntu-x64]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable

- name: Cargo Test
run: cargo test

trunk_check_runner:
name: Trunk Check runner [linux]
runs-on: ubuntu-latest
runs-on: [self-hosted, ubuntu-x64]

steps:
- name: Checkout
uses: actions/checkout@v2

# Caching is only needed when using ephemeral CI runners
- name: Cache Linters/Formatters
uses: actions/cache@v2
with:
path: ~/.cache/trunk
key: trunk-${{ runner.os }}
- uses: actions/checkout@v4

- name: Trunk Check
uses: trunk-io/[email protected]
uses: trunk-io/trunk-action@v1
with:
cache: false
2 changes: 2 additions & 0 deletions .trunk/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
*logs
*actions
*notifications
*tools
plugins
user_trunk.yaml
user.yaml
tmp
7 changes: 7 additions & 0 deletions .trunk/config/.shellcheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
enable=all
source-path=SCRIPTDIR
disable=SC2154

# If you're having issues with shellcheck following source, disable the errors via:
# disable=SC1090
# disable=SC1091
10 changes: 10 additions & 0 deletions .trunk/config/.yamllint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
rules:
quoted-strings:
required: only-when-needed
extra-allowed: ["{|}"]
empty-values:
forbid-in-block-mappings: true
forbid-in-flow-mappings: true
key-duplicates: {}
octal-values:
forbid-implicit-octal: true
11 changes: 11 additions & 0 deletions .trunk/setup-ci/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: trunk-io/trunk setup for trunk check/upgrade
description: Set up

runs:
using: composite
steps:
- uses: dtolnay/rust-toolchain@stable

- name: Build trunk-toolbox
shell: bash
run: cargo build
77 changes: 61 additions & 16 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,79 @@ version: 0.1
plugins:
sources:
- id: trunk
ref: v0.0.6
ref: v1.4.2
uri: https://github.com/trunk-io/plugins
runtimes:
enabled:
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
cli:
version: 1.10.1-beta.25
version: 1.19.0
api:
address: api.trunk-staging.io:8443

downloads:
- name: trunk-toolbox
version: 0.0.1
downloads:
- version: 0.0.1
os:
linux: unknown-linux-gnu
macos: apple-darwin
cpu:
x86_64: x86_64
arm_64: aarch64
url: https://github.com/trunk-io/toolbox/releases/download/${version}/trunk-toolbox-${version}-${cpu}-${os}.tar.gz
tools:
definitions:
- name: trunk-toolbox
download: trunk-toolbox
shims: [trunk-toolbox]
known_good_version: 0.0.1
runtimes:
- rust
lint:
linters:
- name: horton
type: sarif
definitions:
- name: trunk-toolbox
tools: [trunk-toolbox]
files: [ALL]
command: ["${workspace}/target/debug/horton", "--file", "${path}"]
success_codes: [0, 1]
commands:
- name: lint
run: ${workspace}/toolbox-latest --upstream=${upstream-ref} --results=${tmpfile} ${target}
output: sarif
batch: true
success_codes: [0]
read_output_from: tmp_file
disable_upstream: true
version_command:
parse_regex: ${semver}
run: trunk-toolbox --version
environment:
- name: PATH
list: ["${linter}"]

enabled:
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- git-diff-check
- taplo@0.7.0
- [email protected].22
- clippy@1.65.0
- gitleaks@8.15.2
- markdownlint@0.32.2
- prettier@2.8.1
- rustfmt@1.65.0
- taplo@0.8.1
- [email protected].26
- clippy@1.76.0
- gitleaks@8.18.2
- markdownlint@0.39.0
- prettier@3.2.5
- rustfmt@1.76.0
actions:
enabled:
- trunk-upgrade-available
- trunk-announce
- trunk-check-pre-push
- trunk-fmt-pre-commit
31 changes: 31 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Contribution

Thanks for contributing to the trunk toolbox! Read on to learn more.

- [Overview](#overview)
- [Development](#development)
- [Testing](#testing)
- [Guidelines](#guidelines)
- [Docs](https://docs.trunk.io)

## Overview

Trunk toolbox is a place for rules that transcend particular languages and are relevant to any code in a repo.

## Development

The trunk.yaml in this repo has been modified to run your local iteration of toolbox as you are building. This is managed through the `trunk-latest` script. Effectively as you run `cargo build` or `cargo build release` the script will pick up the last built binary and use that.

If no local binary has been built then the pinned version in the trunk.yaml will be used.

## Testing

`cargo test` will execute the unit and integration tests for the repo

## Guidelines

Please follow the guidelines below when contributing:

- After defining a rule, please add it to [`README.md`](README.md).
- If you run into any problems while defining a rule, feel free to reach out on our
[Slack](https://slack.trunk.io/).
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ serde = { version = "1.0.145", features = ["derive"] }
serde_json = "1.0.85"
serde-sarif = "0.3.4"
content_inspector = "0.2.4"
rayon = "1.5.1"

[dev-dependencies]
assert_cmd = "2.0"
Expand Down
58 changes: 54 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<!-- trunk-ignore-all(trunk-toolbox) -->
<!-- trunk-ignore-all(markdownlint/MD024) -->

<!-- trunk-ignore(markdownlint/MD041) -->
<p align="center">
<a href="https://marketplace.visualstudio.com/items?itemName=Trunk.io">
Expand All @@ -18,17 +21,64 @@

Toolbox is our custom collection of must have tools for any large software project. We've got a backlog of small tools to built into our toolbox here and happy to take contributions as well. `toolbox` is best used through `trunk check` to keep your development on rails (not the ruby kind).

### Rules
This repo is open to contributions! See our
[contribution guidelines](https://github.com/trunk-io/toolbox/blob/main/CONTRIBUTING.md)

### Enabling

To enable the toolbox rules in your repository run:

```bash
trunk check enable trunk-toolbox
```

| rule | description |
| --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| DONOTLAND | Sometimes you write some code but want to make sure it doesn't actually land. With this rule you can keep yourself from that embarrassing commit that get's pushed for review with hacks or temporary junk inside it |
### Rules

#### do-not-land

##### What it does

Keeps you from accidentally commiting code to a repository that is experimental, temporary, debugging cruft. It keeps you from pushing a PR with a bunch of printf() statements you added while debugging an error.

Valid triggers for this rule are: DONOTLAND, DO-NOT-LAND, DO_NOT_LAND, donotland, do-not-land, do_not_land

##### Why if this bad?

Anything you intentionally don't want in your repo should really not be there. This lets you flag the code you are writing to do testing without worrying that you'll forget you dropped it in your files before pushing your Pull Request.

##### Example

```typescript
// DONOTLAND
console.log("I don't think this code should execute");
```

#### if-change-then-change

##### What it does

Allows you to enforce code synchronization. Often, we have code in one file that is reliant on code in another loosely - say an enum has 4 options and you want to make sure consumers of that enum are kept in sync as new enums are added. This rule will make sure the code is updated in both places when a modification occurs to the code block.

##### Why if this bad?

If code has baked-in assumptions that are not enforced through a check - then they can easily get out of sync. This rule allows you to encode that dependency and ensure all related code is updated when a modification occurs.

##### Example

This rule will report a violation if picker.rs is not updated when the content inside this enum block is modified:

```rust
let x = 7;

// IfChange
enum Flavor {
Strawberry,
Chocholate
}
// ThenChange srcs/robot/picker.rs

x += 9; // why not
```

### Disclaimer

Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn main() {
println!("cargo:rustc-env=CARGO_PKG_VERSION={}", val);
} else {
let output = Command::new("git")
.args(&["rev-parse", "--abbrev-ref", "HEAD"])
.args(["rev-parse", "--abbrev-ref", "HEAD"])
.output()
.unwrap();
let git_ref = String::from_utf8(output.stdout).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[toolchain]
channel = "1.70.0"
channel = "1.76.0"
5 changes: 3 additions & 2 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ fn is_lfs(repo: &Repository, path: &Path) -> bool {
}
}

pub fn modified_since(upstream: &str) -> anyhow::Result<NewOrModified> {
let repo = Repository::open(".")?;
pub fn modified_since(upstream: &str, repo_path: Option<&Path>) -> anyhow::Result<NewOrModified> {
let path = repo_path.unwrap_or(Path::new("."));
let repo = Repository::open(path)?;

let upstream_tree = match repo.find_reference(upstream) {
Ok(reference) => reference.peel_to_tree()?,
Expand Down
Loading

0 comments on commit 843d2ad

Please sign in to comment.