Git Product home page Git Product logo

add-and-commit's Introduction

Add & Commit

Public workflows that use this action. All Contributors

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....

This is heavily inspired by git-auto-commit-action (by Stefan Zweifel): 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).
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.

Usage

Add a step like this to your workflow:

- uses: EndBug/add-and-commit@v6 # You can change this to use a specific version
  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: author of the commit that triggered the run
    author_name: Your Name

    # The email of the user that will be displayed as the author of the commit
    # Default: author of the commit that triggered the run
    author_email: [email protected]

    # Name of the branch to use, if different from the one that triggered the workflow
    # Default: the branch that triggered the run
    branch: some-branch

    # 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'

    # The message for the commit
    # Default: 'Commit from GitHub Actions (name of the workflow)'
    message: 'Your commit message'

    # The flag used on the pull strategy
    # Default: '--no-rebase'
    pull_strategy: '--no-rebase or --no-ff or --rebase'

    # 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'

    # Whether to use the --signoff option on `git commit` (only `true` and `false` are accepted)
    # Default: false
    signoff: true

    # 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'

    # Token to use for pushing the commit. The default value won't trigger any workflows, you need to use a Personal Access Token for that.
    # Default: secrets.GITHUB_TOKEN
    token: ${{ secrets.GITHUB_TOKEN }}

Adding files:

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.
The script will not stop if one of the git commands fails. E.g.: if your command shows a "fatal: pathspec 'yourFile' did not match any files" error the action will go on.
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.

Deleting files:

You can delete files with the remove option: that runs a git rm command that will stage the files in the given path for removal. As with the add argument, you can use every option git rm allows (e.g. add --force to ignore .gitignore rules).
The script will not stop if one of the git commands fails. E.g.: if your command shows a "fatal: pathspec 'yourFile' did not match any files" error the action will go on.
You can also use JSON or YAML arrays (e.g. '["first", "second"]', "['first', 'second']") to make the action run multiple git rm 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.

Pushing:

By default the action runs the following command: git push origin ${branch input} --set-upstream. You can use the push input to modify this behavior, here's what you can set it to:

  • true: this is the default value, it will behave as usual.
  • false: this prevents the action from pushing at all, no git push command is run.
  • any other string:
    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).

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.

Tagging:

You can use the tag option to enter the arguments for a git add 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).

Outputs:

The action provides these outputs:

  • committed: whether the action has created a commit ('true' or 'false')
  • pushed: whether the action has pushed to teh remote('true' or 'false')
  • tagged: whether the action has created a tag ('true' or 'false')

For more info on how to use outputs, see "Context and expression syntax".

Examples:

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:

name: Lint source code
on: push

jobs:
  run:
    name: Lint with ESLint
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repo
        uses: actions/checkout@v2

      - name: Set up Node.js
        uses: actions/setup-node@v1
        with:
          node-version: 12.x

      - name: Install dependencies
        run: npm install

      - name: Update source code
        run: eslint "src/**" --fix

      - name: Commit changes
        uses: EndBug/add-and-commit@v6
        with:
          author_name: Your Name
          author_email: [email protected]
          message: 'Your commit message'
          add: '*.js'

If you need to run the action on a repository that is not located in $GITHUB_WORKSPACE, you can use the cwd option: the action uses a cd normal command, so the path should follow bash standards.

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@v2
        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@v6
        with:
          message: 'Add the very useful text file'
          add: '*.txt --force'
          cwd: './pathToRepo/'

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Federico Grandi

πŸ’» πŸ“–

Tor Egil Jacobsen

πŸ’»

Ivan Yelizariev

πŸ€”

jhhughes

πŸ›

Π”ΠΌΠΈΡ‚Ρ€ΠΈΠΉ ОкСаний

πŸ€”

Brahma Dev

πŸ›

Felix Rojo Lapalma

πŸ›

Robin Wijnant

πŸ› πŸ’»

Onilton Maciel

πŸ€”

Josh Soref

πŸ“–

ToMe25

πŸ’» πŸ€”

JonasJacobsUserspace

πŸ›

pvogt09

πŸ’»

Connor Clark

πŸ€”

Benedek Kozma

πŸ€” πŸ’»

Dustin Brown

πŸ›

Chris McIntosh

πŸ›

Kevin Saliou

πŸ€”

Joachim Jablon

πŸ€”

Tim Schwenke

πŸ€”

Possible Triangle

πŸ€”

This project follows the all-contributors specification. Contributions of any kind welcome!

License

This action is distributed under the MIT license, check the license for more info.

add-and-commit's People

Contributors

allcontributors[bot] avatar coffeegoddd avatar cyberbeni avatar dependabot[bot] avatar endbug avatar jsoref avatar kimuraz avatar pvogt09 avatar robinwijnant avatar tome25 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.