diff --git a/.github/actions/format-setup/action.yml b/.github/actions/format-setup/action.yml index f5e36a7836..8f92f0c9e7 100644 --- a/.github/actions/format-setup/action.yml +++ b/.github/actions/format-setup/action.yml @@ -22,7 +22,16 @@ runs: - name: install prettier shell: bash - run: | + run: | npm install prettier@3.3.3 echo "$(npm bin -g)" >> $GITHUB_PATH + - name: install shfmt + shell: bash + run: | + tmpdir=$(mktemp -d) + curl -L -H "Authorization: token ${{github.token}}" \ + -o "$tmpdir/shfmt" \ + https://github.com/mvdan/sh/releases/download/v3.10.0/shfmt_v3.10.0_linux_amd64 + chmod +x "$tmpdir/shfmt" + echo "$tmpdir" >> $GITHUB_PATH diff --git a/docs/scripts/release-note.sh b/docs/scripts/release-note.sh index 250873bb01..d63ee8736c 100644 --- a/docs/scripts/release-note.sh +++ b/docs/scripts/release-note.sh @@ -16,27 +16,23 @@ verbose=true $verbose && echo "Reminder: PLEASE make sure your local repo is up-to-date before running the script." >&2 gh="" -for candidate in "$(which gh.exe)" "/mnt/c/Program Files/GitHub CLI/gh.exe" "/c/Program Files/GitHub CLI/gh.exe" "/cygdrive/c/Program Files/GitHub CLI/gh.exe" -do - if [ -x "$candidate" ] - then - gh="$candidate" - break - fi +for candidate in "$(which gh.exe)" "/mnt/c/Program Files/GitHub CLI/gh.exe" "/c/Program Files/GitHub CLI/gh.exe" "/cygdrive/c/Program Files/GitHub CLI/gh.exe"; do + if [ -x "$candidate" ]; then + gh="$candidate" + break + fi done -if [ "x$gh" = "x" ] || ! [ -x "$gh" ] -then - echo "File not found: gh.exe" - echo "gh.exe can be downloaded from https://cli.github.com" - exit 1 +if [ "x$gh" = "x" ] || ! [ -x "$gh" ]; then + echo "File not found: gh.exe" + echo "gh.exe can be downloaded from https://cli.github.com" + exit 1 fi $verbose && echo "gh.exe is found from: $gh" >&2 -if [ "x$1" = "x" ] -then - echo "This script requires 'since' information for git-log command." - echo "Usage: $0 2024-07-30" - exit 1 +if [ "x$1" = "x" ]; then + echo "This script requires 'since' information for git-log command." + echo "Usage: $0 2024-07-30" + exit 1 fi since="$1" @@ -45,62 +41,55 @@ commitsCount="$(echo "$commits" | wc -l)" echo "=== Breaking changes ===" breakingChanges="" -for i in $(seq $commitsCount) -do - line="$(echo "$commits" | head -$i | tail -1)" - - # Get PR number from the git commit title - pr="$(echo "$line" | grep '#[1-9][0-9][0-9][0-9][0-9]*' | sed 's|.* (\#\([1-9][0-9][0-9][0-9][0-9]*\))|\1|')" - [ "x$pr" = "x" ] && continue - - # Check if the PR is marked as a breaking change - if "$gh" issue view $pr --json labels | grep -q 'pr: breaking change' - then - breakingChanges+="$line" - fi +for i in $(seq $commitsCount); do + line="$(echo "$commits" | head -$i | tail -1)" + + # Get PR number from the git commit title + pr="$(echo "$line" | grep '#[1-9][0-9][0-9][0-9][0-9]*' | sed 's|.* (\#\([1-9][0-9][0-9][0-9][0-9]*\))|\1|')" + [ "x$pr" = "x" ] && continue + + # Check if the PR is marked as a breaking change + if "$gh" issue view $pr --json labels | grep -q 'pr: breaking change'; then + breakingChanges+="$line" + fi done -if [ "x$breakingChanges" = "x" ] -then - echo "No breaking changes" +if [ "x$breakingChanges" = "x" ]; then + echo "No breaking changes" else - echo "$breakingChanges" + echo "$breakingChanges" fi echo "" echo "=== All changes for this release ===" -for i in $(seq $commitsCount) -do - line="$(echo "$commits" | head -$i | tail -1)" - - result="$line" - for dummy in 1 - do - # Get PR number from the git commit title - pr="$(echo "$line" | grep '#[1-9][0-9][0-9][0-9][0-9]*' | sed 's|.* (\#\([1-9][0-9][0-9][0-9][0-9]*\))|\1|')" - [ "x$pr" = "x" ] && break - - # Mark breaking changes with "[BREAKING]" - if "$gh" issue view $pr --json labels | grep -q 'pr: breaking change' - then - result="[BREAKING] $line" - fi - - # Get the issue number for the PR - body="$("$gh" issue view $pr --json body)" - [ "x$body" = "x" ] && break - issue="$(echo "$body" | grep '#[1-9][0-9][0-9][0-9][0-9]*' | sed 's|.*\#\([1-9][0-9][0-9][0-9][0-9]*\).*|\1|')" - [ "x$issue" = "x" ] && break - - # Get the labels of the issue - label="$("$gh" issue view $issue --json labels)" - [ "x$label" = "x" ] && break - - # Get the goal type from the labels - goal="$(echo "$label" | grep '"goal:' | sed 's|.*"goal:\([^"]*\)".*|\1|')" - [ "x$goal" = "x" ] && break - - result+=" (#$issue:$goal)" - done - echo "$result" +for i in $(seq $commitsCount); do + line="$(echo "$commits" | head -$i | tail -1)" + + result="$line" + for dummy in 1; do + # Get PR number from the git commit title + pr="$(echo "$line" | grep '#[1-9][0-9][0-9][0-9][0-9]*' | sed 's|.* (\#\([1-9][0-9][0-9][0-9][0-9]*\))|\1|')" + [ "x$pr" = "x" ] && break + + # Mark breaking changes with "[BREAKING]" + if "$gh" issue view $pr --json labels | grep -q 'pr: breaking change'; then + result="[BREAKING] $line" + fi + + # Get the issue number for the PR + body="$("$gh" issue view $pr --json body)" + [ "x$body" = "x" ] && break + issue="$(echo "$body" | grep '#[1-9][0-9][0-9][0-9][0-9]*' | sed 's|.*\#\([1-9][0-9][0-9][0-9][0-9]*\).*|\1|')" + [ "x$issue" = "x" ] && break + + # Get the labels of the issue + label="$("$gh" issue view $issue --json labels)" + [ "x$label" = "x" ] && break + + # Get the goal type from the labels + goal="$(echo "$label" | grep '"goal:' | sed 's|.*"goal:\([^"]*\)".*|\1|')" + [ "x$goal" = "x" ] && break + + result+=" (#$issue:$goal)" + done + echo "$result" done - diff --git a/external/build-llvm.sh b/external/build-llvm.sh index 95302a742b..0575bf4bfb 100755 --- a/external/build-llvm.sh +++ b/external/build-llvm.sh @@ -20,7 +20,7 @@ EOF # # Some helper functions # -msg(){ +msg() { printf "%s\n" "$1" >&2 } @@ -62,13 +62,35 @@ extra_arguments=() while [[ "$#" -gt 0 ]]; do case $1 in - -h | --help) help; exit ;; - --repo) repo=$2; shift;; - --branch) branch=$2; shift;; - --source-dir) source_dir=$2; shift;; - --config) config=$2; shift;; - --install-prefix) install_prefix=$2; shift;; - --) shift; extra_arguments+=("$@"); break;; + -h | --help) + help + exit + ;; + --repo) + repo=$2 + shift + ;; + --branch) + branch=$2 + shift + ;; + --source-dir) + source_dir=$2 + shift + ;; + --config) + config=$2 + shift + ;; + --install-prefix) + install_prefix=$2 + shift + ;; + --) + shift + extra_arguments+=("$@") + break + ;; *) msg "Unknown parameter passed: $1" help >&2 diff --git a/external/bump-glslang.sh b/external/bump-glslang.sh index b7d30e3a07..d3923cf0e7 100755 --- a/external/bump-glslang.sh +++ b/external/bump-glslang.sh @@ -35,7 +35,7 @@ while [[ "$#" -gt 0 ]]; do shift done -if [ $help ]; then +if [ "$help" ]; then me=$(basename "$0") cat < /dev/null - then - echo "This script needs $1, but it isn't in \$PATH" - missing_bin=1 +require_bin() { + if ! command -v "$1" &>/dev/null; then + echo "This script needs $1, but it isn't in \$PATH" + missing_bin=1 fi } require_bin "jq" require_bin "git" require_bin "python" require_bin "cmake" -if [ $missing_bin ]; then +if [ "$missing_bin" ]; then exit 1 fi @@ -100,13 +97,13 @@ if ! test -f "$glslang/.git"; then exit 1 fi -known_good_commit(){ +known_good_commit() { jq <"$glslang/known_good.json" \ ".commits | .[] | select(.name == \"$1\") | .commit" \ --raw-output } -bump_dep(){ +bump_dep() { commit=$(known_good_commit "$2") big_msg "Fetching $commit from origin in $1" git -C "$1" fetch origin "$commit" @@ -116,7 +113,7 @@ bump_dep(){ declare -A old_ref declare -A new_ref -merge_dep(){ +merge_dep() { name=$1 dir=$2 up=$3 @@ -180,14 +177,15 @@ rm -f "$spirv_tools_generated/*.{inc,h}" cp --target-directory "$spirv_tools_generated" "$build"/*.{inc,h} set +x -if [ $do_commit ]; then +if [ "$do_commit" ]; then big_msg "Committing changes" - msg=$(cat < ${new_ref["glslang"]} external/spirv-tools: ${old_ref["spirv-tools"]} -> ${new_ref["spirv-tools"]}" EOF -) + ) git commit \ --message "$msg" \ diff --git a/extras/formatting.sh b/extras/formatting.sh index 9bf2bdba6e..88bf219ff0 100755 --- a/extras/formatting.sh +++ b/extras/formatting.sh @@ -75,6 +75,7 @@ require_bin "xargs" "3" require_bin "diff" "2" require_bin "clang-format" "17" "18" require_bin "prettier" "3" +require_bin "shfmt" "3" if [ "$missing_bin" ]; then exit 1 @@ -83,6 +84,8 @@ fi exit_code=0 cmake_formatting() { + echo "Formatting CMake files..." + readarray -t files < <(git ls-files '*.cmake' 'CMakeLists.txt' '**/CMakeLists.txt') common_args=( @@ -100,7 +103,9 @@ cmake_formatting() { } cpp_formatting() { - readarray -t files < <(git ls-files '*.cpp' '*.hpp' '*.c' '*.h') + echo "Formatting cpp files..." + + readarray -t files < <(git ls-files '*.cpp' '*.hpp' '*.c' '*.h' ':!external/**') if [ "$check_only" -eq 1 ]; then local tmpdir @@ -125,17 +130,37 @@ cpp_formatting() { } yaml_json_formatting() { + echo "Formatting yaml and json files..." + readarray -t files < <(git ls-files "*.yaml" "*.yml" "*.json" ':!external/**') if [ "$check_only" -eq 1 ]; then prettier --check "${files[@]}" || exit_code=1 else - prettier --write "${files[@]}" | grep -v '(unchanged)' + prettier --write "${files[@]}" | grep -v '(unchanged)' || : + fi +} + +sh_formatting() { + echo "Formatting sh files..." + + readarray -t files < <(git ls-files "*.sh") + + common_args=( + # default 8 is way too wide + --indent 2 + ) + + if [ "$check_only" -eq 1 ]; then + shfmt "${common_args[@]}" --diff "${files[@]}" || exit_code=1 + else + shfmt "${common_args[@]}" --write "${files[@]}" fi } -# cmake_formatting -# cpp_formatting +cmake_formatting +cpp_formatting yaml_json_formatting +sh_formatting exit $exit_code