Skip to content

Improve GH Actions in CLI #157

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

Merged
merged 10 commits into from
May 23, 2025
Merged

Conversation

iMattPro
Copy link
Contributor

@iMattPro iMattPro commented May 21, 2025

Make choosing the Github Action type of workflow a choice:
Screenshot 2025-05-22 at 6 53 51 AM

This prevents confusing and asking the user twice about creating a github action workflow

@codecov-commenter
Copy link

codecov-commenter commented May 21, 2025

Codecov Report

Attention: Patch coverage is 89.65517% with 3 lines in your changes missing coverage. Please review.

Project coverage is 74.30%. Comparing base (e06c67f) to head (3024ae0).

Files with missing lines Patch % Lines
console/create.php 89.65% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #157      +/-   ##
============================================
+ Coverage     72.89%   74.30%   +1.40%     
- Complexity      125      131       +6     
============================================
  Files             8        8              
  Lines           369      393      +24     
============================================
+ Hits            269      292      +23     
- Misses          100      101       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@rxu rxu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • It would be handy to suggest current date as default for Please enter the date of the extension option. So you just hit "Enter" and go next option.
  • Option [1] for Create Github Actions workflow would be good as default.
  • For 'Reusable (Recommended – uses phpBB’s maintained workflow)' language entry got this in Windows console: [1] Reusable (Recommended – uses phpBB’s maintained workflow), but not sure if it's Windows console issue with UTF8 support.
    - At the final step, got this error:
In FilesystemLoader.php line 250:

  Unable to find template ".github/workflows/tests.yml.twig" (looked into: [ROOT]\ext\phpbb\skeleton\skeleton).

@iMattPro
Copy link
Contributor Author

iMattPro commented May 22, 2025

  • It would be handy to suggest current date as default for Please enter the date of the extension option. So you just hit "Enter" and go next option.
  • Option [1] for Create Github Actions workflow would be good as default.
  • For 'Reusable (Recommended – uses phpBB’s maintained workflow)' language entry got this in Windows console: [1] Reusable (Recommended – uses phpBB’s maintained workflow), but not sure if it's Windows console issue with UTF8 support.
  • At the final step, got this error:
In FilesystemLoader.php line 250:

  Unable to find template ".github/workflows/tests.yml.twig" (looked into: [ROOT]\ext\phpbb\skeleton\skeleton).
  1. Date thing would be a different PR
  2. No/0 is the default answer for every component
  3. Language stuff fixed
  4. I never see that reported or experienced. Maybe you have some file system where dot-folders are hidden/ignored?

@rxu
Copy link
Contributor

rxu commented May 22, 2025

I never see that reported or experienced.

It's just won't download from Github from the Code dropdown :) So it was missing in the archive for me.

@rxu
Copy link
Contributor

rxu commented May 22, 2025

No/0 is the default answer for every component

So, it can't be changed for the specific option?

@iMattPro
Copy link
Contributor Author

No/0 is the default answer for every component

So, it can't be changed for the specific option?

We don't want to install/set anything unless the user explicitly chooses it. So the default is always to skip or leave empty or say no.

@iMattPro
Copy link
Contributor Author

@codecov-ai-reviewer review

Copy link

codecov-ai bot commented May 22, 2025

On it! We are reviewing the PR and will provide feedback shortly.

Copy link

codecov-ai bot commented May 22, 2025

PR Description

This pull request refactors the extension skeleton generator to improve the handling of GitHub Actions workflows and enhance code organization. The primary goal is to provide a more streamlined and user-friendly experience for developers creating new phpBB extensions, with a focus on modernizing the testing workflow.

Click to see more

Key Technical Changes

Key technical changes include: 1) Introducing a choice-based selection for GitHub Actions workflows (None, Reusable, Standalone), replacing the previous boolean approach. 2) Extracting dependency checking logic into a dedicated check_dependencies() method for improved reusability. 3) Creating a handle_github_actions() method to encapsulate the specific logic for configuring GitHub Actions based on user selection. 4) Updating language strings to provide clearer descriptions of the GitHub Actions workflow options, including deprecation warnings for the Standalone option. 5) Correcting formatting inconsistencies in the .gitattributes file.

Architecture Decisions

The main architectural decision is to move away from a simple boolean choice for GitHub Actions to a more nuanced selection using Symfony's ChoiceQuestion. This allows for better control over the generated workflow and provides options for using a phpBB-maintained reusable workflow or a fully customizable standalone workflow. The introduction of dedicated methods for dependency checking and GitHub Actions handling promotes separation of concerns and improves code maintainability.

Dependencies and Interactions

This pull request primarily interacts with the Symfony Console component for handling user input and generating questions. It also relies on the language files for providing user-facing text. The changes affect the generation of the .github/workflows/tests.yml file, depending on the selected GitHub Actions option. The changes also interact with the Packager class (though the diff doesn't show changes to it), which is responsible for providing the component dialog values.

Risk Considerations

Potential risks include: 1) Incorrectly configured GitHub Actions workflows if the choice selection logic is flawed. 2) Compatibility issues if the minimum PHP version is not aligned with the use of array spread operators (although this is not explicitly used, it was suggested in the previous review). 3) The Standalone GitHub Actions workflow is now deprecated, which might cause confusion for existing users. Thorough testing is required to ensure the new workflow selection logic functions correctly and that the generated workflows are valid. The deprecation of the Standalone workflow should be clearly communicated to users.

Notable Implementation Details

Notable implementation details include: 1) The use of a lookup table ($github_actions_types) to map the selected choice to the corresponding component settings. 2) The early skipping of the githubactions_custom component in the main loop, which requires careful consideration to ensure all components are handled correctly. 3) The update to the test suite to reflect the new GitHub Actions selection logic. Reviewers should pay special attention to the handle_github_actions() method and the associated language strings to ensure they accurately reflect the intended behavior and provide clear guidance to users.

Comment on lines 217 to +229

return $return_value;
}

/**
* Check if all dependencies are satisfied
*
* @param array $dependencies List of dependencies to check
* @return bool
*/
private function check_dependencies(array $dependencies): bool
{
foreach ($dependencies as $depends)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've extracted the dependency checking logic to a separate method check_dependencies() which is a good practice for code reusability and maintainability. However, this method returns a boolean but doesn't provide any information about which dependency failed. Consider enhancing it to return more descriptive information for better error handling or logging.

Suggested change
return $return_value;
}
/**
* Check if all dependencies are satisfied
*
* @param array $dependencies List of dependencies to check
* @return bool
*/
private function check_dependencies(array $dependencies): bool
{
foreach ($dependencies as $depends)
/**
* Check if all dependencies are satisfied
*
* @param array $dependencies List of dependencies to check
* @return array|bool Returns true if all dependencies are met, or array with failed dependency info
*/
private function check_dependencies(array $dependencies): bool|array
{
$failed_dependencies = [];
foreach ($dependencies as $depends)
{
if (empty($this->data['components'][$depends]))
{
$failed_dependencies[] = $depends;
}
}
return empty($failed_dependencies) ? true : $failed_dependencies;
}

Comment on lines +230 to +245
{
if (empty($this->data['components'][$depends]))
{
return false;
}
}
return true;
}

/**
* Handle GitHub Actions specific logic
*/
private function handle_github_actions(): void
{
// Lookup table of GitHub Action component settings
$github_actions_types = [
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The handle_github_actions() method is a good separation of concerns for handling GitHub Actions specific logic. However, the hardcoded array indices (0, 1, 2) in the lookup table might make the code less maintainable if you add more options in the future. Consider using named constants or an enum-like approach for better readability and maintainability.

Suggested change
{
if (empty($this->data['components'][$depends]))
{
return false;
}
}
return true;
}
/**
* Handle GitHub Actions specific logic
*/
private function handle_github_actions(): void
{
// Lookup table of GitHub Action component settings
$github_actions_types = [
/**
* Handle GitHub Actions specific logic
*/
private function handle_github_actions(): void
{
// Define option constants for better readability
const OPTION_NONE = 0;
const OPTION_REUSABLE = 1;
const OPTION_STANDALONE = 2;
// Lookup table of GitHub Action component settings
$github_actions_types = [
self::OPTION_NONE => ['githubactions' => false, 'githubactions_custom' => false], // No (default)
self::OPTION_REUSABLE => ['githubactions' => true, 'githubactions_custom' => false], // Reusable
self::OPTION_STANDALONE => ['githubactions' => false, 'githubactions_custom' => true], // Standalone
];
// Rest of the method remains the same
$question_text = $this->language->lang('SKELETON_QUESTION_COMPONENT_GITHUBACTIONS') . $this->language->lang('COLON');
$choices = [];
foreach (array_keys($github_actions_types) as $i)
{
$choices[] = $this->language->lang('SKELETON_QUESTION_COMPONENT_GITHUBACTIONS_CLI', $i);
}

Comment on lines +260 to +267
$index = array_search($choice, $choices, true);

$component_settings = $github_actions_types[$index] ?? $github_actions_types[0];
$this->data['components'] = array_merge(
$this->data['components'] ?? [],
$component_settings
);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The handling of component dependencies and GitHub Actions has been improved, but I noticed that you're manually merging arrays with array_merge(). Consider using PHP 7.4+ array spread operator ([...$array1, ...$array2]) for a more modern and readable approach if your minimum PHP version supports it.

Suggested change
$index = array_search($choice, $choices, true);
$component_settings = $github_actions_types[$index] ?? $github_actions_types[0];
$this->data['components'] = array_merge(
$this->data['components'] ?? [],
$component_settings
);
}
$this->data['components'] = [
...$this->data['components'] ?? [],
...$component_settings
];

Comment on lines 159 to 166
$components = $this->packager->get_component_dialog_values();
foreach ($components as $component => $details)
{
foreach ($details['dependencies'] as $depends)
// Skip early as it's handled elsewhere
if ($component === 'githubactions_custom')
{
if (empty($this->data['components'][$depends]))
{
$this->data['components'][$component] = false;
continue 2;
}
continue;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the get_component_data() method, you're now skipping the 'githubactions_custom' component early in the loop. This creates a special case that might be confusing for future developers. Consider restructuring this to handle special components in a more systematic way, perhaps through a component registry or handler pattern.

Suggested change
$components = $this->packager->get_component_dialog_values();
foreach ($components as $component => $details)
{
foreach ($details['dependencies'] as $depends)
// Skip early as it's handled elsewhere
if ($component === 'githubactions_custom')
{
if (empty($this->data['components'][$depends]))
{
$this->data['components'][$component] = false;
continue 2;
}
continue;
}
protected function get_component_data()
{
$components = $this->packager->get_component_dialog_values();
$special_components = ['githubactions', 'githubactions_custom'];
foreach ($components as $component => $details)
{
// Handle special components with custom logic
if (in_array($component, $special_components, true))
{
if ($component === 'githubactions')
{
$this->handle_github_actions();
}
continue;
}
// Check dependencies
if (!$this->check_dependencies($details['dependencies']))
{
$this->data['components'][$component] = false;
continue;
}
// Default logic for all other components
$this->data['components'][$component] = $this->get_user_input(
'component_' . $component,
$details['default']
);
}
}

@iMattPro
Copy link
Contributor Author

@codecov-ai-reviewer test

Copy link

codecov-ai bot commented May 23, 2025

On it! Codecov is generating unit tests for this PR.

Copy link

codecov-ai bot commented May 23, 2025

Sentry has determined that unit tests are not necessary for this PR.

@iMattPro iMattPro merged commit 4a21d9e into phpbb-extensions:master May 23, 2025
35 checks passed
@iMattPro iMattPro deleted the updates branch May 23, 2025 05:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants