- Project
- Git
- Branches
- Example Workflow
- Pull Request Norms
- Merge Conflicts
- Patching
- Updates
- Module Uninstal / Removal
- Pull a ticket, move to 'In Development'
- Review the ticket's story, Acceptance Criteria, and Implementation Notes. Raise any questions/concerns/risks in the ticket comments and mention the relevant/appropriate people.
- Write a manual to test ticket completion.
In this repo, we recommend working in individual branches and creating PRs to merge the branches to main. You can use the GitHub CLI, gh
, to make PRs from the command line much faster. Or after you push you will see a link in the output to ctrl + click and create a new PR from the branch you just pushed. See Getting started for more details.
We are currently working off a single main
branch. main
is protected and requires both approval from code review and passing tests to be merged. Commits within pull requests are squashed and merged when they are accepted so that the only relate to one git commit, even if they originally contained multiple commits, the commit messages are added as a bulleted list so they are retained in the merge commit.
git fetch --all
git checkout -b <VACMS-000-name> origin/main
ddev composer install
ddev start
orddev restart
ddev pull va --skip-files
orddev pull va
idf you need managed files (images and pdfs)- Running
ddev test
will build the frontend web and run all tests (PHPUnit, accessibility, FE web) See testing for additional details. - If possible, write your test, before you write code. The test should fail initially and not pass until you succeed.
- Fix code formatting issues with CodeSniffer, Drupal standard (linters should run automatically upon trying to commit).
- Commit your changes. Each commit should be logically atomic (e.g. module adds in one commit, config in another, custom code in additional logical commits), and your commit messages should follow the pattern: "VACMS-123: A grammatically correct sentence starting with an action verb and ending with punctuation." Example: VACMS-1234 Add configuration for menu reduction.
- Push work in your branch to the remote repository so a Pull Request may be created
git push origin <branchname>
- Once your PR is merged it will be automatically deployed to staging.cms.va.gov. If it is merged before 2:30pm ET and tests pass it will be in the daily, scheduled deploy to prod.cms.va.gov at 3:30pm ET.
While working on your own branch, you may have to rebase it on main which will make it out of sync with your remote branch and will require you to force push to your branch.
It is never ok to force push to the main branch or an integration branch where other folks may be working from. On your own branch, it is perfectly acceptable to do force pushes. If you have recently rebased your branch on main, you may have to do a force push to your branch. When in doubt, ask in Slack.
- Pull requests should be made against the
main
branch. - Pull Request title should be in the format: "VACMS-123: ticket title, starting with an action verb and ending with punctuation."
- If your PR is a work in progress or should not be merged, use the Draft feature.
- Put a link to the ticket at the top of the PR description.
- Add required notes in the PR description:
- If the PR requires manual deployment steps (this should rarely happen).
- If the timing of the merging of the PR affects or has dependencies on additional PRs in this or other repositories.
- If the PR removes existing functionality that may impact other developers.
- When the PR is ready for review, add appropriate QA steps and take it out of draft.
Merge conflicts result when multiple developers submit PRs modifying the same code and Git cannot automatically resolve the conflict. For instance, if two developers add update hooks to the same module at the same time, these will necessarily conflict, because update hooks must be numbered in a defined sequence.
Developers are responsible for fixing merge conflicts on their own PRs. Follow this process to resolve a merge conflict:
- Fetch upstream history:
git fetch upstream
- Check out the branch against which you opened your PR (e.g., main):
git checkout main
- Make sure it matches upstream:
git reset --hard upstream/main
- Check out your feature branch:
git checkout feature/VACMS-123-short-desc-mi
- Merge
main
branch:git rebase main
- At this point, Git will complain about a merge conflict. Run
git status
to find the conflicting file(s). - Edit the files to fix the conflict. The resources at the end of this section provide more information on this process.
- Use git add to add all of the files you fixed. (Do not commit them)
- Finally, run
git rebase --continue
to finish the merge, thengit push origin VACMS-123-short-desc-mi -f
to update the PR.
Additional resources:
- https://confluence.atlassian.com/bitbucket/resolve-merge-conflicts-704414003.html
- https://githowto.com/resolving_conflicts
If your composer.lock ends up with a conflict due to incoming changes, these steps should safely resolve the conflict.
- Make note of what new packages are coming in from main.
- Make note of what package(s) you were adding.
- Checkout the incoming changes to composer.
git checkout upstream/main -- composer.lock composer.json
- Replay your package addition(s).
ddev composer require {new/package} --update-with-dependencies
- Run the new updates to make sure you have them locally.
ddev composer update {incoming/package}
- repeat for each incoming package additionddev composer update {your/package}
- repeat for each package you were adding
- Your environment can now be tested with the new code.
- Commit the changes to composer.json and composer.lock.
We follow the Drupal core javascript workflow, writing code in es6.js
files and transpiling to ES5 for backwards compatibility. Both the es6.js
and transpiled .js
files are committed to the repository. To follow this workflow:
- Create or edit a
.es6.js
file underdocroot/modules/custom
ordocroot/themes/custom
- Run
ddev npm install
to ensure that all dependencies are up to date - From the repository root, execute the command
ddev npm run build:js
(To have changes automatically transpiled while you work, runddev npm run watch:js
) - When you are finished, commit the changes to both files
We use the Composer plugin Composer Patches (https://github.com/cweagans/composer-patches) to apply patches that haven't been merged upstream yet. Patches should always be temporarily applied with an upstream issue being opened and/or tracked and the intention for the patch to be removed as soon as it is merged upstream and a new release created and included with Composer.
- Get the patch file:
- e.g. https://patch-diff.githubusercontent.com/raw/drupal-graphql/graphql/pull/726.patch
- For GitHub, you can usually type in
.patch
at the end of the PR URL to get the patch file - Some people use GitHub, some use drupal.org. Drupal moved to GitLab recently.
- If the patch is from a PR rather than an actual file, add it to the upstream issue as a file so that we can reference the file rather than a patch that will float with the upstream PR. A floating patch is a security risk.
- In the
patches
section ofcomposer.json
, make an entry for the package you are patching, if not already there, write an explanation to what the patch does, and then include the URL to the patch, e.g.:-
"patches": { "drupal/migration_tools": { "Add changeHtmlContents DomModifier method": "https://www.drupal.org/files/issues/2018-11-26/change_html_contents-3015381-3.patch",
-
Whenever possible, we want to contribute patches to support the community at the same time as our own project needs. For Drupal contributions, here are some suggestions for setting up module or issue contributions to make sure your company and the Department of Veteran Affairs get credited correctly.
Updating Drupal Core (dependabot usually does this so you shouldn't need to do this, but if you do...)
ddev composer update drupal/core --with-dependencies --dry-run
This will show you what is to change, without actually changing anything.ddev composer update drupal/core --with-dependencies
ddev composer update --lock
ddev drush updatedb --yes
ddev drush cache:rebuild
ddev test
- Review your changes then commit, e.g.
git commit --message "ddev composer update drupal/core --with-dependencies"
ddev composer update drupal/MODULE_NAME --with-dependencies
# This updates the composer.lock fileddev drush updatedb --yes
ddev drush cache:rebuild
ddev test
to make sure nothing broke.- Commit your work, e.g.
git commit --message "ddev composer update drupal/MODULE_NAME --with-dependencies"
flowchart TD
A[Module removal] --> B{Is the module installed?}
B -- Yes --> D[Needs a full uninstall.];
B -- NO --> C[Create and merge PR that removes module from composer.];
D --> E[Create PR with Drupal config removal. And remove any patches and patch section.];
E --> F[Wait until PR makes it to CMS Prod.];
F --> C;
C --> Z[Process complete];