bugfix double kill process, update scripts

This commit is contained in:
AJ ONeal 2020-10-09 08:34:46 +00:00
parent fd361fd43a
commit f78fafd3c4
2 changed files with 26 additions and 12 deletions

View File

@ -1,18 +1,22 @@
#!/bin/bash
for x in $@; do
echo "$x"
done
# These environment variables are set by the caller
my_envs='GIT_REF_NAME
GIT_REF_TYPE
GIT_REPO_ID
GIT_REPO_OWNER
GIT_REPO_NAME
GIT_CLONE_URL'
echo 'Doing "work" ...'
sleep 5
for x in $my_envs; do
base_dir="$(dirname "$(readlink -f "$0")")"
if [[ -f "scripts/${GIT_REPO_ID}/deploy.sh" ]]
then
echo "Running deplay script for ${GIT_REPO_ID}"
bash "scripts/${GIT_REPO_ID}/deploy.sh"
else
echo "Nothing to do for ${GIT_REPO_ID}"
for x in $my_envs; do
echo "$x=${!x}"
done
done
sleep 1
fi

14
main.go
View File

@ -10,6 +10,7 @@ import (
"net/http"
"os"
"os/exec"
"strings"
"time"
"git.ryanburnette.com/ryanburnette/git-deploy/assets"
@ -316,11 +317,18 @@ func runHook(hook webhooks.Ref) {
}
cmd := exec.Command("bash", args...)
// https://git.example.com/example/project.git
// => git.example.com/example/project
repoID := strings.TrimPrefix(hook.HTTPSURL, "https://")
repoID = strings.TrimPrefix(repoID, "https://")
repoID = strings.TrimSuffix(repoID, ".git")
env := os.Environ()
envs := []string{
"GIT_DEPLOY_JOB_ID=" + jobID,
"GIT_REF_NAME=" + hook.RefName,
"GIT_REF_TYPE=" + hook.RefType,
"GIT_REPO_ID=" + repoID,
"GIT_REPO_OWNER=" + hook.Owner,
"GIT_REPO_NAME=" + hook.Repo,
"GIT_CLONE_URL=" + hook.HTTPSURL,
@ -349,8 +357,10 @@ func runHook(hook webhooks.Ref) {
go func() {
log.Printf("git-deploy job for %s#%s started\n", hook.HTTPSURL, hook.RefName)
_ = cmd.Wait()
killers <- jobID
if err := cmd.Wait(); nil != err {
log.Printf("git-deploy job for %s#%s exited with error: %v", hook.HTTPSURL, hook.RefName, err)
return
}
log.Printf("git-deploy job for %s#%s finished\n", hook.HTTPSURL, hook.RefName)
// TODO check for backlog
}()