Skip to content

Commit f6a7acd

Browse files
authored
Merge pull request #31 from noplanman/autoupdate_support_bot
Automatically update code and composer install on Support Bot release.
2 parents a6b0d73 + 5e6d73f commit f6a7acd

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Environment
22
TG_ENV='development'
3+
TG_AUTOUPDATE=1
34

45
# Directories
56
TG_BASE_DIR='/var/www/tg-support-bot'

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
66
## [Unreleased]
77
### Added
88
- Code checkers to ensure coding standard.
9+
- When releasing a new version of the Support Bot, automatically fetch the latest code and install with composer.
910
### Changed
1011
- Bumped Manager to 1.5.
1112
- Logging is now decoupled with custom Monolog logger.

public/webhooks/github.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,12 @@
5353
}
5454

5555
// Handle event.
56-
switch ($webhook->getEvent()) {
57-
case 'release':
58-
handleRelease($data);
59-
break;
56+
if ($webhook->getEvent() === 'release') {
57+
handleRelease($data);
58+
59+
if ($repo === 'php-telegram-bot/support-bot' && getenv('TG_AUTOUPDATE') === '1') {
60+
pullLatestAndUpdate();
61+
}
6062
}
6163

6264
/**
@@ -166,3 +168,16 @@ function sendTelegramMessage($chat_id, $text): ?ServerResponse
166168

167169
return null;
168170
}
171+
172+
/**
173+
* Pull the latest code from the repository and install with composer.
174+
*/
175+
function pullLatestAndUpdate(): void
176+
{
177+
exec('sudo -u www-data /usr/bin/git stash');
178+
exec('sudo -u www-data /usr/bin/git fetch');
179+
exec('sudo -u www-data /usr/bin/git reset --hard');
180+
exec('sudo -u www-data /usr/bin/git rebase');
181+
exec('sudo -u www-data /usr/bin/git pull');
182+
exec('sudo -u www-data /usr/local/bin/composer install --no-dev');
183+
}

0 commit comments

Comments
 (0)