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

Update component migration to support status of "stable" #1262

Merged
merged 14 commits into from
Aug 2, 2022

Conversation

mxriverlynn
Copy link
Contributor

@mxriverlynn mxriverlynn commented Aug 2, 2022

problem

as part of #676, there are some components that need to be renamed but are already set as status :stable. for example, the Primer::BoxComponent needs to be renamed to Primer::Box. however, the current component migration task only support a status of alpha, beta, or deprecaated.

solution

this PR makes significant updates to component_status_migrator.thor, to allow for a status of stable in addition to the existing status entries.

with this change, there are many file moves and file content changes that need to understand whether or not the new status is set to stable, and adjust the changes accordingly. for example, files do not need to be placed in a stable sub-folder. they should be placed in the root components folder. class names, variable names, etc, need to exclude the word stable when updating files, as well.

this PR also cleans up some of the inconsistencies in the thor task code by extracting a move_file method, and adding some additional helper methods. some additional logging was also added to note when file moves or other changes are not needed

example: migrating BoxComponent to Box

the Primer::BoxComponent is currently stable and exists in the correct folder. however, the word Component needs to be removed. here is the output of running the status migrator to handle the rename:

> bundle exec thor component_status_migrator BoxComponent --status stable

      create  app/components/primer/box.rb
      remove  app/components/primer/box_component.rb
Nothing moved. Template file not found: stories/primer/box_component_stories.rb
      create  test/components/box_test.rb
      remove  test/components/box_component_test.rb
      create  stories/primer/box_stories.rb
      remove  stories/primer/box_component_stories.rb
No change needed - module Stable not added
        gsub  app/components/primer/box.rb
        gsub  test/components/box_test.rb
      insert  stories/primer/box_stories.rb
        gsub  stories/primer/box_stories.rb
        gsub  docs/src/@primer/gatsby-theme-doctocat/nav.yml
         run  grep -rl BoxComponent . --exclude=CHANGELOG.md --exclude=test/components/box_component_test.rb | xargs sed -i 's/Primer::BoxComponent/Primer::Box/g' from "."
      append  app/components/primer/box.rb
      insert  lib/rubocop/cop/primer/component_name_migration.rb
         run  bundle exec rubocop -a from "."

      ... etc

and the file changes from git status (after git add . to ensure file renames are displayed correctly):

> git status

On branch migrate-to-stable-component
Your branch is up to date with 'origin/migrate-to-stable-component'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	renamed:    app/components/primer/box_component.rb -> app/components/primer/box.rb
	modified:   app/components/primer/flex_component.rb
	modified:   app/components/primer/flex_item_component.rb
	modified:   app/components/primer/popover_component.rb
	modified:   lib/rubocop/cop/primer/component_name_migration.rb
	modified:   static/arguments.yml
	modified:   static/audited_at.json
	modified:   static/constants.json
	modified:   static/statuses.json
	renamed:    stories/primer/box_component_stories.rb -> stories/primer/box_stories.rb
	renamed:    test/components/box_component_test.rb -> test/components/box_test.rb

known issues

both the current and this updated version of the migration script are unable to move files from any folder other than the root components/primer folder. for example, Primer::Alpha::ButtonMarketing currently exists in the components/primer/alpha folder. if the migration script is run to try and move this folder it will fail because the files don't currently exist in the root folder.

> bundle exec thor component_status_migrator ButtonMarketing --status beta

Nothing moved. Controller file not found: stories/primer/button_marketing_stories.rb
Nothing moved. Template file not found: stories/primer/button_marketing_stories.rb
Nothing moved. Test file not found: stories/primer/button_marketing_stories.rb
Nothing moved. Story file not found: stories/primer/button_marketing_stories.rb
The file /Users/riverlynn/dev/github/view_components/app/components/primer/beta/button_marketing.rb does not appear to exist

this is a separate issue that has been logged as issue #1263 and will require a separate PR to correct

@changeset-bot
Copy link

changeset-bot bot commented Aug 2, 2022

🦋 Changeset detected

Latest commit: cb19c67

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/view-components Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@mxriverlynn mxriverlynn temporarily deployed to github-pages August 2, 2022 17:02 Inactive
@mxriverlynn mxriverlynn changed the title [WIP] Update component migration to support status of "stable" Update component migration to support status of "stable" Aug 2, 2022
@mxriverlynn mxriverlynn marked this pull request as ready for review August 2, 2022 17:44
@mxriverlynn mxriverlynn requested review from a team and keithamus August 2, 2022 17:44
@mxriverlynn mxriverlynn mentioned this pull request Aug 2, 2022
54 tasks
Copy link
Contributor

@camertron camertron left a comment

Choose a reason for hiding this comment

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

Wow awesome, thanks! 🎉 Could you add a changeset tho?

component_status_migrator.thor Outdated Show resolved Hide resolved
Co-authored-by: Cameron Dutro <camertron@gmail.com>
@mxriverlynn mxriverlynn temporarily deployed to github-pages August 2, 2022 18:42 Inactive
@mxriverlynn mxriverlynn temporarily deployed to github-pages August 2, 2022 18:49 Inactive
@mxriverlynn mxriverlynn temporarily deployed to github-pages August 2, 2022 20:24 Inactive
@mxriverlynn mxriverlynn enabled auto-merge (squash) August 2, 2022 20:30
@mxriverlynn mxriverlynn temporarily deployed to github-pages August 2, 2022 20:35 Inactive
@mxriverlynn mxriverlynn merged commit 4a347b6 into main Aug 2, 2022
@mxriverlynn mxriverlynn deleted the migrate-to-stable-component branch August 2, 2022 20:40
@primer-css primer-css mentioned this pull request Aug 2, 2022
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.

2 participants