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

[4.x] Add push options to git push process #9401

Open
wants to merge 3 commits into
base: 4.x
Choose a base branch
from

Conversation

jhhazelaar
Copy link
Contributor

@jhhazelaar jhhazelaar commented Jan 25, 2024

Add push options to git push Process: statamic/ideas#1113

Closes statamic/ideas#1113

@jhhazelaar jhhazelaar changed the title Add push options to git push process [4.x] Add push options to git push process Jan 25, 2024
@jasonvarga
Copy link
Member

Can you go into more details on exactly what you'd be doing with this feature (either here or on the ideas issue)? This would allow us to better understand and test this PR.

@jesseleite jesseleite self-requested a review January 26, 2024 17:22
@jhhazelaar
Copy link
Contributor Author

Of course!

We at the company are using a stage of ci/cd jobs and php deployer to deploy our website. Every project has 4 environments: local, staging, acceptance and production. Every environment has a git-flow branch or tag, that are:

  • local is workbranch created from develop branch;
  • staging is the develop branch, used for internal testing (Deployed when pushed to develop);
  • acceptance is the acceptance branch, using for external testing (Deployed when pushed to acceptance);
  • main branch doesn't do anythink, is there to accept push from production
  • v-* tags is to deploy to production.

With php deployer the hole installation get's installed in a folder and then symlinks to the webroot folder when everything is build and installed. Just like laravel envoy. Link to deployer here: https://deployer.org/

This is the setup, hopefully you get the picture of the current situation.

Now we what to automate the merge between main and acceptance. So that the acceptance is a 1 to 1 copy of production. The production pushes to main. We where thinking of doing a scheduled Merge Request in GitLab, but that will create a lot of unnecessary merge request if there is nothing to merge. Then we discovered the push options in Gitlab (https://docs.gitlab.com/ee/user/project/push_options.html) that will create a merge request and merge it for us, and deploy a fresh installation to acceptance.

Hopefully this helps something to understand the PR.

@jasonvarga
Copy link
Member

Thank you for that.

If you're triggering a Merge Request from every push, wouldn't that also result in a lot of them?

@jhhazelaar
Copy link
Contributor Author

It could, but we have tested it and it with a delayed commit. A lot of commit and eventual the push will combine in one merge request. When the pipeline is runnen and there's another push it's won't merge because the pipeline is running.

@jasonvarga
Copy link
Member

Thank you 👍

@jesseleite
Copy link
Member

Rad! Your use case makes sense, but curious if we could also see the exact array format of your options in your config? (Sorry!)

The reason I ask is that I have some thoughts re: consistency in how we allow customization of the push command in this PR, compared to how we currently allow customization of the git add/commit commands in the commands array.

For example, our commands array expects a string syntax, whereas I see you are parsing an array...

$pushOptions = collect(config('statamic.git.push_options'))
    ->map(fn ($item, $key) => is_int($key) ? $item : implode('=', [$key, $item]))
    ->map(fn ($item) => implode(' ', ['-o', $item]))
    ->flatten();

@jesseleite
Copy link
Member

Oh derp, I see the array in your test case...

'push_options' => [
	'merge_request.create',
	'merge_request.target' => 'develop',
],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add push option to git automation
3 participants