Skip to content

Commit

Permalink
fix: add conditional logic to drush deploy quicksilver script (#484)
Browse files Browse the repository at this point in the history
`drush deploy` that runs in CI was getting no output because it was first running on the platform from Quicksilver.
This updated script uses Pantheon's workflow API endpoint to check if the sync_code hook was initiated by our machine user or not.
This commit also renames this file and references in pantheon.yml, since it is now doing more than just a config import.
  • Loading branch information
vinmassaro authored Nov 17, 2023
1 parent ec9e292 commit ac5b5f4
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 14 deletions.
12 changes: 6 additions & 6 deletions pantheon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ workflows:
clone_database:
after:
- type: webphp
description: Import configuration from .yml files
script: private/scripts/confim.php
description: Run drush deploy
script: private/scripts/drush_deploy.php
deploy:
after:
- type: webphp
description: Import configuration from .yml files
script: private/scripts/confim.php
description: Run drush deploy
script: private/scripts/drush_deploy.php
sync_code:
after:
- type: webphp
description: Import configuration from .yml files
script: private/scripts/confim.php
description: Run drush deploy
script: private/scripts/drush_deploy.php
8 changes: 0 additions & 8 deletions web/private/scripts/confim.php

This file was deleted.

50 changes: 50 additions & 0 deletions web/private/scripts/drush_deploy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/*
* This script conditionally runs `drush deploy`.
* We only want it to run conditionally if:
* 1. The current workflow is a code sync
* 2. The previous workflow applied upstream updates
* 3. The user applying upstream updates is not [email protected]
* This stops it from running from Quicksilver when we are updating sites in CI,
* but lets it run when manually applied from a site dashboard.
* This allows for the command output to be captured in CI.
*/

$workflowType = $_POST['wf_type'];
$userEmail = $_POST['user_email'];
$skipMessage = "Skipping drush deploy...\n";
$runMessage = "Running drush deploy...\n";

// Handle code_sync workflows.
if (in_array($workflowType, ['sync_code', 'sync_code_with_build'])) {
$workflows = json_decode(pantheon_curl('https://api.live.getpantheon.com/sites/self/workflows?limit=5', NULL, 8443, 'GET')['body']);

// sync_code is always run by the Pantheon user, so we need to check
// if apply_upstream_updates was a nearby previous workflow triggered by a different user.
// Get only the first occurence in case there are multiple.
$previousWorkflow = null;
foreach ($workflows as $workflow) {
if ($workflow->type == 'apply_upstream_updates') {
$previousWorkflow = $workflow;
break;
}
}

if ($previousWorkflow && $previousWorkflow->user_email !== '[email protected]') {
print $runMessage;
passthru('drush deploy');
}
else {
print $skipMessage;
}
}
// Handle deploy workflows.
elseif ($workflowType == 'deploy' && $userEmail !== '[email protected]') {
print $runMessage;
passthru('drush deploy');
}
// Handle any other workflows where it should always run.
else {
print $runMessage;
passthru('drush deploy');
}

0 comments on commit ac5b5f4

Please sign in to comment.