scripts/update-dependencies
Rama main · réplica de lectura del repositorio original.
#!/bin/bash
set -euo pipefail
_project_root="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)/.."
replace-in-file() {
local _search="${1?"search is required"}"
local _replace="${2?"replace is required"}"
local _file="${3?"file is required"}"
local _tmp
_tmp="$(mktemp)"
sed -E 's/'"$_search"'/'"$_replace"'/g' "$_file" >"$_tmp"
mv "$_tmp" "$_file"
}
require-command() {
local _command="${1?"command is required"}"
if ! command -v "$_command" >/dev/null 2>&1; then
echo "$_command is required"
exit 1
fi
}
get-tool-version() {
local _tool="${1?"tool is required"}"
require-command asdf
asdf current --no-header "$_tool" | tr -s ' ' | cut -d ' ' -f2
}
get-docker-tag-with-version() {
local _name="${1?"name is required"}"
local _tag="${2?"tag is required"}"
require-command docker
require-command jq
echo "$_tag@$(docker buildx imagetools inspect --format '{{json .}}' "$_name":"$_tag" | jq -r .manifest.digest)"
}
update-docker() {
pushd "$_project_root"
local _go_tag
_go_tag="$(get-docker-tag-with-version golang "$(get-tool-version golang)-bookworm")"
local _nodejs_tag
_nodejs_tag="$(get-docker-tag-with-version node "$(get-tool-version nodejs)-bookworm")"
find . -type f -name "Dockerfile*" | while read _file; do
replace-in-file '^FROM golang:(.*) AS (.*)$' 'FROM golang:'"$_go_tag"' AS \2' "$_file"
replace-in-file '^FROM node:(.*) AS (.*)$' 'FROM node:'"$_nodejs_tag"' AS \2' "$_file"
done
popd
}
get-commit-sha() {
local _repo_url="${1?"repo url is required"}"
local _branch="${2?"branch is required"}"
require-command git
git ls-remote "$_repo_url" "refs/heads/$_branch" | awk '{print $1}'
}
go-get-direct() {
local _dependency="${1?"dependency is required"}"
local _branch="${2?"branch is required"}"
env GOPRIVATE="$_dependency" \
go get "$_dependency@$(get-commit-sha "https://$_dependency" "$_branch")"
}
update-pomerium() {
pushd "$_project_root"
require-command go
go-get-direct github.com/pomerium/datasource main
go-get-direct github.com/pomerium/protoutil main
go-get-direct github.com/pomerium/webauthn main
go mod tidy
popd
}
update-tools() {
pushd "$_project_root"
require-command asdf
asdf install golang latest:1.27
asdf set golang latest:1.27
asdf install golangci-lint latest:2
asdf set golangci-lint latest:2
asdf install nodejs latest:24
asdf set nodejs latest:24
asdf plugin add protoc
asdf install protoc latest
asdf set protoc latest
asdf plugin add goreleaser || true
asdf install goreleaser latest:2
asdf set goreleaser latest:2
popd
}
run() {
local _command="$1"
case "$_command" in
docker)
update-docker
;;
pomerium)
update-pomerium
;;
tools)
update-tools
;;
*)
echo "unknown command $_command"
exit 1
;;
esac
}
run "${1?'command is required'}"