11package gitreceive
22
3+ import (
4+ "fmt"
5+ "path/filepath"
6+ "strings"
7+ )
8+
9+ const shortShaIdx = 8
10+
11+ type errGitShaTooShort struct {
12+ sha string
13+ }
14+
15+ func (e errGitShaTooShort ) Error () string {
16+ return fmt .Sprintf ("git sha %s was too short" , e .sha )
17+ }
18+
319func build (conf * Config , newRev string ) error {
420 // #!/usr/bin/env bash
521 // #
@@ -43,18 +59,34 @@ func build(conf *Config, newRev string) error {
4359 // exit 1
4460 // fi
4561 //
62+
4663 // USER=$1
4764 // REPO=$2
4865 // GIT_SHA=$3
4966 // SHORT_SHA=${GIT_SHA:0:8}
5067 // APP_NAME="${REPO%.*}"
68+ user := conf .Username
69+ repo := conf .Repository
70+ gitSha := conf .SHA
71+ if len (gitSha ) <= shortShaIdx {
72+ return errGitShaTooShort {sha : gitSha }
73+ }
74+ shortSha := conf .SHA [0 :8 ]
75+ appName := conf .App
5176 //
5277 // cd $(dirname $0) # ensure we are in the root dir
5378 //
5479 // ROOT_DIR=$(pwd)
5580 // REPO_DIR="${ROOT_DIR}/${REPO}"
5681 // BUILD_DIR="${REPO_DIR}/build"
5782 // CACHE_DIR="${REPO_DIR}/cache"
83+ rootDir , err := os .Getwd ()
84+ if err != nil {
85+ return nil
86+ }
87+ repoDir := filepath .Join (rootDir , repo )
88+ buildDir := filepath .Join (repoDir , "build" )
89+ cacheDir := filepath .Join (repoDir , "cache" )
5890 //
5991 // # define image names
6092 // SLUG_NAME="$APP_NAME:git-$SHORT_SHA"
@@ -64,6 +96,15 @@ func build(conf *Config, newRev string) error {
6496 // mkdir -p $BUILD_DIR $CACHE_DIR
6597 // # create temporary directory inside the build dir for this push
6698 // TMP_DIR=$(mktemp -d -p $BUILD_DIR)
99+ slugName := fmt .Sprintf ("%s:git-%s" , appName , shortSha )
100+ metaName := strings .Replace (slugName , ":" , "-" )
101+ tmpImage := fmt .Sprintf ("%s:%s/%s" , conf .RegistryHost , conf .RegistryPort , conf .ImageName )
102+ if err := os .MkdirAll (buildDir , os .ModeDir ); err != nil {
103+ return errMkdir {dir : buildDir , err : err }
104+ }
105+
106+ //TODO: make tmp_dir
107+
67108 //
68109 // cd $REPO_DIR
69110 // # use Procfile if provided, otherwise try default process types from ./release
0 commit comments