Skip to content

Commit

Permalink
Use terminus-github-actions and Sage install script cleanup (#123)
Browse files Browse the repository at this point in the history
* put composer diff into a details block

* use terminus-github-actions

* skip things for CI-only runs

* skip multisite stuff if we're not on multisite

* add a workflow:wait to wait for the commit to finish before switching to sftp

* bail early if CI
rather than continuing if _not_ CI

* check if is_multisite is 1
rather than anything, we might get weird output if it's not true

* only create the directory if it doesn't exist

* wrap statement in quotes

* verbose output and ls the contents of /files

* log that we're checking for multisite
so it looks slightly less weird that we're erroring if it's not

* remove =""

* use config is-true rather than config get

* genrenate a random theme name

* change our grep pattern

* use `config is-true` directly

* replace spaces with hyphens

* remove non alphanumeric characters
this will skip weird stuff and make the output more consistent
  • Loading branch information
jazzsequence committed Aug 1, 2024
1 parent de89b63 commit 20f44e7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 14 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/composer-diff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ jobs:
with:
header: composer-diff
message: |
<strong>Composer Changes</strong>
<details>
<summary><strong>Composer Changes</strong></summary>
${{ steps.composer_diff.outputs.composer_diff }}
</details>
13 changes: 10 additions & 3 deletions .github/workflows/sage-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ jobs:
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Get latest Terminus release
uses: pantheon-systems/action-terminus-install@v1
uses: pantheon-systems/terminus-github-actions@v1
with:
os: ${{ matrix.os }}
pantheon-machine-token: ${{ secrets.TERMINUS_TOKEN }}
- name: Validate Pantheon Host Key
run: |
echo "Host *.drush.in HostKeyAlgorithms +ssh-rsa" >> ~/.ssh/config
Expand Down Expand Up @@ -157,9 +157,16 @@ jobs:
run: |
cd ~/pantheon-local-copies/wpcm-sage-install-tests
composer update
- name: Generate random theme name
run: |
# 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')
echo "SAGENAME=$SAGENAME" >> $GITHUB_ENV
- name: Run Sage Install Script
env:
SAGENAME: sage-test
SAGENAME: ${{ env.SAGENAME }}
SITENAME: wpcm-sage-install-tests
CI: 1
PHPVERSION: ${{ matrix.php-version }}
Expand Down
37 changes: 27 additions & 10 deletions private/scripts/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@ function install_sage_theme() {

# Create the symlink to the cache directory.
function add_symlink() {
echo "Waiting for the last step to finish before switching to SFTP mode."
terminus workflow:wait "$sitename"."$siteenv"

# Switch to SFTP mode
terminus connection:set "$sitename"."$siteenv" sftp

Expand All @@ -331,11 +334,15 @@ function add_symlink() {
mkdir web/app/uploads/cache
fi

# Create a files/cache directory on the host.
sftp -P 2222 "$sftpuser"@"$sftphost" <<EOF
cd /files
mkdir cache
# Create a files/cache directory on the host if one does not already exist.
echo "Checking if /files/cache exists..."
if [ "$(sftp -P 2222 "$sftpuser"@"$sftphost" <<< "ls /files" | grep -c "/cache[[:space:]]*$")" -eq 0 ]; then
echo "Creating /files/cache directory..."
sftp -P 2222 "$sftpuser"@"$sftphost" <<EOF
cd /files
mkdir cache
EOF
fi

# Switch back to Git mode.
terminus connection:set "$sitename"."$siteenv" git
Expand Down Expand Up @@ -460,8 +467,14 @@ function clean_up() {
exit 1;
fi


# If the site is multisite, we'll need to enable the theme so we can activate it.
terminus wp -- "$sitename"."$siteenv" theme enable "$sagename"
echo "${yellow}Checking if this is a multisite.${normal}"
if terminus wp -- "$sitename"."$siteenv" config is-true MULTISITE; then
echo "${yellow}Site is multisite.${normal}"
terminus wp -- "$sitename"."$siteenv" theme enable "$sagename"
fi

# List the themes.
terminus wp -- "$sitename"."$siteenv" theme list

Expand All @@ -475,14 +488,18 @@ function clean_up() {
exit 1;
fi

# If this is a CI environment, stop here.
if [ "$is_ci" == 1 ]; then
echo "${yellow}CI detected. All done here.${normal} 🍵"
exit 0;
fi

# Switch back to SFTP so files can be written.
terminus connection:set "$sitename"."$siteenv" sftp

if [ "$is_ci" -ne 1 ]; then
# Open the site. This should generate requisite files on page load.
echo "${yellow}Opening the ${siteenv}-${sitename}.pantheonsite.io to generate requisite files.${normal}"
open https://"$siteenv"-"$sitename".pantheonsite.io
fi
# Open the site. This should generate requisite files on page load.
echo "${yellow}Opening the ${siteenv}-${sitename}.pantheonsite.io to generate requisite files.${normal}"
open https://"$siteenv"-"$sitename".pantheonsite.io

# Commit any additions found in SFTP mode.
echo "${yellow}Committing any files found in SFTP mode that were created by Sage.${normal}"
Expand Down

0 comments on commit 20f44e7

Please sign in to comment.