Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9a6336d889 | ||
|
|
de8a121ebd | ||
|
|
a2b49385e8 | ||
|
|
ea7cddff4f | ||
|
|
9acdb7d7f4 | ||
|
|
6d08b4f153 | ||
|
|
925751a406 |
2
.github/workflows/versioning.yml
vendored
2
.github/workflows/versioning.yml
vendored
@@ -2,7 +2,7 @@ name: Keep the versions up-to-date
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
release:
|
release:
|
||||||
types: [published]
|
types: [published, edited]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
actions-tagger:
|
actions-tagger:
|
||||||
|
|||||||
66
README.md
66
README.md
@@ -10,30 +10,45 @@ This action lets you choose the path that you want to use when adding & committi
|
|||||||
Add a step like this to your workflow:
|
Add a step like this to your workflow:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: Commit changes # This is the step name that will be displayed in your runs
|
- uses: EndBug/add-and-commit@v2 # You can change this to use a specific version
|
||||||
uses: EndBug/add-and-commit@v2 # You can change this to use a specific version
|
with:
|
||||||
with: # See more info about inputs below
|
# The name of the user that will be displayed as the author of the commit
|
||||||
|
# Default: author of the commit that triggered the run
|
||||||
author_name: Your Name
|
author_name: Your Name
|
||||||
|
|
||||||
|
# The The email of the user that will be displayed as the author of the commit
|
||||||
|
# Default: author of the commit that triggered the run
|
||||||
author_email: mail@example.com
|
author_email: mail@example.com
|
||||||
cwd: "."
|
|
||||||
message: "Your commit message"
|
# The local path to the directory where your repository is located. You should use actions/checkout first to set it up
|
||||||
path: "."
|
# 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'
|
||||||
|
|
||||||
|
# The path to stage files from
|
||||||
|
# Default: '.'
|
||||||
|
path: 'src'
|
||||||
|
|
||||||
|
# The pattern that mathces file names
|
||||||
|
# Default: '*.*'
|
||||||
pattern: "*.js"
|
pattern: "*.js"
|
||||||
force: false
|
|
||||||
|
# The files to remove
|
||||||
|
# Default: ''
|
||||||
|
remove: "./dir/old_file.js"
|
||||||
|
|
||||||
env:
|
env:
|
||||||
|
# This is necessary in order to push a commit to the repo
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Leave this line unchanged
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Leave this line unchanged
|
||||||
```
|
```
|
||||||
|
|
||||||
### Inputs:
|
|
||||||
|
|
||||||
- `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
|
|
||||||
- `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
|
|
||||||
- `cwd` : the working directory in which your repository is located, defaults to `.`
|
|
||||||
- `message` : the message for the commit
|
|
||||||
- `path` : the path(s) to stage files from
|
|
||||||
- `pattern` : the pattern that matches file names
|
|
||||||
- `force` : whether to use the force option on git add, in order to bypass eventual gitignores
|
|
||||||
|
|
||||||
### Environment variables:
|
### Environment variables:
|
||||||
|
|
||||||
The only `env` variable required is the token for the action to run: GitHub generates one automatically, but you need to pass it through `env` to make it available to actions. You can find more about `GITHUB_TOKEN` [here](https://help.github.com/en/articles/virtual-environments-for-github-actions#github_token-secret).
|
The only `env` variable required is the token for the action to run: GitHub generates one automatically, but you need to pass it through `env` to make it available to actions. You can find more about `GITHUB_TOKEN` [here](https://help.github.com/en/articles/virtual-environments-for-github-actions#github_token-secret).
|
||||||
@@ -41,22 +56,7 @@ With that said, you can just copy the example line and don't worry about it. If
|
|||||||
|
|
||||||
### Deleting files:
|
### 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:
|
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.
|
||||||
|
|
||||||
```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 }}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Examples:
|
### Examples:
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,10 @@ inputs:
|
|||||||
description: The pattern that mathces file names
|
description: The pattern that mathces file names
|
||||||
required: false
|
required: false
|
||||||
default: "*.*"
|
default: "*.*"
|
||||||
|
remove:
|
||||||
|
description: The files to remove
|
||||||
|
required: false
|
||||||
|
default: ""
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: node12
|
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;process.env.INPUT_AUTHOR_NAME||(process.env.INPUT_AUTHOR_NAME=b.name),process.env.INPUT_AUTHOR_EMAIL||(process.env.INPUT_AUTHOR_EMAIL=b.email)}else core.warning("No event path available, unable to fetch author info."),process.env.INPUT_AUTHOR_NAME||(process.env.INPUT_AUTHOR_NAME="Add & Commit Action"),process.env.INPUT_AUTHOR_EMAIL||(process.env.INPUT_AUTHOR_EMAIL="actions@github.com");core.info(`Using '${process.env.INPUT_AUTHOR_NAME} <${process.env.INPUT_AUTHOR_EMAIL}>' as author.`)}
|
"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)}
|
||||||
@@ -6,7 +6,7 @@ echo "Running in $PWD."
|
|||||||
|
|
||||||
# Set up .netrc file with GitHub credentials
|
# Set up .netrc file with GitHub credentials
|
||||||
git_setup() {
|
git_setup() {
|
||||||
cat <<- EOF > $HOME/.netrc
|
cat <<-EOF >$HOME/.netrc
|
||||||
machine github.com
|
machine github.com
|
||||||
login $GITHUB_ACTOR
|
login $GITHUB_ACTOR
|
||||||
password $GITHUB_TOKEN
|
password $GITHUB_TOKEN
|
||||||
@@ -16,33 +16,33 @@ git_setup() {
|
|||||||
password $GITHUB_TOKEN
|
password $GITHUB_TOKEN
|
||||||
EOF
|
EOF
|
||||||
chmod 600 $HOME/.netrc
|
chmod 600 $HOME/.netrc
|
||||||
|
|
||||||
git config --global user.email "$INPUT_AUTHOR_EMAIL"
|
git config --global user.email "$INPUT_AUTHOR_EMAIL"
|
||||||
git config --global user.name "$INPUT_AUTHOR_NAME"
|
git config --global user.name "$INPUT_AUTHOR_NAME"
|
||||||
}
|
}
|
||||||
|
|
||||||
add() {
|
add() {
|
||||||
if $INPUT_FORCE
|
if $INPUT_FORCE; then f=-f; else f=; fi
|
||||||
then find $INPUT_PATH -name "$INPUT_PATTERN" | while read x; do git add -f $x; done
|
find $INPUT_PATH -name "$INPUT_PATTERN" | while read x; do git add $f $x; done
|
||||||
else find $INPUT_PATH -name "$INPUT_PATTERN" | while read x; do git add $x; done
|
}
|
||||||
fi
|
|
||||||
|
remove() {
|
||||||
|
if [ -n "$INPUT_REMOVE" ]; then git rm $INPUT_REMOVE; fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# This is needed to make the check work for untracked files
|
# This is needed to make the check work for untracked files
|
||||||
echo "Staging files in commit path..."
|
echo "Staging files..."
|
||||||
add
|
add
|
||||||
|
remove
|
||||||
|
|
||||||
echo "Checking for uncommitted changes in the git working tree..."
|
echo "Checking for uncommitted changes in the git working tree..."
|
||||||
# This section only runs if there have been file changes
|
# This section only runs if there have been file changes
|
||||||
if ! git diff --cached --exit-code
|
if ! git diff --cached --exit-code; then
|
||||||
then
|
|
||||||
git_setup
|
git_setup
|
||||||
|
|
||||||
git fetch
|
git fetch
|
||||||
|
|
||||||
# Verify if the branch needs to be created
|
# Verify if the branch needs to be created
|
||||||
if ! git rev-parse --verify --quiet "${GITHUB_REF:11}"
|
if ! git rev-parse --verify --quiet "${GITHUB_REF:11}"; then
|
||||||
then
|
|
||||||
echo "Creating branch..."
|
echo "Creating branch..."
|
||||||
git branch "${GITHUB_REF:11}"
|
git branch "${GITHUB_REF:11}"
|
||||||
fi
|
fi
|
||||||
@@ -54,9 +54,15 @@ then
|
|||||||
echo "Pulling from remote..."
|
echo "Pulling from remote..."
|
||||||
git fetch && git pull
|
git fetch && git pull
|
||||||
|
|
||||||
|
echo "Resetting files..."
|
||||||
|
git reset
|
||||||
|
|
||||||
echo "Adding files..."
|
echo "Adding files..."
|
||||||
add
|
add
|
||||||
|
|
||||||
|
echo "Removing files..."
|
||||||
|
remove
|
||||||
|
|
||||||
echo "Creating commit..."
|
echo "Creating commit..."
|
||||||
git commit -m "$INPUT_MESSAGE" --author="$INPUT_AUTHOR_NAME <$INPUT_AUTHOR_EMAIL>"
|
git commit -m "$INPUT_MESSAGE" --author="$INPUT_AUTHOR_NAME <$INPUT_AUTHOR_EMAIL>"
|
||||||
|
|
||||||
|
|||||||
15
src/main.ts
15
src/main.ts
@@ -13,12 +13,17 @@ function checkInputs() {
|
|||||||
const eventPath = process.env.GITHUB_EVENT_PATH
|
const eventPath = process.env.GITHUB_EVENT_PATH
|
||||||
if (eventPath) {
|
if (eventPath) {
|
||||||
const { author } = require(eventPath).head_commit
|
const { author } = require(eventPath).head_commit
|
||||||
if (!process.env.INPUT_AUTHOR_NAME) process.env.INPUT_AUTHOR_NAME = author.name
|
setDefault('author_name', author.name)
|
||||||
if (!process.env.INPUT_AUTHOR_EMAIL) process.env.INPUT_AUTHOR_EMAIL = author.email
|
setDefault('author_email', author.email)
|
||||||
} else {
|
} else {
|
||||||
core.warning('No event path available, unable to fetch author info.')
|
core.warning('No event path available, unable to fetch author info.')
|
||||||
if (!process.env.INPUT_AUTHOR_NAME) process.env.INPUT_AUTHOR_NAME = 'Add & Commit Action'
|
setDefault('author_name', 'Add & Commit Action')
|
||||||
if (!process.env.INPUT_AUTHOR_EMAIL) process.env.INPUT_AUTHOR_EMAIL = 'actions@github.com'
|
setDefault('author_email', 'actions@github.com')
|
||||||
}
|
}
|
||||||
core.info(`Using '${process.env.INPUT_AUTHOR_NAME} <${process.env.INPUT_AUTHOR_EMAIL}>' as author.`)
|
core.info(`Using '${core.getInput('author_name')} <${core.getInput('author_email')}>' as author.`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setDefault(input: string, value: string) {
|
||||||
|
const key = 'INPUT_' + input.toUpperCase()
|
||||||
|
if (!process.env[key]) process.env[key] = value
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user