|
| 1 | +# Add & Commit |
| 2 | + |
| 3 | +You can use this GitHub Action to commit changes made in your workflow run directly to your repo: for example, you use it to lint your code, update documentation, commit updated builds and so on... |
| 4 | + |
| 5 | +This is **heavily** inspired by [git-auto-commit-action](https://github.com/stefanzweifel/git-auto-commit-action) (by [Stefan Zweifel](https://github.com/stefanzweifel)): that action automatically detects changed files and commits them. While this is useful for most situations, this doesn't commit untracked files and can sometimes commit unintended changes (such as `package-lock.json` or similar, that may have happened during previous steps). |
| 6 | +This action lets you choose the path that you want to use when adding & committing changes, so that it works as you would normally do using `git` on your machine. |
| 7 | + |
| 8 | +## Usage |
| 9 | + |
| 10 | +Add a step like this to your workflow: |
| 11 | + |
| 12 | +```yaml |
| 13 | +- name: Commit changes # This is the step name that will be displayed in your runs |
| 14 | + uses: EndBug/[email protected] # You can change this to use a specific version |
| 15 | + with: # See more info about inputs below |
| 16 | + author_name: Your Name |
| 17 | + |
| 18 | + message: "Your commit message" |
| 19 | + path: ./*.js |
| 20 | + env: |
| 21 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Leave this line unchanged |
| 22 | +``` |
| 23 | +
|
| 24 | +### Inputs: |
| 25 | +
|
| 26 | +- `author_name` : the name of the user that will be displayed as the author of the commit |
| 27 | +- `author_email` : the email of the user that will be displayed as the author of the commit |
| 28 | +- `message` : the message for the commit |
| 29 | +- `path` : the path to stage files from |
| 30 | + |
| 31 | +### Environment variables: |
| 32 | + |
| 33 | +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). |
| 34 | +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. |
| 35 | + |
| 36 | +### Example: |
| 37 | + |
| 38 | +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: |
| 39 | + |
| 40 | +```yaml |
| 41 | +name: Lint source code |
| 42 | +on: push |
| 43 | +
|
| 44 | +jobs: |
| 45 | + run: |
| 46 | + name: Lint with ESLint |
| 47 | + runs-on: ubuntu-latest |
| 48 | + steps: |
| 49 | + - name: Checkout repo |
| 50 | + uses: actions/checkout@master |
| 51 | +
|
| 52 | + - name: Set up Node.js |
| 53 | + uses: actions/setup-node@master |
| 54 | + with: |
| 55 | + node-version: 10.0.0 |
| 56 | + |
| 57 | + - name: Install dependencies |
| 58 | + run: npm install |
| 59 | +
|
| 60 | + - name: Update source code |
| 61 | + run: eslint "src/**" --fix |
| 62 | +
|
| 63 | + - name: Commit changes |
| 64 | + |
| 65 | + with: |
| 66 | + author_name: Your Name |
| 67 | + |
| 68 | + message: "Your commit message" |
| 69 | + path: ./*.js |
| 70 | + env: |
| 71 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 72 | +``` |
| 73 | + |
| 74 | +## License |
| 75 | + |
| 76 | +This action is distributed under the MIT license, check the [license](LICENSE) for more info. |
0 commit comments