Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7f32f5a

Browse files
authored
Merge pull request ad-m#6 from koppor/add-support-for-sub-directory
Add support for changing directories before push
2 parents 1c8b858 + a8bfc19 commit 7f32f5a

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jobs:
2929
| github_token | string | | Token for the repo. Can be passed in using {{ secrets.GITHUB_TOKEN }}'. |
3030
| branch | string | 'master' | Destination branch to push changes. |
3131
| force | boolean | false | Determines if force push is used. |
32+
| directory | string | '.' | Directory to change to before pushing. |
3233
3334
## License
3435

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ inputs:
1515
force:
1616
description: 'Determines if force push is used'
1717
required: false
18+
directory:
19+
description: 'Directory to change to before pushing.'
20+
required: false
21+
default: '.'
1822
runs:
1923
using: 'docker'
2024
image: 'Dockerfile'

start.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#!/bin/sh
2+
set -e
23

3-
INPUT_BRANCH:='master'
4-
INPUT_FORCE:=false
4+
INPUT_BRANCH=${INPUT_BRANCH:-master}
5+
INPUT_FORCE=${INPUT_FORCE:-false}
6+
INPUT_DIRECTORY=${INPUT_DIRECTORY:-'.'}
57
_FORCE_OPTION=''
68

79
echo "Push to branch $INPUT_BRANCH";
@@ -14,5 +16,10 @@ if ${INPUT_FORCE}; then
1416
_FORCE_OPTION='--force'
1517
fi
1618

19+
cd ${INPUT_DIRECTORY}
20+
21+
# Ensure that the remote of the git repository of the current directory still is the repository where the github action is executed
22+
git remote add origin https://github.com/${GITHUB_REPOSITORY} || git remote set-url origin https://github.com/${GITHUB_REPOSITORY} || true
23+
1724
header=$(echo -n "ad-m:${INPUT_GITHUB_TOKEN}" | base64)
1825
git -c http.extraheader="AUTHORIZATION: basic $header" push origin HEAD:${INPUT_BRANCH} --follow-tags $_FORCE_OPTION;

0 commit comments

Comments
 (0)