Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Added a drush package action and task #1

Merged
merged 5 commits into from 9 months ago

2 participants

Mads Høgstedt Danquah Thomas Fini Hansen
Mads Høgstedt Danquah

No description provided.

ci.drakefile.drushrc.php
@@ -125,6 +125,13 @@
125 125
   ),
126 126
 );
127 127
 
  128
+/**
  129
+ * Fileset that contains everything.
  130
+ */
  131
+$filesets['root'] = array(
1
Thomas Fini Hansen Owner
xendk added a note August 01, 2013

Should be named "all".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
ci.drakefile.drushrc.php
@@ -309,6 +316,37 @@
309 316
 );
310 317
 
311 318
 /*
  319
+ * Package a build into a timestamped zip-file placed in the root of the site.
  320
+ */
  321
+$tasks['package'] = array(
  322
+  'action' => 'package',
  323
+  'files' => fileset('root'),
  324
+  'output-dir' => context_optional('package-output-dir', context('[@self:site:root]')),
  325
+  'basename' => context_optional('package-basename', 'package'),
  326
+  'prefix' => context_optional('package-prefix', date('Y-m-d-His')),
  327
+);
  328
+
  329
+/*
  330
+ * Package a build into a zip-file.
  331
+ */
  332
+$actions['package'] = array(
1
Thomas Fini Hansen Owner
xendk added a note August 01, 2013

Too generic. There might come other packaging commands for tar.gz, etc.

"package-zip" is better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
ci.drakefile.drushrc.php
((28 lines not shown))
  388
+
  389
+  // Add files to the archive.
  390
+  drush_log(dt('Packaging to @file', array('@file' => $output)), 'status');
  391
+  foreach ($context['files'] as $file) {
  392
+    $zip->addFile($file->fullPath(), $file->path());
  393
+  }
  394
+  $zip->close();
  395
+  return TRUE;
  396
+}
  397
+
  398
+/**
  399
+ * Returns a human-readable status.
  400
+ *
  401
+ * Nabbed from http://www.php.net/manual/en/class.ziparchive.php#108601
  402
+ */
  403
+function drake_get_zip_status_string($status) {
1
Thomas Fini Hansen Owner
xendk added a note August 01, 2013

Should be drake_ci_get_zip_status_string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Thomas Fini Hansen xendk merged commit 5fcb306 into from August 01, 2013
Thomas Fini Hansen xendk closed this August 01, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 157 additions and 0 deletions. Show diff stats Hide diff stats

  1. 157  ci.drakefile.drushrc.php
157  ci.drakefile.drushrc.php
@@ -125,6 +125,13 @@
125 125
   ),
126 126
 );
127 127
 
  128
+/**
  129
+ * Fileset that contains everything.
  130
+ */
  131
+$filesets['all'] = array(
  132
+  'dir' => context('root'),
  133
+);
  134
+
128 135
 /*
129 136
  * Convinience tasks.
130 137
  *
@@ -309,6 +316,37 @@
309 316
 );
310 317
 
311 318
 /*
  319
+ * Package a build into a timestamped zip-file placed in the root of the site.
  320
+ */
  321
+$tasks['package-zip'] = array(
  322
+  'action' => 'package-zip',
  323
+  'files' => fileset('all'),
  324
+  'output-dir' => context_optional('package-output-dir', context('[@self:site:root]')),
  325
+  'basename' => context_optional('package-basename', 'package'),
  326
+  'prefix' => context_optional('package-prefix', date('Y-m-d-His')),
  327
+);
  328
+
  329
+/*
  330
+ * Package a build into a zip-file.
  331
+ */
  332
+$actions['package-zip'] = array(
  333
+  'default_message' => 'Packaging build.',
  334
+  'callback' => 'drake_ci_package',
  335
+  'parameters' => array(
  336
+    'files' => 'Files to package',
  337
+    'output-dir' => 'Output directory',
  338
+    'basename' => array(
  339
+      'description' => 'Destination filename without extension',
  340
+      'default' => 'packaged',
  341
+    ),
  342
+    'prefix' => array(
  343
+      'description' => 'Optional prefix to add to the package',
  344
+      'default' => '',
  345
+    ),
  346
+  ),
  347
+);
  348
+
  349
+/*
312 350
  * Clean up output directory, if specified.
313 351
  */
314 352
 $actions['ci-clean'] = array(
@@ -323,6 +361,125 @@
323 361
 );
324 362
 
325 363
 /**
  364
+ * Package a build.
  365
+ */
  366
+function drake_ci_package($context) {
  367
+  if (empty($context['files'])) {
  368
+    return drake_action_error(dt('No files specified.'));
  369
+  }
  370
+
  371
+  // Prepare the path with trailing slash.
  372
+  $output = $context['output-dir'] . (substr($context['output-dir'], -1) == '/' ? '' : '/');
  373
+  if (!is_writable($output)) {
  374
+    return drake_action_error(dt('Output dir @dir is not writable.', array('@dir' => $output)));
  375
+  }
  376
+  // Add the prefix, basename and extension.
  377
+  $output .= (empty($context['prefix']) ? '' : $context['prefix'] . '-');
  378
+  $output .= $context['basename'];
  379
+  $output .= '.zip';
  380
+
  381
+  // Prepare the zip-file.
  382
+  $zip = new ZipArchive();
  383
+  // ZipArchive::CREATE == Create or overwrite.
  384
+  $res = $zip->open($output, ZipArchive::CREATE);
  385
+  if ($res !== TRUE) {
  386
+    return drake_action_error(drake_ci_get_zip_status_string($res));
  387
+  }
  388
+
  389
+  // Add files to the archive.
  390
+  drush_log(dt('Packaging to @file', array('@file' => $output)), 'status');
  391
+  foreach ($context['files'] as $file) {
  392
+    $zip->addFile($file->fullPath(), $file->path());
  393
+  }
  394
+  $zip->close();
  395
+  return TRUE;
  396
+}
  397
+
  398
+/**
  399
+ * Returns a human-readable status.
  400
+ *
  401
+ * Nabbed from http://www.php.net/manual/en/class.ziparchive.php#108601
  402
+ */
  403
+function drake_ci_get_zip_status_string($status) {
  404
+  switch ((int) $status) {
  405
+    case ZipArchive::ER_OK:
  406
+      return 'No error';
  407
+
  408
+    case ZipArchive::ER_MULTIDISK:
  409
+      return 'Multi-disk zip archives not supported';
  410
+
  411
+    case ZipArchive::ER_RENAME:
  412
+      return 'Renaming temporary file failed';
  413
+
  414
+    case ZipArchive::ER_CLOSE:
  415
+      return 'Closing zip archive failed';
  416
+
  417
+    case ZipArchive::ER_SEEK:
  418
+      return 'Seek error';
  419
+
  420
+    case ZipArchive::ER_READ:
  421
+      return 'Read error';
  422
+
  423
+    case ZipArchive::ER_WRITE:
  424
+      return 'Write error';
  425
+
  426
+    case ZipArchive::ER_CRC:
  427
+      return 'CRC error';
  428
+
  429
+    case ZipArchive::ER_ZIPCLOSED:
  430
+      return 'Containing zip archive was closed';
  431
+
  432
+    case ZipArchive::ER_NOENT:
  433
+      return 'No such file';
  434
+
  435
+    case ZipArchive::ER_EXISTS:
  436
+      return 'File already exists';
  437
+
  438
+    case ZipArchive::ER_OPEN:
  439
+      return 'Can\'t open file';
  440
+
  441
+    case ZipArchive::ER_TMPOPEN:
  442
+      return 'Failure to create temporary file';
  443
+
  444
+    case ZipArchive::ER_ZLIB:
  445
+      return 'Zlib error';
  446
+
  447
+    case ZipArchive::ER_MEMORY:
  448
+      return 'Malloc failure';
  449
+
  450
+    case ZipArchive::ER_CHANGED:
  451
+      return 'Entry has been changed';
  452
+
  453
+    case ZipArchive::ER_COMPNOTSUPP:
  454
+      return 'Compression method not supported';
  455
+
  456
+    case ZipArchive::ER_EOF:
  457
+      return 'Premature EOF';
  458
+
  459
+    case ZipArchive::ER_INVAL:
  460
+      return 'Invalid argument';
  461
+
  462
+    case ZipArchive::ER_NOZIP:
  463
+      return 'Not a zip archive';
  464
+
  465
+    case ZipArchive::ER_INTERNAL:
  466
+      return 'Internal error';
  467
+
  468
+    case ZipArchive::ER_INCONS:
  469
+      return 'Zip archive inconsistent';
  470
+
  471
+    case ZipArchive::ER_REMOVE:
  472
+      return 'Can\'t remove file';
  473
+
  474
+    case ZipArchive::ER_DELETED:
  475
+      return 'Entry has been deleted';
  476
+
  477
+    default:
  478
+      return dt('Unknown status @status', array('@status' => $status));
  479
+  }
  480
+}
  481
+
  482
+/**
326 483
  * CI clean action. Empty the output directory, if specified.
327 484
  */
328 485
 function drake_ci_clean($context) {
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.