f-39: build: version de l'agent injectée au build #39
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
9a1e941b15
commit
e34c5df89f
3 changed files with 33 additions and 3 deletions
|
|
@ -33,7 +33,7 @@ jobs:
|
|||
echo "Building for ${BINARI}/${GOOS}/${GOARCH} (release: ${RELEASE_CIBLE})"
|
||||
go env GOOS GOARCH
|
||||
mkdir -p dist/
|
||||
go build -o dist/${BINARI}_${GOOS}_${GOARCH} ./cmd/${BINARI}
|
||||
go build -ldflags "-X main.version=${RELEASE_CIBLE}" -o dist/${BINARI}_${GOOS}_${GOARCH} ./cmd/${BINARI}
|
||||
echo "artifact pour ${RELEASE_CIBLE} ${BINARI} ${GOOS} ${GOARCH}" > dist/${BINARI}-${GOOS}-${GOARCH}.txt
|
||||
ls -l ./dist
|
||||
- name: Upload artifact
|
||||
|
|
|
|||
|
|
@ -30,11 +30,24 @@ clean () {
|
|||
done
|
||||
}
|
||||
|
||||
build_version () {
|
||||
local commit changes
|
||||
commit=$(git -C "${REPO_DIR}" rev-parse --short HEAD) || return 1
|
||||
changes=$(git -C "${REPO_DIR}" status --porcelain) || return 1
|
||||
if [ -n "${changes}" ]; then
|
||||
echo "${commit}-dirty"
|
||||
else
|
||||
echo "${commit}"
|
||||
fi
|
||||
}
|
||||
|
||||
build () {
|
||||
local binary unit script
|
||||
local binary unit script version
|
||||
version=$(build_version) || return 1
|
||||
echo "== version ${version}" >&2
|
||||
for binary in ${BINARIES}; do
|
||||
echo "== ${binary}" >&2
|
||||
(cd "${REPO_DIR}" && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o "${BIN_DIR}/${binary}" "./cmd/${binary}") || return 1
|
||||
(cd "${REPO_DIR}" && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-X main.version=${version}" -o "${BIN_DIR}/${binary}" "./cmd/${binary}") || return 1
|
||||
done
|
||||
for unit in ${UNITS}; do
|
||||
cp "${REPO_DIR}/systemd/${unit}" "${BIN_DIR}/${unit}" || return 1
|
||||
|
|
|
|||
|
|
@ -826,6 +826,23 @@ PY
|
|||
teardown
|
||||
}
|
||||
|
||||
test_build_version_is_the_commit_dirty_when_the_tree_changed () {
|
||||
setup "build_version : commit court, suffixé -dirty si l'arbre a des modifications, échec hors dépôt"
|
||||
local repo="${WORK}/repo" commit
|
||||
git init -q "${repo}" && printf 'a\n' > "${repo}/f" && git -C "${repo}" add f \
|
||||
&& git -C "${repo}" -c user.name=t -c user.email=t@t commit -q -m t || fail "dépôt de test"
|
||||
commit=$(git -C "${repo}" rev-parse --short HEAD)
|
||||
build_version_in () { bash -c ". '${DIR}/build.sh'; REPO_DIR='${1}'; build_version" 2>&1; }
|
||||
[[ $(build_version_in "${repo}") == "${commit}" ]] || fail "arbre propre : $(build_version_in "${repo}")"
|
||||
printf 'b\n' > "${repo}/f"
|
||||
[[ $(build_version_in "${repo}") == "${commit}-dirty" ]] || fail "fichier modifié : $(build_version_in "${repo}")"
|
||||
git -C "${repo}" checkout -q f && printf 'n\n' > "${repo}/nouveau"
|
||||
[[ $(build_version_in "${repo}") == "${commit}-dirty" ]] || fail "fichier non suivi : $(build_version_in "${repo}")"
|
||||
mkdir "${WORK}/hors-depot"
|
||||
build_version_in "${WORK}/hors-depot" >/dev/null && fail "hors dépôt : réussite"
|
||||
teardown
|
||||
}
|
||||
|
||||
for T in $(declare -F | awk '{print $3}' | grep '^test_'); do
|
||||
"${T}"
|
||||
done
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue