From a8bfc1909c63c5d834e2c9b15471fcb45e61a394 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Tue, 1 Oct 2019 21:42:53 +0200 Subject: [PATCH] Add support for changing directories before push --- README.md | 1 + action.yml | 4 ++++ start.sh | 11 +++++++++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 802cb84..06b718f 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ jobs: | github_token | string | | Token for the repo. Can be passed in using {{ secrets.GITHUB_TOKEN }}'. | | branch | string | 'master' | Destination branch to push changes. | | force | boolean | false | Determines if force push is used. | +| directory | string | '.' | Directory to change to before pushing. | ## License diff --git a/action.yml b/action.yml index 23f595b..09ccdc4 100644 --- a/action.yml +++ b/action.yml @@ -15,6 +15,10 @@ inputs: force: description: 'Determines if force push is used' required: false + directory: + description: 'Directory to change to before pushing.' + required: false + default: '.' runs: using: 'docker' image: 'Dockerfile' diff --git a/start.sh b/start.sh index b5709f3..9164fa5 100755 --- a/start.sh +++ b/start.sh @@ -1,7 +1,9 @@ #!/bin/sh +set -e -INPUT_BRANCH:='master' -INPUT_FORCE:=false +INPUT_BRANCH=${INPUT_BRANCH:-master} +INPUT_FORCE=${INPUT_FORCE:-false} +INPUT_DIRECTORY=${INPUT_DIRECTORY:-'.'} _FORCE_OPTION='' echo "Push to branch $INPUT_BRANCH"; @@ -14,5 +16,10 @@ if ${INPUT_FORCE}; then _FORCE_OPTION='--force' fi +cd ${INPUT_DIRECTORY} + +# Ensure that the remote of the git repository of the current directory still is the repository where the github action is executed +git remote add origin https://github.com/${GITHUB_REPOSITORY} || git remote set-url origin https://github.com/${GITHUB_REPOSITORY} || true + header=$(echo -n "ad-m:${INPUT_GITHUB_TOKEN}" | base64) git -c http.extraheader="AUTHORIZATION: basic $header" push origin HEAD:${INPUT_BRANCH} --follow-tags $_FORCE_OPTION;