From 4361341ea12914ff4800cc174cde96f9be0c0b66 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Wed, 26 Jun 2024 12:32:51 -0600 Subject: [PATCH 01/18] set the default php version to 8.1 --- private/scripts/helpers.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/private/scripts/helpers.sh b/private/scripts/helpers.sh index fd0e1c7b..1b820b14 100755 --- a/private/scripts/helpers.sh +++ b/private/scripts/helpers.sh @@ -24,7 +24,7 @@ sitename="${SITENAME:-}" sftpuser="${SFTPUSER:-}" sftphost="${SFTPHOST:-}" sagename="${SAGENAME:-}" -phpversion="${PHPVERSION:-8.0}" +phpversion="${PHPVERSION:-8.1}" is_ci="${CI:-0}" siteenv="${SITEENV:-dev}" if [ "$siteenv" == "dev" ]; then From f28136e73fcfb82de6dda5069f9926ce56589054 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Wed, 26 Jun 2024 12:33:33 -0600 Subject: [PATCH 02/18] update the update_php function to update to 8.1 at minimum --- private/scripts/helpers.sh | 64 ++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 34 deletions(-) diff --git a/private/scripts/helpers.sh b/private/scripts/helpers.sh index 1b820b14..bcb51d05 100755 --- a/private/scripts/helpers.sh +++ b/private/scripts/helpers.sh @@ -233,23 +233,18 @@ get_field() { echo "$2" | awk -v field="$1" '$1 == field { print $2 }' } -# Update to PHP 8.0 +# Update to PHP 8.1 or higher function update_php() { - if [ "$phpversion" == "8" ]; then - phpversion="8.0" - fi - if [ "$phpversion" != "8.0" ]; then - echo "${yellow}You've specified PHP version ${phpversion}. The default is 8.0, but we'll use the version you asked for.${normal}" - if [ "$phpversion" == "8.3" ]; then - echo "${yellow}PHP 8.3 is not yet supported. Using 8.2 instead.${normal}" - phpversion="8.2" - fi - # Check if $phpversion is < 8.0. - if [ "$(echo "$phpversion < 8.0" | bc)" -eq 1 ]; then - echo "${red}PHP version must be 8.0 or greater. Exiting here.${normal}" - exit 1; - fi + if [ "$phpversion" == "8" ] || [ "$phpversion" == "8.0" ]; then + phpversion="8.1" fi + + # Check if $phpversion is < 8.1. + if [ "$(echo "$phpversion < 8.1" | bc)" -eq 1 ]; then + echo "${red}PHP version must be 8.1 or greater. Exiting here.${normal}" + exit 1 + fi + echo "" echo "${yellow}Updating PHP version to ${phpversion}.${normal}" @@ -257,30 +252,31 @@ function update_php() { if [ ! -f "pantheon.yml" ]; then echo "${red}No pantheon.yml file found. Exiting here.${normal}" echo "Make sure you are inside a valid Pantheon repository." - exit 1; + exit 1 fi - # Testing for any version of PHP 8.x and/or PHP 7.4. - phpAlreadyVersion8=$(grep -c "php_version: 8." < pantheon.yml) - phpDeclaredInFile=$(grep -c "php_version: 7.4" < pantheon.yml) + # Check the current PHP version declared in pantheon.yml + currentPhpVersion=$(awk '/php_version:/{print $2}' pantheon.yml) - # Only alter if not already PHP 8.x. - if [ "$phpAlreadyVersion8" -eq 0 ]; then - # Test for PHP version declartion already in pantheon.yml. - if [ ! "$phpDeclaredInFile" -eq 0 ]; then - # Update version to 8.x. - sed -i '' "s/7.4/${phpversion}/" pantheon.yml - else - # Add full PHP version declaration to pantheon.yml. - echo "" >> pantheon.yml - echo "php_version: ${phpversion}" >> pantheon.yml - fi - git diff HEAD~1 HEAD -- pantheon.yml - git commit -am "[Sage Install] Update PHP version to ${phpversion}" - git push origin "$branch" + if [ -z "$currentPhpVersion" ]; then + # Add the PHP version declaration if not present. + echo "" >> pantheon.yml + echo "php_version: ${phpversion}" >> pantheon.yml + elif [ "$(echo "$currentPhpVersion < 8.1" | bc)" -eq 1 ]; then + # Update the PHP version declaration if it's less than 8.1. + sed -i '' "s/php_version: [0-9.]*/php_version: ${phpversion}/" pantheon.yml else - echo "${green}PHP version is already 8.x.${normal}" + echo "${green}PHP version is already ${currentPhpVersion} which is >= 8.1.${normal}" + exit 0 + fi + + if [ "$is_ci" -eq 1 ]; then + echo "${yellow}CI detected. Skipping Git operations. PHP updated to ${phpversion}." + exit 0 fi + git add pantheon.yml + git commit -m "[Sage Install] Update PHP version to ${phpversion}" + git push origin "$branch" } # Install sage and related dependencies. From b36a5d629394f1370acfb4555d4091aa1cb42080 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Wed, 26 Jun 2024 12:33:59 -0600 Subject: [PATCH 03/18] allow the update_php function to be run independently so we can test it --- private/scripts/helpers.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/private/scripts/helpers.sh b/private/scripts/helpers.sh index bcb51d05..32a36bc4 100755 --- a/private/scripts/helpers.sh +++ b/private/scripts/helpers.sh @@ -38,7 +38,8 @@ function main() { help_msg="Usage: bash ./private/scripts/helpers.sh Available commands: install_sage: Install Sage. - maybe_create_symlinks: Create a symlinks to WordPress files, if they don't already exist." + maybe_create_symlinks: Create a symlinks to WordPress files, if they don't already exist. + update_php: Updates PHP version to 8.1 if it's not already set at 8.1 or higher." if [ -z "$1" ]; then echo "${red}No command specified.${normal}" @@ -52,7 +53,7 @@ function main() { fi # Check for a valid command. - if [ "$1" != "install_sage" ] && [ "$1" != "maybe_create_symlinks" ]; then + if [ "$1" != "install_sage" ] && [ "$1" != "maybe_create_symlinks" ] && [ "$1" != "update_php" ]; then echo "${red}Invalid command specified.${normal}" echo "${help_msg}" exit 1; From a2470e29e58a4034daad14760d2d0e6af7bebac8 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Wed, 26 Jun 2024 12:34:35 -0600 Subject: [PATCH 04/18] add tests for the updated update_php function --- .github/fixtures/pantheon-74.yml | 4 ++ .github/fixtures/pantheon-8.yml | 4 ++ .github/fixtures/pantheon-80.yml | 4 ++ .github/fixtures/pantheon-81.yml | 4 ++ .github/fixtures/pantheon-82.yml | 4 ++ .github/fixtures/pantheon-83.yml | 4 ++ .github/tests/1-test-update-php.bats | 72 ++++++++++++++++++++++++++++ 7 files changed, 96 insertions(+) create mode 100644 .github/fixtures/pantheon-74.yml create mode 100644 .github/fixtures/pantheon-8.yml create mode 100644 .github/fixtures/pantheon-80.yml create mode 100644 .github/fixtures/pantheon-81.yml create mode 100644 .github/fixtures/pantheon-82.yml create mode 100644 .github/fixtures/pantheon-83.yml create mode 100755 .github/tests/1-test-update-php.bats diff --git a/.github/fixtures/pantheon-74.yml b/.github/fixtures/pantheon-74.yml new file mode 100644 index 00000000..05bcac4d --- /dev/null +++ b/.github/fixtures/pantheon-74.yml @@ -0,0 +1,4 @@ +# Put overrides to your pantheon.upstream.yml file here. +# For more information, see: https://pantheon.io/docs/pantheon-yml/ +api_version: 1 +php_version: 7.4 diff --git a/.github/fixtures/pantheon-8.yml b/.github/fixtures/pantheon-8.yml new file mode 100644 index 00000000..093e901f --- /dev/null +++ b/.github/fixtures/pantheon-8.yml @@ -0,0 +1,4 @@ +# Put overrides to your pantheon.upstream.yml file here. +# For more information, see: https://pantheon.io/docs/pantheon-yml/ +api_version: 1 +php_version: 8 diff --git a/.github/fixtures/pantheon-80.yml b/.github/fixtures/pantheon-80.yml new file mode 100644 index 00000000..ac52b0c4 --- /dev/null +++ b/.github/fixtures/pantheon-80.yml @@ -0,0 +1,4 @@ +# Put overrides to your pantheon.upstream.yml file here. +# For more information, see: https://pantheon.io/docs/pantheon-yml/ +api_version: 1 +php_version: 8.0 diff --git a/.github/fixtures/pantheon-81.yml b/.github/fixtures/pantheon-81.yml new file mode 100644 index 00000000..846c9102 --- /dev/null +++ b/.github/fixtures/pantheon-81.yml @@ -0,0 +1,4 @@ +# Put overrides to your pantheon.upstream.yml file here. +# For more information, see: https://pantheon.io/docs/pantheon-yml/ +api_version: 1 +php_version: 8.1 diff --git a/.github/fixtures/pantheon-82.yml b/.github/fixtures/pantheon-82.yml new file mode 100644 index 00000000..a8f4a3b1 --- /dev/null +++ b/.github/fixtures/pantheon-82.yml @@ -0,0 +1,4 @@ +# Put overrides to your pantheon.upstream.yml file here. +# For more information, see: https://pantheon.io/docs/pantheon-yml/ +api_version: 1 +php_version: 8.2 diff --git a/.github/fixtures/pantheon-83.yml b/.github/fixtures/pantheon-83.yml new file mode 100644 index 00000000..9988e9dd --- /dev/null +++ b/.github/fixtures/pantheon-83.yml @@ -0,0 +1,4 @@ +# Put overrides to your pantheon.upstream.yml file here. +# For more information, see: https://pantheon.io/docs/pantheon-yml/ +api_version: 1 +php_version: 8.3 diff --git a/.github/tests/1-test-update-php.bats b/.github/tests/1-test-update-php.bats new file mode 100755 index 00000000..e5cafbc7 --- /dev/null +++ b/.github/tests/1-test-update-php.bats @@ -0,0 +1,72 @@ +#!/usr/bin/env bats + +custom_setup() { + local version=$1 + # Print debugging information + echo "BATS_TEST_DIRNAME: $BATS_TEST_DIRNAME" + echo "Current directory before cd: $(pwd)" + + # Check if the .github directory exists + if [ ! -d ".github" ]; then + echo "Error: .github directory not found in $(pwd)" + exit 1 + fi + + if [ ! -f "pantheon.upstream.yml" ]; then + echo "It doesn't look like you are in an upstream repository. Check the current directory: $(pwd)" + exit 1 + fi + + # Copy the fixture file to pantheon.yml before each test + cp ".github/fixtures/pantheon-${version}.yml" pantheon.yml +} + +teardown() { + # Clean up by removing the pantheon.yml file after each test + rm -f pantheon.yml +} + +@test "Update PHP version 7.4 to 8.1" { + custom_setup "74" + run bash private/scripts/helpers.sh update_php + echo "$output" + [ "$status" -eq 0 ] + run grep -q "php_version: 8.1" pantheon.yml + [ "$status" -eq 0 ] +} + +@test "Update PHP version 8.0 to 8.1" { + custom_setup "80" + run bash private/scripts/helpers.sh update_php + echo "$output" + [ "$status" -eq 0 ] + run grep -q "php_version: 8.1" pantheon.yml + [ "$status" -eq 0 ] +} + +@test "Keep PHP version 8.1" { + custom_setup "81" + run bash private/scripts/helpers.sh update_php + echo "$output" + [ "$status" -eq 0 ] + run grep -q "php_version: 8.1" pantheon.yml + [ "$status" -eq 0 ] +} + +@test "Keep PHP version 8.2" { + custom_setup "82" + run bash private/scripts/helpers.sh update_php + echo "$output" + [ "$status" -eq 0 ] + run grep -q "php_version: 8.2" pantheon.yml + [ "$status" -eq 0 ] +} + +@test "Keep PHP version 8.3" { + custom_setup "83" + run bash private/scripts/helpers.sh update_php + echo "$output" + [ "$status" -eq 0 ] + run grep -q "php_version: 8.3" pantheon.yml + [ "$status" -eq 0 ] +} From d1a28cd8a922f6ca701e76bbbf3a2c91fab3b3db Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Wed, 26 Jun 2024 12:36:46 -0600 Subject: [PATCH 05/18] update the test script to add bats tests --- .github/workflows/ci.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c290e644..506fcb1f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,3 +46,12 @@ jobs: - name: Run tests run: composer test + + - name: Install bats + uses: bats-core/bats-action@2.0.0 + + - name: Test Helper functions + env: + CI: 1 + run: | + bats -p -t .github/tests From 39ed2d73c6d805b8d217d3db392ec008b006e691 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Wed, 26 Jun 2024 12:42:38 -0600 Subject: [PATCH 06/18] update the echo to be more accurate --- private/scripts/helpers.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/private/scripts/helpers.sh b/private/scripts/helpers.sh index 32a36bc4..4765c03c 100755 --- a/private/scripts/helpers.sh +++ b/private/scripts/helpers.sh @@ -247,7 +247,7 @@ function update_php() { fi echo "" - echo "${yellow}Updating PHP version to ${phpversion}.${normal}" + echo "${yellow}Checking PHP version and maybe updating to ${phpversion}.${normal}" # Check for pantheon.yml file. if [ ! -f "pantheon.yml" ]; then From 0000fe4ef8297659fcc7ef72dcf92d782497ce32 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Wed, 26 Jun 2024 12:42:52 -0600 Subject: [PATCH 07/18] add more verbose inline docs --- private/scripts/helpers.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/private/scripts/helpers.sh b/private/scripts/helpers.sh index 4765c03c..196ec3a2 100755 --- a/private/scripts/helpers.sh +++ b/private/scripts/helpers.sh @@ -236,11 +236,12 @@ get_field() { # Update to PHP 8.1 or higher function update_php() { + # If an old PHP version was passed into the script from the outside, fall back to 8.1. if [ "$phpversion" == "8" ] || [ "$phpversion" == "8.0" ]; then phpversion="8.1" fi - # Check if $phpversion is < 8.1. + # Check if $phpversion is < 8.1. We shouldn't get here because we just updated $phpversion (which is passed from the environment), so if we are here, it's a problem. if [ "$(echo "$phpversion < 8.1" | bc)" -eq 1 ]; then echo "${red}PHP version must be 8.1 or greater. Exiting here.${normal}" exit 1 @@ -267,10 +268,12 @@ function update_php() { # Update the PHP version declaration if it's less than 8.1. sed -i '' "s/php_version: [0-9.]*/php_version: ${phpversion}/" pantheon.yml else + # We've got a good PHP version, so we can bail here. echo "${green}PHP version is already ${currentPhpVersion} which is >= 8.1.${normal}" exit 0 fi + # If we're in CI, don't run the push actions. Note: if you're running Bats tests locally, you should pass CI=1 before running the tests. if [ "$is_ci" -eq 1 ]; then echo "${yellow}CI detected. Skipping Git operations. PHP updated to ${phpversion}." exit 0 From 9c6605250eba493f2a190fe3c8d918e010b32628 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Wed, 26 Jun 2024 12:49:29 -0600 Subject: [PATCH 08/18] bail if we can't copy the file --- .github/tests/1-test-update-php.bats | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/tests/1-test-update-php.bats b/.github/tests/1-test-update-php.bats index e5cafbc7..ff16a22e 100755 --- a/.github/tests/1-test-update-php.bats +++ b/.github/tests/1-test-update-php.bats @@ -4,7 +4,7 @@ custom_setup() { local version=$1 # Print debugging information echo "BATS_TEST_DIRNAME: $BATS_TEST_DIRNAME" - echo "Current directory before cd: $(pwd)" + echo "Current directory: $(pwd)" # Check if the .github directory exists if [ ! -d ".github" ]; then @@ -19,6 +19,12 @@ custom_setup() { # Copy the fixture file to pantheon.yml before each test cp ".github/fixtures/pantheon-${version}.yml" pantheon.yml + + if [ ! -f "pantheon.yml" ]; then + echo "Failed to copy the fixture file to $(pwd)/pantheon.yml" + else + cat pantheon.yml + fi } teardown() { From 79f771f744a14bf4a3f0e5043209e9e1f775df20 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Wed, 26 Jun 2024 12:52:31 -0600 Subject: [PATCH 09/18] ensure the job runner has permission to write to the filesystem --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 506fcb1f..93bbe7e4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,6 +8,9 @@ on: - synchronize - ready_for_review +permissions: + contents: write + jobs: build: runs-on: ubuntu-latest From 17cb536b2891ca53088475e9f4ee23410e5773ea Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Wed, 26 Jun 2024 13:02:29 -0600 Subject: [PATCH 10/18] update the sed command to work cross-platform maybe.... --- private/scripts/helpers.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/private/scripts/helpers.sh b/private/scripts/helpers.sh index 196ec3a2..84ecb146 100755 --- a/private/scripts/helpers.sh +++ b/private/scripts/helpers.sh @@ -266,7 +266,7 @@ function update_php() { echo "php_version: ${phpversion}" >> pantheon.yml elif [ "$(echo "$currentPhpVersion < 8.1" | bc)" -eq 1 ]; then # Update the PHP version declaration if it's less than 8.1. - sed -i '' "s/php_version: [0-9.]*/php_version: ${phpversion}/" pantheon.yml + sed -i.bak "s/php_version: [0-9.]*/php_version: ${phpversion}/" pantheon.yml && rm pantheon.yml.bak else # We've got a good PHP version, so we can bail here. echo "${green}PHP version is already ${currentPhpVersion} which is >= 8.1.${normal}" @@ -274,8 +274,8 @@ function update_php() { fi # If we're in CI, don't run the push actions. Note: if you're running Bats tests locally, you should pass CI=1 before running the tests. - if [ "$is_ci" -eq 1 ]; then - echo "${yellow}CI detected. Skipping Git operations. PHP updated to ${phpversion}." + if [ "$is_ci" -eq 1 ]; then + echo "${yellow}CI detected. Skipping Git operations. PHP updated to ${phpversion}.${normal}" exit 0 fi git add pantheon.yml From 2c6d2e6e29766c1af1f1e1fd5c980025769b2370 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Wed, 26 Jun 2024 13:16:02 -0600 Subject: [PATCH 11/18] don't bail out of the script entirely in the update php script if in CI --- private/scripts/helpers.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/private/scripts/helpers.sh b/private/scripts/helpers.sh index 84ecb146..daf99a00 100755 --- a/private/scripts/helpers.sh +++ b/private/scripts/helpers.sh @@ -274,13 +274,13 @@ function update_php() { fi # If we're in CI, don't run the push actions. Note: if you're running Bats tests locally, you should pass CI=1 before running the tests. - if [ "$is_ci" -eq 1 ]; then + if [ "$is_ci" -eq 0 ]; then + git add pantheon.yml + git commit -m "[Sage Install] Update PHP version to ${phpversion}" + git push origin "$branch" + else echo "${yellow}CI detected. Skipping Git operations. PHP updated to ${phpversion}.${normal}" - exit 0 fi - git add pantheon.yml - git commit -m "[Sage Install] Update PHP version to ${phpversion}" - git push origin "$branch" } # Install sage and related dependencies. From 979607fda85b352fbdce21ac0d9b576404716e1a Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Wed, 26 Jun 2024 13:37:54 -0600 Subject: [PATCH 12/18] bail early (and don't try to activate) if the theme wasn't found --- private/scripts/helpers.sh | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/private/scripts/helpers.sh b/private/scripts/helpers.sh index daf99a00..3572074f 100755 --- a/private/scripts/helpers.sh +++ b/private/scripts/helpers.sh @@ -476,17 +476,24 @@ function clean_up() { # If the site is multisite, we'll need to enable the theme so we can activate it. echo "${yellow}Checking if this is a multisite.${normal}" - if terminus wp -- "$sitename"."$siteenv" config is-true MULTISITE; then + if terminus wp -- "$sitename"."$siteenv" config is-true MULTISITE > /dev/null 2>&1; then echo "${yellow}Site is multisite.${normal}" terminus wp -- "$sitename"."$siteenv" theme enable "$sagename" fi - # List the themes. - terminus wp -- "$sitename"."$siteenv" theme list + # Get the themes. + themelist=$(terminus wp -- "$sitename"."$siteenv" theme list --format=csv) + + if ! echo "$themelist" | grep -w "^sagename"; then + echo "${red}Theme $sagename not found in the theme list. Exiting here.${normal}" + terminus wp -- "$sitename"."$siteenv" theme list + exit 1; + fi # Activate the new theme echo "${yellow}Activating the ${sagename} theme.${normal}" if ! terminus wp -- "$sitename"."$siteenv" theme activate "$sagename"; then + terminus wp -- "$sitename"."$siteenv" theme list echo "${red}Theme activation failed. Exiting here.${normal}" echo "Check the theme list above. If the theme you created is not listed, it's possible that the deploy has not completed. You can try again in a few minutes using the following command:" echo "terminus wp -- $sitename.dev theme activate $sagename" From 089cda429a50a3560d83540f406a1b415c220fba Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Wed, 26 Jun 2024 13:56:32 -0600 Subject: [PATCH 13/18] remove line breaks or spaces from the theme name --- private/scripts/helpers.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/private/scripts/helpers.sh b/private/scripts/helpers.sh index 3572074f..d6213366 100755 --- a/private/scripts/helpers.sh +++ b/private/scripts/helpers.sh @@ -482,7 +482,7 @@ function clean_up() { fi # Get the themes. - themelist=$(terminus wp -- "$sitename"."$siteenv" theme list --format=csv) + themelist=$(terminus wp -- "$sitename"."$siteenv" theme list --format=csv | tr -d '\n' | tr -d ' ') if ! echo "$themelist" | grep -w "^sagename"; then echo "${red}Theme $sagename not found in the theme list. Exiting here.${normal}" From 635f2574c8b9efe65af883cc252716fbd6123a93 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Wed, 26 Jun 2024 14:11:38 -0600 Subject: [PATCH 14/18] echo the themelist so we can see what's being grepped --- private/scripts/helpers.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/private/scripts/helpers.sh b/private/scripts/helpers.sh index d6213366..acab4fd9 100755 --- a/private/scripts/helpers.sh +++ b/private/scripts/helpers.sh @@ -486,7 +486,7 @@ function clean_up() { if ! echo "$themelist" | grep -w "^sagename"; then echo "${red}Theme $sagename not found in the theme list. Exiting here.${normal}" - terminus wp -- "$sitename"."$siteenv" theme list + echo "$themelist" exit 1; fi From 36f32dfa86ed79043cee5eb58e81570077732d91 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Wed, 26 Jun 2024 14:25:33 -0600 Subject: [PATCH 15/18] change the grep to be more inclusive --- private/scripts/helpers.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/private/scripts/helpers.sh b/private/scripts/helpers.sh index acab4fd9..d0f9c420 100755 --- a/private/scripts/helpers.sh +++ b/private/scripts/helpers.sh @@ -484,7 +484,7 @@ function clean_up() { # Get the themes. themelist=$(terminus wp -- "$sitename"."$siteenv" theme list --format=csv | tr -d '\n' | tr -d ' ') - if ! echo "$themelist" | grep -w "^sagename"; then + if ! echo "$themelist" | grep -q -E "(^|,)$sagename($|,)"; then echo "${red}Theme $sagename not found in the theme list. Exiting here.${normal}" echo "$themelist" exit 1; From 1870338647709d8571293e717bd652d3f28f78e3 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Wed, 26 Jun 2024 14:31:36 -0600 Subject: [PATCH 16/18] use grep -q instead of -w --- private/scripts/helpers.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/private/scripts/helpers.sh b/private/scripts/helpers.sh index d0f9c420..f2fb9b26 100755 --- a/private/scripts/helpers.sh +++ b/private/scripts/helpers.sh @@ -484,7 +484,7 @@ function clean_up() { # Get the themes. themelist=$(terminus wp -- "$sitename"."$siteenv" theme list --format=csv | tr -d '\n' | tr -d ' ') - if ! echo "$themelist" | grep -q -E "(^|,)$sagename($|,)"; then + if ! echo "$themelist" | grep -q "$sagename"; then echo "${red}Theme $sagename not found in the theme list. Exiting here.${normal}" echo "$themelist" exit 1; From 218e6fee9ee0c5585a0dc766a7a4e4e0b4129b92 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Wed, 26 Jun 2024 14:49:17 -0600 Subject: [PATCH 17/18] normalize genrenated theme names --- .github/workflows/sage-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sage-test.yml b/.github/workflows/sage-test.yml index 933037b0..da395fc0 100644 --- a/.github/workflows/sage-test.yml +++ b/.github/workflows/sage-test.yml @@ -162,7 +162,7 @@ jobs: # Fetch the genre name from the Genrenator API SAGENAME=$(curl -s https://binaryjazz.us/wp-json/genrenator/v1/genre/) # Replace spaces with hyphens and remove all non-alphanumeric characters except hyphens - SAGENAME=$(echo "$SAGENAME" | tr ' ' '-' | sed 's/[^a-zA-Z0-9\-]//g') + SAGENAME=$(echo "$SAGENAME" | tr ' ' '-' | tr -cd 'a-zA-Z0-9-') echo "SAGENAME=$SAGENAME" >> $GITHUB_ENV - name: Run Sage Install Script env: From aff12de30aa53a33e873ef14964ff8d6b5797e9d Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Wed, 26 Jun 2024 15:52:08 -0600 Subject: [PATCH 18/18] move the messaging about the theme not being in the list up to that check we can also remove the conditional around activation because if it's in the list, we should be able to activate it --- private/scripts/helpers.sh | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/private/scripts/helpers.sh b/private/scripts/helpers.sh index f2fb9b26..dd67d739 100755 --- a/private/scripts/helpers.sh +++ b/private/scripts/helpers.sh @@ -486,21 +486,17 @@ function clean_up() { if ! echo "$themelist" | grep -q "$sagename"; then echo "${red}Theme $sagename not found in the theme list. Exiting here.${normal}" - echo "$themelist" - exit 1; - fi - - # Activate the new theme - echo "${yellow}Activating the ${sagename} theme.${normal}" - if ! terminus wp -- "$sitename"."$siteenv" theme activate "$sagename"; then terminus wp -- "$sitename"."$siteenv" theme list - echo "${red}Theme activation failed. Exiting here.${normal}" echo "Check the theme list above. If the theme you created is not listed, it's possible that the deploy has not completed. You can try again in a few minutes using the following command:" echo "terminus wp -- $sitename.dev theme activate $sagename" echo "Once you do this, you will need to open the site to generate the requisite files and then commit them in SFTP mode." exit 1; fi + # Activate the new theme + echo "${yellow}Activating the ${sagename} theme.${normal}" + terminus wp -- "$sitename"."$siteenv" theme activate "$sagename" + # If this is a CI environment, stop here. if [ "$is_ci" == 1 ]; then echo "${yellow}CI detected. All done here.${normal} 🍵"