Merge pull request #11631 from cevich/replace_hack-get_release_info

Fix Error, empty output for info: 'VERSION'
This commit is contained in:
OpenShift Merge Robot
2021-09-21 14:05:41 -04:00
committed by GitHub
4 changed files with 30 additions and 85 deletions

1
.gitignore vendored
View File

@ -31,6 +31,7 @@ release.txt
/test/checkseccomp/checkseccomp
/test/copyimg/copyimg
/test/goecho/goecho
/test/version/version
/test/testvol/testvol
.vscode*
tags

View File

@ -107,12 +107,9 @@ LIBSECCOMP_COMMIT := v2.3.3
# caller may override in special circumstances if needed.
GINKGOTIMEOUT ?= -timeout=90m
RELEASE_VERSION ?= $(shell hack/get_release_info.sh VERSION)
RELEASE_NUMBER ?= $(shell hack/get_release_info.sh NUMBER|sed -e 's/^v\(.*\)/\1/')
RELEASE_DIST ?= $(shell hack/get_release_info.sh DIST)
RELEASE_DIST_VER ?= $(shell hack/get_release_info.sh DIST_VER)
RELEASE_ARCH ?= $(shell hack/get_release_info.sh ARCH)
RELEASE_BASENAME := $(shell hack/get_release_info.sh BASENAME)
# Conditional required to produce empty-output if binary not built yet.
RELEASE_VERSION = $(shell if test -x test/version/version; then test/version/version; fi)
RELEASE_NUMBER = $(shell echo "$(RELEASE_VERSION)" | sed -e 's/^v\(.*\)/\1/')
# If non-empty, logs all output from server during remote system testing
PODMAN_SERVER_LOG ?=
@ -256,6 +253,9 @@ volume-plugin-test-img:
test/goecho/goecho: .gopathok $(wildcard test/goecho/*.go)
$(GO) build $(BUILDFLAGS) -ldflags '$(LDFLAGS_PODMAN)' -o $@ ./test/goecho
test/version/version: .gopathok version/version.go
$(GO) build -o $@ ./test/version/
.PHONY: codespell
codespell:
codespell -S bin,vendor,.git,go.sum,.cirrus.yml,"RELEASE_NOTES.md,*.xz,*.gz,*.ps1,*.tar,*.tgz,bin2img,*ico,*.png,*.1,*.5,copyimg,*.orig,apidoc.go" -L uint,iff,od,seeked,splitted,marge,ERRO,hist,ether -w
@ -491,7 +491,7 @@ run-docker-py-tests:
-rm test/__init__.py
.PHONY: localunit
localunit: test/goecho/goecho
localunit: test/goecho/goecho test/version/version
rm -rf ${COVERAGE_PATH} && mkdir -p ${COVERAGE_PATH}
$(GOBIN)/ginkgo \
-r \
@ -581,7 +581,8 @@ system.test-binary: .install.ginkgo
$(GO) test -c ./test/system
.PHONY: test-binaries
test-binaries: test/checkseccomp/checkseccomp test/goecho/goecho install.catatonit
test-binaries: test/checkseccomp/checkseccomp test/goecho/goecho install.catatonit test/version/version
@echo "Canonical source version: $(call err_if_empty,RELEASE_VERSION)"
.PHONY: tests-included
tests-included:
@ -601,18 +602,18 @@ tests-expect-exit:
### Release/Packaging targets
###
podman-release.tar.gz: binaries docs ## Build all binaries, docs., and installation tree, into a tarball.
podman-release.tar.gz: test/version/version binaries docs ## Build all binaries, docs., and installation tree, into a tarball.
$(eval TMPDIR := $(shell mktemp -d podman_tmp_XXXX))
$(eval SUBDIR := podman-v$(RELEASE_NUMBER))
$(eval SUBDIR := podman-v$(call err_if_empty,RELEASE_NUMBER))
mkdir -p "$(TMPDIR)/$(SUBDIR)"
$(MAKE) install.bin install.man \
$(MAKE) install.bin install.remote install.man \
install.systemd "DESTDIR=$(TMPDIR)/$(SUBDIR)" "PREFIX=/usr"
tar -czvf $@ --xattrs -C "$(TMPDIR)" "./$(SUBDIR)"
-rm -rf "$(TMPDIR)"
podman-remote-release-%.zip: podman-remote-% install-podman-remote-%-docs ## Build podman-remote for GOOS=%, docs., and installation zip.
podman-remote-release-%.zip: test/version/version podman-remote-% install-podman-remote-%-docs ## Build podman-remote for GOOS=%, docs., and installation zip.
$(eval TMPDIR := $(shell mktemp -d podman_tmp_XXXX))
$(eval SUBDIR := podman-$(RELEASE_NUMBER))
$(eval SUBDIR := podman-$(call err_if_empty,RELEASE_NUMBER))
mkdir -p "$(TMPDIR)/$(SUBDIR)"
$(MAKE) \
GOOS=$* \
@ -627,14 +628,15 @@ podman-remote-release-%.zip: podman-remote-% install-podman-remote-%-docs ## Bu
-rm -rf "$(TMPDIR)"
.PHONY: podman.msi
podman.msi: podman-v$(RELEASE_NUMBER).msi ## Build podman-remote, package for installation on Windows
podman.msi: test/version/version ## Build podman-remote, package for installation on Windows
$(MAKE) podman-v$(RELEASE_NUMBER).msi
podman-v$(RELEASE_NUMBER).msi: podman-remote-windows install-podman-remote-windows-docs
$(eval DOCFILE := docs/build/remote/windows)
find $(DOCFILE) -print | \
wixl-heat --var var.ManSourceDir --component-group ManFiles \
--directory-ref INSTALLDIR --prefix $(DOCFILE)/ > \
$(DOCFILE)/pages.wsx
wixl -D VERSION=$(RELEASE_VERSION) -D ManSourceDir=$(DOCFILE) \
wixl -D VERSION=$(call err_if_empty,RELEASE_VERSION) -D ManSourceDir=$(DOCFILE) \
-o $@ contrib/msi/podman.wxs $(DOCFILE)/pages.wsx
.PHONY: package
@ -832,6 +834,7 @@ clean: ## Clean all make artifacts
build \
test/checkseccomp/checkseccomp \
test/goecho/goecho \
test/version/version \
test/__init__.py \
test/testdata/redis-image \
libpod/container_ffjson.go \

View File

@ -1,70 +0,0 @@
#!/usr/bin/env bash
# This script produces various bits of metadata needed by Makefile. Using
# a script allows uniform behavior across multiple environments and
# distributions. The script expects a single argument, as reflected below.
set -euo pipefail
cd "${GOSRC:-$(dirname $0)/../}"
valid_args() {
REGEX='^\s+[[:upper:]]+\*[)]'
egrep --text --no-filename --group-separator=' ' --only-matching "$REGEX" "$0" | \
cut -d '*' -f 1
}
# `git describe` will never produce a useful version number under all
# branches. This is because the podman release process (see `RELEASE_PROCESS.md`)
# tags release versions only on release-branches (i.e. never on main).
# Scraping the version number directly from the source, is the only way
# to reliably obtain the number from all the various contexts supported by
# the `Makefile`.
scrape_version() {
local v
# extract the value of 'var Version'
v=$(sed -ne 's/^var\s\+Version\s\+=\s.*("\(.*\)").*/\1/p' <version/version.go)
# If it's empty, something has changed in version.go, that would be bad!
test -n "$v"
# Value consumed literally, must not have any embedded newlines
echo -n "$v"
}
unset OUTPUT
case "$1" in
# Wild-card suffix needed by valid_args() e.g. possible bad grep of "$(echo $FOO)"
VERSION*)
OUTPUT="${CIRRUS_TAG:-$(scrape_version)}"
;;
NUMBER*)
OUTPUT="$($0 VERSION | sed 's/-.*//')"
;;
DIST_VER*)
OUTPUT="$(source /etc/os-release; echo $VERSION_ID | cut -d '.' -f 1)"
;;
DIST*)
OUTPUT="$(source /etc/os-release; echo $ID)"
;;
ARCH*)
OUTPUT="${GOARCH:-$(go env GOARCH 2> /dev/null)}"
;;
BASENAME*)
OUTPUT="podman"
;;
REMOTENAME*)
OUTPUT="$($0 BASENAME)-remote"
;;
*)
echo "Error, unknown/unsupported argument '$1', valid arguments:"
valid_args
exit 1
;;
esac
if [[ -n "$OUTPUT" ]]
then
echo -n "$OUTPUT"
else
echo "Error, empty output for info: '$1'" > /dev/stderr
exit 2
fi

11
test/version/main.go Normal file
View File

@ -0,0 +1,11 @@
package main
import (
"fmt"
"github.com/containers/podman/v3/version"
)
func main() {
fmt.Printf(version.Version.String())
}