Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3f7ee98226 | ||
|
|
7a1f5ecb56 | ||
|
|
6d22917a33 | ||
|
|
cf96c454b6 | ||
|
|
98ce691ee3 | ||
|
|
abd5c01a4d | ||
|
|
f97486922d | ||
|
|
a34577c63e |
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
.idea
|
||||
*.iml
|
||||
@@ -9,6 +9,8 @@ LABEL "repository"="https://github.com/EndBug/add-and-commit"
|
||||
LABEL "homepage"="https://github.com/EndBug/add-and-commit"
|
||||
LABEL "maintainer"="Federico Grandi <fgrandi30@gmail.com>"
|
||||
|
||||
RUN apk add jq
|
||||
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
|
||||
ENTRYPOINT ["sh", "/entrypoint.sh"]
|
||||
|
||||
27
README.md
27
README.md
@@ -11,13 +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@v2.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: "."
|
||||
pattern: "*.js"
|
||||
force: false
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Leave this line unchanged
|
||||
```
|
||||
@@ -29,12 +30,32 @@ Add a step like this to your workflow:
|
||||
- `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:
|
||||
|
||||
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:
|
||||
@@ -63,7 +84,7 @@ jobs:
|
||||
run: eslint "src/**" --fix
|
||||
|
||||
- name: Commit changes
|
||||
uses: EndBug/add-and-commit@v2.0.0
|
||||
uses: EndBug/add-and-commit@v2.1.1
|
||||
with:
|
||||
author_name: Your Name
|
||||
author_email: mail@example.com
|
||||
@@ -76,4 +97,4 @@ jobs:
|
||||
|
||||
## 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.
|
||||
|
||||
14
action.yml
14
action.yml
@@ -3,13 +3,15 @@ description: 'Add & commit files from a path directly from GitHub Actions'
|
||||
|
||||
inputs:
|
||||
author_name:
|
||||
description: 'The name of the user that will be displayed as the author of the commit'
|
||||
required: true
|
||||
default: 'Add & Commit GitHub Action'
|
||||
description: 'The name of the user that will be displayed as the author of the commit, defaults to author name of head commit'
|
||||
required: false
|
||||
author_email:
|
||||
description: 'The email of the user that will be displayed as the author of the commit'
|
||||
required: true
|
||||
default: 'actions@github.com'
|
||||
description: 'The email of the user that will be displayed as the author of the commit, defaults to author email of head commit'
|
||||
required: false
|
||||
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
|
||||
|
||||
@@ -1,6 +1,18 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
if [ -z "$INPUT_AUTHOR_NAME" ] # Check if the variable is empty
|
||||
then AUTHOR_NAME=$(cat "$GITHUB_EVENT_PATH" | jq '.head_commit.author.name' | sed 's/"//g') # If so, fetch the author from the event
|
||||
else AUTHOR_NAME=$INPUT_AUTHOR_NAME # If not, use that value
|
||||
fi
|
||||
|
||||
if [ -z "$INPUT_AUTHOR_EMAIL" ]
|
||||
then AUTHOR_EMAIL=$(cat "$GITHUB_EVENT_PATH" | jq '.head_commit.author.email' | sed 's/"//g')
|
||||
else AUTHOR_EMAIL=$INPUT_AUTHOR_EMAIL
|
||||
fi
|
||||
|
||||
echo "Using '$AUTHOR_NAME' and '$AUTHOR_EMAIL' as author information."
|
||||
|
||||
# Set up .netrc file with GitHub credentials
|
||||
git_setup() {
|
||||
cat <<- EOF > $HOME/.netrc
|
||||
@@ -14,12 +26,15 @@ git_setup() {
|
||||
EOF
|
||||
chmod 600 $HOME/.netrc
|
||||
|
||||
git config --global user.email "actions@github.com"
|
||||
git config --global user.name "Add & Commit GitHub Action"
|
||||
git config --global user.email "$AUTHOR_EMAIL"
|
||||
git config --global user.name "$AUTHOR_NAME"
|
||||
}
|
||||
|
||||
add() {
|
||||
find $INPUT_PATH -name "$INPUT_PATTERN" | while read x; do git add $x; done
|
||||
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
|
||||
@@ -34,16 +49,22 @@ 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..."
|
||||
add
|
||||
|
||||
echo "Creating commit..."
|
||||
git commit -m "$INPUT_MESSAGE" --author="$INPUT_AUTHOR_NAME <$INPUT_AUTHOR_EMAIL>"
|
||||
git commit -m "$INPUT_MESSAGE" --author="$AUTHOR_NAME <$AUTHOR_EMAIL>"
|
||||
|
||||
echo "Pushing to repo..."
|
||||
git push --set-upstream origin "${GITHUB_REF:11}"
|
||||
|
||||
Reference in New Issue
Block a user