Files
job-search/scripts/install-dev-tools.sh
bwilliams 1988d07a29 Ran the installed ocdsgen, and added a script that installs the dev tools
go generate ran ocdsgen with go run, from go.mod, but go-ocds had been
dropped from go.mod (nothing imports it, so go mod tidy removes it), which
broke go generate and so scripts/build.sh. It now runs the installed
ocdsgen from PATH, as it does swag.

scripts/install-dev-tools.sh installs the Go tools (ocdsgen v1.0.0 and swag
v2.0.0-rc6 pinned, as other versions could generate different code;
golangci-lint, goose and cobra-cli at their latest), checks for Node.js 24
or later and runs npm ci in web/. The README's dev tools section now points
to it and lists what each tool is for.
2026-10-16 16:03:48 +01:00

62 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env bash
# Installs the tools needed to develop and build job-search: the Go tools
# (with go install, into $(go env GOBIN), or $(go env GOPATH)/bin), and the
# frontend's npm packages (with npm ci in web/). Run it from anywhere; run it
# again after a version below changes.
set -euo pipefail
cd "$(dirname "$0")/.."
# The Go tools. A generator is pinned, as a different version could generate
# different code; the others follow their latest release.
GO_TOOLS=(
# Generates the OCDS types (internal/findatender/ocds) from extensions.json
"git.avsdev.uk/Go/go-ocds/cmd/ocdsgen@v1.0.0"
# Generates the API's OpenAPI 3.1 description; v2 is only a release
# candidate so far
"github.com/swaggo/swag/v2/cmd/swag@v2.0.0-rc6"
# Lints the Go code with .golangci.json
"github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest"
# Creates migration files (internal/store/migrations)
"github.com/pressly/goose/v3/cmd/goose@latest"
# Adds cobra commands
"github.com/spf13/cobra-cli@latest"
)
# The oldest Node.js the frontend's scripts run on: they run TypeScript
# directly.
NODE_MAJOR=24
for tool in "${GO_TOOLS[@]}"; do
echo "go install $tool"
go install "$tool"
done
if ! command -v node >/dev/null || ! command -v npm >/dev/null; then
echo "Node.js $NODE_MAJOR or later (with npm) is needed for web/: install it, then run this again" >&2
exit 1
fi
node_version=$(node --version)
node_major=${node_version#v}
node_major=${node_major%%.*}
if (( node_major < NODE_MAJOR )); then
echo "Node.js $NODE_MAJOR or later is needed for web/, found $node_version" >&2
exit 1
fi
echo "npm ci (web/)"
(cd web && npm ci)
# go generate and the build script find the Go tools on PATH.
bin_dir=$(go env GOBIN)
if [[ -z $bin_dir ]]; then
bin_dir=$(go env GOPATH)/bin
fi
if [[ ":$PATH:" != *":$bin_dir:"* ]]; then
echo "Add $bin_dir to PATH, where the Go tools were installed" >&2
fi
echo "Installed the development tools"