Skip to content

Jra.80ch.test1 #3990

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
84 changes: 84 additions & 0 deletions .github/workflows/80ch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/usr/bin/env bash

#**************************************************************************#
#* *#
#* OCaml *#
#* *#
#* James Rayman, Jane Street, New York *#
#* *#
#* Copyright 2025 Jane Street Group LLC *#
#* *#
#* All rights reserved. This file is distributed under the terms of *#
#* the GNU Lesser General Public License version 2.1, with the *#
#* special exception on linking described in the file LICENSE. *#
#* *#
#**************************************************************************#

# 80ch.sh: A GitHub-actions-friendly script which finds lines added in the
# current feature which are longer than 80 characters. To be less
# annoying, 80ch.sh never fails, but instead emits warnings, and only
# checks a subset of all files (See SKIP FILES).

set -u

git fetch origin main --deepen 1 -q # Need to have a local copy of origin/main
# for this script to work

feature_base="$(git merge-base origin/main HEAD)"
# N.b.: main is always considered the parent feature

# Iterate through all files changed since this branch forked off of main.
#
# Separate file names with NULLs. This is Read the next token
# standard for lists of files since file | Tokens are delimited
# names may contain newlines | | | with NULLs
# |- |--- |-------
git diff --name-only "$feature_base" -z | while read -d $'\0' -r changed_file
# ^| ^^^^^^^^^^^|
# Don't allow backslashes to escape characters |
# Store the token in $changed_file
do
# SKIP FILES

# Only check regular files that currently exists
[[ -f "$changed_file" ]] || continue

# Only check ml, mli, and mly files for long lines
[[ "$changed_file" =~ \.ml(i|y)?$ ]] || continue

# Don't check tests for long lines
# (a more sophisticated script would instead remove %%expect blocks)
[[ "$changed_file" == testsuite/tests/* ]] && continue

# Bash doesn't allow for comments on multiline commands, so excuse the
# workaround of putting a groups of argument in a variable
f='--old-line-format= --unchanged-line-format= --new-line-format=%dn:%L'
# |^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |^^^^^^^^^^^^^^^^^^^^^^^
# Don't print deleted or unchanged lines Show added lines (%L),
# prepended with the line number
# (%dn) and a colon

# If $changed_file is new, then
# `git show` will error, but
# ignoring the error results in
# Print the contents of $changed_file a blank output, which is what
# at the feature base we want
# |------------------------------------- |----------
diff $f <(git show "$feature_base:$changed_file" 2>/dev/null) \
"$changed_file" \
| grep -E ":.{81}" | while read -r -d $'\n' long_line
# |^^^^^^^^^^^^^^^
# Search through the output of `diff`,
# looking for 81 characters after the line
# number and colon
do
line="${long_line#*:}" # These parameter expansions split
number="${long_line%%:*}" # on the first colon

# Warning workflow command for GitHub Actions
printf '::warning file=%s,line=%s,title=%s::%s\n' \
"$changed_file" "$number" \
'Line is longer than 80 characters' \
'Consider rewrapping this line'
done
done
23 changes: 23 additions & 0 deletions .github/workflows/80ch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: 80ch
on:
push:
branches:
- main
pull_request:
jobs:
build:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-latest]

steps:
- name: Checkout the Flambda backend repo
uses: actions/checkout@master
with:
path: 'flambda_backend'

- name: Check for new >80 character lines
working-directory: flambda_backend
run: bash .github/workflows/80ch.sh
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ https://help.github.com/articles/allowing-changes-to-a-pull-request-branch-creat
significantly delay the inclusion of an otherwise perfectly ok
contribution.

Only ml, mli, and mly files are subject to 80ch
https://help.github.com/articles/allowing-changes-to-a-pull-request-branch-created-from-a-fork/

### Maintainers

The current list of maintainers is as follows:
Expand Down
Loading
Loading