|
| 1 | +# Code of Conduct Patching Script |
| 2 | + |
| 3 | +This document explains the knowledge behind the patching script used |
| 4 | +to make any changes on the `CODE_OF_CONDUCT.md` file. |
| 5 | + |
| 6 | +The patching script lives under |
| 7 | +[pkgjs/patch-my-code-of-conduct][project-link] repository. |
| 8 | +It is developed as a GitHub workflow to make it easier for projects |
| 9 | +to adopt into their existing repositories. |
| 10 | + |
| 11 | +## Goal |
| 12 | + |
| 13 | +The goal of the patching script is to make Code of Conduct upgrade |
| 14 | +and review process easier to maintain for open-source projects. |
| 15 | +It removes any direct changes done to the original document, and |
| 16 | +provides an easier to review and accept changes to the document |
| 17 | +provided by the Contributor Covenant. |
| 18 | + |
| 19 | +## GitHub Workflow configuration |
| 20 | + |
| 21 | +The configuration file for the patching script lives inside |
| 22 | +`.github/workflows/patch-code-of-conduct.yml` file. The configuration |
| 23 | +file also includes an additional GitHub workflow to automatically |
| 24 | +open a pull request in the event of a changed file after the |
| 25 | +work of the patching scripts job is complete. |
| 26 | + |
| 27 | +### Settings |
| 28 | + |
| 29 | +- `base_url`: Base URL is the path to the preamble file (the file |
| 30 | + that is prepended to the Code of Conduct document). |
| 31 | +- `template_url`: It is the URL to the Contributor Covenant website |
| 32 | + that includes the original unchanged document. |
| 33 | +- `patch_file_path`: It is the path to the patching file. |
| 34 | +- `output_file_path`: It is the path to the file where the changes |
| 35 | + should apply to. |
| 36 | + |
| 37 | +### Files |
| 38 | + |
| 39 | +- `workflows/patch-code-of-conduct.yml`: This file contains |
| 40 | + the necessary configuration to setup the patching script. |
| 41 | +- `CODE_OF_CONDUCT_PREAMBLE.md`: This file contains the text |
| 42 | + prepended to the original Code of Conduct file. It may contain |
| 43 | + project/organization specific information that may live outside |
| 44 | + of the definition of the original Code of Conduct versions. |
| 45 | +- `CODE_OF_CONDUCT_PATCH.patch`: This file contains a patch |
| 46 | + generated by the contributors of the project to update **only** |
| 47 | + the texts defined in the Code of Conduct URL defined by the |
| 48 | + patching script. |
| 49 | + |
| 50 | +## Workflows |
| 51 | + |
| 52 | +### Make a change to `PREAMBLE.md` file |
| 53 | + |
| 54 | +1. Open a pull-request updating either `CODE_OF_CONDUCT_PATCH.patch` |
| 55 | + or `CODE_OF_CONDUCT_PREAMBLE.md` file. The default procedures of |
| 56 | + merging a pull request will be followed as usual. |
| 57 | +2. Upon successful merging the proposed changes to the main branch |
| 58 | + patching script will open a pull request with a target of `main` |
| 59 | + branch updating `CODE_OF_CONDUCT.md` file with the proposed changes. |
| 60 | +3. Since the approval for the original change is done in step 1, unless |
| 61 | + there is a bug with the CoC patching script this pull request opened |
| 62 | + by the bot from the workflow should land without issue. |
| 63 | + |
| 64 | +### Make a change to `PATCH.patch` file |
| 65 | + |
| 66 | +1. Copy the original file and rename it as `PREVIOUS_COC.md` |
| 67 | +2. Update `PREVIOUS_COC.md` according to your needs. |
| 68 | +3. Run the following command to generate the patching file: |
| 69 | + `diff -Naur PREVIOUS_COC.md CODE_OF_CONDUCT.md > conduct/artifacts/CODE_OF_CONDUCT_PATCH.patch` |
| 70 | +4. Delete the temporary `PREVIOUS_COC.md` file. |
| 71 | +5. Push your changes to a new branch and open a pull-request with a target |
| 72 | + of `main` branch. |
| 73 | + |
| 74 | +**Testing**: You can run the following command to apply the changes of |
| 75 | +your patching script to validate the output: |
| 76 | + |
| 77 | +``` |
| 78 | +patch -i conduct/artifacts/CODE_OF_CONDUCT_PATCH.patch CODE_OF_CONDUCT.md --no-backup-if-mismatch |
| 79 | +``` |
| 80 | + |
| 81 | +### Update Code of Conduct version |
| 82 | + |
| 83 | +1. Update Github Workflow `template_url` attribute. |
| 84 | +2. Regenerate your patching file by following the patch file workflow. |
| 85 | + |
| 86 | +## Recommendations |
| 87 | + |
| 88 | +1. In order to decrease the maintenance cost of the updating |
| 89 | + Code of Conduct, it is recommended to use the correct CoC version |
| 90 | + in the GitHub workflow configuration. |
| 91 | +2. It is recommended to create a pull request for the changes made |
| 92 | + by the patching script to avoid committing changes. Remember that, |
| 93 | + this should be dealt with an extremely delecate process due to the |
| 94 | + probability of the concerns mentioned in recommendation 3. |
| 95 | +3. The pull requests opened by the patching script bot should be approved |
| 96 | + without issue. Modifying the PR created from the workflow would put |
| 97 | + our code in an ambiguous state where the `CODE_OF_CONDUCT.md` file and |
| 98 | + the files that the script depend on do not match with each other. |
| 99 | + All changes should happen in the files outlined above and resulting PRs |
| 100 | + should remain unmodified. |
| 101 | + |
| 102 | +[project-link]: https://github.com/pkgjs/patch-my-code-of-conduct |
0 commit comments