summaryrefslogtreecommitdiff
path: root/WP/plugin-deploy-script-for-wp-org.php
blob: 3b66d49a2be93a994803d38d9e6565cf8c563167 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env php

<?php

$pluginSourcePath = $argv[1] ?? die('source path missing');
$svnDestinationPath = $argv[2] ?? die('desination path missing');

$pluginSourcePath = realpath($pluginSourcePath) ?: die('source path doesn\'t exist');
$svnDestinationPath = realpath($svnDestinationPath) ?: die('desination path doesn\'t exist');

if (! file_exists("$pluginSourcePath/composer.json")) {
    die('plugin is missing a composer.json file');
}
if (! is_dir("$svnDestinationPath/.svn")) {
    die('desination is not a svn repository. initialize it with "svn co https://plugins.svn.wordpress.org/your-plugin" first');
}

// get composer info
$composer = json_decode(file_get_contents("$pluginSourcePath/composer.json"));

// set files into deployable state
chdir($pluginSourcePath);
exec('composer install --no-dev');
exec('npm run build'); # if wp-scripts is used # TODO: how to use with .nvmrc?

// bundling deployable files
exec('composer archive -f zip');
$zipFilenames = glob('*.zip');
$zipFilename = $zipFilenames[array_key_last($zipFilenames)];
exec("unzip $pluginSourcePath/$zipFilename -d $svnDestinationPath/$zipFilename");

// copying files to svn trunk folder
chdir($svnDestinationPath);
exec("rsync -av $svnDestinationPath/$zipFilename/ $svnDestinationPath/trunk --delete");

// copy new version to tags
exec('svn cp trunk tags/' . $composer->version);

// commit
exec("svn commit -m 'updating to v{$composer->version}'");

// clean up files
unlink("$pluginSourcePath/$zipFilename");
exec("rm -rf $svnDestinationPath/$zipFilename"); # feeling dangerous