Skip to content

Commit de8a121

Browse files
authored
* Add remove option * [auto] Update compiled version * Add fixes * [auto] Update compiled version * Update docs
1 parent a2b4938 commit de8a121

File tree

5 files changed

+27
-23
lines changed

5 files changed

+27
-23
lines changed

README.md

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ Add a step like this to your workflow:
2424
# Default: '.'
2525
cwd: './path/to/the/repo'
2626

27+
# Whether to use the --force option on git add, in order to bypass eventual gitignores
28+
# Default: false
29+
force: true
30+
2731
# The message for the commit
2832
# Default: 'Commit from GitHub Actions'
2933
message: 'Your commit message'
@@ -36,9 +40,10 @@ Add a step like this to your workflow:
3640
# Default: '*.*'
3741
pattern: "*.js"
3842

39-
# Whether to use the --force option on git add, in order to bypass eventual gitignores
40-
# Default: false
41-
force: true
43+
# The files to remove
44+
# Default: ''
45+
remove: "./dir/old_file.js"
46+
4247
env:
4348
# This is necessary in order to push a commit to the repo
4449
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Leave this line unchanged
@@ -51,22 +56,7 @@ With that said, you can just copy the example line and don't worry about it. If
5156

5257
### Deleting files:
5358

54-
This action only **adds** files so in order to commit a file deletion you need to stage that separately: for that, you can run `git rm` in a previous step. Here's a quick example:
55-
56-
```yaml
57-
- run: git rm delete_me.txt
58-
59-
- uses: EndBug/add-and-commit@v2
60-
with:
61-
author_name: Your Name
62-
author_email: mail@example.com
63-
message: "Remove file"
64-
path: "."
65-
pattern: "*.js" # The path is not important, the file will get removed anyway: that means you can still use the action as usual
66-
force: true
67-
env:
68-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
69-
```
59+
You can delete files with the `remove` option: that runs a `git remove` command that will stage the files in the given path for removal. Please keep in mind that if the path is wrong the action will stop.
7060

7161
### Examples:
7262

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ inputs:
2828
description: The pattern that mathces file names
2929
required: false
3030
default: "*.*"
31+
remove:
32+
description: The files to remove
33+
required: false
34+
default: ""
3135

3236
runs:
3337
using: node12

lib/main.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/entrypoint.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,18 @@ EOF
2121
}
2222

2323
add() {
24-
if $INPUT_FORCE; then f=-f; fi
24+
if $INPUT_FORCE; then f=-f; else f=; fi
2525
find $INPUT_PATH -name "$INPUT_PATTERN" | while read x; do git add $f $x; done
2626
}
2727

28+
remove() {
29+
if [ -n "$INPUT_REMOVE" ]; then git rm $INPUT_REMOVE; fi
30+
}
31+
2832
# This is needed to make the check work for untracked files
29-
echo "Staging files in commit path..."
33+
echo "Staging files..."
3034
add
35+
remove
3136

3237
echo "Checking for uncommitted changes in the git working tree..."
3338
# This section only runs if there have been file changes
@@ -49,9 +54,15 @@ if ! git diff --cached --exit-code; then
4954
echo "Pulling from remote..."
5055
git fetch && git pull
5156

57+
echo "Resetting files..."
58+
git reset
59+
5260
echo "Adding files..."
5361
add
5462

63+
echo "Removing files..."
64+
remove
65+
5566
echo "Creating commit..."
5667
git commit -m "$INPUT_MESSAGE" --author="$INPUT_AUTHOR_NAME <$INPUT_AUTHOR_EMAIL>"
5768

src/main.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ function checkInputs() {
2121
setDefault('author_email', 'actions@github.com')
2222
}
2323
core.info(`Using '${core.getInput('author_name')} <${core.getInput('author_email')}>' as author.`)
24-
core.info(`Using '${process.env.INPUT_AUTHOR_NAME} <${process.env.INPUT_AUTHOR_EMAIL}>' as author.`)
2524
}
2625

2726
function setDefault(input: string, value: string) {

0 commit comments

Comments
 (0)