1
1
mirror of https://github.com/github/semantic.git synced 2024-11-29 21:52:59 +03:00

Merge pull request #377 from github/sha-sha-sha-cha-cha-cha

Embed SHA in Docker builds by passing it in as an environment variable.
This commit is contained in:
Patrick Thomson 2019-11-07 13:59:28 -05:00 committed by GitHub
commit 9855903e1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 43 deletions

1
.gitignore vendored
View File

@ -19,6 +19,7 @@ dist-repl
tmp/
/bin/
/src/Semantic/Version.hs.bak
/semanticd/test/current
/semanticd/test/rover-example-config/semantic.log
/test/fixtures/*/examples

View File

@ -22,22 +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-ast semantic-ast/
COPY semantic-core semantic-core/
COPY semantic-java semantic-java/
COPY semantic-json semantic-json/
COPY semantic-python semantic-python/
COPY semantic-tags semantic-tags/
COPY cabal.project .
RUN cabal v2-update && \
cabal v2-build --flags="release" --only-dependencies
# Build all of semantic
COPY . .
RUN cabal v2-build --flags="release" 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

View File

@ -10,17 +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
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

View File

@ -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

View File

@ -1,28 +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 @<development>@.
buildSHA :: String
#ifdef COMPUTE_GIT_SHA
buildSHA = $(gitHash)
#else
buildSHA = "<development>"
#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 @<development>@.
buildSHA :: String
buildSHA = "<development>"