From 52d021bcd69620d2c5f02beb481ad6a1a38f2cf1 Mon Sep 17 00:00:00 2001 From: Patrick Thomson Date: Fri, 1 Nov 2019 14:40:07 -0400 Subject: [PATCH 1/4] First attempt. --- Dockerfile | 1 + script/publish | 2 +- semantic.cabal | 4 ---- src/Semantic/Version.hs | 6 ++++-- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index adc3af597..3bc4f2bd8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,6 +33,7 @@ COPY semantic-source semantic-source/ COPY semantic-tags semantic-tags/ COPY cabal.project . RUN cabal v2-update && \ + cabal configure --ghc-options="-D$GIT_COMMIT" cabal v2-build --flags="release" --only-dependencies # Build all of semantic diff --git a/script/publish b/script/publish index 63d1c6c28..bbb6a2590 100755 --- a/script/publish +++ b/script/publish @@ -11,7 +11,7 @@ BUILD_SHA=$(git rev-parse HEAD 2>/dev/null) DOCKER_IMAGE=docker.pkg.github.com/github/semantic/semantic # Build -docker build -t $DOCKER_IMAGE . +docker build -t $DOCKER_IMAGE --build-arg BUILD_SHA=$BUILD_SHA. # Make sure semantic is in the image. docker run --rm $DOCKER_IMAGE --version diff --git a/semantic.cabal b/semantic.cabal index 0a843d020..725dd2e61 100644 --- a/semantic.cabal +++ b/semantic.cabal @@ -303,15 +303,11 @@ library , tree-sitter-ruby ^>= 0.2 , tree-sitter-typescript ^>= 0.2.1 , tree-sitter-tsx ^>= 0.2.1 - if flag(release) - cpp-options: -DCOMPUTE_GIT_SHA executable semantic import: haskell, dependencies, executable-flags hs-source-dirs: app main-is: Main.hs - if flag(release) - cpp-options: -DCOMPUTE_GIT_SHA build-depends: base , semantic diff --git a/src/Semantic/Version.hs b/src/Semantic/Version.hs index 6a71f534f..3174453f4 100644 --- a/src/Semantic/Version.hs +++ b/src/Semantic/Version.hs @@ -17,10 +17,12 @@ import Paths_semantic (version) -- The SHA1 hash of this build of semantic. -- If compiled as a development build, this will be @@. buildSHA :: String -#ifdef COMPUTE_GIT_SHA +#if defined(GIT_COMMIT) +buildSHA = "GIT_COMMIT" +#elif defined(COMPUTE_GIT_SHA) buildSHA = $(gitHash) #else -buildSHA = "" +buildSHA = "unspecified" #endif -- The version string of this build of semantic. From f0956624a0149a81548b3af5737996c6fa7cd5ac Mon Sep 17 00:00:00 2001 From: Patrick Thomson Date: Mon, 4 Nov 2019 14:33:57 -0500 Subject: [PATCH 2/4] closer --- Dockerfile | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3bc4f2bd8..b25450e77 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,14 +31,17 @@ COPY semantic-json semantic-json/ COPY semantic-python semantic-python/ COPY semantic-source semantic-source/ COPY semantic-tags semantic-tags/ +COPY semantic-ast semantic-ast/ COPY cabal.project . RUN cabal v2-update && \ - cabal configure --ghc-options="-D$GIT_COMMIT" - cabal v2-build --flags="release" --only-dependencies + cabal v2-configure --flags="release" --ghc-options="-D$GIT_COMMIT" +COPY cabal.project.local . +RUN cabal v2-build --only-dependencies + # Build all of semantic COPY . . -RUN cabal v2-build --flags="release" semantic:exe:semantic +RUN cabal v2-build semantic:exe:semantic # A fake `install` target until we can get `cabal v2-install` to work RUN cp $(find dist-newstyle/build/x86_64-linux -name semantic -type f -perm -u=x) /usr/local/bin/semantic From 1ab38e297a9e2f636bcc22ee85d3359191e06deb Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Wed, 6 Nov 2019 16:20:14 -0800 Subject: [PATCH 3/4] Try a different approach for embedding the git commit sha --- .dockerignore | 1 + .gitignore | 1 + Dockerfile | 21 +++------------------ script/publish | 3 ++- src/Semantic/Version.hs | 24 +++++------------------- 5 files changed, 12 insertions(+), 38 deletions(-) diff --git a/.dockerignore b/.dockerignore index 619162c4f..bdb208923 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,5 +1,6 @@ Dockerfile /.licenses +/.git .ghc.environment.x86_64-darwin-8.6.5 /bin diff --git a/.gitignore b/.gitignore index 0a5922aab..47833ee4c 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ dist-repl tmp/ /bin/ +/src/Semantic/Version.hs.bak /semanticd/test/current /semanticd/test/rover-example-config/semantic.log /test/fixtures/*/examples diff --git a/Dockerfile b/Dockerfile index b25450e77..8249fa34e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,26 +22,11 @@ ENTRYPOINT ["/protobuf/bin/protoc", "-I/protobuf", "--plugin=protoc-gen-haskell= FROM haskell:8.6 as build WORKDIR /build -# Build just the dependencies so that this layer can be cached -COPY semantic.cabal . -COPY semantic-analysis semantic-analysis/ -COPY semantic-core semantic-core/ -COPY semantic-java semantic-java/ -COPY semantic-json semantic-json/ -COPY semantic-python semantic-python/ -COPY semantic-source semantic-source/ -COPY semantic-tags semantic-tags/ -COPY semantic-ast semantic-ast/ -COPY cabal.project . -RUN cabal v2-update && \ - cabal v2-configure --flags="release" --ghc-options="-D$GIT_COMMIT" -COPY cabal.project.local . -RUN cabal v2-build --only-dependencies - - # Build all of semantic COPY . . -RUN cabal v2-build semantic:exe:semantic +RUN cabal v2-update && \ + cabal v2-configure --flags="release" && \ + cabal v2-build semantic:exe:semantic # A fake `install` target until we can get `cabal v2-install` to work RUN cp $(find dist-newstyle/build/x86_64-linux -name semantic -type f -perm -u=x) /usr/local/bin/semantic diff --git a/script/publish b/script/publish index bbb6a2590..9c6286062 100755 --- a/script/publish +++ b/script/publish @@ -11,7 +11,8 @@ BUILD_SHA=$(git rev-parse HEAD 2>/dev/null) DOCKER_IMAGE=docker.pkg.github.com/github/semantic/semantic # Build -docker build -t $DOCKER_IMAGE --build-arg BUILD_SHA=$BUILD_SHA. +sed -i .bak "s/buildSHA =.*/buildSHA = \"$BUILD_SHA\"/" src/Semantic/Version.hs +docker build -t $DOCKER_IMAGE . # Make sure semantic is in the image. docker run --rm $DOCKER_IMAGE --version diff --git a/src/Semantic/Version.hs b/src/Semantic/Version.hs index 3174453f4..3a05699f2 100644 --- a/src/Semantic/Version.hs +++ b/src/Semantic/Version.hs @@ -1,30 +1,16 @@ -{-# LANGUAGE CPP #-} -#ifdef COMPUTE_GIT_SHA -{-# OPTIONS_GHC -fforce-recomp #-} -- So that gitHash is correct. -{-# LANGUAGE TemplateHaskell #-} -#endif module Semantic.Version ( buildSHA , buildVersion ) where import Data.Version (showVersion) -#ifdef COMPUTE_GIT_SHA -import Development.GitRev -#endif import Paths_semantic (version) --- The SHA1 hash of this build of semantic. --- If compiled as a development build, this will be @@. -buildSHA :: String -#if defined(GIT_COMMIT) -buildSHA = "GIT_COMMIT" -#elif defined(COMPUTE_GIT_SHA) -buildSHA = $(gitHash) -#else -buildSHA = "unspecified" -#endif - -- The version string of this build of semantic. buildVersion :: String buildVersion = showVersion version + +-- The SHA1 hash of this build of semantic. +-- If compiled as a development build, this will be @@. +buildSHA :: String +buildSHA = "" From 8f4d405070d935c4b495130fcb57849696347889 Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Thu, 7 Nov 2019 10:00:01 -0800 Subject: [PATCH 4/4] Various versions of sed and prompt before push --- script/publish | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/script/publish b/script/publish index 9c6286062..1058ac640 100755 --- a/script/publish +++ b/script/publish @@ -10,18 +10,28 @@ VERSION="0.8.0.0" BUILD_SHA=$(git rev-parse HEAD 2>/dev/null) DOCKER_IMAGE=docker.pkg.github.com/github/semantic/semantic +# Set the version to the current commit sha +SED_ARGS="-i" +if [[ "$(uname -s)" = "Darwin" ]]; then + SED_ARGS="$SED_ARGS .bak" +fi +sed $SED_ARGS "s/buildSHA =.*/buildSHA = \"$BUILD_SHA\"/" src/Semantic/Version.hs + # Build -sed -i .bak "s/buildSHA =.*/buildSHA = \"$BUILD_SHA\"/" src/Semantic/Version.hs docker build -t $DOCKER_IMAGE . # Make sure semantic is in the image. docker run --rm $DOCKER_IMAGE --version -# Requires that you've logged in to the GPR (e.g. `docker login docker.pkg.github.com`) -# https://help.github.com/en/articles/configuring-docker-for-use-with-github-package-registry -docker tag $DOCKER_IMAGE $DOCKER_IMAGE:latest -docker tag $DOCKER_IMAGE $DOCKER_IMAGE:$VERSION -docker tag $DOCKER_IMAGE $DOCKER_IMAGE:sha_$BUILD_SHA -docker push $DOCKER_IMAGE:sha_$BUILD_SHA -docker push $DOCKER_IMAGE:$VERSION -docker push $DOCKER_IMAGE:latest +read -p "Do you want to publish to the GitHub Registry [y/n]? " -n 1 -r +echo +if [[ $REPLY =~ ^[Yy]$ ]]; then + # Requires that you've logged in to the GPR (e.g. `docker login docker.pkg.github.com`) + # https://help.github.com/en/articles/configuring-docker-for-use-with-github-package-registry + docker tag $DOCKER_IMAGE $DOCKER_IMAGE:latest + docker tag $DOCKER_IMAGE $DOCKER_IMAGE:$VERSION + docker tag $DOCKER_IMAGE $DOCKER_IMAGE:sha_$BUILD_SHA + docker push $DOCKER_IMAGE:sha_$BUILD_SHA + docker push $DOCKER_IMAGE:$VERSION + docker push $DOCKER_IMAGE:latest +fi