mirror of
https://github.com/stefanzweifel/git-auto-commit-action.git
synced 2025-07-31 15:26:10 +08:00
Compare commits
85 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
f7e2c0f118 | ||
|
8db04fa14f | ||
|
44a415d3cb | ||
|
af9e1689a5 | ||
|
2b22ba6212 | ||
|
b1b8ae8b5c | ||
|
fb3de05451 | ||
|
284d0b78f0 | ||
|
188fc2bd58 | ||
|
65d8bdf167 | ||
|
40255153c4 | ||
|
0ef5bf58dc | ||
|
e924b16154 | ||
|
2fb839c669 | ||
|
908446c002 | ||
|
2d23a29775 | ||
|
bdc88aff2c | ||
|
ddcd35eaa8 | ||
|
760c9be2dc | ||
|
69d0349561 | ||
|
eecee2898e | ||
|
3889fd6a6c | ||
|
1ad5315ba7 | ||
|
fa043bd474 | ||
|
af33cfbb5c | ||
|
677efa2969 | ||
|
b6dcf94303 | ||
|
a65a3a47cd | ||
|
a607c57aa4 | ||
|
134234c02d | ||
|
73ba09a90c | ||
|
92d05a9fc5 | ||
|
25c0d721b7 | ||
|
d6493da30b | ||
|
5de23163f2 | ||
|
16f4dc5956 | ||
|
03de600c97 | ||
|
40956d2dbd | ||
|
9fc8aa621f | ||
|
81c04ebd3c | ||
|
ef21fa22a3 | ||
|
e29ffba3a7 | ||
|
c1a88fc967 | ||
|
12d8aff89d | ||
|
62474225c7 | ||
|
b60aaac666 | ||
|
3ffeab2fe0 | ||
|
5adbb8cb3e | ||
|
97f9868da0 | ||
|
8a0c95d76c | ||
|
4c6d2819f0 | ||
|
7fec5eda4a | ||
|
6c17ba31a9 | ||
|
6f1c9227f5 | ||
|
72e2d4cb1e | ||
|
8cc484cbc5 | ||
|
ed0ebb9072 | ||
|
0b91625aed | ||
|
ba1c2a6047 | ||
|
12282205b7 | ||
|
ef8610f6df | ||
|
f4fd59c4d4 | ||
|
ea88bd7cde | ||
|
80f825a9bc | ||
|
845dc426e7 | ||
|
fcfae8cf7e | ||
|
ef125417f8 | ||
|
709206b68e | ||
|
c37291d29c | ||
|
fc34a4d3a2 | ||
|
e14499263c | ||
|
11769ba87f | ||
|
0364ecfe57 | ||
|
8d47eb33c5 | ||
|
49fa6b4e7a | ||
|
ef070dad05 | ||
|
fbe300afdf | ||
|
4b2201fcd1 | ||
|
a93a9a308d | ||
|
fdf062fc1c | ||
|
6280a31960 | ||
|
1dd709d949 | ||
|
8620a4b744 | ||
|
6057956931 | ||
|
3fe53a7d31 |
30
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
30
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Version of the Action**
|
||||
`v2.x.x`
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
36
CHANGELOG.md
36
CHANGELOG.md
@@ -4,7 +4,41 @@ All notable changes to this project will be documented in this file.
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased](https://github.com/stefanzweifel/git-auto-commit-action/compare/v1.0.0...HEAD)
|
||||
## [Unreleased](https://github.com/stefanzweifel/git-auto-commit-action/compare/v2.4.0...HEAD)
|
||||
|
||||
## [v2.4.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v2.3.0...v2.4.0) - 2019-11-30
|
||||
|
||||
### Added
|
||||
- Commit untracked files [#19](https://github.com/stefanzweifel/git-auto-commit-action/pull/19) (fixes [#16](https://github.com/stefanzweifel/git-auto-commit-action/issues/16))
|
||||
- Add support for Git-LFS [#21](https://github.com/stefanzweifel/git-auto-commit-action/pull/21) (fixes [#20](https://github.com/stefanzweifel/git-auto-commit-action/issues/20))
|
||||
|
||||
## [v2.3.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v2.2.0...v2.3.0) - 2019-11-04
|
||||
|
||||
### Added
|
||||
- Add a new `commit_option`-argument. Allows users to define additional commit options for the `git-commit` command. [#14](https://github.com/stefanzweifel/git-auto-commit-action/pull/15)
|
||||
|
||||
## [v2.2.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v2.1.0...v2.2.0) - 2019-10-26
|
||||
|
||||
### Added
|
||||
- Add new `file_pattern`-argument. Allows users to define which files should be added in the commit. [#13](https://github.com/stefanzweifel/git-auto-commit-action/pull/13)
|
||||
|
||||
## [v2.1.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v2.0.0...v2.1.0) - 2019-09-20
|
||||
|
||||
### Added
|
||||
- Add `branch`-argument to determine, to which branch changes should be pushed. See README for usage details.
|
||||
|
||||
### Fixed
|
||||
- Fixes Issue where changes couldn't be pushed to GitHub due to wrong ref-name.
|
||||
|
||||
### Removed
|
||||
- Remove `commit_author_email` and `commit_author_name` arguments. The `$GITHUB_ACTOR` is now used as the Git Author
|
||||
|
||||
|
||||
## [v2.0.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v1.0.0...v2.0.0) - 2019-08-31
|
||||
|
||||
### Changed
|
||||
- Make Action Compatible with latest beta of GitHub Actions [#3](https://github.com/stefanzweifel/git-auto-commit-action/pull/3)
|
||||
|
||||
|
||||
## v1.0.0 - 2019-06-10
|
||||
|
||||
|
76
CODE_OF_CONDUCT.md
Normal file
76
CODE_OF_CONDUCT.md
Normal file
@@ -0,0 +1,76 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as
|
||||
contributors and maintainers pledge to making participation in our project and
|
||||
our community a harassment-free experience for everyone, regardless of age, body
|
||||
size, disability, ethnicity, sex characteristics, gender identity and expression,
|
||||
level of experience, education, socio-economic status, nationality, personal
|
||||
appearance, race, religion, or sexual identity and orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment
|
||||
include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or
|
||||
advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic
|
||||
address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable
|
||||
behavior and are expected to take appropriate and fair corrective action in
|
||||
response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or
|
||||
reject comments, commits, code, wiki edits, issues, and other contributions
|
||||
that are not aligned to this Code of Conduct, or to ban temporarily or
|
||||
permanently any contributor for other behaviors that they deem inappropriate,
|
||||
threatening, offensive, or harmful.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces
|
||||
when an individual is representing the project or its community. Examples of
|
||||
representing a project or community include using an official project e-mail
|
||||
address, posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event. Representation of a project may be
|
||||
further defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported by contacting the project team at hello@stefanzweifel.io. All
|
||||
complaints will be reviewed and investigated and will result in a response that
|
||||
is deemed necessary and appropriate to the circumstances. The project team is
|
||||
obligated to maintain confidentiality with regard to the reporter of an incident.
|
||||
Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good
|
||||
faith may face temporary or permanent repercussions as determined by other
|
||||
members of the project's leadership.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
||||
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
||||
|
||||
[homepage]: https://www.contributor-covenant.org
|
||||
|
||||
For answers to common questions about this code of conduct, see
|
||||
https://www.contributor-covenant.org/faq
|
@@ -1,7 +1,7 @@
|
||||
FROM alpine/git:1.0.7
|
||||
|
||||
LABEL "com.github.actions.name"="Auto Commit changed files"
|
||||
LABEL "com.github.actions.description"="Auotmatically commit changed files and push changes back to remote repository."
|
||||
LABEL "com.github.actions.description"="Automatically commits files which have been changed during the workflow run and push changes back to remote repository."
|
||||
LABEL "com.github.actions.icon"="git-commit"
|
||||
LABEL "com.github.actions.color"="orange"
|
||||
|
||||
@@ -9,6 +9,8 @@ LABEL "repository"="http://github.com/stefanzweifel/git-auto-commit-action"
|
||||
LABEL "homepage"="http://github.com/stefanzweifel/git-auto-commit-action"
|
||||
LABEL "maintainer"="Stefan Zweifel <hello@stefanzweifel.io>"
|
||||
|
||||
RUN apk add git-lfs
|
||||
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
|
||||
ENTRYPOINT ["sh", "/entrypoint.sh"]
|
||||
|
92
README.md
92
README.md
@@ -1,56 +1,80 @@
|
||||
# git-auto-commit-action
|
||||
|
||||
This GitHub Action automatically commits files which have been changed during a Workflow run and pushes the Commit back to GitHub.
|
||||
The Committer is "GitHub Actions <actions@github.com>" and the Author of the Commit can be configured with environment variables.
|
||||
The Committer is "GitHub Actions <actions@github.com>" and the Author of the Commit is "Your GitHub Username <github_username@users.noreply.github.com>.
|
||||
|
||||
If no changes are available, the Actions does nothing.
|
||||
|
||||
This Action has been inspired and adapted from the [auto-commit](https://github.com/cds-snc/github-actions/tree/master/auto-commit
|
||||
)-Action of the Canadian Digital Service.
|
||||
)-Action of the Canadian Digital Service and the [commit](https://github.com/elstudio/actions-js-build/blob/41d604d6e73d632e22eac40df8cc69b5added04b/commit/entrypoint.sh)-Action by Eric Johnson.
|
||||
|
||||
## Usage
|
||||
|
||||
You have to have an Action in your Workflow, which changes some of your project files.
|
||||
Add the following step at the end of your job.
|
||||
|
||||
```yaml
|
||||
- uses: stefanzweifel/git-auto-commit-action@v2.3.0
|
||||
with:
|
||||
commit_message: Apply automatic changes
|
||||
branch: ${{ github.head_ref }}
|
||||
|
||||
# Optional git params
|
||||
commit_options: '--no-verify --signoff'
|
||||
|
||||
# Optional glob pattern of files which should be added to the commit
|
||||
file_pattern: src/\*.js
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
```
|
||||
|
||||
You **do not** have to create a new secret called `GITHUB_TOKEN` in your repository. `GITHUB_TOKEN` is a special token GitHub creates automatically during an Action run. (See [the documentation](https://help.github.com/en/articles/virtual-environments-for-github-actions#creating-and-using-secrets-encrypted-variables) for details)
|
||||
|
||||
The Action will only commit files back, if changes are available. The resulting commit **will not trigger** another GitHub Actions Workflow run!
|
||||
|
||||
It is recommended to use this Action in Workflows which listen to the `pull_request` event. If you want to use the Action on other events, you have to hardcode the value for `branch` as `github.head_ref` is only available in Pull Requests.
|
||||
|
||||
## Example Usage
|
||||
|
||||
This Action will only work, if the job in your workflow changes project files.
|
||||
The most common use case for this, is when you're running a Linter or Code-Style fixer on GitHub Actions.
|
||||
|
||||
In this example I'm running `php-cs-fixer` in a PHP project.
|
||||
|
||||
```terraform
|
||||
workflow "php-cs-fixer" {
|
||||
on = "push"
|
||||
resolves = [
|
||||
"auto-commit-php-cs-fixer"
|
||||
]
|
||||
}
|
||||
|
||||
action "php-cs-fixer" {
|
||||
uses = "docker://oskarstark/php-cs-fixer-ga"
|
||||
}
|
||||
```yaml
|
||||
name: php-cs-fixer
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
paths:
|
||||
- '**.php'
|
||||
|
||||
jobs:
|
||||
php-cs-fixer:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
with:
|
||||
fetch-depth: 1
|
||||
|
||||
- name: Run php-cs-fixer
|
||||
uses: docker://oskarstark/php-cs-fixer-ga
|
||||
|
||||
- name: Commit changed files
|
||||
uses: stefanzweifel/git-auto-commit-action@v2.3.0
|
||||
with:
|
||||
commit_message: Apply php-cs-fixer changes
|
||||
branch: ${{ github.head_ref }}
|
||||
file_pattern: src/\*.php
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
action "auto-commit-php-cs-fixer" {
|
||||
needs = ["php-cs-fixer"]
|
||||
uses = "stefanzweifel/git-auto-commit-action@v1.0.0"
|
||||
secrets = ["GITHUB_TOKEN"]
|
||||
env = {
|
||||
COMMIT_MESSAGE = "Apply php-cs-fixer changes"
|
||||
COMMIT_AUTHOR_EMAIL = "john.doe@example.com"
|
||||
COMMIT_AUTHOR_NAME = "John Doe"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Secrets
|
||||
|
||||
The `GITHUB_TOKEN` secret is required. Add the secret in the Workflow Editor on github.com.
|
||||
|
||||
## Environment variables
|
||||
|
||||
The following environment variables are required:
|
||||
|
||||
- `COMMIT_MESSAGE`: The commit message used when changes are available
|
||||
- `COMMIT_AUTHOR_EMAIL`: The Commit Authors Email Address
|
||||
- `COMMIT_AUTHOR_NAME`: The Commit Authors Name
|
||||
### Inputs
|
||||
|
||||
Checkout [`action.yml`](https://github.com/stefanzweifel/git-auto-commit-action/blob/master/action.yml) for a full list of supported inputs.
|
||||
|
||||
## Versioning
|
||||
|
||||
|
32
action.yml
Normal file
32
action.yml
Normal file
@@ -0,0 +1,32 @@
|
||||
name: Git Auto Commit
|
||||
description: 'Automatically commits files which have been changed during the workflow run and push changes back to remote repository.'
|
||||
|
||||
author: Stefan Zweifel <hello@stefanzweifel.io>
|
||||
|
||||
inputs:
|
||||
commit_message:
|
||||
description: Commit message
|
||||
required: true
|
||||
commit_options:
|
||||
description: Commit options
|
||||
required: false
|
||||
branch:
|
||||
description: Branch where changes should be pushed too
|
||||
required: true
|
||||
file_pattern:
|
||||
description: File pattern used for "git add"
|
||||
required: false
|
||||
default: '.'
|
||||
|
||||
runs:
|
||||
using: 'docker'
|
||||
image: 'Dockerfile'
|
||||
args:
|
||||
- ${{ inputs.commit_message }}
|
||||
- ${{ inputs.commit_options }}
|
||||
- ${{ inputs.branch }}
|
||||
- ${{ inputs.file_pattern }}
|
||||
|
||||
branding:
|
||||
icon: 'git-commit'
|
||||
color: orange
|
@@ -1,10 +1,44 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -eu
|
||||
|
||||
git config --global user.email "actions@github.com"
|
||||
git config --global user.name "GitHub Actions"
|
||||
# Set up .netrc file with GitHub credentials
|
||||
git_setup ( ) {
|
||||
cat <<- EOF > $HOME/.netrc
|
||||
machine github.com
|
||||
login $GITHUB_ACTOR
|
||||
password $GITHUB_TOKEN
|
||||
|
||||
git add -A
|
||||
git status
|
||||
git commit -m "$COMMIT_MESSAGE" --author="$COMMIT_AUTHOR_NAME <$COMMIT_AUTHOR_EMAIL>" || echo "No changes found. Nothing to commit."
|
||||
git push -u origin HEAD
|
||||
machine api.github.com
|
||||
login $GITHUB_ACTOR
|
||||
password $GITHUB_TOKEN
|
||||
EOF
|
||||
chmod 600 $HOME/.netrc
|
||||
|
||||
git config --global user.email "actions@github.com"
|
||||
git config --global user.name "GitHub Actions"
|
||||
}
|
||||
|
||||
# This section only runs if there have been file changes
|
||||
echo "Checking for uncommitted changes in the git working tree."
|
||||
if [[ -n "$(git status -s)" ]]
|
||||
then
|
||||
git_setup
|
||||
|
||||
echo "INPUT_BRANCH value: $INPUT_BRANCH";
|
||||
|
||||
# Switch to branch from current Workflow run
|
||||
git checkout $INPUT_BRANCH
|
||||
|
||||
echo "INPUT_FILE_PATTERN: ${INPUT_FILE_PATTERN}"
|
||||
|
||||
git add "${INPUT_FILE_PATTERN}"
|
||||
|
||||
echo "INPUT_COMMIT_OPTIONS: ${INPUT_COMMIT_OPTIONS}"
|
||||
|
||||
git commit -m "$INPUT_COMMIT_MESSAGE" --author="$GITHUB_ACTOR <$GITHUB_ACTOR@users.noreply.github.com>" ${INPUT_COMMIT_OPTIONS:+"$INPUT_COMMIT_OPTIONS"}
|
||||
|
||||
git push --set-upstream origin "HEAD:$INPUT_BRANCH"
|
||||
else
|
||||
echo "Working tree clean. Nothing to commit."
|
||||
fi
|
||||
|
Reference in New Issue
Block a user