github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/scripts/check-codegen.sh (about) 1 #!/usr/bin/env bash 2 3 # This script ensures that codegen files are up-to-date based on changes to HEAD as 4 # compared to origin/master. 5 # 6 # Because the codegen script is pretty slow, it bails early if no files in pkg/apis 7 # (or pkg/openapi) were modified. 8 # 9 # If there were changed files, the codegen script is run and if there are any uncommitted 10 # files as a result, it fails with an error. 11 12 set -e 13 14 dir=$(dirname "$0") 15 cd "${dir}/.." 16 17 codegen_regex="pkg/apis|pkg/openapi" 18 19 function print_file_list() { 20 while IFS= read -r line 21 do 22 if [[ $line =~ $codegen_regex ]]; then 23 printf " - %s\n" "${line}" 24 fi 25 done < <(printf '%s\n' "${*}") 26 } 27 28 master_sha=$(git rev-parse origin/master) 29 changes=$(git diff-tree --no-commit-id --no-renames --name-only -r "$(git merge-base "${master_sha}" HEAD)" HEAD) 30 if [[ $changes =~ $codegen_regex ]]; then 31 echo "Found changed API files (compared to origin/master):" 32 print_file_list "${changes}" 33 printf "\nRunning codegen to ensure up-to-date...\n\n" 34 make update-codegen-go 35 # TODO - get this working in CI and swap these all out with `make update-codegeen` 36 # make update-codegen-ts 37 make update-codegen-starlark 38 else 39 echo "No API files modified (skipping up-to-date check)" 40 exit 0 41 fi 42 43 # find any uncommitted changes: getting a list of modified (staged + unstaged) as well as 44 # untracked is really only doable with git status; the porcelain format is stable and has 45 # a fixed length prefix for each line that can be chopped off to just get the filenames 46 modified=$(git status --porcelain --no-renames | cut -c 4-) 47 if [[ $modified =~ $codegen_regex ]]; then 48 >&2 echo "Found out of sync codegen files:" 49 >&2 print_file_list "${modified}" 50 if [[ -n "${CIRCLECI}" ]]; then 51 >&2 printf "\nRun make update-codegen locally and push the changes.\n" 52 else 53 >&2 printf "\nThe modified files should be committed before pushing.\n" 54 fi 55 exit 1 56 fi 57 58 echo "All codegen files up to date!"