diff --git a/.github/workflows/check_diff.yml b/.github/workflows/check_diff.yml index 6f139a4ace2..f8e978eec19 100644 --- a/.github/workflows/check_diff.yml +++ b/.github/workflows/check_diff.yml @@ -8,6 +8,12 @@ on: branch_name: description: 'Name of the feature branch on the forked repo' required: true + language_edition: + description: 'Language edition to run both rustfmt with; can be overridden by language edition settings in `rustfmt_configs`' + required: true + style_edition: + description: 'Style edition to run both rustfmt with; can be overridden by style edition settings in `rustfmt_configs`' + required: true commit_hash: description: 'Optional commit hash from the feature branch' required: false @@ -30,4 +36,4 @@ jobs: rustup target add x86_64-unknown-linux-gnu - name: check diff - run: bash ${GITHUB_WORKSPACE}/ci/check_diff.sh ${{ github.event.inputs.clone_url }} ${{ github.event.inputs.branch_name }} ${{ github.event.inputs.commit_hash || github.event.inputs.branch_name }} ${{ github.event.inputs.rustfmt_configs }} + run: bash ${GITHUB_WORKSPACE}/ci/check_diff.sh ${{ github.event.inputs.clone_url }} ${{ github.event.inputs.branch_name }} ${{ github.events.inputs.language_edition }} ${{ github.events.inputs.style_edition }} ${{ github.event.inputs.commit_hash || github.event.inputs.branch_name }} ${{ github.event.inputs.rustfmt_configs }} diff --git a/ci/check_diff.sh b/ci/check_diff.sh index 5155ec1f0be..40b03ce5a66 100755 --- a/ci/check_diff.sh +++ b/ci/check_diff.sh @@ -3,7 +3,7 @@ set -e function print_usage() { - echo "usage check_diff REMOTE_REPO FEATURE_BRANCH [COMMIT_HASH] [OPTIONAL_RUSTFMT_CONFIGS]" + echo "usage check_diff REMOTE_REPO FEATURE_BRANCH LANGUAGE_EDITION STYLE_EDITION [COMMIT_HASH] [OPTIONAL_RUSTFMT_CONFIGS]" } if [ $# -le 1 ]; then @@ -13,8 +13,17 @@ fi REMOTE_REPO=$1 FEATURE_BRANCH=$2 -OPTIONAL_COMMIT_HASH=$3 -OPTIONAL_RUSTFMT_CONFIGS=$4 + +# Required language edition and style edition inputs. +# +# Can still be overridden by style edition configuration in `OPTIONAL_RUSTFMT_CONFIGS`. They are +# separate arg mostly to make sure they are not forgotten when manually dispatching the Diff Check +# workflow. +LANGUAGE_EDITION=$3 +STYLE_EDITION=$4 + +OPTIONAL_COMMIT_HASH=$5 +OPTIONAL_RUSTFMT_CONFIGS=$6 # OUTPUT array used to collect all the status of running diffs on various repos STATUSES=() @@ -36,7 +45,7 @@ function init_submodules() { git submodule update --init $1 } -# Run rusfmt with the --check flag to see if a diff is produced. +# Run rustfmt with the --check flag to see if a diff is produced. # # Parameters: # $1: Path to a rustfmt binary @@ -44,13 +53,28 @@ function init_submodules() { # $3: Any additional configuration options to pass to rustfmt # # Globals: -# $OPTIONAL_RUSTFMT_CONFIGS: Optional configs passed to the script from $4 +# $LANGUAGE_EDITION: Language edition. When not specified, `rustfmt` (like +# `rustc`) will default to Edition 2015, which for the projects being +# compared will likely cause parse errors since they tend to be on +# Edition 2024 (or later). Can still be override by language edition +# specified in `$OPTIONAL_RUSTFMT_CONFIGS`. +# $STYLE_EDITION: Style edition; can be overridden by style edition specified in +# `$OPTIONAL_RUSTFMT_CONFIGS`. +# $OPTIONAL_RUSTFMT_CONFIGS: Optional configs passed to the script function create_diff() { local config; + # Unconditionally set + config="--config=error_on_line_overflow=false,error_on_unformatted=false" + # Can still be overridden by later `edition` configurations in + # `$OPTIONAL_RUSTFMT_CONFIGS`. + config="$config,edition=$LANGUAGE_EDITION" + + # Can still be overridden by later `style_edition` configurations in + # `$OPTIONAL_RUSTFMT_CONFIGS`. + config="$config,style_edition=$STYLE_EDITION" + if [ -z "$3" ]; then - config="--config=error_on_line_overflow=false,error_on_unformatted=false" - else - config="--config=error_on_line_overflow=false,error_on_unformatted=false,$OPTIONAL_RUSTFMT_CONFIGS" + config="$config,$OPTIONAL_RUSTFMT_CONFIGS" fi for i in `find . | grep "\.rs$"` @@ -65,12 +89,12 @@ function create_diff() { # $1: Name of the repository (used for logging) # # Globals: -# $RUSFMT_BIN: Path to the rustfmt main binary. Created when running `compile_rustfmt` +# $RUSTFMT_BIN: Path to the rustfmt main binary. Created when running `compile_rustfmt` # $FEATURE_BIN: Path to the rustfmt feature binary. Created when running `compile_rustfmt` # $OPTIONAL_RUSTFMT_CONFIGS: Optional configs passed to the script from $4 function check_diff() { echo "running rustfmt (main) on $1" - create_diff $RUSFMT_BIN rustfmt_diff.txt + create_diff $RUSTFMT_BIN rustfmt_diff.txt echo "running rustfmt (feature) on $1" create_diff $FEATURE_BIN feature_diff.txt $OPTIONAL_RUSTFMT_CONFIGS @@ -140,9 +164,9 @@ function compile_rustfmt() { echo -e "\nRuntime dependencies for rustfmt -- LD_LIBRARY_PATH: $LD_LIBRARY_PATH" - RUSFMT_BIN=$1/rustfmt - RUSTFMT_VERSION=$($RUSFMT_BIN --version) - echo -e "\nRUSFMT_BIN $RUSTFMT_VERSION\n" + RUSTFMT_BIN=$1/rustfmt + RUSTFMT_VERSION=$($RUSTFMT_BIN --version) + echo -e "\nRUSTFMT_BIN $RUSTFMT_VERSION\n" FEATURE_BIN=$1/feature_rustfmt FEATURE_VERSION=$($FEATURE_BIN --version) @@ -191,6 +215,10 @@ function log_inputs() { echo "$REMOTE_REPO" echo "Feature branch:" echo "$FEATURE_BRANCH" + echo "Language edition:" + echo "$LANGUAGE_EDITION" + echo "Style edition:" + echo "$STYLE_EDITION" echo "(Optional) Commit hash:" echo "$OPTIONAL_COMMIT_HASH" echo "(Optional) Rustfmt configs:"