|
| 1 | +# Add, commit, and push |
| 2 | + |
| 3 | +✨ Automagically `git add`, `git commit`, and `git push` |
| 4 | + |
| 5 | +<table align=center><td> |
| 6 | + |
| 7 | +```yml |
| 8 | +on: |
| 9 | + pull_request: |
| 10 | +jobs: |
| 11 | + job: |
| 12 | + permissions: |
| 13 | + contents: write |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v4 |
| 17 | + - run: npx --yes prettier --write . |
| 18 | + - uses: actions4git/add-commit-push@v1 |
| 19 | +``` |
| 20 | +
|
| 21 | +</table> |
| 22 | +
|
| 23 | +➕ Adds all files by default \ |
| 24 | +👨 Uses `github.actor` as the default author \ |
| 25 | +🤖 Uses @github-actions\[bot\] as the default committer \ |
| 26 | +🔼 Pushes changes to the current branch or tag \ |
| 27 | +🏷️ Will automatically use `--force` if it's a Git tag |
| 28 | + |
| 29 | +A convenience wrapper with sensible defaults so that you don't have to do |
| 30 | +`git add`, `git commit`, and `git push` manually all the time. 😉 |
| 31 | + |
| 32 | +## Usage |
| 33 | + |
| 34 | +**🚀 Here's what you want:** |
| 35 | + |
| 36 | +```yml |
| 37 | +on: |
| 38 | + pull_request: |
| 39 | +jobs: |
| 40 | + job: |
| 41 | + permissions: |
| 42 | + contents: write |
| 43 | + runs-on: ubuntu-latest |
| 44 | + steps: |
| 45 | + - uses: actions/checkout@v4 |
| 46 | + - run: npx --yes prettier --write . |
| 47 | + - uses: actions4git/add-commit-push@v1 |
| 48 | +``` |
| 49 | + |
| 50 | +🔒 Make sure you have the `permissions` set to `contents: write`! We need to be |
| 51 | +able to edit the repository contents to push things. |
| 52 | + |
| 53 | +<details><summary>You can also use this GitHub Action with tags/releases</summary> |
| 54 | + |
| 55 | +```yml |
| 56 | +on: |
| 57 | + release: |
| 58 | + types: released |
| 59 | +jobs: |
| 60 | + job: |
| 61 | + permissions: |
| 62 | + contents: write |
| 63 | + runs-on: ubuntu-latest |
| 64 | + steps: |
| 65 | + - uses: actions/checkout@v4 |
| 66 | + - run: echo "$TAG" > VERSION.txt |
| 67 | + env: |
| 68 | + TAG: ${{ github.event.release.tag_name }} |
| 69 | + - uses: actions4git/add-commit-push@v1 |
| 70 | +``` |
| 71 | + |
| 72 | +</details> |
| 73 | + |
| 74 | +If you're looking to have more control than the options provided below, it's |
| 75 | +best if you tap in to the `git` CLI directly. The only tricky bit is setting a |
| 76 | +default Git user (it's unset by default). You can either set it manually or use |
| 77 | +a premade action like [actions4git/setup-git] to configure the `user.name` and |
| 78 | +`user.email` settings. |
| 79 | + |
| 80 | +```yml |
| 81 | +- uses: actions/checkout@v4 |
| 82 | +
|
| 83 | +- uses: actions4git/setup-git@v1 |
| 84 | +# OR |
| 85 | +- run: | |
| 86 | + git config user.name "$GITHUB_ACTOR" |
| 87 | + git config user.email "[email protected]" |
| 88 | +# OR |
| 89 | +- run: | |
| 90 | + git config user.name 'github-actions[bot]' |
| 91 | + git config user.email '41898282+github-actions[bot]@users.noreply.github.com' |
| 92 | +
|
| 93 | +# Then you can do whatever you want! |
| 94 | +- run: git add ... |
| 95 | +- run: git rebase ... |
| 96 | +- run: git merge ... |
| 97 | +- run: git commit ... |
| 98 | +- run: git push ... |
| 99 | +``` |
| 100 | + |
| 101 | +### Inputs |
| 102 | + |
| 103 | +- **`path`:** The path to the repository root folder to perform the Git |
| 104 | + operations in. This defaults to the current working directory (`.`). Change |
| 105 | + this to a subfolder if you are using a different folder other than the default |
| 106 | + `github.workspace` for your Git repository. |
| 107 | + |
| 108 | +- **`add-pathspec`:** Additional path specifiers to be passed to `git add`. |
| 109 | + These can be files, folders, globs, or even some fancy Git pathspec things |
| 110 | + such as `:!ignoreme.txt`. Check out the CSS-Tricks [Git Pathspecs and How to |
| 111 | + Use Them] article for the highlights of Git pathspecs. If this input is not |
| 112 | + specified, `git add --all` will be used instead. Specifying `.` has slightly |
| 113 | + different behavior from `--all`. |
| 114 | + |
| 115 | +- **`add-force`:** Whether or not to use the `--force` flag when performing the |
| 116 | + `git add` operation. Use this if you really want to add something but it's in |
| 117 | + your `.gitignore`. This can be useful if you ever need to commit build |
| 118 | + artifacts to Git that are normally ignored by your `.gitignore`. Defaults to |
| 119 | + `false`. |
| 120 | + |
| 121 | +- **`commit-author`:** A `Name Here <[email protected]>` AiO author name & |
| 122 | + email string. This is a shortcut alternative to the independent |
| 123 | + `commit-author-name` and `commit-author-email` options that are also |
| 124 | + available. This defaults to the current `github.actor`. Note that this is |
| 125 | + different from the `commit-committer`. [The author of a commit is who wrote |
| 126 | + the thing, and the committer is who committed it to Git.] It's recommended to |
| 127 | + leave this as the default. |
| 128 | + |
| 129 | +- **`commit-author-name`:** The name of the author to associate with the commit. |
| 130 | + Should be left unspecified if `commit-author` is specified. |
| 131 | + |
| 132 | +- **`commit-author-email`:** The email address of the author to associate with |
| 133 | + the commit. Should be left unspecified if `commit-author` is specified. |
| 134 | + |
| 135 | +- **`commit-committer`:** A `Name Here <[email protected]>` AiO author name |
| 136 | + & email string. This input is a shortcut for the `commit-committer-name` and |
| 137 | + `commit-committer-email` inputs that can also be individually specified. This |
| 138 | + defaults to the `github-actions[bot]` user which is probably what you want. |
| 139 | + It's recommended to change the `commit-author` before changing the |
| 140 | + `commit-committer`. |
| 141 | + |
| 142 | +- **`commit-committer-name`:** The name of the committer to associate with the |
| 143 | + commit. Should be left unspecified if `commit-committer` is specified. |
| 144 | + |
| 145 | +- **`commit-committer-email`:** The email address of the committer to associate |
| 146 | + with the commit. Should be left unspecified if `commit-committer` is |
| 147 | + specified. |
| 148 | + |
| 149 | +- **`commit-message`:** The `--message` parameter to use for the commit. This |
| 150 | + can be a multiline string if you want to specify a title and body. The default |
| 151 | + is 'Automated changes'. |
| 152 | + |
| 153 | +- **`push-repository`:** The first argument to |
| 154 | + `git push [repository] [refspec]`. You can change this to another remote name |
| 155 | + like `upstream` (as long as you have push rights) or another Git remote |
| 156 | + entirely like `https://github.com/octocat/another-repo.git`. The default |
| 157 | + `origin` is probably what you want. |
| 158 | + |
| 159 | +- **`push-refspec`:** A specific branch or tag name to push to. If this is a |
| 160 | + tag, `push-force` will default to `true` unless explicitly set otherwise. |
| 161 | + Defaults to whatever the current Git `HEAD` target is. |
| 162 | + |
| 163 | +- **`push-force`:** Whether or not to use the `--force` parameter when doing the |
| 164 | + `git push`. You may need to specify this if you are rewriting history or |
| 165 | + editing a tag. Defaults to `false` if the `push-refspec` is a branch and |
| 166 | + `true` if it's a tag. |
| 167 | + |
| 168 | +### Outputs |
| 169 | + |
| 170 | +TODO! |
| 171 | + |
| 172 | +## Development |
| 173 | + |
| 174 | + |
| 175 | + |
| 176 | +**How do I test my changes?** |
| 177 | + |
| 178 | +The easiest way is to open a Draft Pull Request either against the upstream |
| 179 | +repository or against your own fork's main branch and watch the GitHub Actions |
| 180 | +do their thing. |
| 181 | + |
| 182 | +<!-- prettier-ignore-start --> |
| 183 | +[Git Pathspecs and How to Use Them]: https://css-tricks.com/git-pathspecs-and-how-to-use-them/ |
| 184 | +[The author of a commit is who wrote the thing, and the committer is who committed it to Git.]: https://stackoverflow.com/questions/18750808/difference-between-author-and-committer-in-git |
| 185 | +<!-- prettier-ignore-end --> |
0 commit comments