Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Several improvements #68

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ MS_GITHUB_TOKEN=abc123 php run.php update --cms-major=5 --branch=next-minor --dr
| ---- | ------------|
| --cms-major=[version] | The major version of CMS to use (default: 5) which determines the list of supported modules to use |
| --branch=[type] | The branch type to use - `next-minor`\|`next-patch`\|`github-default` (default: `next-patch`) |
| --script=[scriptname] | Only run a specific script. This is the name of the script file without the file extension e.g. `tag-patch-release` |
| --only=[modules] | Only include the specified modules (without account prefix) separated by commas e.g. `silverstripe-config,silverstripe-assets` |
| --exclude=[modules] | Exclude the specified modules (without account prefix) separated by commas e.g. `silverstripe-mfa,silverstripe-totp` |
| --dry-run | Do not push to github or create pull-requests |
Expand Down
16 changes: 16 additions & 0 deletions funcs_utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
function error($message)
{
output_prs_created();
output_repos_with_prs_to_close();
output_repos_with_prs_created();
io()->error($message);
if (!running_unit_tests()) {
Expand Down Expand Up @@ -227,6 +228,21 @@ function output_repos_with_prs_created()
$io->writeln('');
}

function output_repos_with_prs_to_close()
{
if (running_unit_tests()) {
return;
}
global $REPOS_WITH_PRS_TO_CLOSE;
$io = io();
$io->writeln('');
$io->writeln('Repos with pull requests that should be closed:');
foreach ($REPOS_WITH_PRS_TO_CLOSE as $pr) {
$io->writeln("- $pr");
}
$io->writeln('');
}

/**
* Outputs a list of repos that that had labels updated
* If there was an error with a run (probably a secondary rate limit), this can be
Expand Down
9 changes: 9 additions & 0 deletions run.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
$REPOS_WITH_PRS_CREATED = [];
$REPOS_WITH_LABELS_UPDATED = [];
$REPOS_WITH_RULESETS_UPDATED = [];
$REPOS_WITH_PRS_TO_CLOSE = [];
$OUT = null;

// options
Expand All @@ -48,6 +49,13 @@
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,
Expand Down Expand Up @@ -99,6 +107,7 @@
->setDescription('The main script of module-standardiser')
->addOption(...$optionCmsMajor)
->addOption(...$optionBranch)
->addOption(...$optionScript)
->addOption(...$optionOnly)
->addOption(...$optionExclude)
->addOption(...$optionDryRun)
Expand Down
21 changes: 19 additions & 2 deletions scripts/cms-any/tag-patch-release.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,26 @@
EOT;

$workflowPath = '.github/workflows/tag-patch-release.yml';
$ciPath = '.github/workflows/ci.yml';
$ciPaths = [ '.github/workflows/ci.yml', '.github/workflows/action-ci.yml' ];
$shouldHaveAction = false;

if (check_file_exists($ciPath)) {
foreach ($ciPaths as $ciPath) {
if (check_file_exists($ciPath)) {
$shouldHaveAction = true;
}
}

$notAllowedRepos = [
'cow',
'rhino',
'github-issue-search-client',
'module-standardiser',
'silverstripe-tx-translator',
'supported-modules',
];
$shouldHaveAction = $shouldHaveAction && !is_misc() && !module_is_one_of($notAllowedRepos);

if ($shouldHaveAction) {
write_file_even_if_exists($workflowPath, $content);
} else {
delete_file_if_exists($workflowPath);
Expand Down
34 changes: 20 additions & 14 deletions update_command.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// This is the code that is executed when running the 'update' command

// variables
global $MODULE_DIR, $GITHUB_REF, $OUT, $PRS_CREATED, $REPOS_WITH_PRS_CREATED;
global $MODULE_DIR, $GITHUB_REF, $OUT, $PRS_CREATED, $REPOS_WITH_PRS_CREATED, $REPOS_WITH_PRS_TO_CLOSE;
$OUT = $output;

$reposMissingBranch = [];
Expand Down Expand Up @@ -161,15 +161,26 @@
error("Branch $branchToCheckout does not support CMS major version $cmsMajor");
}

// create a new branch used for the pull-request
if (!$input->getOption('update-prs')) {
if ($input->getOption('update-prs')) {
// Delete the last commit so we're starting as through we didn't do the previous run
$lastCommitMessage = cmd('git log -1 --pretty=%B', $MODULE_DIR);
if ($lastCommitMessage !== PR_TITLE) {
error("Last commit message \"$lastCommitMessage\" does not match PR_TITLE \"" . PR_TITLE . "\"");
}
cmd("git reset HEAD~ --hard", $MODULE_DIR);
} else {
// create a new branch used for the pull-request
$timestamp = time();
$prBranch = "pulls/$branchToCheckout/module-standardiser-$timestamp";
cmd("git checkout -b $prBranch", $MODULE_DIR);
}

// run scripts
$onlyThisScript = $input->getOption('script');
foreach ($scriptFiles as $scriptFile) {
if ($onlyThisScript && basename($scriptFile, '.php') !== $onlyThisScript) {
continue;
}
$contents = file_get_contents($scriptFile);
$contents = str_replace('<?php', '', $contents);
// wrap in an anonymous function to ensure that script variables do not go into the global scope
Expand All @@ -181,20 +192,14 @@
$status = cmd('git status', $MODULE_DIR);
if (strpos($status, 'nothing to commit') !== false) {
info("No changes to commit for $repo");
if ($input->getOption('update-prs')) {
$REPOS_WITH_PRS_TO_CLOSE[] = $GITHUB_REF;
}
continue;
}
// create new commit
cmd('git add .', $MODULE_DIR);
if ($input->getOption('update-prs')) {
// squash on to existing commit
$lastCommitMessage = cmd('git log -1 --pretty=%B', $MODULE_DIR);
if ($lastCommitMessage !== PR_TITLE) {
error("Last commit message \"$lastCommitMessage\" does not match PR_TITLE \"" . PR_TITLE . "\"");
}
cmd("git commit --amend --no-edit", $MODULE_DIR);
} else {
// create new commit
cmd("git commit -m '" . PR_TITLE . "'", $MODULE_DIR);
}
cmd("git commit -m '" . PR_TITLE . "'", $MODULE_DIR);
if ($input->getOption('dry-run')) {
info('Not pushing changes or creating pull-request because --dry-run option is set');
continue;
Expand Down Expand Up @@ -223,6 +228,7 @@
}
output_repos_with_prs_created();
output_prs_created();
output_repos_with_prs_to_close();

// Report about any repos for which we couldn't find the right branch.
if (count($reposMissingBranch)) {
Expand Down
Loading