Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: include commit hash & version #2453

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b954ff3
repo: add `ipfs repo stat` command
atomgardner Feb 3, 2016
8aa1cc2
`repo stat`: add Type
atomgardner Feb 5, 2016
ae7d672
Humanize byte size
atomgardner Feb 10, 2016
5726f29
repo-stat
daviddias Mar 2, 2016
ea870a1
t0300: improve docker_build debug message
chriscool Mar 7, 2016
129656e
build: include commit hash & version
Mar 7, 2016
595db0a
various bugfixes
Mar 9, 2016
d801991
feat: Update the webui to work with the latest changes in 0.4
dignifiedquire Mar 14, 2016
aeb1ed2
fix double transfer encoding head problem
whyrusleeping Mar 14, 2016
22937ad
fix whitespace trimming
whyrusleeping Mar 14, 2016
d5169e4
Alphabetized subcommands
RichardLitt Mar 15, 2016
53b1681
appveyor fix to make it execute tests again
kalmi Mar 18, 2016
5346331
Edited the grammar for diag
RichardLitt Mar 18, 2016
a3357b8
docker: start daemon with --enable-gc
Mar 21, 2016
1e7e383
clean up dependencies
whyrusleeping Mar 22, 2016
0f48247
correct import in fuse tests
MichaelMure Mar 25, 2016
a65f3c0
clean deprecated Key.Pretty()
MichaelMure Mar 20, 2016
30d8be7
allow users to override the IPFS API address when fetching dependencies
Stebalien Mar 28, 2016
fadd9a4
update utp and cleanup more godeps along the way
whyrusleeping Mar 30, 2016
7ebfe81
change `ipfs pin` response field name from `Pinned` to `Pins`
Stebalien Mar 15, 2016
5ef4074
use the builtin option parser to set the default for `ipfs pin ls --t…
Stebalien Mar 16, 2016
8837cb8
Merge branch 'master' into fix/version-commit-hash
Apr 4, 2016
74af4c8
Merge branch 'master' into fix/version-commit-hash
Apr 5, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ ENV GOPATH /go
ENV PATH /go/bin:$PATH
ENV SRC_PATH /go/src/github.com/ipfs/go-ipfs

ARG IPFS_VERSION

# Get the go-ipfs sourcecode
COPY . $SRC_PATH

Expand All @@ -53,10 +55,11 @@ RUN apk add --update musl go=$GO_VERSION git bash wget ca-certificates \
# This saves us quite a bit of image size.
&& ref="$(cat .git/HEAD | cut -d' ' -f2)" \
&& commit="$(cat .git/$ref | head -c 7)" \
&& echo "ldflags=-X github.com/ipfs/go-ipfs/repo/config.CurrentCommit=$commit" \
# Build and install IPFS and entrypoint script
&& ldflags="-X github.com/ipfs/go-ipfs/repo/config.CurrentCommit=$commit \
-X github.com/ipfs/go-ipfs/repo/config.CurrentVersionNumber=$IPFS_VERSION" \
&& echo "ldflags: $ldflags" \
&& cd $SRC_PATH/cmd/ipfs \
&& go build -ldflags "-X github.com/ipfs/go-ipfs/repo/config.CurrentCommit=$commit" \
&& go build -ldflags "$ldflags" \
&& cp ipfs /usr/local/bin/ipfs \
&& cp $SRC_PATH/bin/container_daemon /usr/local/bin/start_ipfs \
&& chmod 755 /usr/local/bin/start_ipfs \
Expand Down
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ else
go_test=go test
endif

COMMIT := $(shell git rev-parse --short HEAD)
ldflags = "-X "github.com/ipfs/go-ipfs/repo/config".CurrentCommit=$(COMMIT)"
VERSION := $(shell bin/genversion --version)
COMMIT := $(shell bin/genversion --commit)
ldflags = "-X "github.com/ipfs/go-ipfs/repo/config".CurrentVersionNumber=$(VERSION) \
-X "github.com/ipfs/go-ipfs/repo/config".CurrentCommit=$(COMMIT)"

MAKEFLAGS += --no-print-directory


Expand Down Expand Up @@ -59,8 +62,11 @@ clean:
uninstall:
cd cmd/ipfs && go clean -i -ldflags=$(ldflags)

docker:
docker build --build-arg IPFS_VERSION=$(VERSION) .

PHONY += all help godep toolkit_upgrade gx_upgrade gxgo_upgrade gx_check
PHONY += go_check deps vendor install build nofuse clean uninstall
PHONY += go_check deps vendor install build nofuse clean uninstall docker

##############################################################
# tests targets
Expand Down
78 changes: 78 additions & 0 deletions bin/genversion
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash

#
# Calls git describe and extracts SemVer-compatible version and meta info
# Assumes git tags are properly formatted: vX.Y.Z or vX.Y.Z-some-tag
#
# Examples:
#
# $ genversion --version
# 0.4.0-rc2
#
# or:
#
# $ genversion --commit
# c148.91c6f0f.dirty
#
# (148 commits ahead of the version 0.4.0-rc2, dirty workdir with HEAD at 91c6f0f)


PRINT_VERSION=0
PRINT_COMMIT=0

test $# -ge 1 || PRINT_VERSION=1

while test $# -gt 0; do
case "$1" in
"--version")
PRINT_VERSION=1
;;
"--commit")
PRINT_COMMIT=1
;;
esac
shift
done


string_join (){
local IFS="$1"
shift
echo "$*"
}

if [[ "$PRINT_VERSION" == "1" ]] || [[ "$PRINT_COMMIT" == "1" ]]; then
DESCRIBE=( $(git describe --always --tags --match 'v*' --dirty --long | tr '-' '\n') )

FIELDS=${#DESCRIBE[@]}
if [[ "${DESCRIBE[$FIELDS-1]}" == "dirty" ]]; then
DIRTY=1
FIELDS=$FIELDS-1
fi
COMMIT_HASH=${DESCRIBE[$FIELDS-1]}
COMMIT_NO=${DESCRIBE[$FIELDS-2]}
VERSION=$(string_join - ${DESCRIBE[@]:0:$FIELDS-2})
VERSION=${VERSION:1}
HASH=${DESCRIBE[$FIELDS-1]}
COMMIT=$(printf "c%s.%s" ${DESCRIBE[$FIELDS-2]} ${HASH:1})

if [[ "$DIRTY" == "1" ]]; then
COMMIT="$COMMIT.dirty"
fi

fi

if [[ "$PRINT_VERSION" == "1" ]]; then
printf $VERSION
fi

if [[ "$PRINT_VERSION" == "1" ]] && [[ "$PRINT_COMMIT" == "1" ]]; then
printf "+"
fi

if [[ "$PRINT_COMMIT" == "1" ]]; then
printf $COMMIT
fi

echo

2 changes: 1 addition & 1 deletion core/commands/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var VersionCmd = &cmds.Command{
return nil, err
}
if found && commit {
commitTxt = "-" + v.Commit
commitTxt = "+" + v.Commit
}

number, found, err := res.Request().Option("number").Bool()
Expand Down
6 changes: 4 additions & 2 deletions repo/config/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import (
"time"
)

// CurrentVersionNumber and CurrentCommit are normally set via ldflags -X

// CurrentCommit is the current git commit, this is set as a ldflag in the Makefile
var CurrentCommit string

// CurrentVersionNumber is the current application's version literal
const CurrentVersionNumber = "0.4.0-dev"
var CurrentVersionNumber = "0.0.0-dev"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CurrentVersionNumber should stay as it is and not carry commit information -- it's used in too many places where the assumption is a simple vN.N.N string. Maybe just use CurrentCommit?


const ApiVersion = "/go-ipfs/" + CurrentVersionNumber + "/"
var ApiVersion = "/go-ipfs/" + CurrentVersionNumber + "/"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this do what expected when changing CurrentVersionNumber via ldflags? In any case the same vN.N.N expectation applies here.


// Version regulates checking if the most recent version is run
type Version struct {
Expand Down
8 changes: 6 additions & 2 deletions test/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,16 @@ RUN apk add --update musl go=$GO_VERSION git bash wget ca-certificates \

COPY . $SRC_PATH

ARG IPFS_VERSION

RUN cd $SRC_PATH \
&& ref="$(cat .git/HEAD | cut -d' ' -f2)" \
&& commit="$(cat .git/$ref | head -c 7)" \
&& echo "ldflags=-X github.com/ipfs/go-ipfs/repo/config.CurrentCommit=$commit" \
&& ldflags="-X github.com/ipfs/go-ipfs/repo/config.CurrentCommit=$commit \
-X github.com/ipfs/go-ipfs/repo/config.CurrentVersionNumber=$IPFS_VERSION" \
&& echo "ldflags: $ldflags" \
&& cd $SRC_PATH/cmd/ipfs \
&& go build -ldflags "-X github.com/ipfs/go-ipfs/repo/config.CurrentCommit=$commit" \
&& go build -ldflags "$ldflags" \
&& cp ipfs /usr/local/bin/ipfs \
&& cp $SRC_PATH/bin/container_daemon /usr/local/bin/start_ipfs \
&& chmod 755 /usr/local/bin/start_ipfs \
Expand Down
12 changes: 11 additions & 1 deletion test/ipfs-test-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,17 @@ shellquote() {

# This takes a Dockerfile, and a build context directory
docker_build() {
docker build --rm -f "$1" "$2"
ipfs_version=$($2/bin/genversion --version)

# Workaround for docker < 1.9
if test "$TRAVIS" = true
then
cat "$1" | sed "s/^ARG IPFS_VERSION.*/ENV IPFS_VERSION=$ipfs_version/" > "$1.travis"
docker build --rm -f "$1.travis" "$2"
rm "$1.travis"
else
docker build --rm --build-arg IPFS_VERSION=$ipfs_version -f "$1" "$2"
fi
}

# This takes an image as argument and writes a docker ID on stdout
Expand Down