Skip to content

Commit aa1a8ce

Browse files
authored
Add cwd option (#15)
* Add cwd option * Commit dist files * Debugging * Remove modules * Update docs * Remove debugging command * Minor formatting change
1 parent df80e17 commit aa1a8ce

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Add a step like this to your workflow:
1515
with: # See more info about inputs below
1616
author_name: Your Name
1717
author_email: [email protected]
18+
cwd: "."
1819
message: "Your commit message"
1920
path: "."
2021
pattern: "*.js"
@@ -27,6 +28,7 @@ Add a step like this to your workflow:
2728
2829
- `author_name` : the name of the user that will be displayed as the author of the commit, defaults to the author of the commit that triggered the run
2930
- `author_email` : the email of the user that will be displayed as the author of the commit, defaults to the author of the commit that triggered the run
31+
- `cwd` : the working directory in which your repository is located, defaults to `.`
3032
- `message` : the message for the commit
3133
- `path` : the path(s) to stage files from
3234
- `pattern` : the pattern that matches file names
@@ -70,7 +72,7 @@ jobs:
7072
runs-on: ubuntu-latest
7173
steps:
7274
- name: Checkout repo
73-
uses: actions/checkout@v1
75+
uses: actions/checkout@v2
7476
7577
- name: Set up Node.js
7678
uses: actions/setup-node@v1
@@ -95,6 +97,38 @@ jobs:
9597
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9698
```
9799

100+
If you need to run the action on a repository that is not located in [`$GITHUB_WORKSPACE`](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/using-environment-variables#default-environment-variables), you can use the `cwd` option: the action uses a `cd` normal command, so the path should follow bash standards.
101+
102+
```yaml
103+
name: Use a different repository directory
104+
on: push
105+
106+
jobs:
107+
run:
108+
name: Add a text file
109+
runs-on: ubuntu-latest
110+
111+
steps:
112+
# If you need to, you can checkout your repo to a different location
113+
- uses: actions/checkout@v2
114+
with:
115+
path: "./pathToRepo/"
116+
117+
# You can make whatever type of change to the repo...
118+
- run: echo "123" > ./pathToRepo/file.txt
119+
120+
# ...and then use the action as you would normally do, but providing the path to the repo
121+
- uses: EndBug/add-and-commit@v2
122+
with:
123+
message: "Add the very useful text file"
124+
path: "."
125+
pattern: "*.txt"
126+
cwd: "./pathToRepo/"
127+
force: true
128+
env:
129+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
130+
```
131+
98132
## License
99133

100134
This action is distributed under the MIT license, check the [license](LICENSE) for more info.

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ inputs:
88
author_email:
99
description: The email of the user that will be displayed as the author of the commit
1010
required: false
11+
cwd:
12+
description: The directory where your repository is located. You should use actions/checkout first to set it up
13+
required: false
14+
default: "."
1115
force:
1216
description: Whether to use the force option on git add, in order to bypass eventual gitignores
1317
required: false

src/entrypoint.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#!/bin/bash
22
set -eu
33

4+
cd $INPUT_CWD
5+
echo "Running in $PWD."
6+
47
# Set up .netrc file with GitHub credentials
58
git_setup() {
69
cat <<- EOF > $HOME/.netrc

0 commit comments

Comments
 (0)