GithubHelp home page GithubHelp logo

endbug / add-and-commit Goto Github PK

View Code? Open in Web Editor NEW
1.0K 5.0 110.0 13.01 MB

:octocat: Automatically commit changes made in your workflow run directly to your repo

License: MIT License

TypeScript 99.71% JavaScript 0.29%
actions git git-add commit git-commit automation workflow git-rm lint github-actions

add-and-commit's Introduction

Add & Commit

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

Table of contents

Inputs

Add a step like this to your workflow:

- uses: EndBug/add-and-commit@v9 # 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: 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: [email protected]

    # 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: [email protected]

    # 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 <[email protected]>
    # - user_info -> Your Display Name <[email protected]>
    # - github_actions -> github-actions <email associated with the github logo>
    # 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'

Git arguments

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, and then used with simple-git.
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 for your workflow runs or by testing it directly with string-argv (RunKit demo): if each argument and option is parsed correctly you'll see an array where every string is an option or value.

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

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, you can also use JSON or YAML arrays to make the action run multiple git rm commands.

If you want deleted files to be auto-detected and committed, you can use the --no-ignore-removal/-A git arguments.

Pushing

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:

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

Creating a new branch

If you want the action to commit in a new branch, you can use the new_branch input.

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.

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

If you want to commit files "across different branches", here are two ways to do it:

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

Tagging

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).
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.
For more info on how git arguments are parsed, see the "Git arguments" section.

Outputs

The action provides these outputs:

  • committed: whether the action has created a commit ('true' or 'false')
  • commit_long_sha: the full SHA of the commit that has just been created
  • commit_sha: the short 7-character SHA of the commit that has just been created
  • pushed: whether the action has pushed to the remote ('true' or 'false')
  • tagged: whether the action has created a tag ('true' or 'false')
  • tag_pushed: whether the action has pushed a tag ('true' or 'false')

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

FAQs

Working with PRs

By default, when you use actions/checkout on a PR, it will checkout the head commit in a detached head state. If you want to make some changes, you have to checkout the branch the PR is coming from in the head repo.
You can set it up like this:

- uses: actions/checkout@v4
  with:
    repository: ${{ github.event.pull_request.head.repo.full_name }}
    ref: ${{ github.event.pull_request.head.ref }}

You can find the full docs for payloads of pull_request events here.

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.
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. You can try setting up the repo with your PAT, as explained in the "About tokens" paragraph of this section.

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.
If you wish to do so, you can use the step.if property, here's the docs.

About tokens

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 then you have to add the token there.
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.

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.

The commit from the action is not triggering CI!

That's because you're checking out the repo using the built-in GITHUB_TOKEN secret: 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.

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): this will make the resulting commit the same as if you made it yourself.
If you're using actions/checkout, check out their docs to see how to set your repo token.

About actions/checkout

The token you use when setting up the repo with this action will determine what token add-and-commit will use.
Some users reported that they were getting an error:

> fatal: could not read Username for 'https://github.com': No such device or address

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

Performance on large repos

By default, the action will fetch the repository before starting to work on it: this ensures that it can see the already existing refs.

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.

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

Examples

Different author/committer configurations

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.

on: push
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: EndBug/add-and-commit@v9
        with:
          default_author: github_actions

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:

- uses: EndBug/add-and-commit@v9
  with:
    message: Show GitHub Actions logo
    committer_name: GitHub Actions
    committer_email: [email protected]

- uses: EndBug/add-and-commit@v9
  with:
    message: Show GitHub logo
    committer_name: GitHub Actions
    committer_email: 41898282+github-actions[bot]@users.noreply.github.com

Automated linting

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@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@v9
        with:
          author_name: Your Name
          author_email: [email protected]
          message: 'Your commit message'
          add: '*.js'

Running the action in a different directory

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

Articles

Contributors โœจ

Thanks goes to these wonderful people (emoji key):

Federico Grandi
Federico Grandi

๐Ÿ’ป ๐Ÿ“–
Tor Egil Jacobsen
Tor Egil Jacobsen

๐Ÿ’ป
Ivan Yelizariev
Ivan Yelizariev

๐Ÿค”
jhhughes
jhhughes

๐Ÿ›
ะ”ะผะธั‚ั€ะธะน ะžะบะตะฐะฝะธะน
ะ”ะผะธั‚ั€ะธะน ะžะบะตะฐะฝะธะน

๐Ÿค”
Brahma Dev
Brahma Dev

๐Ÿ›
Felix Rojo Lapalma
Felix Rojo Lapalma

๐Ÿ›
Robin Wijnant
Robin Wijnant

๐Ÿ› ๐Ÿ’ป
Onilton Maciel
Onilton Maciel

๐Ÿค”
Josh Soref
Josh Soref

๐Ÿ“–
ToMe25
ToMe25

๐Ÿ’ป ๐Ÿค”
JonasJacobsUserspace
JonasJacobsUserspace

๐Ÿ›
pvogt09
pvogt09

๐Ÿ’ป
Connor Clark
Connor Clark

๐Ÿค”
Benedek Kozma
Benedek Kozma

๐Ÿค” ๐Ÿ’ป
Dustin Brown
Dustin Brown

๐Ÿ›
Chris McIntosh
Chris McIntosh

๐Ÿ›
Kevin Saliou
Kevin Saliou

๐Ÿค”
Joachim Jablon
Joachim Jablon

๐Ÿค”
Tim Schwenke
Tim Schwenke

๐Ÿค”
Possible Triangle
Possible Triangle

๐Ÿค”
Dominik Schilling
Dominik Schilling

๐Ÿค” ๐Ÿ“– ๐Ÿ’ป
rugk
rugk

๐Ÿ“–
Caleb Cushing
Caleb Cushing

๐Ÿ›
Eero Ruohola
Eero Ruohola

๐Ÿ› ๐Ÿค”
Vincent Chu
Vincent Chu

๐Ÿ›
Matt H
Matt H

๐Ÿ“– ๐Ÿค”
danielwerg
danielwerg

๐Ÿ“–
Oliver Kopp
Oliver Kopp

๐Ÿค”
Glenn Ko
Glenn Ko

๐Ÿค”
Drew Wells
Drew Wells

๐Ÿค”
Javier Segovia Cรณrdoba
Javier Segovia Cรณrdoba

๐Ÿค”
Darylgolden
Darylgolden

๐Ÿ›
mcargille
mcargille

๐Ÿ› ๐Ÿ’ป
secondman
secondman

๐Ÿ“–
Chris Mc
Chris Mc

๐Ÿ“–
Namya LG
Namya LG

๐Ÿ“–
Janne Julkunen
Janne Julkunen

๐Ÿค”
Joshua Chen
Joshua Chen

๐Ÿ›
Akimo
Akimo

๐Ÿ“–
Julien Bouquillon
Julien Bouquillon

๐Ÿ“–
Aviv Peled
Aviv Peled

๐Ÿ›
Devin Buhl
Devin Buhl

๐Ÿ›
Erek Speed
Erek Speed

๐Ÿ›
Alexander Kachkaev
Alexander Kachkaev

๐Ÿ›
Manuel Rauber
Manuel Rauber

๐Ÿ’ป
Gabor Greif
Gabor Greif

๐Ÿšง ๐Ÿ“–
Keith Fung
Keith Fung

๐Ÿ“–
Jonah Lawrence
Jonah Lawrence

๐Ÿ› ๐Ÿ’ป
Azeem Bande-Ali
Azeem Bande-Ali

๐Ÿ“–
Viacheslav Kudinov
Viacheslav Kudinov

๐Ÿ›ก๏ธ
justanotheranonymoususer
justanotheranonymoususer

๐Ÿ›
Christophe Dervieux
Christophe Dervieux

๐Ÿ“–
Andreas Deininger
Andreas Deininger

๐Ÿ“–
Michael Droettboom
Michael Droettboom

๐Ÿšง

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

Additional credits

This action is inspired by git-auto-commit-action by Stefan Zweifel.

License

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

add-and-commit's People

Contributors

akimon658 avatar allcontributors[bot] avatar azeemba avatar cderv avatar coffeegoddd avatar cyberbeni avatar danielwerg avatar deining avatar denvercoder1 avatar dependabot[bot] avatar endbug avatar ggreif avatar jsoref avatar kimuraz avatar manuelrauber avatar mcargille avatar ocean90 avatar pvogt09 avatar robinwijnant avatar rugk avatar tome25 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

add-and-commit's Issues

Ts-only not working

##[error]Error: warning: Pulling without specifying how to reconcile divergent branches is
discouraged. You can squelch this message by running one of the following
commands sometime before your next pull:

It seems like EndBug/add-and-commit@ts-only does not work yet.

Originally posted by @bmartinez287 in #53 (comment)

Changes Not Committed Due to Lack of Write Access

You can check out this pull request (TheRenegadeCoder/sample-programs-website#375), but basically I generate images during pull requests. It works fine when I make the pull request, but it doesn't seem to be working for someone else. I gave them write access, but it still won't commit. I suspect it has something to do with the fact that they're on a fork, but again... I don't really know what's happening.

Here's the workflow file:

# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
  pull_request:
    branches:
      - master

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v2
      - uses: actions/setup-python@v2
        with:
          python-version: '3.8'

      # Runs a single command using the runners shell
      - name: Install Image Titler
        run: pip install image-titler

      # Runs a set of commands using the runners shell
      - name: Generate Images
        run: |
          sources=assets/sources/
          images=assets/images/
          logo=icon-small.png
          for file in "$sources"*
          do
            image-titler --path "$file" --output "$images" --logo "$images$logo"
            filename=$(basename "$file")
            edit=$(cd "$images" && ls -t | head -n1)
            mv "$images$edit" "$images$filename" 
          done
      
      - name: Commit Changes
        uses: EndBug/add-and-commit@v5 # You can change this to use a specific version
        with:
          # The message for the commit
          # Default: 'Commit from GitHub Actions'
          message: 'Generated featured images from sources'

        env:
          # This is necessary in order to push a commit to the repo
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Leave this line unchanged

I recently changed it to commit as me through the author name and email options, but I'm not sure if that will change anything. Ultimately, here's the log:

2020-10-24T18:05:58.1644820Z ##[group]Run EndBug/add-and-commit@v5
2020-10-24T18:05:58.1645104Z with:
2020-10-24T18:05:58.1645382Z   message: Generated featured images from sources
2020-10-24T18:05:58.1645652Z   add: .
2020-10-24T18:05:58.1645818Z   cwd: .
2020-10-24T18:05:58.1645965Z env:
2020-10-24T18:05:58.1646275Z   pythonLocation: /opt/hostedtoolcache/Python/3.8.6/x64
2020-10-24T18:05:58.1646709Z   LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.8.6/x64/lib
2020-10-24T18:05:58.1648545Z   GITHUB_TOKEN: ***
2020-10-24T18:05:58.1648797Z ##[endgroup]
2020-10-24T18:05:58.2126836Z Running in /home/runner/work/sample-programs-website/sample-programs-website
2020-10-24T18:05:58.2136841Z > Unable to get commit from workflow event: trying with the GitHub API...
2020-10-24T18:05:58.4029890Z > Using 'Stuart Irwin <[email protected]>' as author.
2020-10-24T18:05:58.4030529Z > Using "Generated featured images from sources" as commit message.
2020-10-24T18:05:58.4031219Z > Running for a PR, the action will use 'master' as ref.
2020-10-24T18:05:58.4035676Z ##[group]Internal logs
2020-10-24T18:05:58.4037460Z > Staging files...
2020-10-24T18:05:58.4039492Z > Adding files...
2020-10-24T18:05:59.0066683Z > No files to remove.
2020-10-24T18:05:59.0067187Z > Checking for uncommitted changes in the git working tree...
2020-10-24T18:05:59.0124287Z > Found 9 changed files.
2020-10-24T18:05:59.4908043Z FetchSummary {
2020-10-24T18:05:59.4909472Z   raw: 'From https://github.com/TheRenegadeCoder/sample-programs-website\n' +
2020-10-24T18:05:59.4910353Z     ' * [new branch]      master     -> origin/master\n',
2020-10-24T18:05:59.4911220Z   remote: 'https://github.com/TheRenegadeCoder/sample-programs-website',
2020-10-24T18:05:59.4912159Z   branches: [ { name: 'master', tracking: 'origin/master' } ],
2020-10-24T18:05:59.4912523Z   tags: []
2020-10-24T18:05:59.4912720Z }
2020-10-24T18:05:59.4913019Z > Switching/creating branch...
2020-10-24T18:05:59.5033444Z A	assets/images/baklava-in-c.jpg
2020-10-24T18:05:59.5034711Z A	assets/images/baklava-in-kotlin.jpg
2020-10-24T18:05:59.5035610Z A	assets/images/file-io-in-every-language.jpg
2020-10-24T18:05:59.5036485Z A	assets/images/fizz-buzz-in-befunge.jpg
2020-10-24T18:05:59.5037264Z A	assets/images/fizz-buzz-in-java.jpg
2020-10-24T18:05:59.5038012Z A	assets/images/fizz-buzz-in-lisp.jpg
2020-10-24T18:05:59.5038813Z A	assets/images/reverse-a-string-in-c.jpg
2020-10-24T18:05:59.5039825Z A	assets/images/reverse-a-string-in-every-language.jpg
2020-10-24T18:05:59.5040885Z A	assets/images/reverse-a-string-in-python.jpg
2020-10-24T18:05:59.5041792Z Branch 'master' set up to track remote branch 'master' from 'origin'.
2020-10-24T18:05:59.5042189Z 
2020-10-24T18:05:59.5042570Z > Pulling from remote...
2020-10-24T18:05:59.6287177Z FetchSummary { raw: '', remote: null, branches: [], tags: [] }
2020-10-24T18:05:59.7638843Z PullSummary {
2020-10-24T18:05:59.7639670Z   remoteMessages: RemoteMessageSummary { all: [] },
2020-10-24T18:05:59.7640204Z   created: [],
2020-10-24T18:05:59.7640542Z   deleted: [],
2020-10-24T18:05:59.7640848Z   files: [],
2020-10-24T18:05:59.7641216Z   deletions: {},
2020-10-24T18:05:59.7641572Z   insertions: {},
2020-10-24T18:05:59.7642011Z   summary: { changes: 0, deletions: 0, insertions: 0 }
2020-10-24T18:05:59.7642409Z }
2020-10-24T18:05:59.7643217Z > Re-staging files...
2020-10-24T18:05:59.7708578Z > Creating commit...
2020-10-24T18:05:59.7799416Z CommitSummary {
2020-10-24T18:05:59.7800345Z   branch: 'master',
2020-10-24T18:05:59.7801024Z   commit: 'a5dfd6c',
2020-10-24T18:05:59.7801818Z   summary: { changes: 9, insertions: 0, deletions: 0 },
2020-10-24T18:05:59.7802387Z   author: null
2020-10-24T18:05:59.7802821Z }
2020-10-24T18:05:59.7803536Z > No tag info provided.
2020-10-24T18:05:59.7804075Z > Pushing commit to repo...
2020-10-24T18:05:59.9026378Z ##[error]Error: Pushing to https://github.com/TheRenegadeCoder/sample-programs-website
remote: Permission to TheRenegadeCoder/sample-programs-website.git denied to github-actions[bot].
fatal: unable to access 'https://github.com/TheRenegadeCoder/sample-programs-website/': The requested URL returned error: 403

2020-10-24T18:05:59.9038586Z ##[endgroup]
2020-10-24T18:05:59.9049301Z ##[error]Error: Pushing to https://github.com/TheRenegadeCoder/sample-programs-website
remote: Permission to TheRenegadeCoder/sample-programs-website.git denied to github-actions[bot].
fatal: unable to access 'https://github.com/TheRenegadeCoder/sample-programs-website/': The requested URL returned error: 403

ref not working

The docs:

    # Name of the branch to use, if different from the one that triggered the workflow
    # Default: the branch that triggered the workflow (from GITHUB_REF)
    ref: 'someOtherBranch'

The reality:

##[warning]Unexpected input(s) 'ref', valid inputs are ['add', 'author_name', 'author_email', 'cwd', 'force', 'message', 'remove']

Also, I thought ref should be set to the branch I want the commit to be pushed, but reading the docs and the code, I'm not really sure what it's supposed to do. What I wanted is to push the change to a different branch than the one it's running on.

refusing to allow a GitHub App to create or update workflow `.github/workflows/rating-chart.yml` without `workflows` permission

Thanks for the repo. I am using this to add and commit my README.md using workflows ... I am able to successfully commit and push README.md however, I am not able to push workflows YAML file which fails with a permission issue, even though commit and add works fine here. The issue is :

! [remote rejected] master -> master (refusing to allow a GitHub App to create or update workflow .github/workflows/rating-chart.yml without workflows permission)

I have tried adding a secret environment variable of a new token with workflow scope as well. There seems to be no improvement (I am guessing workflow scope in a token vs workflow permission are two separate things, but I may be wrong)

Can you let me know how this can be resolved.
Here is my repo - https://github.com/sciencepal/sciencepal
Here is a sample workflow (Check internal logs of add-and-commit job step) - https://github.com/sciencepal/sciencepal/runs/984418665

Create a Pull Request

Hi, I love this action, but I can't use it on one of my repos, because the master branch there is protected. As it's protected for good reasons but I'd still like to automate some of the repo content, I thought whether I could add-and-commit-and-send-pr. Would something like this be a responsibility of this action or it's out of the scope of the project and I should look at other actions?

Receive spawn UNKNOWN in windows-latest

Error

Error: spawn UNKNOWN
at ChildProcess.spawn (internal/child_process.js:394:11)
at spawn (child_process.js:540:9)
at Object.execFile (child_process.js:224:17)
at Object.131 (D:\a_actions\EndBug\add-and-commit\v4\lib\index.js:1:592)
at webpack_require (D:\a_actions\EndBug\add-and-commit\v4\lib\index.js:1:154)
at startup (D:\a_actions\EndBug\add-and-commit\v4\lib\index.js:1:291)
at module.exports.87 (D:\a_actions\EndBug\add-and-commit\v4\lib\index.js:1:323)
at Object. (D:\a_actions\EndBug\add-and-commit\v4\lib\index.js:1:333)
##[error]spawn UNKNOWN
at Module._compile (internal/modules/cjs/loader.js:959:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10) {
errno: 'UNKNOWN',
code: 'UNKNOWN',
syscall: 'spawn'

The following system:

Operating System
Microsoft Windows Server 2019
10.0.17763
Datacenter
Virtual Environment
Environment: windows-2019
Version: 20200630.0

ESling not found

Hi !
I ve tried your add with ESLint , but it says
Run eslint "**.html" --fix /home/runner/work/_temp/bbd2754b-0c9c-4db7-8c11-3e0101871637.sh: line 1: eslint: command not found Error: Process completed with exit code 127.

Do you have an idea, please ?

Ability to trigger "on push" actions

I have a separate workflow that normally runs any time a change is pushed to the repo. It looks like this:

on:
  push:
    branches:
      - master
    paths:
      - "**"

I expected changes committed by EndBug/add-and-commit@v4 to trigger the same behavior, but they do not.

Change how Github token is retrieved

It works fine for me without the token: https://github.com/Cyberbeni/ShowTouches/runs/1579363839?check_suite_focus=true#step:5:63

There is also this similar action that gets GITHUB_TOKEN like this: https://github.com/peter-evans/create-pull-request/blob/master/action.yml#L4-L6

Edit: it works without the token because I checked out the repo before and that also got the token the same way as the other action: https://github.com/actions/checkout/blob/main/action.yml#L12-L24

Changes are not committed

In version 4, the local changes were committed, but in v5 it is not committed and it tries to pull with the dirty local directory. The changes from the previous configuration were the version and I specified branch instead of ref. Any idea what could be my issue?

This is the workflow:

---
name: Test
on: push
jobs:
  build-linux:
    runs-on: runner
    name: Test
    steps:
      - name: Fetch
        uses: actions/checkout@v2
        with:
          path: netrc
          ref: netrc
      - name: modify
        run: echo test >> netrc/tokens
      - name: Commit changes
        uses: EndBug/add-and-commit@v5
        with:
          branch: "netrc"
          cwd: "netrc"
          author_name: <my name>
          author_email: <my email>
          message: "Save"
          add: "tokens"
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

and here is the internal log:

  > Staging files...
  > Adding files...
  > No files to remove.
  > Checking for uncommitted changes in the git working tree...
  > Found 1 changed files.
  FetchSummary {
    raw: 'From https://github.com/sot/test-actions\n' +
      '   16d867b..daa2b2b  master     -> origin/master\n',
    remote: 'https://github.com/sot/test-actions',
    branches: [],
    tags: []
  }
  > Switching/creating branch...
  M	tokens
  Your branch is up to date with 'origin/netrc'.
  
  > Pulling from remote...
  FetchSummary { raw: '', remote: null, branches: [], tags: [] }
  Error: Error: error: cannot pull with rebase: Your index contains uncommitted changes.
  error: please commit or stash them.

fatal: invalid refspec '/merge'

When running this on a pull-request I get the following error.

fatal: invalid refspec '/merge'

Another issue is that even if it fails it reports as successful.

Action doesn't support PRs

- name: Commit new expectations
      if: failure() && github.actor != 'patrickhulce' && github.actor != 'brendankenny'
      uses: EndBug/add-and-commit@v4
      with:
        cwd: ${{ github.workspace }}/lighthouse
        add: lighthouse-core/scripts/chromium-web-tests/webtests
        message: update webtest expectations
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

results

2020-07-30T17:18:06.7641560Z ##[group]Run EndBug/add-and-commit@v4
2020-07-30T17:18:06.7641780Z with:
2020-07-30T17:18:06.7641920Z   cwd: /Users/runner/work/lighthouse/lighthouse/lighthouse
2020-07-30T17:18:06.7642060Z   add: lighthouse-core/scripts/chromium-web-tests/webtests
2020-07-30T17:18:06.7642190Z   message: update webtest expectations
2020-07-30T17:18:06.7642310Z   force: false
2020-07-30T17:18:06.7642430Z   signoff: false
2020-07-30T17:18:06.7642520Z env:
2020-07-30T17:18:06.7643020Z   DEPOT_TOOLS_PATH: /Users/runner/work/lighthouse/lighthouse/depot-tools
2020-07-30T17:18:06.7643180Z   DEVTOOLS_PATH: /Users/runner/work/lighthouse/lighthouse/devtools-frontend
2020-07-30T17:18:06.7643320Z   BLINK_TOOLS_PATH: /Users/runner/work/lighthouse/lighthouse/blink_tools
2020-07-30T17:18:06.7643660Z   PATH: /Users/runner/work/lighthouse/lighthouse/depot-tools:/Users/runner/.cargo/bin:/usr/local/lib/ruby/gems/2.6.0/bin:/usr/local/opt/ruby/bin:/usr/local/opt/curl/bin:/usr/local/bin:/usr/local/sbin:/Users/runner/bin:/Users/runner/.yarn/bin:/usr/local/go/bin:/Users/runner/Library/Android/sdk/tools:/Users/runner/Library/Android/sdk/platform-tools:/Users/runner/Library/Android/sdk/ndk-bundle:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/usr/bin:/bin:/usr/sbin:/sbin:/Users/runner/.dotnet/tools:/Users/runner/.ghcup/bin:/Users/runner/hostedtoolcache/stack/2.3.1/x64
2020-07-30T17:18:06.7645500Z   GITHUB_TOKEN: ***
2020-07-30T17:18:06.7645680Z ##[endgroup]
2020-07-30T17:18:06.8307770Z ##[warning]Unable to fetch author info: couldn't find commit.
2020-07-30T17:18:06.8310040Z Using 'Add & Commit Action <[email protected]>' as author.
2020-07-30T17:18:07.0264680Z ##[group]Internal logs
2020-07-30T17:18:07.0266530Z Running in /Users/runner/work/lighthouse/lighthouse/lighthouse.
2020-07-30T17:18:07.0267290Z Staging files...
2020-07-30T17:18:07.0818220Z Checking for uncommitted changes in the git working tree...
2020-07-30T17:18:13.0685140Z From https://github.com/GoogleChrome/lighthouse
2020-07-30T17:18:13.0703980Z  * [new branch]      520viewer               -> origin/520viewer
2020-07-30T17:18:13.0723380Z  * [new branch]      78a1a8f                 -> origin/78a1a8f
... snip ...
2020-07-30T17:18:13.9081000Z Creating branch...
2020-07-30T17:18:13.9081220Z Switching branch...
2020-07-30T17:18:13.9082160Z M	lighthouse-core/scripts/chromium-web-tests/webtests/http/tests/devtools/lighthouse/lighthouse-successful-run-expected.txt
2020-07-30T17:18:13.9082410Z Pulling from remote...
2020-07-30T17:18:13.9082610Z Resetting files...
2020-07-30T17:18:13.9082830Z Unstaged changes after reset:
2020-07-30T17:18:13.9084080Z M	lighthouse-core/scripts/chromium-web-tests/webtests/http/tests/devtools/lighthouse/lighthouse-successful-run-expected.txt
2020-07-30T17:18:13.9084310Z Adding files...
2020-07-30T17:18:13.9084500Z Removing files...
2020-07-30T17:18:13.9084660Z Creating commit...
2020-07-30T17:18:13.9084920Z [1176/merge eb1d6c829] update webtest expectations
2020-07-30T17:18:13.9085880Z  1 file changed, 2 insertions(+), 2 deletions(-)
2020-07-30T17:18:13.9086140Z Tagging commit...
2020-07-30T17:18:13.9086360Z Pushing commits to repo...
... snip ...
2020-07-30T17:18:13.9211750Z Switched to branch '1176/merge'
2020-07-30T17:18:13.9212410Z warning: Pulling without specifying how to reconcile divergent branches is
2020-07-30T17:18:13.9212810Z discouraged. You can squelch this message by running one of the following
2020-07-30T17:18:13.9213080Z commands sometime before your next pull:
2020-07-30T17:18:13.9213160Z 
2020-07-30T17:18:13.9213380Z   git config pull.rebase false  # merge (the default strategy)
2020-07-30T17:18:13.9213570Z   git config pull.rebase true   # rebase
2020-07-30T17:18:13.9214200Z   git config pull.ff only       # fast-forward only
2020-07-30T17:18:13.9214290Z 
2020-07-30T17:18:13.9214960Z You can replace "git config" with "git config --global" to set a default
2020-07-30T17:18:13.9215670Z preference for all repositories. You can also pass --rebase, --no-rebase,
2020-07-30T17:18:13.9216380Z or --ff-only on the command line to override the configured default per
2020-07-30T17:18:13.9216630Z invocation.
2020-07-30T17:18:13.9216750Z 
2020-07-30T17:18:13.9216960Z There is no tracking information for the current branch.
2020-07-30T17:18:13.9217240Z Please specify which branch you want to merge with.
2020-07-30T17:18:13.9217830Z See git-pull(1) for details.
2020-07-30T17:18:13.9217970Z 
2020-07-30T17:18:13.9218150Z     git pull <remote> <branch>
2020-07-30T17:18:13.9218220Z 
2020-07-30T17:18:13.9218500Z If you wish to set tracking information for this branch you can do so with:
2020-07-30T17:18:13.9218630Z 
2020-07-30T17:18:13.9219170Z     git branch --set-upstream-to=origin/<branch> 1176/merge
2020-07-30T17:18:13.9219330Z 
2020-07-30T17:18:17.3261630Z remote: 
2020-07-30T17:18:17.3263040Z remote: Create a pull request for '1176/merge' on GitHub by visiting:        
2020-07-30T17:18:17.3263530Z remote:      https://github.com/GoogleChrome/lighthouse/pull/new/1176/merge        
2020-07-30T17:18:17.3263770Z remote: 
2020-07-30T17:18:17.3293910Z To https://github.com/GoogleChrome/lighthouse
2020-07-30T17:18:17.3294840Z  * [new branch]          1176/merge -> 1176/merge
2020-07-30T17:18:17.3367900Z Branch '1176/merge' set up to track remote branch '1176/merge' from 'origin'.
2020-07-30T17:18:17.3371130Z Pushing tags to repo...
2020-07-30T17:18:17.6857510Z Everything up-to-date
2020-07-30T17:18:17.6881390Z Branch '1176/merge' set up to track remote branch '1176/merge' from 'origin'.

ref https://github.com/GoogleChrome/lighthouse/runs/928694099?check_suite_focus=true#step:20:332

It seems that GITHUB_REF is set to 1176/merge, a branch that GitHub made which merges master into the PR branch before running the tests. If GitHub does that, how can this action commit to the PR branch directly?

Can't push to protected branch

May not be a bug but I can't figure it out. How do I grant access to action runner to be able to push to protected branch?
What's interesting is that error indicates it's pull request which it is not.
Describe the bug
So if branch has any of given protections:

  • Require pull request reviews before merging
  • Status checks found in the last week for this repository
    it fails to push the changes.

Workflow used

        run: ./docker.sh vendor/bin/php-cs-fixer fix
      - name: Commit fixes
        uses: EndBug/add-and-commit@v5
        with:
          author_name: Github Actions
          author_email: [email protected]
          message: '[auto] php-cs-fixer'
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expected behavior
To push the changes

Logs

Pushing commit to repo...
Error: Error: Pushing to XXXX
POST git-receive-pack (683 bytes)
remote: error: GH006: Protected branch update failed for refs/heads/master.
remote: error: At least 1 approving review is required by reviewers with write access.
error: failed to push some refs to XXXX

Commit all changed files?

As I understand the code below, using pattern: "*" will try to add files from .git repository

else find $INPUT_PATH -name "$INPUT_PATTERN" | while read x; do git add $x; done

Support collections as values for `add`, `rm` and so on

Hello, I think it would improve usability if we could use multiple git add commands with within a single action. For example:

- name: Commit changes
      uses: EndBug/add-and-commit@v5
      with:
        author_name: Your Name
        author_email: [email protected]
        message: "Your commit message"
        add:
            - "something/file.txt"
            - "crazy/*"
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

This wouldn't even be a breaking change if both collections and scalars are supported.

At the moment it is possible to to it like this git add file-1 file-2 file-3, which translates to add: file-1 file-2 file-3, but what if the path has a space in it?

ENOBUFS error when the to be committed files exceed 1MB

I am trying to commit the docs folder generated in a previous step. This throws the following error after 1s on execFileSync. I found that ENOBUFS is thrown when the maxBuffer (1MB by default) gets exceeded.

This happens to be the case here. When only committing a single HTML file from the docs folder, the action succeeds as expected.

Possible solution
The buffer size can be specified as an option with execFileSync. More in the docs of Node.js. Setting an increased maxBuffer might solve the issue.

Run EndBug/add-and-commit@v4
  with:
    add: docs
    author_name: Github Workflow Bot
    author_email: [email protected]
    message: build docs and dist
    cwd: .
    force: false
  env:
    GITHUB_TOKEN: ***
Using 'Github Workflow Bot <[email protected]>' as author.
Error: spawnSync /home/runner/work/_actions/EndBug/add-and-commit/v4/lib/entrypoint.sh ENOBUFS
    at Object.spawnSync (internal/child_process.js:1041:20)
    at spawnSync (child_process.js:607:24)
    at Object.execFileSync (child_process.js:634:15)
    at Object.131 (/home/runner/work/_actions/EndBug/add-and-commit/v4/lib/index.js:1:576)
    at __webpack_require__ (/home/runner/work/_actions/EndBug/add-and-commit/v4/lib/index.js:1:154)
    at startup (/home/runner/work/_actions/EndBug/add-and-commit/v4/lib/index.js:1:291)
    at module.exports.87 (/home/runner/work/_actions/EndBug/add-and-commit/v4/lib/index.js:1:323)
    at Object.<anonymous> (/home/runner/work/_actions/EndBug/add-and-commit/v4/lib/index.js:1:333)
    at Module._compile (internal/modules/cjs/loader.js:959:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)

My workflow yml:

name: Build and release

on:
  push:
    # branches:
    #   - master
    paths-ignore:
      - 'docs/**'

jobs:
  node:
    name: Node 12
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Sync packages with cache
        uses: actions/cache@v1
        with:
          path: ./node_modules
          key: ${{ runner.os }}-node_modules-${{ hashFiles('**/yarn.lock') }}
          restore-keys: ${{ runner.os }}-node_modules-

      - name: Install packages
        run: yarn install --frozen-lockfile

      - name: Build the docs
        run: yarn document

      - name: Commit docs
        uses: EndBug/add-and-commit@v4
        with:
          add: 'docs'
          author_name: Github Workflow Bot
          author_email: [email protected]
          message: 'build docs'
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Run the action from a different directory

Hi,

I am trying to use this Github Actions to push a VuePress website from a source branch to a master branch.
The website is generated using a regular npm run build script and the build outputs to ./docs/.vuepress/dist.

./ here is the root of my repo.

I would like to only push files inside of this directory to the master, not the whole path.

The problem is that currently the action is running git add from the root folder, instead of running it from .docs/.vuepress/dist... resulting in having the full path pushed to the master branch.

As for now Github Actions working-directory can't be used in addition with the uses command, it would be nice to have a directory option to tell the action where to run the git add command.

Here is my worflow:

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      (...)
      - name: Commit changes
        uses: EndBug/add-and-commit@master
        with:
          branch: "master"
          add: "docs/.vuepress/dist --force"
          message: "Deploy docs"

Here is a workflow we could have:

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      (...)
      - name: Commit changes
        uses: EndBug/add-and-commit@master
        with:
          branch: "master"
          directory: "docs/.vuepress/dist" <--- the action will run "cd [directory]" command before running
          add: ". --force"
          message: "Deploy docs"

You can have a look at the current VuePress deploy script here:
https://vuepress.vuejs.org/guide/deploy.html#github-pages

Thanks for your feedback! ๐Ÿ˜‰

v2.3.3 appears to be broken

Hi,

The latest update, v2.3.3, appears to have broken the action from the previous version as I am now seeing this in my workflow log instead of changes being committed:

Switching branch...
Switched to branch 'master'
M	addon/install.rdf
M	updates.json
Pulling from remote...
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> master

Also, it does not cause the workflow step to error either so the workflow appears to have completed successfully even though the changes were not applied back to the remote/master

Pinning to v2.3.2 has the step working perfectly fine once again (and has stopped me pulling my hair out thinking it was something I'd done seeing as I'm new to github workflows ;-p )

[Request] Add option to delete files

I know that it can be cleared using command like this - run: git rm delete_me.txt.
But syntax of this action is not full human understandable and need to know git commands.

Request is to add clear option. I think this simple action can close many issues and cases when needed to fully recreate destination folder/repository. And make code more simple and clear.

This is not functionality issue, but syntax and clean code.

PS: And documentation after that will be more simple too. No need big example of how to clean. Just one new option.

Error: could not read Username for 'https://github.com': No such device or address

I get an error trying to use this

Run EndBug/add-and-commit@v5
  with:
    message: [ESLint] Auto formatting.
    add: *.js
    cwd: .
  env:
    GITHUB_TOKEN: ***
Running in /home/runner/work/actions-test/actions-test
> Using 'WilsontheWolf <[email protected]>' as author.
> Using "[ESLint] Auto formatting." as commit message.
Internal logs
  > Staging files...
  > Adding files...
  > No files to remove.
  > Checking for uncommitted changes in the git working tree...
  > Found 1 changed files.
  FetchSummary { raw: '', remote: null, branches: [], tags: [] }
  > Switching/creating branch...
  M	index.js
  Branch 'master' set up to track remote branch 'master' from 'origin'.
  
  > Pulling from remote...
  FetchSummary { raw: '', remote: null, branches: [], tags: [] }
  PullSummary {
    remoteMessages: RemoteMessageSummary { all: [] },
    created: [],
    deleted: [],
    files: [],
    deletions: {},
    insertions: {},
    summary: { changes: 0, deletions: 0, insertions: 0 }
  }
  > Re-staging files...
  > Creating commit...
  CommitSummary {
    branch: 'master',
    commit: '84f00c4',
    summary: { changes: 1, insertions: 3, deletions: 3 },
    author: null
  }
  > No tag info provided.
  > Pushing commit to repo...
  Error: Error: Pushing to https://github.com/WilsontheWolf/actions-test
  fatal: could not read Username for 'https://github.com': No such device or address
  
Error: Error: Pushing to https://github.com/WilsontheWolf/actions-test
fatal: could not read Username for 'https://github.com': No such device or address

file
I'm not sure what I'm doing wrong.

Action creates a .netrc file in home directory

In my setup, I am using a runner on premises. This runner does a couple other things. I included this action on a workflow I sent to that runner, and a side effect of the action is a .netrc file in the home directory of the user running the github runner (overwriting a previous .netrc in the same place). The action configuration is nothing special:

      - name: Commit changes
        uses: EndBug/add-and-commit@v4
        with:
          ref: "test"
          cwd: "test"
          author_name: <my name>
          author_email: <my email>
          message: "Save"
          add: "docs"
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

The test directory contains the test branch of the repository, and was checked out using Github's actions/checkout.

To convince myself that this action was responsible, I tried with a few different values for GITHUB_TOKEN (setting it to other valid github tokens in my secrets list). That token always ended up in the .netrc file. Needless to say, this behavior is a deal breaker.

I don't know what more information to give you. You can replicate it by using this on your own runner, and checking that a .netrc is created.

Force push

This is not a bug report but a simple question.
Is it possible to tell the action to force push?

v5 is not released

Example from README

- uses: EndBug/add-and-commit@v5

But on github actions

image

Failure to push isn't considered an error.

In case pushing changes fails (most likely due to incorrect permissions) the action and workflow is considered successful.
I expected it to cause a failure.

  Tagging commit...
  Pushing commits to repo...
  remote: Permission to karliss/github-integration-test.git denied to github-actions[bot].
  fatal: unable to access 'https://github.com/karliss/github-integration-test/': The requested URL returned error: 403
  Pushing tags to repo...
  remote: Permission to karliss/github-integration-test.git denied to github-actions[bot].
  fatal: unable to access 'https://github.com/karliss/github-integration-test/': The requested URL returned error: 403

Avoid workflow get launched after commit in a loop !

Describe the bug
I am using EndBug/add-and-commit@v5 but it launches a loop of Github Actions because, everytime there is a change the workflow get launched.

There is no support for that, and it looks like every body is gonna have the same issue.

Workflow used

name: Workflow branch master
on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master

jobs:
  build:
    name: Build and push image
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          token: ${{ secrets.REPO_TOKEN }}
      - name: Upgrade the version
        run: |
          VERSION=$(grep -oP '(?<=latest-)[0-9]+' ./.github/workflows/build-and-push-image-to-registry.yaml)
          OLD_VERSION=$VERSION
          NEW_VERSION=$(($VERSION + 1))
          sed -i "s/latest-$OLD_VERSION/latest-$NEW_VERSION/g" ./scaleway/values.yaml
          sed -i "s/latest-$OLD_VERSION/latest-$NEW_VERSION/g" ./.github/workflows/build-and-push-image-to-registry.yaml
      - name: Commit changes
        uses: EndBug/add-and-commit@v5
        with:
          message: "Robot version upgrade"
          add: "."
        env:
          GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }}

Expected behavior
I wanna launch this workflow only if commit message is Robot version upgrade

Question: pull from main - push to otherbranch?

Use case:
I have a front-end (Angular/React) and a backend repository. When the CI is building the front-end, the result of the build folder needs to be committed to the /static directory of the backend repo. With your contribution I came close - love it.
The last hurdle is the error:

** Error: warning: Pulling without specifying how to reconcile divergent branches is discouraged **

which AFAIK stems from the fact that I checkout master from backend and try to push to (the non-existing) branch ui-contribution. Is there a way I can push to a new (or eventually existing) branch. -u --force might do the trick, but where to put in in the YAML. My stuff so far:

name: Reconcile front and backend

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  buildui:
    name: Building UI
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Backend
        uses: actions/checkout@v2
        with:
          repository: acme/backend
          token: ${{secrets.UI_PUSH_TOKEN }}
          ref: main
          path: backend
      - name: Checkout UI
        uses: actions/checkout@v2
      - name: Deploy NodeJS
        uses: actions/setup-node@v1
        with:
          node-version: "12.x"
      - run: npm install
      - run: npm run build --if present
      - run: npm test
      - name: Send them back
        uses: EndBug/add-and-commit@v5
        with:
          cwd: "./backend"
          branch: "ui-commit"
          message: "[Auto-commit] from UI"
        env:
          GITHUB_TOKEN: ${{secrets.UI_PUSH_TOKEN }}

Love your work!

From docker to node

Hi

My fork of your repository is rewritten as a node-artifact and do not need any Dockerfile. However, my GitHub workflow fails when using the node-branch (I also tried the master branch with docker). The failure is caused by the folder node_modules being ignored: https://github.com/jactor-rises/add-and-commit/runs/345587672

Is this a suspected failure and has something todo with the default pattern?

Default secret name is invalid

GitHub wont allow a Secret named GITHUB_TOKEN, it complains Failed to add secret. Name is invalid.

Then the action complains:

/Users/runner/work/_actions/EndBug/add-and-commit/v4/lib/entrypoint.sh: line 11: GITHUB_TOKEN: unbound variable

Pushing commits to repo...
  fatal: could not read Username for 'https://github.com': Device not configured
Pushing tags to repo...
  fatal: could not read Username for 'https://github.com': Device not configured

And it wont commit nor push.
Would be nice to change the default Secret name.

Can't find commit when triggering on release publish

When working on a pipeline that is triggered by a release publish:

on:
  release:
    types: [ published ]

I get the following error:

Unable to get commit from workflow event: trying with the GitHub API...
Error: Request failed with status code 404
    at createError (/home/runner/work/_actions/EndBug/add-and-commit/v4.4.0/lib/index.js:1:428)
    at settle (/home/runner/work/_actions/EndBug/add-and-commit/v4.4.0/lib/index.js:1:31578)

It seems like the latest changes have broken this functionality. I pinned the library to v4.3.0 and was able to run successfully.

Specify branch name

On scheduled workflow it is not possible to run add-and-commit against a specific branch since it relies on ${GITHUB_REF}.

schedule always use the last commit on default branch.

on:
  schedule:
    - cron: "50 10,17,20,23 * * *"

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
      with:
        ref: gh-pages # a custom branch

    - name: Commit changes
      uses: EndBug/add-and-commit@v4
      with:
        message: "Updated file"
        add: "file.csv"
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

I tried passing GITHUB_REF: refs/heads/gh-pages in env, but it didn't work

Github errors when pushing a second PR

It worked for the first PR I made but then it kept erroring out.

Run EndBug/add-and-commit@v4
Unable to get commit from workflow event: trying with the GitHub API...
Using 'Bernardo Martinez <[email protected]>' as author.
Running for a PR, the action will use 'bmartinez287-particle' as ref.
Internal logs
error: failed to push some refs to 'https://github.com/UTCWeb/particle'
Task completed.

Here is the config file

`name: Node.js CI

on:
  push:
    branches: [ develop ]
  pull_request:
    branches: [ develop ]

jobs:
  build:

    runs-on: ubuntu-latest
strategy:
  matrix:
    node-version: [12.x, 14.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
  uses: actions/setup-node@v1
  with:
    node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build:drupal --if-present
- run: npm run build:pl --if-present
- name: Commit changes
  uses: EndBug/add-and-commit@v4
  with:
    author_name: Bernardo Martinez
    author_email: [email protected]
    message: "Compiling assets"
    add: "*"
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}`

Action can only commit once in the same workflow run

If the action is used twice in the same run, and it has to commit in both, it will fail the second time.

Example:

fatal: A branch named 'master' already exists.
Creating and switching branch...
##[error]Docker run failed with exit code 128

This seems to be linked with the fact that the action tries to create a new branch every time it runs and fails if the branch has already been created in previous steps.
It could be fixed by checking for the branch's existence before creating the new one.

Not sure how to use add-and-commit to push changes from master to gh-pages

Hi,

I am trying to:

  1. Run jsdoc on my src files located in the master branch to generate HTML documentation in a top-level api-docs/ directory.
  2. Commit these changes to the gh-pages branch (so that I can see them in a browser).

My workflow is here:

https://github.com/radgrad/radgrad2/actions/runs/338143921/workflow

But when it runs, it doesn't see any changes so nothing is committed:

https://github.com/radgrad/radgrad2/runs/1333440463?check_suite_focus=true

I know I am missing something simple here, probably with git, but perhaps with your package. Could you advise me on what to do differently?

Thanks!

TypeError: Object prototype may only be an Object or null: undefined

Getting the below error when using the newest version v5.1.1
This has worked up until recently and rolling back to v5.1.0 works great.
So far, going through the code I haven't been able to find the issue.

Run EndBug/add-and-commit@v5
Running in /home/runner/work/<repo>
> Unable to get commit from workflow event: trying with the GitHub API...
> Using 'Devops Bot <email>' as author.
> Using "Updating members.csv" as commit message.
Internal logs
Error: TypeError: Object prototype may only be an Object or null: undefined

Add the possibility NOT to push

Hi,

thanks for this action, pretty handy.
I just have a little request : I have a use case where I run a series of tasks and on every step I would like to commit the changed/new files, but I only would like to push at the very end of the process. So in my case it would make sense to have an option to skip the git push on specific tasks.
What do you think?

It is not possible to push a tag without changing files

If no files in the repository has been changed or touched, the action will do nothing, even when the tag option is used.

My use case for this is I have a workflow which merges from a staging branch to a production branch, a build to some third party (without changing any local files), and should add a tag which indicates that this commit is what was sent to the third party.

Thank you!

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.