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

Commit via php artisan does not work with Laravel scheduler or Cronjob #11318

Open
sparmin opened this issue Jan 7, 2025 · 3 comments
Open
Labels

Comments

@sparmin
Copy link

sparmin commented Jan 7, 2025

Bug description

The docs offer a way to use Git Automation with Laravel Scheduler to consolidate changes. Unfortunately the php artisan command php artisan statamic:git:commit does not work via the Laravel Scheduler or Cronjob but it works when executing it manually via terminal.

I've set up two scheduler tasks in console.php: one for committing, one for pushing.

Schedule::command('statamic:git:commit')->everyTenMinutes()->appendOutputTo(storage_path('logs/git.log'));
Schedule::exec('git push')->everyTenMinutes()->appendOutputTo(storage_path('logs/git.log'));

The log file shows the success message saying "Content committed", but a git status proves that nothing has been committed. When executing php artisan statamic:git:commit manually in the terminal, it commits correctly and the second scheduled task of pushing also works.

To test it without the usage of schedulers, I've set up the two tasks as cronjobs:

* * * * * cd /home/ohostudi/public_html/laravel/firalux.ohodesign.ch/src && php artisan statamic:git:commit >> storage/logs/git.log
* * * * * cd /home/ohostudi/public_html/laravel/firalux.ohodesign.ch/src && git push >> storage/logs/git.log

The behaviour was the same: first one only returned a success message without actual commit, but after manual committing the push was successful.

When nothing is to be committed, the log message also says so accordingly. So it seems like the command is indeed executed, and also kinda works but not really.

I also don't think it's a git issue, since the commit and push work per se.

How to reproduce

Set up Git Automation. Use these settings in the .env:

STATAMIC_GIT_ENABLED=true
STATAMIC_GIT_AUTOMATIC=false
STATAMIC_GIT_PUSH=false
STATAMIC_GIT_DISPATCH_DELAY=

Set up the two scheduler tasks as shown above or the two cronjobs. Make a change in a tracked file. Track if the commit command was successful with git status.

Logs

No response

Environment

Environment
Application Name: Firalux
Laravel Version: 11.34.2
PHP Version: 8.3.10
Composer Version: 2.8.3
Environment: production
Debug Mode: ENABLED
URL: firalux.ohodesign.ch
Maintenance Mode: OFF
Timezone: Europe/Zurich
Locale: de_CH

Cache
Config: NOT CACHED
Events: CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: file
Database: sqlite
Logs: stack / single
Mail: log
Queue: sync
Session: file

Sentry
Enabled: MISSING DSN
Environment: production
Laravel SDK Version: 4.10.1
PHP SDK Version: 4.10.0
Release: NOT SET
Sample Rate Errors: 100%
Sample Rate Performance Monitoring: NOT SET
Sample Rate Profiling: NOT SET
Send Default PII: DISABLED

Statamic
Addons: 4
Sites: 4 (Firalux - DE, Firalux - EN, Firalux - FR, Firalux - IT)
Stache Watcher: Disabled (auto)
Static Caching: half
Version: 5.41.0 PRO

Statamic Addons
aryehraber/statamic-logbook: 3.3.0
mitydigital/statamic-two-factor: 2.4.1
statamic/eloquent-driver: 4.18.0
webographen/statamic-admin-log: 1.1.0

Statamic Eloquent Driver
Asset Containers: file
Assets: file
Blueprints: file
Collection Trees: file
Collections: file
Entries: file
Forms: file
Global Sets: file
Global Variables: file
Navigation Trees: file
Navigations: file
Revisions: file
Sites: file
Taxonomies: file
Terms: file
Tokens: file

Installation

Fresh statamic/statamic site via CLI

Additional details

Our host provider has several php functions disabled for security reason, for example exec(), shell_exec(), system(), dl() and passthru(). I've enabled them for testing purposes, but that didn't change anything. There might be possibly some other similar setting responsible, although I doubt it personally.

@duncanmcclean
Copy link
Member

Can you try running git status as a cron job and post the output?

Also, I'm assuming your cron jobs are running as the same user as you're logged into when executing the commands manually? If they're not, that might be causing issues.

@sparmin
Copy link
Author

sparmin commented Jan 7, 2025

Output of git status with cronjob:

# On branch main
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   content/collections/pages/2025-01-06.test.md
#
no changes added to commit (use "git add" and/or "git commit -a")

Yep, running whoami via cronjob is the same user as the one I log in with to execute the command.

@duncanmcclean
Copy link
Member

Thanks for checking!

What does your config/statamic/git.php config file look like?

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

No branches or pull requests

2 participants