Skip to content

Commit

Permalink
Setup script (WIP).
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinHeinz committed Dec 30, 2021
1 parent 6fb642c commit 7aafae2
Showing 3 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/app/utils/utils.go
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ import (

func InitGitHubClient() {
tr := http.DefaultTransport
itr, err := ghinstallation.NewKeyFromFile(tr, 12345, 123456789, "/config/github-app.pem")
itr, err := ghinstallation.NewKeyFromFile(tr, APP_ID, INSTALLATION_ID, "/config/github-app.pem")

if err != nil {
log.Fatal(err)
2 changes: 1 addition & 1 deletion config/server.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github_webhook_secret: "verysecret"
github_webhook_secret: "WEBHOOK_SECRET"
40 changes: 40 additions & 0 deletions configure_project.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
for ARGUMENT in "$@"
do

KEY=$(echo $ARGUMENT | cut -f1 -d=)
VALUE=$(echo $ARGUMENT | cut -f2 -d=)

case "$KEY" in
APP_ID) APP_ID=${VALUE} ;;
INSTALLATION_ID) INSTALLATION_ID=${VALUE} ;;
WEBHOOK_SECRET) WEBHOOK_SECRET=${VALUE} ;;
REGISTRY) REGISTRY=${VALUE} ;;
*)
esac
done

DUMMY_REGISTRY='ghcr.io/martinheinz/go-github-app'
BLUE='\033[0;34m'
NC='\033[0m' # No Color

echo -e "\n${BLUE}Renaming variables and files...${NC}\n"

sed -i s~APP_ID~$APP_ID~g cmd/app/utils/utils.go
sed -i s~INSTALLATION_ID~$INSTALLATION_ID~g cmd/app/utils/utils.go
sed -i s~WEBHOOK_SECRET~$WEBHOOK_SECRET~g config/server.yaml
sed -i s~$DUMMY_REGISTRY~$REGISTRY~g Makefile

cat $KEY_PATH > config/github-app.pem

echo -e "\n${BLUE}Installing dependencies...${NC}\n"
go mod vendor

echo -e "\n${BLUE}Testing if everything works...${NC}\n"

echo -e "\n${BLUE}Test: make test${NC}\n"
make test
echo -e "\n${BLUE}Test: make build${NC}\n"
make build

# Usage:
# ./configure_project.sh APP_ID="12345" INSTALLATION_ID="12345678" WEBHOOK_SECRET="verysecret" KEY_PATH="./github_key.pem" REGISTRY="ghcr.io/<GITHUB_USERNAME>/go-github-app"

0 comments on commit 7aafae2

Please sign in to comment.