github.com/safedep/dry@v0.0.0-20241016050132-a15651f0548b/apiguard/tykgen/git_push.sh (about) 1 #!/bin/sh 2 # ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ 3 # 4 # Usage example: /bin/sh ./git_push.sh wing328 swagger-petstore-perl "minor update" 5 6 git_user_id=$1 7 git_repo_id=$2 8 release_note=$3 9 10 if [ "$git_user_id" = "" ]; then 11 git_user_id="GIT_USER_ID" 12 echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id" 13 fi 14 15 if [ "$git_repo_id" = "" ]; then 16 git_repo_id="GIT_REPO_ID" 17 echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id" 18 fi 19 20 if [ "$release_note" = "" ]; then 21 release_note="Minor update" 22 echo "[INFO] No command line input provided. Set \$release_note to $release_note" 23 fi 24 25 # Initialize the local directory as a Git repository 26 git init 27 28 # Adds the files in the local repository and stages them for commit. 29 git add . 30 31 # Commits the tracked changes and prepares them to be pushed to a remote repository. 32 git commit -m "$release_note" 33 34 # Sets the new remote 35 git_remote=`git remote` 36 if [ "$git_remote" = "" ]; then # git remote not defined 37 38 if [ "$GIT_TOKEN" = "" ]; then 39 echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment." 40 git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git 41 else 42 git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git 43 fi 44 45 fi 46 47 git pull origin master 48 49 # Pushes (Forces) the changes in the local repository up to the remote repository 50 echo "Git pushing to https://github.com/${git_user_id}/${git_repo_id}.git" 51 git push origin master 2>&1 | grep -v 'To https' 52