diff --git a/README.md b/README.md index c9902b6..4c5b14d 100644 --- a/README.md +++ b/README.md @@ -63,8 +63,13 @@ Example showing all options: branch: ${{ github.head_ref || github.ref_name }} empty: true file_pattern: '*.txt *.md *.json *.hcl' + repository: 'path/to/subdir' env: GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} ``` +The `repository` input is optional. When set, it must be a relative path under +`$GITHUB_WORKSPACE` pointing to the git repository to operate on. Defaults to +the root of the repository (`.`). + See [`action.yaml`](./action.yaml) for current list of supported inputs. diff --git a/action.yaml b/action.yaml index e5f8ba1..e36fde3 100644 --- a/action.yaml +++ b/action.yaml @@ -24,6 +24,10 @@ inputs: description: File pattern used for `git add`. For example `src/*.js` required: false default: "." + repository: + description: Relative file path under $GITHUB_WORKSPACE to the git repository. Defaults to the root of the repository (`.`). + required: false + default: "." outputs: commit-url: @@ -40,3 +44,4 @@ runs: - ${{ inputs.branch }} - ${{ inputs.empty }} - ${{ inputs.file_pattern }} + - ${{ inputs.repository }} diff --git a/entrypoint.sh b/entrypoint.sh index 6c7f739..a16fb46 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -48,8 +48,14 @@ REPO="${2:?Missing repo input}" BRANCH="${3:?Missing branch input}" EMPTY="${4:-false}" read -r -a FILE_PATTERNS <<<"${5:?Missing file_pattern input}" +REPOSITORY="${6:-.}" -git config --global --add safe.directory "$GITHUB_WORKSPACE" +REPOSITORY_PATH="$GITHUB_WORKSPACE/$REPOSITORY" +echo "Repository path: $REPOSITORY_PATH" + +git config --global --add safe.directory "$REPOSITORY_PATH" + +cd "$REPOSITORY_PATH" adds=() deletes=()