Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make commit and push into separated optional steps #240

Open
ZeroRin opened this issue Sep 4, 2022 · 9 comments
Open

Make commit and push into separated optional steps #240

ZeroRin opened this issue Sep 4, 2022 · 9 comments
Labels
enhancement New feature or request v6

Comments

@ZeroRin
Copy link
Contributor

ZeroRin commented Sep 4, 2022

Is your feature request related to a problem? Please describe.
I have a repository with two workflows:

  • A scheduled workflow 1 that downloads update data from different sources and create one commit for each source.
  • A on-push workflow 2 that triggers on new data, analyzes the data and create a new commit.

As soon as workflow 1 commits data from first source, it triggers workflow 2. As the two workflows now run in parallel and both may have new commits, further commit from one workflow will be rejected.

Describe the solution you'd like
Add an option to disable the commit or push step of this action. As in workflow, the push event may be intentionally used to trigger other workflows, it makes sense to provide more controllable push to me.
In my case, I want workflow 1 to create multiple commits without push, and a single push at the end of the workflow.

@stefanzweifel stefanzweifel added the enhancement New feature or request label Sep 4, 2022
@stefanzweifel
Copy link
Owner

Thanks for the suggestion!
This is something we could add to the Action and is something I will consider adding.

The only issue I currently see is in educating users how this feature should be used.
For example, users might want to write a single workflow with 3 job steps:

  • Job 1 generates changes and creates a commit
  • Job 2 generates changes and creates a commit
  • Job 3 generates changes, creates a commit and pushes 3 commits to GitHub

This won't work, as the state of each job is independent. Job 1 doesn't know about the state of the git repo in Job 2.
The commit would have to be pushed in each job, as it would otherwise get lost forever.


But users who would build such workflows/jobs probably already know, that they have to checkout their repo in each job step.

@ZeroRin
Copy link
Contributor Author

ZeroRin commented Sep 5, 2022

Oh, I just noticed that maybe I can achieve this by simply passing push_options: --dry-run to the action

@p0358
Copy link

p0358 commented Sep 30, 2022

push_options: --dry-run sounds like it should do the tricks, at least when running under one job and under one git repo clone. The question is, will the last action invocation that's meant to push indeed attempt to git push even if it didn't create any commits itself (when only the previous ones happened to create any)?

@p0358
Copy link

p0358 commented Sep 30, 2022

It seems like it does not. The action in case there was nothing to commit shows this output:

Working tree clean. Nothing to commit.

But if git push was invoked, it'd show this, which was not shown:

Everything up-to-date

So properly supporting this might require two new options, one to skip pushing, and one to always attempt pushing... (or just always attempt pushing even if no commit creation was expected?)

@ZeroRin
Copy link
Contributor Author

ZeroRin commented Sep 30, 2022

You're right. In my own repo I didn't rely on this action for the final push and simply call a run: git push at the end, so I didn't notice this.

@ZeroRin
Copy link
Contributor Author

ZeroRin commented Nov 30, 2022

@stefanzweifel btw does push have to be protected by the status check? Pushing with no change seems to be harmless.

If we put this step outside the if block, this action can be used to push changes committed before running the action.

@stefanzweifel
Copy link
Owner

@ZeroRin

btw does push have to be protected by the status check? Pushing with no change seems to be harmless.

When I developed the Action, this made the most sense (and it still does to me).
Only push something, if something has been committed and – therefore – the repo has been dirty.

Do you have in mind, that the Action the would always execute _push_to_github?
So the Action would output "Working tree clean. Nothing to commit." and then try to push to GitHub.

If we do that, I think we would have to test different scenarios. On top of my head the following come to mind:

  • what happens if remote is out of sync and we try to push?
  • what happens if repo is not dirty but a tag should be created and pushed?

Maybe it would make sense to split the logic of the Action in to 2 buckets: "Creating Commit" / "Pushing Commit".
Both features can individually be enabled/disabled. By default both are active.

[…] this action can be used to push changes committed before running the action.

I think something got lost in translation here. Would you use the Action like this?

# This step would always try to push something.
- uses: stefanzweifel/git-auto-commit-action@v4

- name: Change Files
  run: # Do something to make repo dirty

# This step would create a commit and push it.
- uses: stefanzweifel/git-auto-commit-action@v4

Would be so great if you could share workflow examples of how you intend to use the Action.

@ZeroRin
Copy link
Contributor Author

ZeroRin commented Dec 2, 2022

@stefanzweifel
This is my actual workflow
To simplify, it's a scheduled workflow that works like:

- name: Change Files
  run: # Do something to make repo dirty

# This step would create a commit for data source 1 if there is change
- uses: stefanzweifel/git-auto-commit-action@v4
    with:
      commit_message: source 1 autoupdate
      file_pattern: data/source1
      push_options: --dry-run 

# Same for date source 2
- uses: stefanzweifel/git-auto-commit-action@v4
    with:
      commit_message: source 2 autoupdate
      file_pattern: data/source2
      push_options: --dry-run 

# Same for date source 3
- uses: stefanzweifel/git-auto-commit-action@v4
    with:
      commit_message: source 3 autoupdate
      file_pattern: data/source3
      push_options: --dry-run 

# A final step that push all the changes
# To cope with other workflows that triggered on push 
# this action is not allowed to push anything until all commits are done
# Now I'm using a command run here but I would like to use action here
- run: git push

In the final step we are facing a state where there is only committed but un-pushed changes, which would not be picked up by the action.

@stefanzweifel
Copy link
Owner

@ZeroRin Thanks for sharing the workflow. This makes understanding your problem much easier and I can see that this is a legitimate usage of the Action.

My plan is to work on the Action more in December/January. Will try different things and hopefully release a new version with this feature soonish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request v6
Projects
None yet
Development

No branches or pull requests

3 participants