-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add conditional logic to drush deploy quicksilver script (#484)
`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
1 parent
ec9e292
commit ac5b5f4
Showing
3 changed files
with
56 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} |