|
| 1 | +# Testing primitives using a feature flag |
| 2 | + |
| 3 | +## 1. Create a PR |
| 4 | + |
| 5 | +Start by creating a PR in `primer/primitives`. Once all the tests are passing you are ready to move on. |
| 6 | + |
| 7 | +You will needs the pre-release version later in the process. So copy the version number from the `Published @primer/primitives` job. This is something like `0.0.0-20241007214729`. |
| 8 | + |
| 9 | +## 2. Create the feature flag |
| 10 | + |
| 11 | +To create the feature flag, you need to log into the [DevPortal](https://devportal.githubapp.com/feature-flags) and navigate to the [feature flags](https://devportal.githubapp.com/feature-flags) section. |
| 12 | + |
| 13 | +Click on the `New feature flag` button and fill in the required information. |
| 14 | + |
| 15 | +**Important:** Make sure to choose a descriptive name that is easy to understand. You **CANNOT** change the name. |
| 16 | + |
| 17 | +Confirm with the `Save feature` button. |
| 18 | + |
| 19 | +## 3. Add yourself to the feature flag |
| 20 | + |
| 21 | +You should first add yourself to the feature flag and test that everything is working. Afterwards you can add others. |
| 22 | + |
| 23 | +To do so, open the feature flag and navigate to the `Targeting rules` tab. |
| 24 | +Now click the `Switch to another stamp` dropdown and select `ditcom`. |
| 25 | +Under `Actors` add yourself. |
| 26 | + |
| 27 | +## 4. Create a PR in `github/github` |
| 28 | + |
| 29 | +Now it is time to create a PR in `github/github` to add your feature for all users that have the feature flag active. |
| 30 | + |
| 31 | +This requires a few changes: |
| 32 | + |
| 33 | +### Preload the feature flag |
| 34 | + |
| 35 | +You need to add your feature flag to `app/controllers/application_controller/preload_feature_flags_dependency.rb`: |
| 36 | + |
| 37 | +``` |
| 38 | +:primitives_my_feature_flag # a comment describing what the feature flag does |
| 39 | +``` |
| 40 | + |
| 41 | +### Install your pre-release |
| 42 | + |
| 43 | +In `github/github` dependencies are installed in workspaces. Primitives are part of the `@npm-workspaces/primer` workspace. |
| 44 | +Additionally, since the stable version of primitives is already installed, you need to install your version with an [npm alias](https://docs.npmjs.com/cli/v8/commands/npm-install#:~:text=npm%20install%20%3Calias%3E%40npm%3A%3Cname%3E%3A). |
| 45 | + |
| 46 | +For example: |
| 47 | + |
| 48 | +```bash |
| 49 | +npm i @primer/primitives-my-feature-flag@npm:@primer/ [email protected] --workspace=@npm-workspaces/primer |
| 50 | +``` |
| 51 | + |
| 52 | +**NOTE:** This package needs to be checked into git. On dotcom all packages are added in git. |
| 53 | + |
| 54 | +### Create a new bundle (optional) |
| 55 | + |
| 56 | +If you want to load some new tokens you can add a new bundle and load it for users who have the feature flags enabled. |
| 57 | + |
| 58 | +To do so, first create a new bundle by creating a new folder in `app/assets/stylesheets/bundles/` for example `primer-primitives-your-bundle`. |
| 59 | +In this folder add an `index.scss` file that includes all files you want to load: |
| 60 | + |
| 61 | +```scss |
| 62 | +@import '@primer/primitives-my-feature-flag/dist/css/functional/themes/new-theme.css'; |
| 63 | +``` |
| 64 | + |
| 65 | +You now need to load your css bundle if the feature flag is active by placing the code below in all nessesary places, for example `app/views/layouts/application.html.erb`. |
| 66 | + |
| 67 | +```ruby |
| 68 | +# this bundle (index.scss in the folder) will only be loaded if the users has the primitives_my_feature_flag feature flag enabled |
| 69 | +<%= stylesheet_bundle "primer-primitives-your-bundle" if user_feature_enabled?(:primitives_my_feature_flag) %> |
| 70 | +``` |
| 71 | +
|
| 72 | +Now you need to generate the `SERVICEOWNERS` and `CODEOWNERS` by running `bin/generate-service-files.rb` in the console or by running it as a task in vs code. |
| 73 | +
|
| 74 | +It should add a line like this to the `SERVICEOWNERS`: |
| 75 | +
|
| 76 | +``` |
| 77 | +app/assets/stylesheets/bundles/primer-primitives-your-bundle/ :primer_dotcom |
| 78 | +``` |
| 79 | +
|
| 80 | +And a line like this to the `CODEOWNERS`: |
| 81 | +
|
| 82 | +``` |
| 83 | +/app/assets/stylesheets/bundles/primer-primitives-your-bundle/ @github/primer-reviewers |
| 84 | +``` |
0 commit comments