diff --git a/.forgejo/workflows/build.yml b/.forgejo/workflows/build.yml index d80e151..947e046 100644 --- a/.forgejo/workflows/build.yml +++ b/.forgejo/workflows/build.yml @@ -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 diff --git a/test/e2e/build.sh b/test/e2e/build.sh index abba46f..749b25b 100755 --- a/test/e2e/build.sh +++ b/test/e2e/build.sh @@ -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 diff --git a/test/e2e/run_test.sh b/test/e2e/run_test.sh index cb983cf..8371111 100755 --- a/test/e2e/run_test.sh +++ b/test/e2e/run_test.sh @@ -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