24 |
25 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/config.yml:
--------------------------------------------------------------------------------
1 | blank_issues_enabled: false
2 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/question.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Question
3 | about: Ask a question on how to use the action
4 | title: ''
5 | labels: 'type: question'
6 | assignees: ''
7 |
8 | ---
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | # To get started with Dependabot version updates, you'll need to specify which
2 | # package ecosystems to update and where the package manifests are located.
3 | # Please see the documentation for all configuration options:
4 | # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5 |
6 | version: 2
7 | updates:
8 | - package-ecosystem: 'npm' # See documentation for possible values
9 | directory: '/' # Location of package manifests
10 | schedule:
11 | interval: 'weekly'
12 | commit-message:
13 | prefix: 'chore'
14 | include: 'scope'
15 | labels:
16 | - 'type: chore'
17 | - package-ecosystem: github-actions
18 | directory: /
19 | schedule:
20 | interval: weekly
21 | open-pull-requests-limit: 10
22 | commit-message:
23 | include: scope
24 | prefix: ci
25 | labels:
26 | - 'type: chore'
27 |
--------------------------------------------------------------------------------
/.github/labels.yml:
--------------------------------------------------------------------------------
1 | - name: 'good first issue'
2 | color: '5319e7'
3 | description: 'Good for newcomers'
4 | aliases: []
5 |
6 | - name: 'help wanted'
7 | color: '008672'
8 | description: 'Extra attention is needed'
9 | aliases: []
10 |
11 | - name: 'status: pending'
12 | color: c5def5
13 | description: 'More info is needed before deciding what to do'
14 | aliases: []
15 |
16 | - name: 'status: pinned'
17 | color: 0052cc
18 | description: 'Should not be labeled as stale'
19 | aliases: []
20 |
21 | - name: 'status: stale'
22 | color: fbca04
23 | description: 'Inactive issues and PRs'
24 | aliases: ['stale']
25 |
26 | - name: 'status: wontfix'
27 | color: cfd3d7
28 | description: 'This will not be worked on'
29 | aliases: ['wontfix']
30 |
31 | - name: 'type: bug'
32 | color: d73a4a
33 | description: 'Verified problems that need to be worked on'
34 | aliases: ['bug']
35 |
36 | - name: 'type: chore'
37 | color: C5DEF5
38 | description: 'Code changes that neither fix bugs nor add features (refactoring, dependency chnages, ...)'
39 | aliases: ['dependencies', 'type: dependencies', 'automation', 'type: automation']
40 |
41 | - name: 'type: docs'
42 | color: C5DEF5
43 | description: "Documentation changes"
44 | aliases: ['documentation', 'maintenance', 'type: maintenance']
45 |
46 | - name: 'type: duplicate'
47 | color: cfd3d7
48 | description: 'This issue or pull request already exists'
49 | aliases: ['duplicate']
50 |
51 | - name: 'type: feature'
52 | color: 0E8A16
53 | description: 'New feature or feature request'
54 | aliases: ['enhancement', 'type: enhancement']
55 |
56 | - name: 'type: fix'
57 | color: 1D76DB
58 | description: 'Updates to existing functionalities'
59 | aliases: ['fix']
60 |
61 | - name: 'type: invalid'
62 | color: e4e669
63 | description: "This doesn't seem right"
64 | aliases: ['invalid']
65 |
66 | - name: 'type: not a bug'
67 | color: 0e8a16
68 | description: 'Reports that happen not be our fault'
69 | aliases: ['not a bug']
70 |
71 | - name: 'type: question'
72 | color: d876e3
73 | description: 'Further information is requested'
74 | aliases: ['question']
75 |
--------------------------------------------------------------------------------
/.github/workflows/codeql-analysis.yml:
--------------------------------------------------------------------------------
1 | # For most projects, this workflow file will not need changing; you simply need
2 | # to commit it to your repository.
3 | #
4 | # You may wish to alter this file to override the set of languages analyzed,
5 | # or to provide custom queries or build logic.
6 | #
7 | # ******** NOTE ********
8 | # We have attempted to detect the languages in your repository. Please check
9 | # the `language` matrix defined below to confirm you have the correct set of
10 | # supported CodeQL languages.
11 | #
12 | name: "CodeQL"
13 |
14 | on:
15 | push:
16 | branches: [ main ]
17 | pull_request:
18 | # The branches below must be a subset of the branches above
19 | branches: [ main ]
20 | schedule:
21 | - cron: '40 12 * * 2'
22 |
23 | jobs:
24 | analyze:
25 | name: Analyze
26 | runs-on: ubuntu-latest
27 | permissions:
28 | actions: read
29 | contents: read
30 | security-events: write
31 |
32 | steps:
33 | - name: Checkout repository
34 | uses: actions/checkout@v4
35 |
36 | # Initializes the CodeQL tools for scanning.
37 | - name: Initialize CodeQL
38 | uses: github/codeql-action/init@v3
39 | # Override language selection by uncommenting this and choosing your languages
40 | # with:
41 | # languages: go, javascript, csharp, python, cpp, java
42 |
43 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
44 | # If this step fails, then you should remove it and run the build manually (see below).
45 | - name: Autobuild
46 | uses: github/codeql-action/autobuild@v3
47 |
48 | # ℹ️ Command-line programs to run using the OS shell.
49 | # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
50 |
51 | # ✏️ If the Autobuild fails above, remove it and uncomment the following
52 | # three lines and modify them (or add more) to build your code if your
53 | # project uses a compiled language
54 |
55 | #- run: |
56 | # make bootstrap
57 | # make release
58 |
59 | - name: Perform CodeQL Analysis
60 | uses: github/codeql-action/analyze@v3
61 |
--------------------------------------------------------------------------------
/.github/workflows/dependency-review.yml:
--------------------------------------------------------------------------------
1 | name: 'Dependency Review'
2 | on: [pull_request]
3 |
4 | permissions:
5 | contents: read
6 |
7 | jobs:
8 | dependency-review:
9 | runs-on: ubuntu-latest
10 | steps:
11 | - name: 'Checkout Repository'
12 | uses: actions/checkout@v4
13 | - name: 'Dependency Review'
14 | uses: actions/dependency-review-action@v4
15 |
--------------------------------------------------------------------------------
/.github/workflows/export-labels.yml:
--------------------------------------------------------------------------------
1 | name: Export label config
2 | on:
3 | # You can run this with every event, but it's better to run it only when you actually need it.
4 | workflow_dispatch:
5 |
6 | jobs:
7 | labels:
8 | runs-on: ubuntu-latest
9 |
10 | steps:
11 | - uses: EndBug/export-label-config@main
12 | with:
13 | # This is needed if you're dealing with private repos.
14 | token: ${{ secrets.GITHUB_TOKEN }}
15 |
16 | # Set this to `true` if you want to get the raw API response. Defaults to `false`.
17 | raw-result: false
18 |
19 | # By default every label entry will have an `aliases` property set to an empty array.
20 | # It's for EndBug/label-sync, if you don't want it you cans set this to `false`
21 | add-aliases: true
22 |
--------------------------------------------------------------------------------
/.github/workflows/label-sync.yml:
--------------------------------------------------------------------------------
1 | name: Sync labels
2 | on:
3 | push:
4 | branches:
5 | - main
6 | paths:
7 | - '.github/labels.yml'
8 | workflow_dispatch:
9 |
10 | jobs:
11 | sync:
12 | name: Run EndBug/label-sync
13 | runs-on: ubuntu-latest
14 | steps:
15 | - uses: actions/checkout@v4
16 | - uses: EndBug/label-sync@v2
17 | with:
18 | config-file: '.github/labels.yml'
19 |
--------------------------------------------------------------------------------
/.github/workflows/stale.yml:
--------------------------------------------------------------------------------
1 | name: 'Handle stale issues and PR'
2 | on:
3 | schedule:
4 | - cron: '00 5,17 * * *'
5 | workflow_dispatch:
6 |
7 | jobs:
8 | stale:
9 | uses: EndBug/workflows/.github/workflows/stale.yml@main
10 |
--------------------------------------------------------------------------------
/.github/workflows/test.yml:
--------------------------------------------------------------------------------
1 | name: Test
2 | on:
3 | push:
4 | pull_request:
5 | workflow_dispatch:
6 |
7 | jobs:
8 | build:
9 | name: Build
10 | runs-on: ubuntu-latest
11 | steps:
12 | - uses: actions/checkout@v4
13 | - uses: actions/setup-node@v4
14 | with:
15 | cache: npm
16 | - run: npm ci
17 | - run: npm run build
18 |
19 | lint:
20 | name: Lint
21 | runs-on: ubuntu-latest
22 | steps:
23 | - uses: actions/checkout@v4
24 | - uses: actions/setup-node@v4
25 | with:
26 | cache: npm
27 | - run: npm ci
28 | - run: npm run lint
29 |
--------------------------------------------------------------------------------
/.github/workflows/versioning.yml:
--------------------------------------------------------------------------------
1 | name: Update tags
2 |
3 | on:
4 | release:
5 | types: [published, edited]
6 |
7 | jobs:
8 | actions-tagger:
9 | runs-on: windows-2022
10 | steps:
11 | - uses: Actions-R-Us/actions-tagger@v2
12 | with:
13 | publish_latest_tag: true
14 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | build
3 |
--------------------------------------------------------------------------------
/.husky/.gitignore:
--------------------------------------------------------------------------------
1 | _
2 |
--------------------------------------------------------------------------------
/.husky/pre-commit:
--------------------------------------------------------------------------------
1 | npm run build
2 | git add lib
3 |
--------------------------------------------------------------------------------
/.prettierrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | ...require('gts/.prettierrc.json'),
3 | };
4 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | If you want to contribute to this project, check out this steps!
4 |
5 | 1. Check out existing features to make sure your case is not already covered. Also, try [searching open or closed issues](https://github.com/EndBug/add-and-commit/issues) that may cover the same topic.
6 | 2. Either [open a new issue](https://github.com/EndBug/add-and-commit/issues/new/choose) or comment on an existing one to let everyone know what you're working on.
7 | 3. Edit the source files to implement your feature or fix.
8 | 4. Build the action and test it in a test repo.
9 | 5. Update the [action manifest](./action.yml) AND the [README](./README.md) with your changes.
10 | 6. [Open a PR](https://github.com/EndBug/add-and-commit/compare).
11 |
12 | Thanks! 💖
13 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Federico Grandi
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Add & Commit
2 |
3 | [](#contributors-)
4 |
5 | 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, etc...
6 |
7 | ## Table of contents
8 |
9 | - [Inputs](#inputs)
10 | - [Outputs](#outputs)
11 | - [FAQs](#faqs)
12 | - [Examples](#examples)
13 | - [Contributors](#contributors-)
14 | - [Articles](#articles)
15 |
16 | ## Inputs
17 |
18 | Add a step like this to your workflow:
19 |
20 | ```yaml
21 | - uses: EndBug/add-and-commit@v9 # You can change this to use a specific version.
22 | with:
23 | # The arguments for the `git add` command (see the paragraph below for more info)
24 | # Default: '.'
25 | add: 'src'
26 |
27 | # The name of the user that will be displayed as the author of the commit.
28 | # Default: depends on the default_author input
29 | author_name: Author Name
30 |
31 | # The email of the user that will be displayed as the author of the commit.
32 | # Default: depends on the default_author input
33 | author_email: mail@example.com
34 |
35 | # Additional arguments for the git commit command. The --message argument is already set by the message input.
36 | # Default: ''
37 | commit: --signoff
38 |
39 | # The name of the custom committer you want to use, if different from the author of the commit.
40 | # Default: the name of the author (set with either author_name or default_author)
41 | committer_name: Committer Name
42 |
43 | # The email of the custom committer you want to use, if different from the author of the commit.
44 | # Default: the email of the author (set with either author_email or default_author)
45 | committer_email: mail@example.com
46 |
47 | # The local path to the directory where your repository is located. You should use actions/checkout first to set it up.
48 | # Default: '.'
49 | cwd: './path/to/the/repo'
50 |
51 | # Determines the way the action fills missing author name and email. Three options are available:
52 | # - github_actor -> UserName
53 | # - user_info -> Your Display Name
54 | # - github_actions -> github-actions
55 | # Default: github_actor
56 | default_author: github_actor
57 |
58 | # Arguments for the git fetch command. If set to false, the action won't fetch the repo.
59 | # For more info as to why fetching is usually recommended, please see the "Performance on large repos" FAQ.
60 | # Default: --tags --force
61 | fetch: false
62 |
63 | # The message for the commit.
64 | # Default: 'Commit from GitHub Actions (name of the workflow)'
65 | message: 'Your commit message'
66 |
67 | # If this input is set, the action will push the commit to a new branch with this name.
68 | # Default: ''
69 | new_branch: custom-new-branch
70 |
71 | # The way the action should handle pathspec errors from the add and remove commands. Three options are available:
72 | # - ignore -> errors will be logged but the step won't fail
73 | # - exitImmediately -> the action will stop right away, and the step will fail
74 | # - exitAtEnd -> the action will go on, every pathspec error will be logged at the end, the step will fail.
75 | # Default: ignore
76 | pathspec_error_handling: ignore
77 |
78 | # Arguments for the git pull command. By default, the action does not pull.
79 | # Default: ''
80 | pull: '--rebase --autostash ...'
81 |
82 | # Whether to push the commit and, if any, its tags to the repo. It can also be used to set the git push arguments (see the paragraph below for more info)
83 | # Default: true
84 | push: false
85 |
86 | # The arguments for the `git rm` command (see the paragraph below for more info)
87 | # Default: ''
88 | remove: './dir/old_file.js'
89 |
90 | # Arguments for the git tag command (the tag name always needs to be the first word not preceded by an hyphen)
91 | # Default: ''
92 | tag: 'v1.0.0 --force'
93 |
94 | # Arguments for the git push --tags command (any additional argument will be added after --tags)
95 | # Default: ''
96 | tag_push: '--force'
97 | ```
98 |
99 | ### Git arguments
100 |
101 | Multiple options let you provide the `git` arguments that you want the action to use. It's important to note that these arguments **are not actually used with a CLI command**, but they are parsed by a package called [`string-argv`](https://npm.im/string-argv), and then used with [`simple-git`](https://npm.im/simple-git).
102 | What does this mean for you? It means that strings that contain a lot of nested quotes may be parsed incorrectly, and that specific ways of declaring arguments may not be supported by these libraries. If you're having issues with your argument strings you can check whether they're being parsed correctly either by [enabling debug logging](https://docs.github.com/en/actions/managing-workflow-runs/enabling-debug-logging) for your workflow runs or by testing it directly with `string-argv` ([RunKit demo](https://npm.runkit.com/string-argv)): if each argument and option is parsed correctly you'll see an array where every string is an option or value.
103 |
104 | ### Adding files
105 |
106 | The action adds files using a regular `git add` command, so you can put every kind of argument in the `add` option. For example, if you want to force-add a file: `./path/to/file.txt --force`.
107 | The script will not stop if one of the git commands doesn't match any file. E.g.: if your command shows a "fatal: pathspec 'yourFile' did not match any files" error the action will go on.
108 | You can also use JSON or YAML arrays (e.g. `'["first", "second"]'`, `"['first', 'second']"`) to make the action run multiple `git add` commands: the action will log how your input has been parsed. Please mind that your input still needs to be a string because of how GitHub Actions works with inputs: just write your array inside the string, the action will parse it later.
109 |
110 | ### Deleting files
111 |
112 | The `remove` option can be used if a predetermined list of files needs to be removed. It runs the `git rm` command, so you can pass every kind of argument with it. As if with the [`add` input](#adding-files), you can also use JSON or YAML arrays to make the action run multiple `git rm` commands.
113 |
114 | If you want deleted files to be auto-detected and committed, you can use the [`--no-ignore-removal`/`-A`](https://git-scm.com/docs/git-add#Documentation/git-add.txt--A) git arguments.
115 |
116 | ### Pushing
117 |
118 | By default the action runs the following command: `git push origin ${new_branch input} --set-upstream`. You can use the `push` input to modify this behavior, here's what you can set it to:
119 |
120 | - `true`: this is the default value, it will behave as usual.
121 | - `false`: this prevents the action from pushing at all, no `git push` command is run.
122 | - any other string:
123 | The action will use your string as the arguments for the `git push` command. Please note that nothing is used other than your arguments, and the command will result in `git push ${push input}` (no remote, no branch, no `--set-upstream`, you have to include them yourself).
124 |
125 | One way to use this is if you want to force push to a branch of your repo: you'll need to set the `push` input to, for example, `origin yourBranch --force`.
126 |
127 | ### Creating a new branch
128 |
129 | If you want the action to commit in a new branch, you can use the `new_branch` input.
130 |
131 | Please note that if the branch exists, the action will still try push to it, but it's possible that the push will be rejected by the remote as non-straightforward.
132 |
133 | If that's the case, you need to make sure that the branch you want to commit to is already checked out before you run the action.
134 | If you're **really** sure that you want to commit to that branch, you can also force-push by setting the `push` input to something like `origin yourBranchName --set-upstream --force`.
135 |
136 | If you want to commit files "across different branches", here are two ways to do it:
137 |
138 | 1. You can check them out in two different directories, generate your files, move them to your destination and then run `add-and-commit` in the destination directory using the `cwd` input.
139 | 2. You can manually commit those files with `git` commands as you would on your machine. There are several ways to do this depending on the scenario. One of them if to stash your changes, checkout the destination branch, and popping the stash. You can then use the `add-and-commit` action as usual. Please note that this is just an example and may not work for you, since your use case may be different.
140 |
141 | ### Tagging
142 |
143 | You can use the `tag` option to enter the arguments for a `git tag` command. In order for the action to isolate the tag name from the rest of the arguments, it should be the first word not preceded by an hyphen (e.g. `-a tag-name -m "some other stuff"` is ok).
144 | You can also change the arguments of the push command for tags: every argument in the `tag_push` input will be appended to the `git push --tags` command.
145 | For more info on how git arguments are parsed, see [the "Git arguments" section](#git-arguments).
146 |
147 | ## Outputs
148 |
149 | The action provides these outputs:
150 |
151 | - `committed`: whether the action has created a commit (`'true'` or `'false'`)
152 | - `commit_long_sha`: the full SHA of the commit that has just been created
153 | - `commit_sha`: the short 7-character SHA of the commit that has just been created
154 | - `pushed`: whether the action has pushed to the remote (`'true'` or `'false'`)
155 | - `tagged`: whether the action has created a tag (`'true'` or `'false'`)
156 | - `tag_pushed`: whether the action has pushed a tag (`'true'` or `'false'`)
157 |
158 | For more info on how to use outputs, see ["Context and expression syntax"](https://docs.github.com/en/free-pro-team@latest/actions/reference/context-and-expression-syntax-for-github-actions).
159 |
160 | ## FAQs
161 |
162 | ### Working with PRs
163 |
164 | By default, when you use `actions/checkout` on a PR, it will checkout the head commit in a detached head state.
165 | If you want to make some changes, you have to checkout the branch the PR is coming from in the head repo.
166 | You can set it up like this:
167 |
168 | ```yaml
169 | - uses: actions/checkout@v4
170 | with:
171 | repository: ${{ github.event.pull_request.head.repo.full_name }}
172 | ref: ${{ github.event.pull_request.head.ref }}
173 | ```
174 |
175 | You can find the full docs for payloads of `pull_request` events [here](https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#webhook-payload-example-32).
176 |
177 | If you're planning on running this only on "internal" PRs (where head and base are in the same repo) then you can omit the `repository` input.
178 | If you're planning to use this with PRs coming from other forks, please keep in mind that you might not have write access to those repos.
179 | You can try setting up the repo with your PAT, as explained in the ["About tokens" paragraph](#about-tokens) of this section.
180 |
181 | Keep in mind that this "custom checkout" is meant only for PRs: if your workflow runs on multiple events (like `push` or `workflow_dispatch`), you could try having this step run only for `pull_request` events, while other ones will trigger the usual checkout.
182 | If you wish to do so, you can use the `step.if` property, [here](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsif)'s the docs.
183 |
184 | ### About tokens
185 |
186 | When pushing, the action uses the token that the local git repository has been configured with: that means that if you want to change it you'll need to do it in the steps that run before this action. For example: if you set up your repo with [`actions/checkout`](https://github.com/actions/checkout/) then you have to add the token there.
187 | Changing the token with which the repo is configured can be useful if you want to run CI checks on the commit pushed by this action; anyway, it has to be set up outside of this action.
188 |
189 | The action automatically gets the GitHub token from a `github_token` input: this input should not be modified by the user, since it doesn't affect the commits as it's only used to access the GitHub API to get user info, in case they selected that option for the commit author.
190 |
191 | ### The commit from the action is not triggering CI!
192 |
193 | That's because you're checking out the repo using the built-in [`GITHUB_TOKEN` secret](https://docs.github.com/en/actions/security-guides/automatic-token-authentication): GitHub sees that the push event has been triggered by a commit generated by CI, and doesn't run any further checks to avoid unintentional check loops.
194 |
195 | **If you're sure** that you want the commits generated during CI to trigger other workflow runs, you can checkout the repo using a [Personal Access Token (PAT)](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token): this will make the resulting commit the same as if you made it yourself.
196 | If you're using `actions/checkout`, check out their [docs](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) to see how to set your repo token.
197 |
198 | ### About `actions/checkout`
199 |
200 | The token you use when setting up the repo with this action will determine what token `add-and-commit` will use.
201 | Some users reported that they were getting an error:
202 |
203 | ```
204 | > fatal: could not read Username for 'https://github.com': No such device or address
205 | ```
206 |
207 | If you're getting this error and you're using `actions/checkout@v1`, try upgrading to `actions/checkout@v2`. If you're still having problems after upgrading, feel free to open an issue. Issue ref: [#146](https://github.com/EndBug/add-and-commit/issues/146)
208 |
209 | Please note that using `persist-credentials: false` will lead to the same issue.
210 |
211 | ### Performance on large repos
212 |
213 | By default, the action will fetch the repository before starting to work on it: this ensures that it can see the already existing refs.
214 |
215 | When working with a repository that has a lot of branches and tags, fetching it can take a long time. If the fetch step is taking too much time, you can decide to skip it by setting the `fetch` input to `false`: this will prevent the action from running `git fetch` altogether.
216 |
217 | Please note that you have to set up your workflow accordingly: not fetching the repo can impact branch and tag creation within the action, and for this reason it's recommended to disable it only if necessary. Issue ref: [#386](https://github.com/EndBug/add-and-commit/issues/386)
218 |
219 | ## Examples
220 |
221 | ### Different author/committer configurations
222 |
223 | If you don't want to use your GitHub username for the CI commits, you can use the `default_author` input to make it appear as if it was made by "GitHub Actions", by setting its value to `github_actions`.
224 |
225 |
226 |
227 | ```yaml
228 | on: push
229 | jobs:
230 | build:
231 | runs-on: ubuntu-latest
232 | steps:
233 | - uses: EndBug/add-and-commit@v9
234 | with:
235 | default_author: github_actions
236 | ```
237 |
238 | You can also use the `committer_name` and `committer_email` inputs to make it appear as if GitHub Actions is the committer, here are a couple of example steps:
239 |
240 |
241 |
242 | ```yaml
243 | - uses: EndBug/add-and-commit@v9
244 | with:
245 | message: Show GitHub Actions logo
246 | committer_name: GitHub Actions
247 | committer_email: actions@github.com
248 | ```
249 |
250 |
251 |
252 | ```yaml
253 | - uses: EndBug/add-and-commit@v9
254 | with:
255 | message: Show GitHub logo
256 | committer_name: GitHub Actions
257 | committer_email: 41898282+github-actions[bot]@users.noreply.github.com
258 | ```
259 |
260 | ### Array inputs
261 |
262 | Due to limitations in the GitHub action APIs, all inputs must be either strings or booleans.
263 | The action supports arrays in `add` and `remove`, but they have to be encoded as a string with a YAML flow sequence:
264 |
265 | ```yaml
266 | - uses: EndBug/add-and-commit@v9
267 | with:
268 | add: '["afile.txt", "anotherfile.txt"]'
269 | ```
270 |
271 | (note the single-quotes) or a YAML block sequence:
272 |
273 | ```yaml
274 | - uses: EndBug/add-and-commit@v9
275 | with:
276 | add: |
277 | - afile.txt
278 | - anotherfile.txt
279 | ```
280 |
281 | (Note the pipe character making it a multiline string.)
282 |
283 | ### Automated linting
284 |
285 | Do 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:
286 |
287 | ```yaml
288 | name: Lint source code
289 | on: push
290 |
291 | jobs:
292 | run:
293 | name: Lint with ESLint
294 | runs-on: ubuntu-latest
295 | steps:
296 | - name: Checkout repo
297 | uses: actions/checkout@v4
298 |
299 | - name: Set up Node.js
300 | uses: actions/setup-node@v4
301 |
302 | - name: Install dependencies
303 | run: npm install
304 |
305 | - name: Update source code
306 | run: eslint "src/**" --fix
307 |
308 | - name: Commit changes
309 | uses: EndBug/add-and-commit@v9
310 | with:
311 | author_name: Your Name
312 | author_email: mail@example.com
313 | message: 'Your commit message'
314 | add: '*.js'
315 | ```
316 |
317 | ### Running the action in a different directory
318 |
319 | If you need to run the action on a repository that is not located in [`$GITHUB_WORKSPACE`](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/using-environment-variables#default-environment-variables), you can use the `cwd` option: the action uses a `cd` normal command, so the path should follow bash standards.
320 |
321 | ```yaml
322 | name: Use a different repository directory
323 | on: push
324 |
325 | jobs:
326 | run:
327 | name: Add a text file
328 | runs-on: ubuntu-latest
329 |
330 | steps:
331 | # If you need to, you can check out your repo to a different location
332 | - uses: actions/checkout@v4
333 | with:
334 | path: './pathToRepo/'
335 |
336 | # You can make whatever type of change to the repo...
337 | - run: echo "123" > ./pathToRepo/file.txt
338 |
339 | # ...and then use the action as you would normally do, but providing the path to the repo
340 | - uses: EndBug/add-and-commit@v9
341 | with:
342 | message: 'Add the very useful text file'
343 | add: '*.txt --force'
344 | cwd: './pathToRepo/'
345 | ```
346 |
347 | ## Articles
348 |
349 | - [Console by CodeSee #156](https://console.substack.com/p/console-156)
350 | - [MichealHeap.com](https://michaelheap.com/add-and-commit-action/)
351 |
352 | ## Contributors ✨
353 |
354 | Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
355 |
356 |
357 |
358 |
359 |