### Get GitHub User Info with TypeScript Source: https://context7.com/endbug/add-and-commit/llms.txt Fetches a GitHub user's display name and public email using the Octokit REST client. Requires the 'github_token' input. Falls back to 'github_actor' values if name or email are null. Returns undefined if the username is falsy. ```typescript import {getUserInfo} from './src/util'; // Requires github_token input to be set in the action environment const info = await getUserInfo('EndBug'); // => { name: 'Federico Grandi', email: 'user@example.com' } // => undefined (if username is falsy) // Falls back to github_actor values if name or email are null ``` -------------------------------- ### Explicit Author and Committer Identity Override Source: https://context7.com/endbug/add-and-commit/llms.txt Provides examples of directly overriding the author and committer names and emails for commits. ```yaml - uses: EndBug/add-and-commit@v10 with: add: '.' message: 'ci: auto-formatted code' author_name: 'CI Bot' author_email: 'ci-bot@example.com' committer_name: 'GitHub Actions' committer_email: 'actions@github.com' ``` -------------------------------- ### Staging Files with `add` Input Source: https://context7.com/endbug/add-and-commit/llms.txt Demonstrates various ways to use the `add` input to stage files, including single globs, force-adding ignored files, and using array formats for multiple commands. ```yaml - uses: EndBug/add-and-commit@v10 with: # Single glob add: '*.js' # Force-add an ignored file # add: './dist/bundle.js --force' # JSON array — runs two separate git add commands # add: '["src/generated.ts", "docs/ --force"]' # YAML block array (equivalent to JSON array above) # add: | # - src/generated.ts # - docs/ --force message: 'chore: update generated files' ``` -------------------------------- ### Force Add a File Source: https://github.com/endbug/add-and-commit/blob/main/README.md Use the `add` option with arguments for `git add`. Forcing a file add is demonstrated. ```bash add: './path/to/file.txt --force' ``` -------------------------------- ### Configuring Pre-commit Fetch Behavior Source: https://context7.com/endbug/add-and-commit/llms.txt Demonstrates how to control the pre-commit fetch behavior using the `fetch` input. It can be disabled entirely or configured with custom arguments. ```yaml - uses: EndBug/add-and-commit@v10 with: add: '.' message: 'chore: update' fetch: false # skip fetch entirely # Custom fetch arguments: # fetch: '--depth 1 --no-tags' ``` -------------------------------- ### Basic Commit with Add & Commit Action Source: https://context7.com/endbug/add-and-commit/llms.txt This is the minimal configuration to stage all changes in the 'dist' directory, commit them with a message, and push to the current branch. ```yaml # .github/workflows/auto-commit.yml name: Auto-commit generated files on: push jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Generate files run: npm run build # produces files in dist/ - uses: EndBug/add-and-commit@v10 with: add: 'dist' message: 'chore: rebuild dist [skip ci]' # Outputs available after this step: # committed: 'true' | 'false' # commit_sha: 'a1b2c3d' (7-char short SHA) # commit_long_sha: 'a1b2c3d...' (full SHA) # pushed: 'true' | 'false' ``` -------------------------------- ### Add Multiple Files using Array Input Source: https://github.com/endbug/add-and-commit/blob/main/README.md Provide a string that represents a JSON or YAML array to execute multiple `git add` commands. The action parses this string. ```bash add: '["first", "second"]' ``` -------------------------------- ### Upgrade actions/checkout Version Source: https://github.com/endbug/add-and-commit/blob/main/README.md If encountering 'fatal: could not read Username for 'https://github.com': No such device or address' errors, try upgrading to actions/checkout@v2 or later. This addresses credential handling issues. ```bash actions/checkout@v2 ``` -------------------------------- ### Configure Add & Commit Action Source: https://github.com/endbug/add-and-commit/blob/main/README.md Add this step to your workflow to integrate the Add & Commit action. Customize inputs like `add`, `author_name`, `message`, and `push` to control its behavior. ```yaml - uses: EndBug/add-and-commit@v10 with: # The arguments for the `git add` command (see the paragraph below for more info) # Default: '.' add: 'src' # The name of the user that will be displayed as the author of the commit. # Default: depends on the default_author input author_name: Author Name # The email of the user that will be displayed as the author of the commit. # Default: depends on the default_author input author_email: mail@example.com # Additional arguments for the git commit command. The --message argument is already set by the message input. # Default: '' commit: --signoff # The name of the custom committer you want to use, if different from the author of the commit. # Default: the name of the author (set with either author_name or default_author) committer_name: Committer Name # The email of the custom committer you want to use, if different from the author of the commit. # Default: the email of the author (set with either author_email or default_author) committer_email: mail@example.com # The local path to the directory where your repository is located. You should use actions/checkout first to set it up. # Default: '.' cwd: './path/to/the/repo' # Determines the way the action fills missing author name and email. Three options are available: # - github_actor -> UserName # - user_info -> Your Display Name # - github_actions -> github-actions # Default: github_actor default_author: github_actor # Arguments for the git fetch command. If set to false, the action won't fetch the repo. # For more info as to why fetching is usually recommended, please see the "Performance on large repos" FAQ. # Default: --tags --force fetch: false # The message for the commit. # Default: 'Commit from GitHub Actions (name of the workflow)' message: 'Your commit message' # If this input is set, the action will push the commit to a new branch with this name. # Default: '' new_branch: custom-new-branch # The way the action should handle pathspec errors from the add and remove commands. Three options are available: # - ignore -> errors will be logged but the step won't fail # - exitImmediately -> the action will stop right away, and the step will fail # - exitAtEnd -> the action will go on, every pathspec error will be logged at the end, the step will fail. # Default: ignore pathspec_error_handling: ignore # Arguments for the git pull command. By default, the action does not pull. # Default: '' pull: '--rebase --autostash ...' # 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) # Default: true push: false # The arguments for the `git rm` command (see the paragraph below for more info) # Default: '' remove: './dir/old_file.js' # Arguments for the git tag command (the tag name always needs to be the first word not preceded by an hyphen) # Default: '' tag: 'v1.0.0 --force' # Arguments for the git push --tags command (any additional argument will be added after --tags) # Default: '' tag_push: '--force' ``` -------------------------------- ### Removing Files with `remove` Input Source: https://context7.com/endbug/add-and-commit/llms.txt Shows how to use the `remove` input to stage files for deletion using `git rm`. It supports single paths and array formats. ```yaml - uses: EndBug/add-and-commit@v10 with: remove: './dir/old_file.js' # Array form: # remove: '["./old/a.js", "./old/b.js"]' message: 'chore: remove stale files' ``` -------------------------------- ### Create and Push to a New Branch Source: https://github.com/endbug/add-and-commit/blob/main/README.md Use the `new_branch` input to specify a new branch for commits. If the branch exists, the action attempts to push to it, potentially requiring a force push. ```bash new_branch: 'yourBranchName' ``` -------------------------------- ### Automated Linting and Committing Changes Source: https://github.com/endbug/add-and-commit/blob/main/README.md This workflow demonstrates how to lint JavaScript files using ESLint and automatically commit any fixable changes. ```yaml name: Lint source code on: push jobs: run: name: Lint with ESLint runs-on: ubuntu-latest steps: - name: Checkout repo uses: actions/checkout@v4 - name: Set up Node.js uses: actions/setup-node@v4 - name: Install dependencies run: npm install - name: Update source code run: eslint "src/**" --fix - name: Commit changes uses: EndBug/add-and-commit@v10 with: author_name: Your Name author_email: mail@example.com message: 'Your commit message' add: '*.js' ``` -------------------------------- ### Internal utility: matchGitArgs argument parser Source: https://context7.com/endbug/add-and-commit/llms.txt The `matchGitArgs` utility, used internally for parsing git command inputs, converts raw argument strings into properly split arrays using the `string-argv` library. ```typescript import {matchGitArgs} from './src/util'; matchGitArgs('--tags --force'); // => ['--tags', '--force'] matchGitArgs(`--longOption 'This uses the "other" quotes' --foo 1234`); // => ['--longOption', 'This uses the "other" quotes', '--foo', '1234'] matchGitArgs(' '); // => [] ``` -------------------------------- ### Customizing `git commit` Flags Source: https://context7.com/endbug/add-and-commit/llms.txt Shows how to pass additional flags to the `git commit` command using the `commit` input, such as `--signoff` or `--allow-empty`. ```yaml - uses: EndBug/add-and-commit@v10 with: add: '.' message: 'chore: signed commit' commit: '--signoff' # Allow an empty commit even when nothing was staged: - uses: EndBug/add-and-commit@v10 with: add: '.' message: 'ci: heartbeat' commit: '--allow-empty' ``` -------------------------------- ### Consuming action outputs in downstream steps Source: https://context7.com/endbug/add-and-commit/llms.txt Access the outputs of the add-and-commit action, such as `committed`, `commit_sha`, `pushed`, `tagged`, and `tag_pushed`, in subsequent steps using the `steps..outputs.` syntax. ```yaml - uses: EndBug/add-and-commit@v10 id: commit_step with: add: '.' message: 'chore: auto-update' - name: Report result if: steps.commit_step.outputs.committed == 'true' run: | echo "Committed: ${{ steps.commit_step.outputs.committed }}" echo "Short SHA: ${{ steps.commit_step.outputs.commit_sha }}" echo "Full SHA: ${{ steps.commit_step.outputs.commit_long_sha }}" echo "Pushed: ${{ steps.commit_step.outputs.pushed }}" echo "Tagged: ${{ steps.commit_step.outputs.tagged }}" echo "Tag pushed: ${{ steps.commit_step.outputs.tag_pushed }}" ``` -------------------------------- ### Checkout PR branch for Pull Request workflows Source: https://context7.com/endbug/add-and-commit/llms.txt When running on a `pull_request` event, explicitly check out the PR branch using `actions/checkout` with specific `repository` and `ref` inputs to avoid detached HEAD state and enable pushing. ```yaml on: pull_request jobs: lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: repository: ${{ github.event.pull_request.head.repo.full_name }} ref: ${{ github.event.pull_request.head.ref }} - run: npx eslint "src/**" --fix - uses: EndBug/add-and-commit@v10 with: add: 'src' message: 'style: auto-fix lint errors' default_author: github_actions ``` -------------------------------- ### Commit to a new or existing branch with 'new_branch' Source: https://context7.com/endbug/add-and-commit/llms.txt Use the `new_branch` input to specify a branch for committing. If the branch exists, it will be checked out; otherwise, it will be created locally before committing. By default, `push` is true, so the branch is also created on the remote. ```yaml - uses: EndBug/add-and-commit@v10 with: add: 'reports/' message: 'ci: nightly report' new_branch: 'ci/nightly-report' # push defaults to true, so the branch is created on the remote too ``` -------------------------------- ### Operate on a non-default checkout path with 'cwd' Source: https://context7.com/endbug/add-and-commit/llms.txt Use the `cwd` input to specify the working directory when the repository is checked out to a subdirectory. This ensures the action operates in the correct path. ```yaml - uses: actions/checkout@v4 with: path: './my-repo' - uses: EndBug/add-and-commit@v10 with: cwd: './my-repo' add: '*.txt --force' message: 'chore: add text files' ``` -------------------------------- ### Tagging commits with 'tag' and 'tag_push' Source: https://context7.com/endbug/add-and-commit/llms.txt Create and push git tags after committing using the `tag` and `tag_push` inputs. The `tag` input specifies the tag name and optional git tag arguments, while `tag_push` provides arguments for `git push --tags`. ```yaml - uses: EndBug/add-and-commit@v10 with: add: '.' message: 'release: v1.2.3' tag: 'v1.2.3 --force' # git tag v1.2.3 --force tag_push: '--force' # git push --tags --force # Outputs: # tagged: 'true' # tag_pushed: 'true' ``` -------------------------------- ### Configure Committer Name and Email Source: https://github.com/endbug/add-and-commit/blob/main/README.md Use `committer_name` and `committer_email` to specify the committer details for GitHub Actions. ```yaml - uses: EndBug/add-and-commit@v10 with: message: Show GitHub Actions logo committer_name: GitHub Actions committer_email: actions@github.com ``` ```yaml - uses: EndBug/add-and-commit@v10 with: message: Show GitHub logo committer_name: GitHub Actions committer_email: 41898282+github-actions[bot]@users.noreply.github.com ``` -------------------------------- ### Pushing Tags Source: https://github.com/endbug/add-and-commit/blob/main/README.md Append arguments to the `git push --tags` command using the `tag_push` input. ```bash tag_push: '--force' ``` -------------------------------- ### Control push behavior with 'push' input Source: https://context7.com/endbug/add-and-commit/llms.txt The `push` input controls whether and how the commit is pushed. It can be set to `true` for a default push, `false` to disable pushing, or a custom argument string for specific push configurations. ```yaml # Default push - uses: EndBug/add-and-commit@v10 with: add: '.' message: 'chore: update' push: true ``` ```yaml # Disable push - uses: EndBug/add-and-commit@v10 with: add: '.' message: 'chore: local only' push: false ``` ```yaml # Force-push to a specific remote branch - uses: EndBug/add-and-commit@v10 with: add: '.' message: 'chore: force sync' push: 'origin main --force' ``` -------------------------------- ### getUserInfo Source: https://context7.com/endbug/add-and-commit/llms.txt Fetches a GitHub user's real display name and public email via the Octokit REST client. Called automatically when `default_author: user_info` is set. ```APIDOC ## `getUserInfo` — GitHub API user lookup ### Description Fetches a GitHub user's real display name and public email via the Octokit REST client. Called automatically when `default_author: user_info` is set. ### Usage ```typescript import {getUserInfo} from './src/util'; // Requires github_token input to be set in the action environment const info = await getUserInfo('EndBug'); // => { name: 'Federico Grandi', email: 'user@example.com' } // => undefined (if username is falsy) // Falls back to github_actor values if name or email are null ``` ``` -------------------------------- ### Tagging a Commit Source: https://github.com/endbug/add-and-commit/blob/main/README.md Use the `tag` option to provide arguments for `git tag`. The tag name should be the first argument not preceded by a hyphen. ```bash tag: '-a tag-name -m "some other stuff"' ``` -------------------------------- ### Encode Array Inputs as YAML Flow Sequence Source: https://github.com/endbug/add-and-commit/blob/main/README.md For array inputs like `add`, encode them as a string using a YAML flow sequence, enclosed in single quotes. ```yaml - uses: EndBug/add-and-commit@v10 with: add: '["afile.txt", "anotherfile.txt"]' ``` -------------------------------- ### Force Push to an Existing Branch Source: https://github.com/endbug/add-and-commit/blob/main/README.md Combine `new_branch` and `push` inputs to force push to a specific branch. Ensure the branch is checked out if it already exists. ```bash new_branch: 'yourBranchName' push: 'origin yourBranchName --set-upstream --force' ``` -------------------------------- ### Control pathspec error handling with 'pathspec_error_handling' Source: https://context7.com/endbug/add-and-commit/llms.txt Configure how the action handles errors from `git add` or `git rm` commands that match no files using the `pathspec_error_handling` input. Options include 'ignore' (default), 'exitImmediately', and 'exitAtEnd'. ```yaml # ignore (default): log the error, continue - uses: EndBug/add-and-commit@v10 with: add: 'maybe-missing-file.txt' message: 'chore: optional file' pathspec_error_handling: ignore ``` ```yaml # exitImmediately: fail the step right away - uses: EndBug/add-and-commit@v10 with: add: 'required-file.txt' message: 'chore: required file' pathspec_error_handling: exitImmediately ``` ```yaml # exitAtEnd: run all commands, then fail after collecting all errors - uses: EndBug/add-and-commit@v10 with: add: '["file-a.txt", "file-b.txt", "file-c.txt"]' message: 'chore: batch' pathspec_error_handling: exitAtEnd ``` -------------------------------- ### Configure Git Push Behavior Source: https://github.com/endbug/add-and-commit/blob/main/README.md Modify the default `git push` command using the `push` input. Setting it to `true` uses the default, `false` disables pushing, and any string customizes the arguments. ```bash push: true ``` ```bash push: false ``` ```bash push: 'origin yourBranch --force' ``` -------------------------------- ### Checkout Pull Request Head Commit Source: https://github.com/endbug/add-and-commit/blob/main/README.md Configure actions/checkout to checkout the head commit of a pull request. This is necessary when you need to make changes to the PR. Ensure the repository and ref are correctly specified. ```yaml - uses: actions/checkout@v4 with: repository: ${{ github.event.pull_request.head.repo.full_name }} ref: ${{ github.event.pull_request.head.ref }} ``` -------------------------------- ### Pull from remote before committing with rebase/merge Source: https://context7.com/endbug/add-and-commit/llms.txt Use the `pull` input to rebase or merge changes from the remote before creating a commit. This is useful for concurrent pushes. If conflicts occur, the action will throw an error listing conflicting files. ```yaml - uses: EndBug/add-and-commit@v10 with: add: '.' message: 'chore: sync' pull: '--rebase --autostash' # If pull produces conflicts, the action throws an error listing # every conflicting file name. ``` -------------------------------- ### Run Action in a Different Directory Source: https://github.com/endbug/add-and-commit/blob/main/README.md Use the `cwd` option to specify a different working directory for the action, following bash standards. ```yaml name: Use a different repository directory on: push jobs: run: name: Add a text file runs-on: ubuntu-latest steps: # If you need to, you can check out your repo to a different location - uses: actions/checkout@v4 with: path: './pathToRepo/' # You can make whatever type of change to the repo... - run: echo "123" > ./pathToRepo/file.txt # ...and then use the action as you would normally do, but providing the path to the repo - uses: EndBug/add-and-commit@v10 with: message: 'Add the very useful text file' add: '*.txt --force' cwd: './pathToRepo/' ``` -------------------------------- ### Remove Multiple Files using Array Input Source: https://github.com/endbug/add-and-commit/blob/main/README.md Use the `remove` option with a string representing a JSON or YAML array to execute multiple `git rm` commands. ```bash remove: '["file1.txt", "file2.txt"]' ``` -------------------------------- ### Configure Default Author as GitHub Actions Source: https://github.com/endbug/add-and-commit/blob/main/README.md Set the `default_author` input to `github_actions` to make commits appear as if they were made by GitHub Actions. ```yaml on: push jobs: build: runs-on: ubuntu-latest steps: - uses: EndBug/add-and-commit@v10 with: default_author: github_actions ``` -------------------------------- ### parseInputArray Source: https://context7.com/endbug/add-and-commit/llms.txt Attempts to parse the input as a YAML sequence (superset of JSON arrays). If parsing fails or the result is not a string array, wraps the raw string in a single-element array. Used by the action internals to support both scalar and list input values. ```APIDOC ## `parseInputArray` — single-string / YAML array normaliser ### Description Attempts to parse the input as a YAML sequence (superset of JSON arrays). If parsing fails or the result is not a string array, wraps the raw string in a single-element array. Used by the action internals to support both scalar and list input values. ### Usage ```typescript import {parseInputArray} from './src/util'; parseInputArray('["src/a.ts", "src/b.ts"]'); // => ['src/a.ts', 'src/b.ts'] parseInputArray('- file1.txt\n- file2.txt'); // YAML block sequence // => ['file1.txt', 'file2.txt'] parseInputArray('src'); // plain string passthrough // => ['src'] parseInputArray('"'); // invalid YAML — passthrough // => ['"'] parseInputArray('[42]'); // non-string elements — passthrough // => ['[42]'] ``` ``` -------------------------------- ### Configuring Commit Author Identity Source: https://context7.com/endbug/add-and-commit/llms.txt Illustrates the three modes for setting the commit author identity: `github_actor` (default), `github_actions` bot, and `user_info` fetched from the GitHub API. ```yaml # Mode 1 (default): github_actor — uses the workflow trigger user - uses: EndBug/add-and-commit@v10 with: add: '.' default_author: github_actor # Resolves to: # Mode 2: github_actions — uses the GitHub Actions bot identity - uses: EndBug/add-and-commit@v10 with: add: '.' default_author: github_actions # Resolves to: github-actions <41898282+github-actions[bot]@users.noreply.github.com> # Mode 3: user_info — fetches real name/email from the GitHub API - uses: EndBug/add-and-commit@v10 with: add: '.' default_author: user_info # Falls back to github_actor values if the API returns no name/email ``` -------------------------------- ### Disable Fetch for Performance Source: https://github.com/endbug/add-and-commit/blob/main/README.md To improve performance on large repositories with many branches and tags, you can disable the default fetch behavior by setting the 'fetch' input to 'false'. This skips the 'git fetch' command. ```yaml fetch: false ``` -------------------------------- ### Encode Array Inputs as YAML Block Sequence Source: https://github.com/endbug/add-and-commit/blob/main/README.md Alternatively, encode array inputs using a YAML block sequence, indicated by a pipe character for multiline strings. ```yaml - uses: EndBug/add-and-commit@v10 with: add: | - afile.txt - anotherfile.txt ``` -------------------------------- ### Parse Input Array with TypeScript Source: https://context7.com/endbug/add-and-commit/llms.txt Parses input strings into YAML arrays or passes them through if parsing fails or the result is not a string array. Handles JSON arrays, YAML block sequences, plain strings, invalid YAML, and non-string array elements. ```typescript import {parseInputArray} from './src/util'; parseInputArray('["src/a.ts", "src/b.ts"]'); // => ['src/a.ts', 'src/b.ts'] ``` ```typescript parseInputArray('- file1.txt - file2.txt'); // YAML block sequence // => ['file1.txt', 'file2.txt'] ``` ```typescript parseInputArray('src'); // plain string passthrough // => ['src'] ``` ```typescript parseInputArray('"'); // invalid YAML — passthrough // => ['"'] ``` ```typescript parseInputArray('[42]'); // non-string elements — passthrough // => ['[42]'] ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.