-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.php
140 lines (129 loc) · 4.32 KB
/
run.php
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
include 'vendor/autoload.php';
include 'funcs_scripts.php';
include 'funcs_utils.php';
include 'update_command.php';
include 'labels_command.php';
include 'rulesets_command.php';
use SilverStripe\SupportedModules\MetaData;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputOption;
// consts
const BRANCH_OPTIONS = ['next-minor', 'next-patch', 'github-default'];
const DEFAULT_BRANCH = 'next-patch';
const DEFAULT_ACCOUNT = 'creative-commoners';
const DATA_DIR = '_data';
const MODULES_DIR = '_modules';
const TOOL_URL = 'https://github.com/silverstripe/module-standardiser';
const PR_TITLE = 'MNT Run module-standardiser';
const PR_DESCRIPTION = 'This pull-request was created automatically by [module-standardiser](' . TOOL_URL . ')';
// DO NOT change these constants or else new ruleset will be created instead of
// updating existing rulesets and we'll end up with 2x rulesets
const BRANCH_RULESET_NAME = 'Silverstripe CMS branch ruleset';
const TAG_RULESET_NAME = 'Silverstripe CMS tag ruleset';
// global variables
$MODULE_DIR = '';
$GITHUB_REF = '';
$PRS_CREATED = [];
$REPOS_WITH_PRS_CREATED = [];
$REPOS_WITH_LABELS_UPDATED = [];
$REPOS_WITH_RULESETS_UPDATED = [];
$REPOS_WITH_PRS_TO_CLOSE = [];
$OUT = null;
// options
$optionCmsMajor = [
'cms-major',
null,
InputOption::VALUE_REQUIRED,
'The CMS major version to use (default: '. MetaData::HIGHEST_STABLE_CMS_MAJOR .')'
];
$optionBranch = [
'branch',
null,
InputOption::VALUE_REQUIRED,
'The branch type to use - ' . implode('|', BRANCH_OPTIONS) . ' (default: ' . DEFAULT_BRANCH . ')'
];
$optionScript = [
'script',
null,
InputOption::VALUE_REQUIRED,
'Only run a specific script. This is the name of the script file without the file extension '
. 'e.g. tag-patch-release'
];
$optionOnly = [
'only',
null,
InputOption::VALUE_REQUIRED,
'Only include the specified modules (without account prefix) separated by commas '
. 'e.g. silverstripe-config,silverstripe-assets'
];
$optionExclude = [
'exclude',
null,
InputOption::VALUE_REQUIRED,
'Exclude the specified modules (without account prefix) separated by commas '
. 'e.g. silverstripe-mfa,silverstripe-totp'
];
$optionDryRun = [
'dry-run',
null,
InputOption::VALUE_NONE,
'Do not push to github or create pull-requests'
];
$optionAccount = [
'account',
null,
InputOption::VALUE_REQUIRED,
'GitHub account to use for creating pull-requests (default: ' . DEFAULT_ACCOUNT . ')'
];
$optionNoDelete = [
'no-delete',
null,
InputOption::VALUE_NONE,
'Do not delete _data and _modules directories before running'
];
$optionUnsupported = [
'unsupported-default-branch',
null,
InputOption::VALUE_NONE,
'Only update unsupported modules that were supported in the previous CMS major. Will use the GitHub default branch for each repository. Can not be used with the --cms-major option and will ignore the --branch option.'
];
$optionUpdatePrs = [
'update-prs',
null,
InputOption::VALUE_NONE,
'Checkout out and update the latest open PR instead of creating a new one'
];
$app = new Application();
$app->register('update')
->setDescription('The main script of module-standardiser')
->addOption(...$optionCmsMajor)
->addOption(...$optionBranch)
->addOption(...$optionScript)
->addOption(...$optionOnly)
->addOption(...$optionExclude)
->addOption(...$optionDryRun)
->addOption(...$optionAccount)
->addOption(...$optionNoDelete)
->addOption(...$optionUnsupported)
->addOption(...$optionUpdatePrs)
->setCode($updateCommand);
$app->register('labels')
->setDescription('Script to set labels on all repos')
->addOption(...$optionOnly)
->addOption(...$optionExclude)
->addOption(...$optionDryRun)
->addOption(...$optionNoDelete)
->setCode($labelsCommand);
$app->register('rulesets')
->setDescription('Script to set rulesets on all repos only on the silverstripe account')
->addOption(...$optionOnly)
->addOption(...$optionExclude)
->addOption(...$optionDryRun)
->setCode($rulesetsCommand);
try {
$app->run();
} catch (Error|Exception $e) {
// Make sure we output and information about PRs which were raised before killing the process.
error("file: {$e->getFile()}\nline: {$e->getLine()}\nmessage: {$e->getMessage()}");
}