Commit a1dca211 by Leonard Gram Committed by GitHub

build: use build workflow id instead of build number. (#13965)

* build: use build workflow id instead of build number.

The workflow id is unique across the whole workflow
while the build number is unique to every job in the
workflow. This change means that jobs that build
artifacts for the same commit but in different jobs
will now have the same id.

* build: fixes pkgver generation.
parent 0df14f3f
...@@ -41,8 +41,8 @@ var ( ...@@ -41,8 +41,8 @@ var (
race bool race bool
phjsToRelease string phjsToRelease string
workingDir string workingDir string
includeBuildNumber bool = true includeBuildId bool = true
buildNumber int = 0 buildId string = "0"
binaries []string = []string{"grafana-server", "grafana-cli"} binaries []string = []string{"grafana-server", "grafana-cli"}
isDev bool = false isDev bool = false
enterprise bool = false enterprise bool = false
...@@ -54,6 +54,8 @@ func main() { ...@@ -54,6 +54,8 @@ func main() {
ensureGoPath() ensureGoPath()
var buildIdRaw string
flag.StringVar(&goarch, "goarch", runtime.GOARCH, "GOARCH") flag.StringVar(&goarch, "goarch", runtime.GOARCH, "GOARCH")
flag.StringVar(&goos, "goos", runtime.GOOS, "GOOS") flag.StringVar(&goos, "goos", runtime.GOOS, "GOOS")
flag.StringVar(&gocc, "cc", "", "CC") flag.StringVar(&gocc, "cc", "", "CC")
...@@ -61,12 +63,14 @@ func main() { ...@@ -61,12 +63,14 @@ func main() {
flag.StringVar(&pkgArch, "pkg-arch", "", "PKG ARCH") flag.StringVar(&pkgArch, "pkg-arch", "", "PKG ARCH")
flag.StringVar(&phjsToRelease, "phjs", "", "PhantomJS binary") flag.StringVar(&phjsToRelease, "phjs", "", "PhantomJS binary")
flag.BoolVar(&race, "race", race, "Use race detector") flag.BoolVar(&race, "race", race, "Use race detector")
flag.BoolVar(&includeBuildNumber, "includeBuildNumber", includeBuildNumber, "IncludeBuildNumber in package name") flag.BoolVar(&includeBuildId, "includeBuildId", includeBuildId, "IncludeBuildId in package name")
flag.BoolVar(&enterprise, "enterprise", enterprise, "Build enterprise version of Grafana") flag.BoolVar(&enterprise, "enterprise", enterprise, "Build enterprise version of Grafana")
flag.IntVar(&buildNumber, "buildNumber", 0, "Build number from CI system") flag.StringVar(&buildIdRaw, "buildId", "0", "Build ID from CI system")
flag.BoolVar(&isDev, "dev", isDev, "optimal for development, skips certain steps") flag.BoolVar(&isDev, "dev", isDev, "optimal for development, skips certain steps")
flag.Parse() flag.Parse()
buildId = shortenBuildId(buildIdRaw)
readVersionFromPackageJson() readVersionFromPackageJson()
if pkgArch == "" { if pkgArch == "" {
...@@ -197,9 +201,9 @@ func readVersionFromPackageJson() { ...@@ -197,9 +201,9 @@ func readVersionFromPackageJson() {
} }
// add timestamp to iteration // add timestamp to iteration
if includeBuildNumber { if includeBuildId {
if buildNumber != 0 { if buildId != "0" {
linuxPackageIteration = fmt.Sprintf("%d%s", buildNumber, linuxPackageIteration) linuxPackageIteration = fmt.Sprintf("%s%s", buildId, linuxPackageIteration)
} else { } else {
linuxPackageIteration = fmt.Sprintf("%d%s", time.Now().Unix(), linuxPackageIteration) linuxPackageIteration = fmt.Sprintf("%d%s", time.Now().Unix(), linuxPackageIteration)
} }
...@@ -392,7 +396,7 @@ func grunt(params ...string) { ...@@ -392,7 +396,7 @@ func grunt(params ...string) {
func gruntBuildArg(task string) []string { func gruntBuildArg(task string) []string {
args := []string{task} args := []string{task}
if includeBuildNumber { if includeBuildId {
args = append(args, fmt.Sprintf("--pkgVer=%v-%v", linuxPackageVersion, linuxPackageIteration)) args = append(args, fmt.Sprintf("--pkgVer=%v-%v", linuxPackageVersion, linuxPackageIteration))
} else { } else {
args = append(args, fmt.Sprintf("--pkgVer=%v", version)) args = append(args, fmt.Sprintf("--pkgVer=%v", version))
...@@ -632,3 +636,11 @@ func shaFile(file string) error { ...@@ -632,3 +636,11 @@ func shaFile(file string) error {
return out.Close() return out.Close()
} }
func shortenBuildId(buildId string) string {
buildId = strings.Replace(buildId, "-", "", -1)
if (len(buildId) < 9) {
return buildId
}
return buildId[0:8]
}
...@@ -22,10 +22,10 @@ echo "current dir: $(pwd)" ...@@ -22,10 +22,10 @@ echo "current dir: $(pwd)"
if [ "$CIRCLE_TAG" != "" ]; then if [ "$CIRCLE_TAG" != "" ]; then
echo "Building releases from tag $CIRCLE_TAG" echo "Building releases from tag $CIRCLE_TAG"
OPT="-includeBuildNumber=false ${EXTRA_OPTS}" OPT="-includeBuildId=false ${EXTRA_OPTS}"
else else
echo "Building incremental build for $CIRCLE_BRANCH" echo "Building incremental build for $CIRCLE_BRANCH"
OPT="-buildNumber=${CIRCLE_BUILD_NUM} ${EXTRA_OPTS}" OPT="-buildId=${CIRCLE_WORKFLOW_ID} ${EXTRA_OPTS}"
fi fi
echo "Build arguments: $OPT" echo "Build arguments: $OPT"
......
...@@ -18,10 +18,10 @@ echo "current dir: $(pwd)" ...@@ -18,10 +18,10 @@ echo "current dir: $(pwd)"
if [ "$CIRCLE_TAG" != "" ]; then if [ "$CIRCLE_TAG" != "" ]; then
echo "Building releases from tag $CIRCLE_TAG" echo "Building releases from tag $CIRCLE_TAG"
OPT="-includeBuildNumber=false ${EXTRA_OPTS}" OPT="-includeBuildId=false ${EXTRA_OPTS}"
else else
echo "Building incremental build for $CIRCLE_BRANCH" echo "Building incremental build for $CIRCLE_BRANCH"
OPT="-buildNumber=${CIRCLE_BUILD_NUM} ${EXTRA_OPTS}" OPT="-buildId=${CIRCLE_WORKFLOW_ID} ${EXTRA_OPTS}"
fi fi
echo "Build arguments: $OPT" echo "Build arguments: $OPT"
......
#!/bin/bash
mkdir -p dist
echo "Circle branch: ${CIRCLE_BRANCH}"
echo "Circle tag: ${CIRCLE_TAG}"
docker run -i -t --name gfbuild \
-v $(pwd):/go/src/github.com/grafana/grafana \
-e "CIRCLE_BRANCH=${CIRCLE_BRANCH}" \
-e "CIRCLE_TAG=${CIRCLE_TAG}" \
-e "CIRCLE_BUILD_NUM=${CIRCLE_BUILD_NUM}" \
grafana/buildcontainer
sudo chown -R ${USER:=$(/usr/bin/id -run)}:$USER dist
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment