diff --git a/README.md b/README.md index 673a293..054127c 100644 --- a/README.md +++ b/README.md @@ -63,8 +63,8 @@ The repository uses a Go workspace and [mise](https://mise.jdx.dev): ``` mise run check # build, vet, format, fix, tidy, test, and lint every module, then lint-context and lint-references; writes nothing -mise run currency # report requirements, Go, tools, actions, images, and Dockerfile source ARGs behind their latest -mise run upgrade # upgrade every module's go directive and requirements, and the tools, to their latest +mise run currency # report tools, Go, requirements, actions, images, and Dockerfile source ARGs behind their latest, except a held one; writes nothing +mise run upgrade # move every pin currency reports to its latest, except a held one: tools, then Go and requirements, actions, images, and Dockerfile source ARGs mise run db:up # build and start the compose PostgreSQL and wait until it is healthy mise run db:down # stop PostgreSQL, discarding its data mise run integration # run the integration tier against the running stack @@ -75,8 +75,11 @@ mise run acceptance # db:up, integration, then db:down whatever the result; pr `GO_DATABASE_DSN` in `mise.toml` follows it. The service builds from `compose/postgres/Dockerfile`, a copy of sqlate's canonical PostgreSQL image: its `FROM` line is the one image pin, `ARG PGVECTOR_VERSION` the extension's, and `mise run currency` reports either -when it trails its latest. The stack is a test-only harness that keeps its data on tmpfs, so every -`db:up` starts empty. +when it trails its latest; `mise run upgrade` moves it. The two tasks run `scripts/currency.sh`'s +`report` and `upgrade` modes, which run the same scans, so `upgrade` moves exactly what `report` +lists. A pin named in `mise.toml`'s `HOLDS` list, one +` : ` line each, is reported as held and never moved. The stack is a test-only +harness that keeps its data on tmpfs, so every `db:up` starts empty. The `postgres/pgvector` module's integration tier sits behind the `integration` build tag and runs against the stack: `admin.Start` activating a declared `vector` extension, a `vector` diff --git a/STANDARDS.md b/STANDARDS.md index 872e1e7..c8b32e7 100644 --- a/STANDARDS.md +++ b/STANDARDS.md @@ -7,6 +7,7 @@ The judgement calls the standards-reviewer applies to go-database, beyond what ` - `architecture/standards/go-elemental/principles/tests-and-docs.md`: the doc.go inventory of `database`, `admin`, `sweep`, `postgres` and `pgvector`, and the unit tier over sqlate's `sqltest`, the `database` tests' stub driver and the `postgres` tests' in-test `pgproto3` server; and `postgres/pgvector`'s integration tier, behind the `integration` tag, over sqlate's `postgres/pgtest` against the compose stack, run locally by `mise run acceptance`. - `architecture/standards/go-elemental/principles/topology-and-naming.md`: the base module with `database`, `admin` and `sweep`, the `postgres` provider sub-module and its tags, and the `postgres/pgvector` sub-module and its tags. - `architecture/standards/go-elemental/principles/release-and-ci.md`: the check, currency and upgrade tasks over `GO_MODULES`, which matches `go.work`'s use-list, the compose stack of `compose.yml` and `compose/postgres`, a test-only harness on tmpfs, and a changelog per module, `CHANGELOG.md`, `postgres/CHANGELOG.md` and `postgres/pgvector/CHANGELOG.md`. +- `architecture/standards/go-elemental/principles/database-extensions.md`: `admin`'s extension status and readiness, the `postgres/pgvector` sub-module, and the compose Dockerfile. - `architecture/standards/go-elemental/principles/lifecycle-and-context.md`: `DB`'s `Start`, `Shutdown` and `Ready`, and `admin.Service`'s `Start` and `Ready`; the constructors' panics on an unfinalized `Config` or a missing pool, and `postgres.New`'s error on a reserved option. - `architecture/standards/go-elemental/principles/baseline-standards.md`: `Config`'s pool-size and timeout defaults, and `admin`, which takes every migration set, seed set, catalog and registry from its consumer. - `architecture/standards/go-elemental/principles/utc-times.md`: `postgres.New`'s connections, which scan `timestamptz` in UTC. diff --git a/mise.toml b/mise.toml index 6654ce8..81a5e1b 100644 --- a/mise.toml +++ b/mise.toml @@ -12,6 +12,8 @@ jq = "1.8.2" [env] GO_MODULES = ". postgres postgres/pgvector" GO_DATABASE_DSN = "postgres://app:app@127.0.0.1:{{ get_env(name='POSTGRES_PORT', default='5438') }}/app?sslmode=disable" +HOLDS = ''' +''' [tasks.check] description = "Build, vet, format, fix, tidy, test, and lint every module, vetting, fixing, and linting the integration tier with its tag but running only the unit tier, then run lint-context and lint-references; writes nothing" @@ -44,25 +46,12 @@ exit "$fail" ''' [tasks.currency] -description = "Report every requirement, Go version, tool, action pin, image tag, and Dockerfile source ARG behind its latest; writes nothing" -run = "scripts/currency.sh" +description = "Report every mise tool, Go version, requirement, action pin, image tag, and Dockerfile source ARG behind its latest, a held one with its reason; writes nothing" +run = "scripts/currency.sh report" [tasks.upgrade] -description = "Upgrade every module's go directive to the current Go minor, with no toolchain line, and its direct requirements and the local mise tools to their latest, rewriting go.mod and mise.toml" -run = ''' -set -eu -export GOWORK=off -go_minor=$(mise latest go | cut -d. -f1,2) -for mod in $GO_MODULES; do - cd "$MISE_PROJECT_ROOT/$mod" - go mod edit -go="$go_minor" -toolchain=none - direct=$(go mod edit -json | jq -r '.Require[]? | select(.Indirect | not) | .Path') - [ -z "$direct" ] || go get $(printf '%s@latest ' $direct) - go mod tidy -done -cd "$MISE_PROJECT_ROOT" -mise upgrade --bump --local -''' +description = "Bump the mise tools, then each module's go directive (to the current Go minor, with no toolchain line) and direct requirements, with a tidy, then the action pins, image tags, Dockerfile FROM tags, and Dockerfile source ARGs, to their latest, but a held one; rewrites mise.toml, go.mod, go.sum, the workflows, and the compose files" +run = "scripts/currency.sh upgrade" [tasks.build] description = "Build every module in GO_MODULES standalone with GOWORK=off, resolving its pins as a consumer does" diff --git a/postgres/CHANGELOG.md b/postgres/CHANGELOG.md index f4566c5..f4bbd0a 100644 --- a/postgres/CHANGELOG.md +++ b/postgres/CHANGELOG.md @@ -7,6 +7,12 @@ changelog covers this sub-module only; the base module keeps its own. ## [Unreleased] +### Changed + +- The `go-database` requirement is v0.13.0, which requires `sqlate` v0.8.0 and adds + `admin.Status.Extensions`, readiness that follows each declared extension, and the + `ErrConflict` mapping of the extension errors. The provider's own API is unchanged. + ## [v0.7.0] - 2026-11-11 ### Changed diff --git a/postgres/go.mod b/postgres/go.mod index cbd329a..d62eff2 100644 --- a/postgres/go.mod +++ b/postgres/go.mod @@ -4,7 +4,7 @@ go 1.27 require ( github.com/jackc/pgx/v5 v5.13.0 - github.com/standards-lab/go-database v0.12.0 + github.com/standards-lab/go-database v0.13.0 ) require ( @@ -12,7 +12,7 @@ require ( github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect github.com/jackc/puddle/v2 v2.2.3 // indirect github.com/standards-lab/go-core v0.12.0 // indirect - github.com/standards-lab/sqlate v0.7.0 // indirect + github.com/standards-lab/sqlate v0.8.0 // indirect golang.org/x/sync v0.22.0 // indirect golang.org/x/text v0.41.0 // indirect ) diff --git a/postgres/go.sum b/postgres/go.sum index beea750..0e01668 100644 --- a/postgres/go.sum +++ b/postgres/go.sum @@ -13,10 +13,10 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/standards-lab/go-core v0.12.0 h1:sqrzK6QSppEYpwvVAyiWgzNuOsjfK0Kwe86GPuZpHsU= github.com/standards-lab/go-core v0.12.0/go.mod h1:Yl/R+gM9YWczsePBCKXdPGh3FSdZ/5i8SapLIh3BDHU= -github.com/standards-lab/go-database v0.12.0 h1:CWAVRmH+GiX5RxDEOknrZ5Dawz5FiYADxb11Iv9B0BE= -github.com/standards-lab/go-database v0.12.0/go.mod h1:CC3FjKyT+6RKEqhSiqjS2tlLO+NRMrs/0UkWa4WM8FI= -github.com/standards-lab/sqlate v0.7.0 h1:GVb3OCDXwSS9RCxQ2BRIfV73zwBeJBhkvDLBJnTYd/U= -github.com/standards-lab/sqlate v0.7.0/go.mod h1:pikNmGf/z3x46SBWFXgt/xKIDZuquSgCoXy5OWBFFR4= +github.com/standards-lab/go-database v0.13.0 h1:xBiN+gZE2Q0x+S/N0DgaDNqT9feHxcu43BrHXpFfLnI= +github.com/standards-lab/go-database v0.13.0/go.mod h1:M4jca1wtAP4MUDAdLa+lgvBGAzyfc8A1EdpVaQssXfc= +github.com/standards-lab/sqlate v0.8.0 h1:G1uUIWmc2DxJz5YhtBvIlftfURnb3b2RKsYB59Wa03Y= +github.com/standards-lab/sqlate v0.8.0/go.mod h1:pikNmGf/z3x46SBWFXgt/xKIDZuquSgCoXy5OWBFFR4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= diff --git a/scripts/currency.sh b/scripts/currency.sh index e6bc92f..8425804 100755 --- a/scripts/currency.sh +++ b/scripts/currency.sh @@ -1,141 +1,346 @@ #!/usr/bin/env bash -# currency reports every dependency, toolchain, and pin that trails its latest -# release, one line each, and exits non-zero when it reports any. It reads the -# network and writes nothing. Run it through `mise run currency`. The actions it -# checks are those of the project root's workflows and, when the repository nests -# the project in a subdirectory, of the git top-level's. A compose Dockerfile's -# `ARG _VERSION` whose `ADD` fetches a GitHub repository at `v${_VERSION}` -# is compared with that repository's highest semver tag. A scan command that fails -# fails currency. +# currency reports, or upgrades, every pin that trails its latest release: the mise tools, each Go +# module's go directive and direct requirements, the workflows' action pins, the image lines of +# the compose files and workflows, each compose Dockerfile's FROM tag, and each compose +# Dockerfile's `ARG _VERSION` whose `ADD` fetches a GitHub repository at +# `v${_VERSION}`, compared with that repository's highest semver tag. Both modes run the same +# scans. report prints one line for each trailing pin, a pin the HOLDS list names as held with its +# reason, and exits 1 when any it reports is not held; it reads the network and writes nothing. +# upgrade moves every trailing pin but a held one, printing one line for each. The actions it +# scans are those of the project root's workflows and, when the repository nests the project in a +# subdirectory, of the git top-level's. A scan command that fails fails currency. +# Run it through `mise run currency` or `mise run upgrade`. +# +# usage: scripts/currency.sh +# See architecture/principles/rolling-currency.md set -euo pipefail cd "$MISE_PROJECT_ROOT" export GOWORK=off -stale=0 -report() { - echo "$1" - stale=1 +if [ $# -ne 1 ] || { [ "$1" != report ] && [ "$1" != upgrade ]; }; then + echo "usage: scripts/currency.sh " >&2 + exit 2 +fi +action=$1 +holds=${HOLDS:-} + +held() { + grep -m1 -E "^$(escape_regex "$1 $2: ")" <<<"$holds" | cut -d: -f2- | sed 's/^ //' || true } -matches() { - local pattern=$1 file - local files=() - shift +go() { + mise exec -- go "$@" +} + +escape_regex() { + # shellcheck disable=SC2001 # a bracket expression, which a ${//} pattern has no escape for + sed 's/[][\\.*^$|+?(){}]/\\&/g' <<<"$1" +} + +existing() { + local file for file in "$@"; do - if [ -e "$file" ]; then files+=("$file"); fi + if [ -e "$file" ]; then echo "$file"; fi done - [ ${#files[@]} -gt 0 ] || return 0 - grep -ho "$pattern" "${files[@]}" || [ $? -eq 1 ] } -report_outdated_requirements() { - local mod=$1 updates line - updates=$(cd "$mod" && go list -m -u -f \ - '{{if and (not .Main) (not .Indirect) .Update}}{{.Path}} {{.Version}} -> {{.Update.Version}}{{end}}' all) - while read -r line; do - if [ -n "$line" ]; then - report "$mod/go.mod: $line" - fi - done <<<"$updates" +matches() { + local pattern=$1 + shift + if [ $# -eq 0 ]; then + return 0 + fi + grep -ho "$pattern" "$@" || [ $? -eq 1 ] } -report_outdated_go_directive() { - local mod=$1 go_minor=$2 directive - directive=$(cd "$mod" && go mod edit -json | jq -r .Go | cut -d. -f1,2) - [ "$directive" = "$go_minor" ] || report "$mod/go.mod: go $directive -> go $go_minor" +outdated_mise_tools() { + mise outdated --bump --no-global --json | + jq -r 'to_entries[] | select(.value.bump != null) | "\(.key) \(.value.requested) \(.value.bump)"' } -report_outdated_mise_tools() { - local outdated line - outdated=$(mise outdated --bump --local --json | - jq -r 'to_entries[] | "\(.key) \(.value.requested) -> \(.value.bump)"') - while read -r line; do - if [ -n "$line" ]; then - report "mise.toml: $line" - fi - done <<<"$outdated" +outdated_requirements() { + go list -m -u -f \ + '{{if and (not .Main) (not .Indirect) .Update}}{{.Path}} {{.Version}} {{.Update.Version}}{{end}}' all } -report_outdated_actions() { - local actions uses action pin repo latest - actions=$(matches 'uses: *[^ ]*@[^ ]*' "${workflows[@]}" | sed 's/uses: *//' | sort -u) +trailing_go_directive() { + local minor + minor=$(go mod edit -json | jq -r .Go | cut -d. -f1,2) || return + if [ "$minor" != "$go_minor" ]; then + echo "go $minor $go_minor" + fi +} + +outdated_actions() { + local actions uses name pinned repo latest + actions=$(matches 'uses: *[^ ]*@[^ ]*' "${workflows[@]}" | sed 's/uses: *//' | sort -u) || return for uses in $actions; do - action=${uses%@*} - pin=${uses#*@} - repo=$(echo "$action" | cut -d/ -f1,2) - latest=$(gh api "repos/$repo/releases/latest" --jq .tag_name) - [ "$pin" = "$latest" ] || report ".github/workflows: $action $pin -> $latest" + name=${uses%@*} + pinned=${uses#*@} + repo=$(echo "$name" | cut -d/ -f1,2) || return + latest=$(gh api "repos/$repo/releases/latest" --jq .tag_name) || return + if [ "$pinned" != "$latest" ]; then + echo "$name $pinned $latest" + fi done } latest_dotted_release_tag() { - local image=$1 pin=$2 suffix dotted_release_pattern latest + local image=$1 pin=$2 suffix dotted_release_pattern tags latest suffix=${pin#"${pin%%[!0-9.]*}"} dotted_release_pattern="^[0-9]+(\.[0-9]+)+${suffix//./\\.}\$" - latest=$(crane ls "$image" | grep -E "$dotted_release_pattern" | sed "s/${suffix}\$//" | sort -V | tail -n1) || return + tags=$(crane ls "$image") || return + latest=$(grep -E "$dotted_release_pattern" <<<"$tags" | sed "s/${suffix}\$//" | sort -V | tail -n1) || return echo "$latest$suffix" } -report_outdated_image_lines() { - local images ref image pin latest - images=$(matches '^ *image: *[^ ]*' compose.yml compose/*.yml "${workflows[@]}" | - sed 's/^ *image: *//' | tr -d "\"'" | sort -u) +outdated_image_lines() { + local images ref image pinned latest + images=$(matches '^ *image: *[^ ]*' "${image_files[@]}" | sed 's/^ *image: *//' | tr -d "\"'" | sort -u) || return for ref in $images; do image=${ref%:*} - pin=${ref##*:} - latest=$(latest_dotted_release_tag "$image" "$pin") - [ "$pin" = "$latest" ] || report "images: $image $pin -> $latest" + pinned=${ref##*:} + latest=$(latest_dotted_release_tag "$image" "$pinned") || return + if [ "$pinned" != "$latest" ]; then + echo "$image $pinned $latest" + fi done } -report_outdated_dockerfile_bases() { - local dockerfile ref image pin latest +outdated_dockerfile_bases() { + local dockerfile ref image pinned latest for dockerfile in compose/*/Dockerfile; do - [ -e "$dockerfile" ] || continue - ref=$(sed -n '/^FROM /{s/^FROM *\([^ ]*\).*/\1/p;q;}' "$dockerfile") + if [ ! -e "$dockerfile" ]; then + continue + fi + ref=$(sed -n '/^FROM /{s/^FROM *\([^ ]*\).*/\1/p;q;}' "$dockerfile") || return image=${ref%:*} - pin=${ref##*:} - latest=$(latest_dotted_release_tag "$image" "$pin") - [ "$pin" = "$latest" ] || report "$dockerfile: $image $pin -> $latest" + pinned=${ref##*:} + latest=$(latest_dotted_release_tag "$image" "$pinned") || return + if [ "$pinned" != "$latest" ]; then + echo "$image $pinned $latest $dockerfile" + fi done } latest_semver_git_tag() { local repo=$1 tags latest tags=$(GIT_TERMINAL_PROMPT=0 git ls-remote --tags --refs "https://github.com/$repo.git") || return - latest=$(echo "$tags" | sed -n 's|.*refs/tags/v\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\)$|\1|p' | sort -V | tail -n1) - [ -n "$latest" ] || return 1 + latest=$(sed -n 's|.*refs/tags/v\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\)$|\1|p' <<<"$tags" | sort -V | tail -n1) || return + if [ -z "$latest" ]; then + return 1 + fi echo "$latest" } -report_outdated_dockerfile_args() { - local dockerfile args name pin repo latest +outdated_dockerfile_args() { + local dockerfile args arg pinned repo latest for dockerfile in compose/*/Dockerfile; do - [ -e "$dockerfile" ] || continue - args=$(sed -n 's/^ARG *\([A-Za-z0-9_]*_VERSION\)=\([^ ]*\) *$/\1 \2/p' "$dockerfile") - while read -r name pin; do - [ -n "$name" ] || continue - repo=$(sed -n "s|^ADD *https://github\.com/\([^/ ]*/[^/ ]*\)\.git#v\\\${$name} .*|\1|p" "$dockerfile") - [ -n "$repo" ] || continue - latest=$(latest_semver_git_tag "$repo") - [ "$pin" = "$latest" ] || report "$dockerfile: $repo $pin -> $latest" + if [ ! -e "$dockerfile" ]; then + continue + fi + args=$(sed -n 's/^ARG *\([A-Za-z0-9_]*_VERSION\)=\([^ ]*\) *$/\1 \2/p' "$dockerfile") || return + while read -r arg pinned; do + if [ -z "$arg" ]; then + continue + fi + repo=$(sed -n "s|^ADD *https://github\.com/\([^/ ]*/[^/ ]*\)\.git#v\\\${$arg} .*|\1|p" "$dockerfile") || return + if [ -z "$repo" ]; then + continue + fi + latest=$(latest_semver_git_tag "$repo") || return + if [ "$pinned" != "$latest" ]; then + echo "$repo $pinned $latest $dockerfile $arg" + fi done <<<"$args" done } +stale=0 +trailing() { + local reason + reason=$(held "$2" "$3") + if [ -n "$reason" ]; then + echo "$1: $2 $3 -> $4 held: $reason" + else + echo "$1: $2 $3 -> $4" + stale=1 + fi +} + +report_mise_tools() { + local scanned name pinned latest + scanned=$(outdated_mise_tools) || return + while read -r name pinned latest; do + if [ -n "$name" ]; then trailing mise.toml "$name" "$pinned" "$latest"; fi + done <<<"$scanned" +} + +report_go_modules() { + local mod scanned name pinned latest + for mod in $GO_MODULES; do + scanned=$(cd "$mod" && outdated_requirements && trailing_go_directive) || return + while read -r name pinned latest; do + if [ -n "$name" ]; then trailing "$mod/go.mod" "$name" "$pinned" "$latest"; fi + done <<<"$scanned" + done +} + +report_actions() { + local scanned name pinned latest + scanned=$(outdated_actions) || return + while read -r name pinned latest; do + if [ -n "$name" ]; then trailing .github/workflows "$name" "$pinned" "$latest"; fi + done <<<"$scanned" +} + +report_image_lines() { + local scanned name pinned latest + scanned=$(outdated_image_lines) || return + while read -r name pinned latest; do + if [ -n "$name" ]; then trailing images "$name" "$pinned" "$latest"; fi + done <<<"$scanned" +} + +report_dockerfile_bases() { + local scanned name pinned latest dockerfile + scanned=$(outdated_dockerfile_bases) || return + while read -r name pinned latest dockerfile; do + if [ -n "$name" ]; then trailing "$dockerfile" "$name" "$pinned" "$latest"; fi + done <<<"$scanned" +} + +report_dockerfile_args() { + local scanned name pinned latest dockerfile + scanned=$(outdated_dockerfile_args) || return + while read -r name pinned latest dockerfile _; do + if [ -n "$name" ]; then trailing "$dockerfile" "$name" "$pinned" "$latest"; fi + done <<<"$scanned" +} + +upgrade_mise_tools() { + local scanned name pinned latest + local tools=() + scanned=$(outdated_mise_tools) || return + while read -r name pinned latest; do + if [ -z "$name" ] || [ -n "$(held "$name" "$pinned")" ]; then + continue + fi + echo "upgrade: mise.toml: $name $pinned -> $latest" + tools+=("$name") + done <<<"$scanned" + if [ ${#tools[@]} -gt 0 ]; then + mise upgrade --bump --no-global "${tools[@]}" + fi +} + +upgrade_go_module() { + local mod=$1 scanned name pinned latest + local requirements=() + scanned=$(trailing_go_directive) || return + if [ -n "$scanned" ]; then + read -r name pinned latest <<<"$scanned" + if [ -z "$(held go "$pinned")" ]; then + echo "upgrade: $mod/go.mod: go $pinned -> $latest" + go mod edit -go="$go_minor" -toolchain=none + fi + fi + scanned=$(outdated_requirements) || return + while read -r name pinned latest; do + if [ -z "$name" ] || [ -n "$(held "$name" "$pinned")" ]; then + continue + fi + echo "upgrade: $mod/go.mod: $name $pinned -> $latest" + requirements+=("$name@latest") + done <<<"$scanned" + if [ ${#requirements[@]} -gt 0 ]; then + go get "${requirements[@]}" + fi + go mod tidy +} + +upgrade_go_modules() { + local mod + for mod in $GO_MODULES; do + ( + cd "$mod" + upgrade_go_module "$mod" + ) + done +} + +upgrade_actions() { + local scanned name pinned latest key + scanned=$(outdated_actions) || return + while read -r name pinned latest; do + if [ -z "$name" ] || [ -n "$(held "$name" "$pinned")" ]; then + continue + fi + echo "upgrade: .github/workflows: $name $pinned -> $latest" + key=$(escape_regex "$name@$pinned") || return + sed -i -E "s#(uses: *)$key( |\$)#\\1$name@$latest\\2#" "${workflows[@]}" + done <<<"$scanned" +} + +upgrade_image_lines() { + local scanned name pinned latest key + scanned=$(outdated_image_lines) || return + while read -r name pinned latest; do + if [ -z "$name" ] || [ -n "$(held "$name" "$pinned")" ]; then + continue + fi + echo "upgrade: images: $name $pinned -> $latest" + key=$(escape_regex "$name:$pinned") || return + sed -i -E "s#^( *image: *[\"']?)$key([\"']?( |\$))#\\1$name:$latest\\2#" "${image_files[@]}" + done <<<"$scanned" +} + +upgrade_dockerfile_bases() { + local scanned name pinned latest dockerfile key + scanned=$(outdated_dockerfile_bases) || return + while read -r name pinned latest dockerfile; do + if [ -z "$name" ] || [ -n "$(held "$name" "$pinned")" ]; then + continue + fi + echo "upgrade: $dockerfile: $name $pinned -> $latest" + key=$(escape_regex "$name:$pinned") || return + sed -i -E "s#^(FROM +)$key( |\$)#\\1$name:$latest\\2#" "$dockerfile" + done <<<"$scanned" +} + +upgrade_dockerfile_args() { + local scanned name pinned latest dockerfile arg key + scanned=$(outdated_dockerfile_args) || return + while read -r name pinned latest dockerfile arg; do + if [ -z "$name" ] || [ -n "$(held "$name" "$pinned")" ]; then + continue + fi + echo "upgrade: $dockerfile: $name $pinned -> $latest" + key=$(escape_regex "$pinned") || return + sed -i -E "s#^(ARG +$arg=)$key( *)\$#\\1$latest\\2#" "$dockerfile" + done <<<"$scanned" +} + root=$(pwd -P) top=$(git rev-parse --show-toplevel 2>/dev/null || echo "$root") -workflows=("$root"/.github/workflows/*.yml) -[ "$top" = "$root" ] || workflows+=("$top"/.github/workflows/*.yml) +candidates=("$root"/.github/workflows/*.yml) +if [ "$top" != "$root" ]; then candidates+=("$top"/.github/workflows/*.yml); fi +mapfile -t workflows < <(existing "${candidates[@]}") +mapfile -t image_files < <(existing compose.yml compose/*.yml "${workflows[@]}") go_minor=$(mise latest go | cut -d. -f1,2) -for mod in $GO_MODULES; do - report_outdated_requirements "$mod" - report_outdated_go_directive "$mod" "$go_minor" -done -report_outdated_mise_tools -report_outdated_actions -report_outdated_image_lines -report_outdated_dockerfile_bases -report_outdated_dockerfile_args -exit "$stale" +if [ "$action" = report ]; then + report_mise_tools + report_go_modules + report_actions + report_image_lines + report_dockerfile_bases + report_dockerfile_args + exit "$stale" +fi +upgrade_mise_tools +upgrade_go_modules +upgrade_actions +upgrade_image_lines +upgrade_dockerfile_bases +upgrade_dockerfile_args