Skip to content

Commit

Permalink
Added GHA for Database, Build, Test and Deploy.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk committed Sep 8, 2024
1 parent 6fe971a commit dde7591
Show file tree
Hide file tree
Showing 14 changed files with 793 additions and 97 deletions.
374 changes: 357 additions & 17 deletions .github/workflows/build-test-deploy.yml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .github/workflows/vortex-test-common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,5 +206,5 @@ jobs:
continue-on-error: ${{ vars.VORTEX_CI_YAMLLINT_IGNORE_FAILURE == '1' }}

- name: Check coding standards with actionlint
run: docker run --rm -v "${GITHUB_WORKSPACE:-.}":/app --workdir /app rhysd/actionlint:1.6.27 -ignore 'SC2002:' -ignore 'SC2155:'
run: docker run --rm -v "${GITHUB_WORKSPACE:-.}":/app --workdir /app rhysd/actionlint:1.6.27 -ignore 'SC2002:' -ignore 'SC2155:' -ignore 'SC2015:' -ignore 'SC2046:'
continue-on-error: ${{ vars.VORTEX_CI_ACTIONLINT_IGNORE_FAILURE == '1' }}
Binary file modified .vortex/docs/static/img/diagram-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .vortex/docs/static/img/diagram-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 77 additions & 0 deletions .vortex/installer/src/Command/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ protected function replaceTokens() {
'database_download_source',
'database_image',
'override_existing_db',
'ci_provider',
'deploy_type',
'preserve_acquia',
'preserve_lagoon',
Expand Down Expand Up @@ -415,6 +416,46 @@ protected function processOverrideExistingDb(string $dir) {
}
}

protected function processCiProvider(string $dir) {
$type = $this->getAnswer('ci_provider');

$remove_gha = FALSE;
$remove_circleci = FALSE;

switch ($type) {
case 'CircleCI':
$remove_gha = TRUE;
break;

case 'GitHub Actions':
$remove_circleci = TRUE;
break;

default:
$remove_circleci = TRUE;
$remove_gha = TRUE;
}

if ($remove_gha) {
@unlink($dir . '/.github/workflows/build-test-deploy.yml');
$this->removeTokenWithContent('CI_PROVIDER_GHA', $dir);
}

if ($remove_circleci) {
static::rmdirRecursive($dir . '/.circleci');
@unlink($dir . '/tests/phpunit/CircleCiConfigTest.php');
$this->removeTokenWithContent('CI_PROVIDER_CIRCLECI', $dir);
}

if ($remove_gha && $remove_circleci) {
@unlink($dir . '/docs/ci.md');
$this->removeTokenWithContent('CI_PROVIDER_ANY', $dir);
}
else {
$this->removeTokenWithContent('!CI_PROVIDER_ANY', $dir);
}
}

protected function processDeployType(string $dir) {
$type = $this->getAnswer('deploy_type');
if ($type != 'none') {
Expand Down Expand Up @@ -762,6 +803,8 @@ protected function collectAnswers() {

$this->askForAnswer('override_existing_db', 'Do you want to override existing database in the environment?');

$this->askForAnswer('ci_provider', 'Which provider do you want to use for CI ([c]ircleci, [g]ithub actions, [n]one)?');

$this->askForAnswer('deploy_type', 'How do you deploy your code to the hosting ([w]ebhook call, [c]ode artifact, [d]ocker image, [l]agoon, [n]one as a comma-separated list)?');

if ($this->getAnswer('database_download_source') != 'ftp') {
Expand Down Expand Up @@ -1059,6 +1102,10 @@ protected function getDefaultValueOverrideExistingDb(): string {
return self::ANSWER_NO;
}

protected function getDefaultValueCiProvider(): string {
return 'GitHub Actions';
}

protected function getDefaultValueDeployType(): string {
return 'artifact';
}
Expand Down Expand Up @@ -1294,6 +1341,18 @@ protected function discoverValueOverrideExistingDb(): string {
return $this->getValueFromDstDotenv('VORTEX_PROVISION_OVERRIDE_DB') ? self::ANSWER_YES : self::ANSWER_NO;
}

protected function discoverValueCiProvider() {
if (is_readable($this->getDstDir() . '/.github/workflows/build-test-deploy.yml')) {
return 'GitHub Actions';
}

if (is_readable($this->getDstDir() . '/.circleci/config.yml')) {
return 'CircleCI';
}

return $this->isInstalled() ? 'none' : NULL;
}

protected function discoverValueDeployType() {
return $this->getValueFromDstDotenv('VORTEX_DEPLOY_TYPES');
}
Expand Down Expand Up @@ -1501,6 +1560,23 @@ protected function normaliseAnswerOverrideExistingDb($value): string {
return strtolower((string) $value) !== self::ANSWER_YES ? self::ANSWER_NO : self::ANSWER_YES;
}

protected function normaliseAnswerCiProvider($value): string {
$value = trim(strtolower((string) $value));

switch ($value) {
case 'c':
case 'circleci':
return 'CircleCI';

case 'g':
case 'gha':
case 'github actions':
return 'GitHub Actions';
}

return 'none';
}

protected function normaliseAnswerDeployType($value): ?string {
$types = explode(',', (string) $value);

Expand Down Expand Up @@ -1669,6 +1745,7 @@ protected function printSummary() {
}

$values['Override existing database'] = $this->formatYesNo($this->getAnswer('override_existing_db'));
$values['CI provider'] = $this->formatNotEmpty($this->getAnswer('ci_provider'), 'None');
$values['Deployment'] = $this->formatNotEmpty($this->getAnswer('deploy_type'), 'Disabled');
$values['FTP integration'] = $this->formatEnabled($this->getAnswer('preserve_ftp'));
$values['Acquia integration'] = $this->formatEnabled($this->getAnswer('preserve_acquia'));
Expand Down
159 changes: 138 additions & 21 deletions .vortex/tests/bats/_helper.bash
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ setup() {
fi

if [ -n "${DOCKER_DEFAULT_PLATFORM:-}" ]; then
step "Using ${DOCKER_DEFAULT_PLATFORM} platform architecture."
if [ "${BATS_VERBOSE_RUN:-}" = "1" ] || [ "${TEST_VORTEX_DEBUG:-}" = "1" ]; then
step "Using ${DOCKER_DEFAULT_PLATFORM} platform architecture."
fi
fi
# LCOV_EXCL_STOP

Expand Down Expand Up @@ -283,6 +285,7 @@ assert_files_not_present_common() {
assert_file_not_exists ".ahoy.yml"

assert_file_not_exists "README.md"
assert_file_not_exists ".github/workflows/build-test-deploy.yml"
assert_file_not_exists ".circleci/config.yml"
assert_file_not_exists "${webroot}/sites/default/settings.php"
assert_file_not_exists "${webroot}/sites/default/services.yml"
Expand All @@ -305,8 +308,6 @@ assert_files_present_vortex() {

pushd "${dir}" >/dev/null || exit 1

assert_file_exists ".circleci/config.yml"

assert_file_exists ".docker/cli.dockerfile"
assert_file_exists ".docker/mariadb.dockerfile"
assert_file_exists ".docker/nginx-drupal.dockerfile"
Expand Down Expand Up @@ -403,7 +404,6 @@ assert_files_present_vortex() {
assert_file_exists "phpunit.xml"

# Documentation information present.
assert_file_exists "docs/ci.md"
assert_file_exists "docs/faqs.md"
assert_file_exists "README.md"
assert_file_exists "docs/releasing.md"
Expand All @@ -415,8 +415,14 @@ assert_files_present_vortex() {
assert_file_not_exists "CODE_OF_CONDUCT.md"
assert_file_not_exists ".github/FUNDING.yml"

assert_file_not_exists ".github/vortex-publish-docs.yml"
assert_file_not_exists ".github/vortex-test-docs.yml"
assert_file_exists ".github/workflows/assign-author.yml"
assert_file_exists ".github/workflows/label-merge-conflict.yml"
assert_file_exists ".github/workflows/draft-release-notes.yml"

assert_file_not_exists ".github/workflows/vortex-release-docs.yml"
assert_file_not_exists ".github/workflows/vortex-test-docs.yml"
assert_file_not_exists ".github/workflows/vortex-test-common.yml"
assert_file_not_exists ".github/workflows/vortex-test-installer.yml"

assert_file_not_contains ".circleci/config.yml" "vortex-dev-test"
assert_file_not_contains ".circleci/config.yml" "vortex-dev-test-workflow"
Expand Down Expand Up @@ -596,6 +602,16 @@ assert_files_present_provision_use_profile() {

assert_file_not_contains "README.md" "ahoy download-db"

assert_file_not_contains ".github/workflows/build-test-deploy.yml" "database:"
assert_file_not_contains ".github/workflows/build-test-deploy.yml" "schedule:"
assert_file_not_contains ".github/workflows/build-test-deploy.yml" "VORTEX_CI_DB_CACHE_TIMESTAMP"
assert_file_not_contains ".github/workflows/build-test-deploy.yml" "VORTEX_CI_DB_CACHE_FALLBACK"
assert_file_not_contains ".github/workflows/build-test-deploy.yml" "VORTEX_CI_DB_CACHE_BRANCH"
assert_file_not_contains ".github/workflows/build-test-deploy.yml" "Save DB cache"
assert_file_not_contains ".github/workflows/build-test-deploy.yml" "Restore DB cache"
assert_file_not_contains ".github/workflows/build-test-deploy.yml" "Create cache keys files for database caching"
assert_file_not_contains ".github/workflows/build-test-deploy.yml" "Show cache key for database caching"

assert_file_not_contains ".circleci/config.yml" "db_ssh_fingerprint"
assert_file_not_contains ".circleci/config.yml" "/root/project/.data"
assert_file_not_contains ".circleci/config.yml" "nightly_db_schedule"
Expand Down Expand Up @@ -624,17 +640,31 @@ assert_files_present_no_provision_use_profile() {

assert_file_contains "README.md" "ahoy download-db"

assert_file_contains ".circleci/config.yml" "db_ssh_fingerprint"
assert_file_contains ".circleci/config.yml" "/root/project/.data"
assert_file_contains ".circleci/config.yml" "nightly_db_schedule"
assert_file_contains ".circleci/config.yml" "VORTEX_DB_DOWNLOAD_SSH_FINGERPRINT"
assert_file_contains ".circleci/config.yml" "VORTEX_CI_DB_CACHE_TIMESTAMP"
assert_file_contains ".circleci/config.yml" "VORTEX_CI_DB_CACHE_FALLBACK"
assert_file_contains ".circleci/config.yml" "VORTEX_CI_DB_CACHE_BRANCH"
assert_file_contains ".circleci/config.yml" "database: &job-database"
assert_file_contains ".circleci/config.yml" "database-nightly"
assert_file_contains ".circleci/config.yml" "name: Set cache keys for database caching"
assert_file_contains ".circleci/config.yml" "- database:"
if [ -f ".github/workflows/build-test-deploy.yml" ]; then
assert_file_contains ".github/workflows/build-test-deploy.yml" "database:"
assert_file_contains ".github/workflows/build-test-deploy.yml" "schedule:"
assert_file_contains ".github/workflows/build-test-deploy.yml" "VORTEX_CI_DB_CACHE_TIMESTAMP"
assert_file_contains ".github/workflows/build-test-deploy.yml" "VORTEX_CI_DB_CACHE_FALLBACK"
assert_file_contains ".github/workflows/build-test-deploy.yml" "VORTEX_CI_DB_CACHE_BRANCH"
assert_file_contains ".github/workflows/build-test-deploy.yml" "Save DB cache"
assert_file_contains ".github/workflows/build-test-deploy.yml" "Restore DB cache"
assert_file_contains ".github/workflows/build-test-deploy.yml" "Create cache keys files for database caching"
assert_file_contains ".github/workflows/build-test-deploy.yml" "Show cache key for database caching"
fi

if [ -f ".circleci/config.yml" ]; then
assert_file_contains ".circleci/config.yml" "db_ssh_fingerprint"
assert_file_contains ".circleci/config.yml" "/root/project/.data"
assert_file_contains ".circleci/config.yml" "nightly_db_schedule"
assert_file_contains ".circleci/config.yml" "VORTEX_DB_DOWNLOAD_SSH_FINGERPRINT"
assert_file_contains ".circleci/config.yml" "VORTEX_CI_DB_CACHE_TIMESTAMP"
assert_file_contains ".circleci/config.yml" "VORTEX_CI_DB_CACHE_FALLBACK"
assert_file_contains ".circleci/config.yml" "VORTEX_CI_DB_CACHE_BRANCH"
assert_file_contains ".circleci/config.yml" "database: &job-database"
assert_file_contains ".circleci/config.yml" "database-nightly"
assert_file_contains ".circleci/config.yml" "name: Set cache keys for database caching"
assert_file_contains ".circleci/config.yml" "- database:"
fi

popd >/dev/null || exit 1
}
Expand All @@ -661,15 +691,95 @@ assert_files_present_no_override_existing_db() {
popd >/dev/null || exit 1
}

assert_files_present_ci_provider_gha() {
local dir="${1:-$(pwd)}"
local suffix="${2:-star_wars}"

pushd "${dir}" >/dev/null || exit 1

assert_file_exists ".github/workflows/build-test-deploy.yml"
assert_file_contains "README.md" "[![Database, Build, Test and Deploy"
assert_file_contains "README.md" "docs/ci.md"
assert_file_contains "docs/ci.md" "GitHub Actions"

assert_files_present_no_ci_provider_circleci "$dir" "$suffix"

popd >/dev/null || exit 1
}

assert_files_present_no_ci_provider_gha() {
local dir="${1:-$(pwd)}"
local suffix="${2:-star_wars}"

pushd "${dir}" >/dev/null || exit 1

assert_file_not_exists ".github/workflows/build-test-deploy.yml"
assert_file_not_contains "README.md" "[![Database, Build, Test and Deploy"
assert_file_not_contains "docs/ci.md" "GitHub Actions"

popd >/dev/null || exit 1
}

assert_files_present_ci_provider_circleci() {
local dir="${1:-$(pwd)}"
local suffix="${2:-star_wars}"

pushd "${dir}" >/dev/null || exit 1

assert_file_exists ".circleci/config.yml"
assert_file_contains "README.md" "[![CircleCI"
assert_file_contains "README.md" "docs/ci.md"
assert_file_contains "docs/ci.md" "CircleCI"

assert_files_present_no_ci_provider_gha "$dir" "$suffix"

popd >/dev/null || exit 1
}

assert_files_present_no_ci_provider_circleci() {
local dir="${1:-$(pwd)}"
local suffix="${2:-star_wars}"

pushd "${dir}" >/dev/null || exit 1

assert_file_not_exists ".circleci/config.yml"
assert_file_not_contains "README.md" "[![CircleCI"
assert_file_not_contains "docs/ci.md" "CircleCI"

popd >/dev/null || exit 1
}

assert_files_present_ci_provider_none() {
local dir="${1:-$(pwd)}"
local suffix="${2:-star_wars}"

pushd "${dir}" >/dev/null || exit 1

assert_files_present_no_ci_provider_gha "$dir" "$suffix"
assert_files_present_no_ci_provider_circleci "$dir" "$suffix"

assert_file_not_exists "docs/ci.md"
assert_file_not_contains "README.md" "docs/ci.md"

popd >/dev/null || exit 1
}

assert_files_present_deployment() {
local dir="${1:-$(pwd)}"
local suffix="${2:-star_wars}"

pushd "${dir}" >/dev/null || exit 1

assert_file_exists "docs/deployment.md"
assert_file_contains ".circleci/config.yml" "deploy: &job_deploy"
assert_file_contains ".circleci/config.yml" "deploy-tags: &job-deploy-tags"

if [ -f ".github/workflows/build-test-deploy.yml" ]; then
assert_file_contains ".github/workflows/build-test-deploy.yml" "deploy:"
fi

if [ -f ".circleci/config.yml" ]; then
assert_file_contains ".circleci/config.yml" "deploy: &job_deploy"
assert_file_contains ".circleci/config.yml" "deploy-tags: &job-deploy-tags"
fi

popd >/dev/null || exit 1
}
Expand All @@ -687,6 +797,8 @@ assert_files_present_no_deployment() {
# 'Required' files can be asserted for modifications only if they were not
# committed.
if [ "${has_committed_files:-}" -eq 0 ]; then
assert_file_not_contains ".github/workflows/build-test-deploy.yml" "deploy:"

assert_file_not_contains ".circleci/config.yml" "deploy: &job_deploy"
assert_file_not_contains ".circleci/config.yml" "deploy-tags: &job-deploy-tags"
assert_file_not_contains ".circleci/config.yml" "- deploy:"
Expand Down Expand Up @@ -853,8 +965,12 @@ assert_files_present_integration_renovatebot() {

assert_file_exists "renovate.json"

assert_file_contains ".circleci/config.yml" "renovatebot-self-hosted"
assert_file_contains ".circleci/config.yml" "renovatebot_schedule"
if [ -f ".circleci/config.yml" ]; then
assert_file_contains ".circleci/config.yml" "renovatebot-self-hosted"
assert_file_contains ".circleci/config.yml" "renovatebot_schedule"
fi

# @todo Add assertions for self-hosted Renovatebot in GitHub Actions.

popd >/dev/null || exit 1
}
Expand All @@ -872,6 +988,7 @@ assert_files_present_no_integration_renovatebot() {
assert_file_not_contains ".circleci/config.yml" "renovatebot-self-hosted"
assert_file_not_contains ".circleci/config.yml" "renovatebot_schedule"

# @todo Add assertions for self-hosted Renovatebot in GitHub Actions.

popd >/dev/null || exit 1
}
Expand Down
2 changes: 2 additions & 0 deletions .vortex/tests/bats/deployment1.bats
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ load _helper.deployment.bash
"nothing" # database_download_source
"nothing" # database_store_type
"nothing" # override_existing_db
"nothing" # ci_provider
"lagoon" # deploy_type
"n" # preserve_ftp
"n" # preserve_acquia
Expand Down Expand Up @@ -235,6 +236,7 @@ load _helper.deployment.bash
"nothing" # webroot
"y" # provision_use_profile
"n" # override_existing_db
"nothing" # ci_provider
"lagoon" # deploy_type
"n" # preserve_ftp
"n" # preserve_acquia
Expand Down
Loading

1 comment on commit dde7591

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.