Compare commits

...

15 Commits

Author SHA1 Message Date
Federico Grandi
7a1f5ecb56 Fix version in docs 2019-12-07 20:53:12 +01:00
Federico Grandi
6d22917a33 Bump version in docs 2019-12-07 20:52:18 +01:00
Federico Grandi
cf96c454b6 Fix branch conflicts (#7)
* Add branch check

* Improve docs
2019-12-07 20:50:05 +01:00
Federico Grandi
98ce691ee3 Merge pull request #3 from EndBug/force
Add force option
2019-09-19 22:21:27 +02:00
Federico Grandi
abd5c01a4d Switch version in docs 2019-09-19 22:21:08 +02:00
Federico Grandi
f97486922d Fix if/else 2019-09-19 22:15:41 +02:00
Federico Grandi
a34577c63e Add force option 2019-09-19 22:09:51 +02:00
Federico Grandi
04cd48bddf Force quotes 2019-09-18 23:06:22 +02:00
Federico Grandi
2de99109b2 Merge pull request #2 from EndBug/better-paths
Add patterns
2019-09-18 23:01:21 +02:00
Federico Grandi
7f082ab428 Add patterns 2019-09-18 23:00:21 +02:00
Federico Grandi
782b6b1816 Merge pull request #1 from EndBug/better-paths
Better paths
2019-09-18 22:51:32 +02:00
Federico Grandi
6a097ea13d Little tweak to README 2019-09-18 22:50:09 +02:00
Federico Grandi
bac719afe5 Use quotes 2019-09-18 22:34:38 +02:00
Federico Grandi
58ecc16393 Allow multiple paths 2019-09-18 22:30:30 +02:00
Federico Grandi
0f9f6c2d95 Add latest-tag to workflows 2019-09-18 19:44:33 +02:00
4 changed files with 77 additions and 14 deletions

18
.github/workflows/latest.yml vendored Normal file
View File

@@ -0,0 +1,18 @@
name: Add latest tag to new release
on:
release:
types: [published]
jobs:
run:
name: Add/update tag to new release
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@master
- name: Run latest-tag
uses: EndBug/latest-tag@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -11,12 +11,14 @@ Add a step like this to your workflow:
```yaml
- name: Commit changes # This is the step name that will be displayed in your runs
uses: EndBug/add-and-commit@v1.0.0 # You can change this to use a specific version
uses: EndBug/add-and-commit@v2.1.1 # You can change this to use a specific version
with: # See more info about inputs below
author_name: Your Name
author_email: mail@example.com
message: "Your commit message"
path: ./*.js
path: "."
pattern: "*.js"
force: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Leave this line unchanged
```
@@ -26,13 +28,34 @@ Add a step like this to your workflow:
- `author_name` : the name of the user that will be displayed as the author of the commit
- `author_email` : the email of the user that will be displayed as the author of the commit
- `message` : the message for the commit
- `path` : the path to stage files from
- `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:
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).
With that said, you can just copy the example line and don't worry about it. If you do want to use a different token you can pass that in, but I wouldn't see any possible advantage in doing so.
### 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.1.1
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 }}
```
### Example:
You want to lint your JavaScript files, located in the `src` folder, with ESLint so that fixable changes are done without your intervention. You can use a workflow like this:
@@ -61,16 +84,17 @@ jobs:
run: eslint "src/**" --fix
- name: Commit changes
uses: EndBug/add-and-commit@v1.0.0
uses: EndBug/add-and-commit@v2.1.1
with:
author_name: Your Name
author_email: mail@example.com
message: "Your commit message"
path: ./*.js
path: "."
pattern: "*.js"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
## License
This action is distributed under the MIT license, check the [license](LICENSE) for more info.
This action is distributed under the MIT license, check the [license](LICENSE) for more info.

View File

@@ -10,6 +10,10 @@ inputs:
description: 'The email of the user that will be displayed as the author of the commit'
required: true
default: 'actions@github.com'
force:
description: 'Whether to use the force option on git add, in order to bypass eventual gitignores'
required: false
default: false
message:
description: 'The message for the commit'
required: true
@@ -17,8 +21,12 @@ inputs:
path:
description: 'The path to stage files from'
required: true
default: './**/*.*'
default: '.'
pattern:
description: 'The pattern that mathces file names'
required: false
default: "*.*"
runs:
using: 'docker'
image: 'Dockerfile'

View File

@@ -2,7 +2,7 @@
set -eu
# Set up .netrc file with GitHub credentials
git_setup ( ) {
git_setup() {
cat <<- EOF > $HOME/.netrc
machine github.com
login $GITHUB_ACTOR
@@ -18,9 +18,16 @@ EOF
git config --global user.name "Add & Commit GitHub Action"
}
add() {
if $INPUT_FORCE
then 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
}
# This is needed to make the check work for untracked files
echo "Staging files in commit path..."
git add "${INPUT_PATH}"
add
echo "Checking for uncommitted changes in the git working tree..."
# This section only runs if there have been file changes
@@ -30,13 +37,19 @@ then
git fetch
# Switch to branch from current Workflow run
echo "Creating and switching branch..."
git branch "${GITHUB_REF:11}"
# Verify if the branch needs to be created
if ! git rev-parse --verify --quiet "${GITHUB_REF:11}"
then
echo "Creating branch..."
git branch "${GITHUB_REF:11}"
fi
# Switch to branch from current workflow run
echo "Switching branch..."
git checkout "${GITHUB_REF:11}"
echo "Adding files..."
git add "${INPUT_PATH}"
add
echo "Creating commit..."
git commit -m "$INPUT_MESSAGE" --author="$INPUT_AUTHOR_NAME <$INPUT_AUTHOR_EMAIL>"