| #!/bin/bash |
| # Updates the pinned version of lucicfg to the latest available. |
| # |
| # Usage: $ update_lucicfg.sh |
| |
| set -o errexit |
| set -o pipefail |
| |
| function main { |
| cd "$(dirname "${BASH_SOURCE[0]}")/.." |
| |
| # Look at the latest version of lucicfg, pull all the git revisions, pick the |
| # one that comes first alphabetically (to minimize churn since many revisions |
| # might refer to the same package), and write that to the lucicfg_version |
| # file. |
| new_version=$( |
| cipd describe "infra/tools/luci/lucicfg/\${platform}" -version latest | |
| grep git_revision | |
| sort | |
| head -n1) |
| new_version="${new_version// /}" # Trim whitespace. |
| |
| ensure_file="$(pwd)/cipd.ensure" |
| # Update pinned version in the ensure file. Assumes that the ensure file is |
| # valid and holds only a single pinned package. |
| in_place_sed "s/git_revision:\w\{40\}/$new_version/" "$ensure_file" |
| |
| # Install the new version of lucicfg so we can run `lucicfg version` to get |
| # the lucicfg tool's semantic version and update the minimum version set by |
| # `lucicfg.check_version()` in the Starlark code. |
| lucicfg=$(./scripts/ensure_lucicfg.sh) |
| semver=$( |
| "$lucicfg" version | |
| head -n1 | |
| sed "s/lucicfg v//" |
| ) |
| |
| version_file="$(pwd)/config/main.star" |
| in_place_sed "s/LUCICFG_VERSION = \".*\"/LUCICFG_VERSION = \"$semver\"/" "$version_file" |
| } |
| |
| function in_place_sed { |
| local directive="$1" |
| local file="$2" |
| # Unfortunately, it's impossible to do an in-place sed that works on both Mac |
| # and Linux without creating a backup file. |
| sed -i.bak "$directive" "$file" |
| rm "$file.bak" |
| } |
| |
| main "$@" |