mirror of
https://github.com/opdavies/build-configs.git
synced 2025-03-13 05:26:56 +00:00
feat: add and enable pre-push Git hooks
This commit is contained in:
parent
c419332bad
commit
2afdf43cd2
|
@ -142,6 +142,10 @@ class GenerateCommand extends Command
|
||||||
if ($filesystem->exists("{$outputDir}/tools/docker/images/php/root/usr/local/bin/docker-entrypoint-php")) {
|
if ($filesystem->exists("{$outputDir}/tools/docker/images/php/root/usr/local/bin/docker-entrypoint-php")) {
|
||||||
$filesystem->chmod("{$outputDir}/tools/docker/images/php/root/usr/local/bin/docker-entrypoint-php", 0755);
|
$filesystem->chmod("{$outputDir}/tools/docker/images/php/root/usr/local/bin/docker-entrypoint-php", 0755);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($filesystem->exists("{$outputDir}/.githooks/pre-push")) {
|
||||||
|
$filesystem->chmod("{$outputDir}/.githooks/pre-push", 0755);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFiles(array $configurationData): Collection
|
function getFiles(array $configurationData): Collection
|
||||||
|
@ -219,6 +223,14 @@ class GenerateCommand extends Command
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Arr::get($configurationData, 'experimental.runGitHooksBeforePush', false) === true) {
|
||||||
|
$filesToGenerate[] = new TemplateFile(
|
||||||
|
data: 'git-hooks/pre-push',
|
||||||
|
name: 'pre-push',
|
||||||
|
path: '.githooks',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return $filesToGenerate;
|
return $filesToGenerate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@ final class Config
|
||||||
allowMissingFields: true,
|
allowMissingFields: true,
|
||||||
fields: [
|
fields: [
|
||||||
'createGitHubActionsConfiguration' => new Assert\Type('boolean'),
|
'createGitHubActionsConfiguration' => new Assert\Type('boolean'),
|
||||||
|
'runGitHooksBeforePush' => new Assert\Type('boolean'),
|
||||||
'useNewDatabaseCredentials' => new Assert\Type('boolean'),
|
'useNewDatabaseCredentials' => new Assert\Type('boolean'),
|
||||||
]
|
]
|
||||||
)]
|
)]
|
||||||
|
|
5
templates/git-hooks/pre-push.twig
Executable file
5
templates/git-hooks/pre-push.twig
Executable file
|
@ -0,0 +1,5 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
just test-commit
|
|
@ -19,7 +19,7 @@ composer *args:
|
||||||
alias phpunit := test
|
alias phpunit := test
|
||||||
|
|
||||||
test *args:
|
test *args:
|
||||||
{{ "just _run php phpunit {{ args }}" | raw }}
|
{{ "just _run php phpunit --colors=always {{ args }}" | raw }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if "drupal-project" is same as type %}
|
{% if "drupal-project" is same as type %}
|
||||||
|
@ -58,6 +58,39 @@ artisan *args:
|
||||||
{{ "just _run artisan {{ args }}" | raw }}
|
{{ "just _run artisan {{ args }}" | raw }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if experimental.runGitHooksBeforePush %}
|
||||||
|
# Enable or disable Git hooks
|
||||||
|
git-hooks command:
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
case "{{ '{{ command }}'|raw }}" in
|
||||||
|
"on")
|
||||||
|
echo "Enabling Git hooks..."
|
||||||
|
git config core.hooksPath .githooks
|
||||||
|
;;
|
||||||
|
"off")
|
||||||
|
echo "Disabling Git hooks..."
|
||||||
|
git config --unset core.hooksPath
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Error: Invalid argument. Must be either 'on' or 'off'"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
test-commit:
|
||||||
|
{% if "phpcs" in php|keys -%}
|
||||||
|
just _run php phpcs
|
||||||
|
{%- endif %}
|
||||||
|
|
||||||
|
{% if "phpstan" in php|keys -%}
|
||||||
|
just _run php phpstan analyze --no-progress --memory-limit=512M
|
||||||
|
{%- endif %}
|
||||||
|
|
||||||
|
just test --testdox --testsuite unit
|
||||||
|
just test --testdox --testsuite kernel
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
_exec +args:
|
_exec +args:
|
||||||
{{ "docker compose exec {{ args }}" | raw }}
|
{{ "docker compose exec {{ args }}" | raw }}
|
||||||
|
|
||||||
|
@ -68,3 +101,5 @@ _run service command *args:
|
||||||
--rm \
|
--rm \
|
||||||
-T \
|
-T \
|
||||||
{{ "{{ service }} {{ args }}"|raw }}
|
{{ "{{ service }} {{ args }}"|raw }}
|
||||||
|
|
||||||
|
# vim: ft=just
|
||||||
|
|
Loading…
Reference in a new issue