Rm (#20)
* Add remove option * [auto] Update compiled version * Add fixes * [auto] Update compiled version * Update docs
This commit is contained in:
28
README.md
28
README.md
@@ -24,6 +24,10 @@ Add a step like this to your workflow:
|
||||
# Default: '.'
|
||||
cwd: './path/to/the/repo'
|
||||
|
||||
# Whether to use the --force option on git add, in order to bypass eventual gitignores
|
||||
# Default: false
|
||||
force: true
|
||||
|
||||
# The message for the commit
|
||||
# Default: 'Commit from GitHub Actions'
|
||||
message: 'Your commit message'
|
||||
@@ -36,9 +40,10 @@ Add a step like this to your workflow:
|
||||
# Default: '*.*'
|
||||
pattern: "*.js"
|
||||
|
||||
# Whether to use the --force option on git add, in order to bypass eventual gitignores
|
||||
# Default: false
|
||||
force: true
|
||||
# The files to remove
|
||||
# Default: ''
|
||||
remove: "./dir/old_file.js"
|
||||
|
||||
env:
|
||||
# This is necessary in order to push a commit to the repo
|
||||
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
|
||||
|
||||
### Deleting files:
|
||||
|
||||
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:
|
||||
|
||||
```yaml
|
||||
- run: git rm delete_me.txt
|
||||
|
||||
- uses: EndBug/add-and-commit@v2
|
||||
with:
|
||||
author_name: Your Name
|
||||
author_email: mail@example.com
|
||||
message: "Remove file"
|
||||
path: "."
|
||||
pattern: "*.js" # The path is not important, the file will get removed anyway: that means you can still use the action as usual
|
||||
force: true
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
```
|
||||
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.
|
||||
|
||||
### Examples:
|
||||
|
||||
|
||||
@@ -28,6 +28,10 @@ inputs:
|
||||
description: The pattern that mathces file names
|
||||
required: false
|
||||
default: "*.*"
|
||||
remove:
|
||||
description: The files to remove
|
||||
required: false
|
||||
default: ""
|
||||
|
||||
runs:
|
||||
using: node12
|
||||
|
||||
@@ -1 +1 @@
|
||||
"use strict";var __importStar=this&&this.__importStar||function(a){if(a&&a.__esModule)return a;var b={};if(null!=a)for(var c in a)Object.hasOwnProperty.call(a,c)&&(b[c]=a[c]);return b["default"]=a,b};Object.defineProperty(exports,"__esModule",{value:!0});const core=__importStar(require("@actions/core")),shell=__importStar(require("shelljs")),path=__importStar(require("path"));try{checkInputs(),shell.exec(path.join(__dirname,"../src/entrypoint.sh"))}catch(a){core.setFailed(a)}function checkInputs(){const a=process.env.GITHUB_EVENT_PATH;if(a){const{author:b}=require(a).head_commit;setDefault("author_name",b.name),setDefault("author_email",b.email)}else core.warning("No event path available, unable to fetch author info."),setDefault("author_name","Add & Commit Action"),setDefault("author_email","actions@github.com");core.info(`Using '${core.getInput("author_name")} <${core.getInput("author_email")}>' as author.`),core.info(`Using '${process.env.INPUT_AUTHOR_NAME} <${process.env.INPUT_AUTHOR_EMAIL}>' as author.`)}function setDefault(a,b){const c="INPUT_"+a.toUpperCase();process.env[c]||(process.env[c]=b)}
|
||||
"use strict";var __importStar=this&&this.__importStar||function(a){if(a&&a.__esModule)return a;var b={};if(null!=a)for(var c in a)Object.hasOwnProperty.call(a,c)&&(b[c]=a[c]);return b["default"]=a,b};Object.defineProperty(exports,"__esModule",{value:!0});const core=__importStar(require("@actions/core")),shell=__importStar(require("shelljs")),path=__importStar(require("path"));try{checkInputs(),shell.exec(path.join(__dirname,"../src/entrypoint.sh"))}catch(a){core.setFailed(a)}function checkInputs(){const a=process.env.GITHUB_EVENT_PATH;if(a){const{author:b}=require(a).head_commit;setDefault("author_name",b.name),setDefault("author_email",b.email)}else core.warning("No event path available, unable to fetch author info."),setDefault("author_name","Add & Commit Action"),setDefault("author_email","actions@github.com");core.info(`Using '${core.getInput("author_name")} <${core.getInput("author_email")}>' as author.`)}function setDefault(a,b){const c="INPUT_"+a.toUpperCase();process.env[c]||(process.env[c]=b)}
|
||||
@@ -21,13 +21,18 @@ EOF
|
||||
}
|
||||
|
||||
add() {
|
||||
if $INPUT_FORCE; then f=-f; fi
|
||||
if $INPUT_FORCE; then f=-f; else f=; fi
|
||||
find $INPUT_PATH -name "$INPUT_PATTERN" | while read x; do git add $f $x; done
|
||||
}
|
||||
|
||||
remove() {
|
||||
if [ -n "$INPUT_REMOVE" ]; then git rm $INPUT_REMOVE; fi
|
||||
}
|
||||
|
||||
# This is needed to make the check work for untracked files
|
||||
echo "Staging files in commit path..."
|
||||
echo "Staging files..."
|
||||
add
|
||||
remove
|
||||
|
||||
echo "Checking for uncommitted changes in the git working tree..."
|
||||
# This section only runs if there have been file changes
|
||||
@@ -49,9 +54,15 @@ if ! git diff --cached --exit-code; then
|
||||
echo "Pulling from remote..."
|
||||
git fetch && git pull
|
||||
|
||||
echo "Resetting files..."
|
||||
git reset
|
||||
|
||||
echo "Adding files..."
|
||||
add
|
||||
|
||||
echo "Removing files..."
|
||||
remove
|
||||
|
||||
echo "Creating commit..."
|
||||
git commit -m "$INPUT_MESSAGE" --author="$INPUT_AUTHOR_NAME <$INPUT_AUTHOR_EMAIL>"
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ function checkInputs() {
|
||||
setDefault('author_email', 'actions@github.com')
|
||||
}
|
||||
core.info(`Using '${core.getInput('author_name')} <${core.getInput('author_email')}>' as author.`)
|
||||
core.info(`Using '${process.env.INPUT_AUTHOR_NAME} <${process.env.INPUT_AUTHOR_EMAIL}>' as author.`)
|
||||
}
|
||||
|
||||
function setDefault(input: string, value: string) {
|
||||
|
||||
Reference in New Issue
Block a user