whatships 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. whatships-0.1.0/.gitignore +10 -0
  2. whatships-0.1.0/CHANGELOG.md +24 -0
  3. whatships-0.1.0/CONTRIBUTING.md +51 -0
  4. whatships-0.1.0/LICENSE +21 -0
  5. whatships-0.1.0/PKG-INFO +289 -0
  6. whatships-0.1.0/README.md +255 -0
  7. whatships-0.1.0/SECURITY.md +87 -0
  8. whatships-0.1.0/action.yml +108 -0
  9. whatships-0.1.0/docs/configuration.md +93 -0
  10. whatships-0.1.0/docs/example-report.md +81 -0
  11. whatships-0.1.0/docs/report.png +0 -0
  12. whatships-0.1.0/examples/demo.py +297 -0
  13. whatships-0.1.0/pyproject.toml +79 -0
  14. whatships-0.1.0/src/whatships/__init__.py +3 -0
  15. whatships-0.1.0/src/whatships/__main__.py +7 -0
  16. whatships-0.1.0/src/whatships/changes.py +272 -0
  17. whatships-0.1.0/src/whatships/cli.py +369 -0
  18. whatships-0.1.0/src/whatships/config.py +287 -0
  19. whatships-0.1.0/src/whatships/github.py +342 -0
  20. whatships-0.1.0/src/whatships/gitrepo.py +223 -0
  21. whatships-0.1.0/src/whatships/migrations/__init__.py +445 -0
  22. whatships-0.1.0/src/whatships/migrations/alembic.py +410 -0
  23. whatships-0.1.0/src/whatships/migrations/django.py +714 -0
  24. whatships-0.1.0/src/whatships/migrations/sql.py +526 -0
  25. whatships-0.1.0/src/whatships/model.py +222 -0
  26. whatships-0.1.0/src/whatships/py.typed +0 -0
  27. whatships-0.1.0/src/whatships/render/__init__.py +0 -0
  28. whatships-0.1.0/src/whatships/render/markdown.py +361 -0
  29. whatships-0.1.0/src/whatships/render/safe.py +68 -0
  30. whatships-0.1.0/src/whatships/render/slack.py +63 -0
  31. whatships-0.1.0/src/whatships/render/text.py +135 -0
  32. whatships-0.1.0/src/whatships/report.py +357 -0
  33. whatships-0.1.0/src/whatships/settings.py +211 -0
  34. whatships-0.1.0/src/whatships/terraform/__init__.py +0 -0
  35. whatships-0.1.0/src/whatships/terraform/diff.py +717 -0
  36. whatships-0.1.0/src/whatships/terraform/hcl.py +351 -0
  37. whatships-0.1.0/src/whatships/terraform/plan.py +303 -0
  38. whatships-0.1.0/tests/__init__.py +0 -0
  39. whatships-0.1.0/tests/conftest.py +114 -0
  40. whatships-0.1.0/tests/test_basics.py +291 -0
  41. whatships-0.1.0/tests/test_changes.py +233 -0
  42. whatships-0.1.0/tests/test_docs.py +179 -0
  43. whatships-0.1.0/tests/test_migrations.py +584 -0
  44. whatships-0.1.0/tests/test_report.py +646 -0
  45. whatships-0.1.0/tests/test_review2_changes.py +103 -0
  46. whatships-0.1.0/tests/test_review2_cli_github.py +243 -0
  47. whatships-0.1.0/tests/test_review2_migrations.py +272 -0
  48. whatships-0.1.0/tests/test_review2_output.py +47 -0
  49. whatships-0.1.0/tests/test_review2_terraform.py +205 -0
  50. whatships-0.1.0/tests/test_review_changes.py +90 -0
  51. whatships-0.1.0/tests/test_review_cli_github.py +191 -0
  52. whatships-0.1.0/tests/test_review_migrations.py +216 -0
  53. whatships-0.1.0/tests/test_review_output.py +56 -0
  54. whatships-0.1.0/tests/test_review_terraform.py +178 -0
  55. whatships-0.1.0/tests/test_second_pass.py +274 -0
  56. whatships-0.1.0/tests/test_terraform.py +451 -0
  57. whatships-0.1.0/tests/test_third_pass.py +217 -0
@@ -0,0 +1,10 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.pyc
4
+ .pytest_cache/
5
+ .mypy_cache/
6
+ .ruff_cache/
7
+ dist/
8
+ build/
9
+ *.egg-info/
10
+ .DS_Store
@@ -0,0 +1,24 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+
5
+ First release.
6
+
7
+ * **Pull requests** from the commits of a range: GitHub merge and squash commits, GitLab, Bitbucket
8
+ and Azure DevOps. Promotions between long-lived branches are skipped and what they carry is
9
+ listed; commits belong to the innermost pull request; commits without one, and reverts, are named.
10
+ * **Database migrations**: Django (with the app's history replayed, so `AlterField` says what
11
+ changes in the table), Alembic, SQL files, and Rails and JavaScript migrations by name. Signals
12
+ at three levels; conflicts, edited and renamed migrations; tables created by the same promotion
13
+ are not flagged, judged against what production has. What could not be read is said so.
14
+ * **Infrastructure**: Terraform and OpenTofu read from the files (resources, modules, variables,
15
+ outputs, providers, backend, lock file, `.tfvars` names), with undeclared renames, `moved` and
16
+ `removed` blocks, and removed guards pointed out; and from a plan in JSON, one per stack, which
17
+ replaces the reading of the files only where it accounts for what they change.
18
+ * **Settings**: environment variables the code starts or stops reading, in nine languages.
19
+ * **Output**: text, Markdown that fits a pull request comment, JSON, a Slack message. Text from the
20
+ repository is escaped, and control and invisible characters are taken out of it.
21
+ * **GitHub**: titles, authors and labels with a token; one comment kept up to date; a composite
22
+ action with a job summary and outputs.
23
+ * Work that production already has under another commit (a squashed promotion, a cherry-pick) is
24
+ not reported again.
@@ -0,0 +1,51 @@
1
+ # Contributing
2
+
3
+ The most useful thing you can send is a case the report got wrong: a migration it should have
4
+ flagged, a false alarm, a pull request it attributed to the wrong place. Reduce it to the smallest
5
+ migration, Terraform block or sequence of git commands that shows it, and change any names that
6
+ are yours to keep.
7
+
8
+ ## Setup
9
+
10
+ ```bash
11
+ python -m venv .venv && . .venv/bin/activate # .venv\Scripts\activate on Windows
12
+ pip install -e ".[dev]"
13
+ ```
14
+
15
+ ## Before you open a pull request
16
+
17
+ ```bash
18
+ pytest
19
+ ruff check . && ruff format --check .
20
+ mypy
21
+ ```
22
+
23
+ * A fix comes with a test that fails without it.
24
+ * The tests build real repositories (`tests/conftest.py`): to test a shape of history, make that
25
+ history. Nothing about git is mocked.
26
+ * `docs/example-report.md` is the output of `python examples/demo.py`; a test compares them. If you
27
+ change what a report says, regenerate it: `python examples/demo.py > docs/example-report.md`.
28
+
29
+ ## What a signal is
30
+
31
+ Every line in a report that says "attention" or "check" is a claim about a database or about
32
+ Terraform, read by someone about to push to production. So:
33
+
34
+ * **It has to be true.** If it depends on the database engine or version, say which.
35
+ * **It says what happens and to what**: "Drops the column of `order.legacy_ref` with its data",
36
+ not "destructive operation detected".
37
+ * **Attention is for data loss and for breaking running code.** Anything whose cost depends on the
38
+ size of a table is a check: whatships cannot see the table.
39
+ * **A false alarm costs more than it looks.** A report that cries wolf on every promotion stops
40
+ being read. When in doubt, be quiet.
41
+
42
+ ## Layout
43
+
44
+ * `gitrepo.py`: everything read from git. `changes.py`: commits to pull requests.
45
+ * `migrations/`: `django.py`, `alembic.py`, `sql.py`, and the finding of files in `__init__.py`.
46
+ * `terraform/`: `hcl.py` reads, `diff.py` compares, `plan.py` reads a plan.
47
+ * `settings.py`: environment variables. `report.py`: puts a report together.
48
+ * `render/`: Markdown, text, Slack. `cli.py`, `github.py`, `action.yml`: the ways in.
49
+
50
+ whatships has no runtime dependencies and should keep none: it runs in CI before anything is
51
+ installed.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Alex Geblea
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,289 @@
1
+ Metadata-Version: 2.5
2
+ Name: whatships
3
+ Version: 0.1.0
4
+ Summary: What ships with this promotion: the pull requests, database migrations, infrastructure changes and new settings between staging and production.
5
+ Project-URL: Homepage, https://github.com/GebleaAlex/whatships
6
+ Project-URL: Documentation, https://github.com/GebleaAlex/whatships#readme
7
+ Project-URL: Issues, https://github.com/GebleaAlex/whatships/issues
8
+ Project-URL: Changelog, https://github.com/GebleaAlex/whatships/blob/main/CHANGELOG.md
9
+ Author: Alex Geblea
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: changelog,deployment,devops,github-actions,migrations,promotion,release,terraform
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Environment :: Console
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Intended Audience :: System Administrators
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3.14
23
+ Classifier: Programming Language :: Python :: 3.15
24
+ Classifier: Topic :: Software Development :: Build Tools
25
+ Classifier: Topic :: Software Development :: Version Control :: Git
26
+ Classifier: Topic :: System :: Software Distribution
27
+ Classifier: Typing :: Typed
28
+ Requires-Python: >=3.11
29
+ Provides-Extra: dev
30
+ Requires-Dist: mypy>=1.11; extra == 'dev'
31
+ Requires-Dist: pytest>=8; extra == 'dev'
32
+ Requires-Dist: ruff>=0.6; extra == 'dev'
33
+ Description-Content-Type: text/markdown
34
+
35
+ # whatships
36
+
37
+ [![CI](https://github.com/GebleaAlex/whatships/actions/workflows/ci.yml/badge.svg)](https://github.com/GebleaAlex/whatships/actions/workflows/ci.yml)
38
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/GebleaAlex/whatships/blob/main/LICENSE)
39
+ ![Python 3.11+](https://img.shields.io/badge/python-3.11%2B-blue.svg)
40
+
41
+ **What ships with this promotion.** Before `stage` is merged into `main`, whatships reads the
42
+ commits between them and writes down what is about to reach production: the pull requests, the
43
+ database migrations and what each one does, the infrastructure changes, and the settings the new
44
+ code expects. It runs in a second, needs nothing but git, and posts the answer on the pull request.
45
+
46
+ ```console
47
+ $ whatships --base main --head stage
48
+ What ships: stage -> main
49
+ 3 pull requests, 1 commit without one, 2 migrations, 6 infrastructure changes, 2 new settings
50
+
51
+ Needs a look before promoting (2)
52
+ !! apps/orders/migrations/0002_drop_legacy_ref.py: Drops the column of `order.legacy_ref` with its data. Code still running on production from before this promotion fails once the migration has run.
53
+ !! aws_s3_bucket.invoices: Looks renamed to `aws_s3_bucket.invoice_archive` without a moved block: Terraform destroys this one and creates the other. A `moved` block from `aws_s3_bucket.invoices` to `aws_s3_bucket.invoice_archive` keeps it. It holds data.
54
+ ? `main` has 1 commit that `stage` does not (a hotfix, most likely). What was tested on `stage` did not include it: merge `main` back first.
55
+ ? 1 commit reached `stage` without a pull request.
56
+ ...
57
+ ```
58
+
59
+ The same report as the comment it leaves on the pull request
60
+ ([all of it](https://github.com/GebleaAlex/whatships/blob/main/docs/example-report.md)):
61
+
62
+ ![The report as a pull request comment: a warning with two points to look at, the pull requests, and the migrations with what each operation does](https://raw.githubusercontent.com/GebleaAlex/whatships/main/docs/report.png)
63
+
64
+ ## Why
65
+
66
+ A team that promotes to production often stops reading what it promotes. The pull request from
67
+ `stage` to `main` says "47 commits, 212 files changed", and the questions that matter are somewhere
68
+ in there:
69
+
70
+ * **Which changes are these?** Not the commits: the pull requests, with their authors and tickets,
71
+ including the ones that came in through `develop` three merges ago.
72
+ * **Does a migration drop or rename something the running code still uses?** Does one build an index
73
+ on the big table, or run a data fix whose duration nobody measured?
74
+ * **Does the infrastructure change, and does anything get destroyed?**
75
+ * **Does the new code need a setting that production does not have yet?**
76
+ * **Did anything skip review?** Is production ahead of what was tested?
77
+
78
+ Each of these is in the diff for whoever goes looking. whatships goes looking every time.
79
+
80
+ ## Install and run
81
+
82
+ ```bash
83
+ pipx run whatships --base main --head stage # or: uvx whatships ...
84
+ pip install whatships # to keep it
85
+ ```
86
+
87
+ It has no dependencies and reads the repository through the `git` command: nothing is checked out,
88
+ fetched or written. Inside a clone:
89
+
90
+ ```bash
91
+ whatships # the current branch against production
92
+ whatships --base main --head stage # both named
93
+ whatships --last # what the last promotion merged into production shipped
94
+ whatships --merge 4f2a91c # what one merge commit brought in
95
+ whatships --base v1.4.0 --head v1.5.0 # between two tags
96
+ whatships --format markdown -o report.md # also: json, slack, text
97
+ whatships --plan plan.json # with what `terraform show -json` says an apply will do
98
+ whatships --plan envs/prod=prod.json # one plan per stack, each for its own directory
99
+ whatships --fail-on attention # exit 1 when something needs a look
100
+ ```
101
+
102
+ ## On every pull request into production
103
+
104
+ ```yaml
105
+ # .github/workflows/whatships.yml
106
+ name: What ships
107
+ on:
108
+ pull_request:
109
+ branches: [main]
110
+
111
+ permissions:
112
+ contents: read
113
+ pull-requests: write # for the comment
114
+
115
+ jobs:
116
+ report:
117
+ runs-on: ubuntu-latest
118
+ steps:
119
+ - uses: actions/checkout@v7
120
+ with:
121
+ fetch-depth: 0 # the report is made from history: a shallow clone has none
122
+ - uses: GebleaAlex/whatships@v0
123
+ ```
124
+
125
+ The action writes one comment and keeps it up to date as the pull request changes, puts the same
126
+ report in the job summary, and sets outputs (`level`, `pull-requests`, `migrations`, `attention`, …)
127
+ for later steps. Inputs: `base`, `head`, `comment`, `last`, `plan`, `fail-on`, `title`, `config`,
128
+ `token`, `working-directory` ([action.yml](https://github.com/GebleaAlex/whatships/blob/main/action.yml)).
129
+ On a pull request from a fork, where the token may not write, the report goes to the job summary
130
+ and the job still passes.
131
+
132
+ On any other CI, run the command and do what you like with the output; `--format json` has
133
+ everything, and `--format slack` is a ready message for a webhook.
134
+
135
+ ## What it reads
136
+
137
+ ### Pull requests
138
+
139
+ From the commits alone: GitHub merge and squash commits, GitLab merge requests, Bitbucket and Azure
140
+ DevOps merges. No API is needed.
141
+
142
+ * A merge **between long-lived branches** (`develop` into `stage`) is a promotion, not a change. It
143
+ is skipped, and the pull requests it carries are listed. The whole branch name counts: `fix/test`
144
+ is a pull request like any other, and so is `main` from somebody's fork.
145
+ * A commit belongs to the **innermost** pull request that brought it; a pull request merged into
146
+ another one is shown inside it.
147
+ * Commits that reached the branch **without any pull request** are listed apart.
148
+ * A pull request **reverted** inside the same promotion is struck through.
149
+ * **Tickets** named in branches and titles (`ABC-123`) are linked when you say where they live.
150
+ * When production already has some of the work under another commit (a promotion that was
151
+ **squashed**, a cherry-pick), only what still differs between the two branches is reported, and
152
+ the pull requests that bring nothing new are named.
153
+
154
+ With a token (`GITHUB_TOKEN`), GitHub is asked for what git does not record: the title as it is
155
+ now, the author's login, labels, and which pull request a rebased commit came from. What GitHub
156
+ says about a number is used only when it was merged as the very commit that was read: `#12` in a
157
+ commit message can be the number of a pull request somewhere else.
158
+
159
+ ### Database migrations
160
+
161
+ | | Read how | Understood |
162
+ | --- | --- | --- |
163
+ | **Django** | the syntax tree; never imported or run | every built-in operation, `RunSQL`, `RunPython`, `SeparateDatabaseAndState` |
164
+ | **Alembic** | the syntax tree of `upgrade()` and of the functions it calls | `op.*` under any name, batch operations, SQL passed to `execute` as text |
165
+ | **SQL files** | Flyway, dbmate, goose, golang-migrate, Prisma, plain directories | statement by statement |
166
+ | Rails, Knex, Sequelize, TypeORM | by the names of the calls | drops, renames, type changes, indexes, raw SQL |
167
+
168
+ Three levels, and only the first goes to the top of the report:
169
+
170
+ * **Attention**: data goes away or running code breaks. A dropped table or column, a rename, a
171
+ `NOT NULL` column without a default, a `DELETE` without `WHERE`; a migration **edited after it was
172
+ applied**, renamed, or left in **conflict** with another (two migrations ending the same app).
173
+ * **Check**: fine or not depending on something only you know, usually the size of a table. An
174
+ index or constraint built without `CONCURRENTLY`, a type change, `SET NOT NULL`, a data migration.
175
+ * **Note**: for the record. No reverse, runs outside a transaction, a squash.
176
+
177
+ What could not be read is said, not passed over: a migration this Python cannot parse, one that
178
+ is not text or is larger than 2 MB, a list of operations put together at run time, SQL built in
179
+ code, a `DO` block, a stored procedure, a helper imported from another module. Each is a "check"
180
+ that says to open the file. What a procedure, function or trigger *defines* is not what the
181
+ migration runs: statements inside such a body are not reported as if they ran.
182
+
183
+ Two things keep the list honest. For Django, the earlier migrations of the app are replayed, so
184
+ `AlterField` is reported for what it changes: *"choices (no change to the table)"*, or
185
+ *"max_length 100 → 30: fails if a longer value exists"*. And a table **created by the same
186
+ promotion** is empty and unknown to production, so nothing done to it is flagged; "created" is
187
+ judged against what production has, so a squashed migration that creates a table again does not
188
+ make it new.
189
+
190
+ ### Infrastructure
191
+
192
+ Terraform and OpenTofu (`.tf` and `.tofu` files), in two ways.
193
+
194
+ **From the files**, always: which resources, modules, variables, outputs, providers and backend
195
+ settings were added, changed or removed, attribute by attribute (`instance_class: "db.t3.medium" →
196
+ "db.r6g.large"`, `tags.Environment`, `lifecycle.prevent_destroy`). No state, credentials or
197
+ `terraform` binary. It flags what the files alone can show:
198
+
199
+ * a resource **gone from the configuration** (it will be destroyed), louder when it holds data;
200
+ the same for a `removed` block, unless it says `destroy = false`, and for `count = 0`;
201
+ * a resource **renamed without a `moved` block**: same type, same content, new name, which
202
+ Terraform carries out as destroy and create. `moved` blocks are followed, through chains and
203
+ into modules;
204
+ * `prevent_destroy` removed, `count` / `for_each` changed, a module or provider version moved, the
205
+ state's backend moved, a variable that now needs a value in every environment;
206
+ * a file it **could not read**: nothing in that file is compared, and the report says so.
207
+
208
+ What `terraform fmt` does to a file is not a change: spacing, the order of nothing, `:` for `=`.
209
+
210
+ **From a plan**, when you give one (`--plan plan.json`, from `terraform show -json`): what an apply
211
+ will actually do, including what the files cannot know, such as a changed attribute that forces a
212
+ replacement, and drift. A plan stands in for the files of the stack it was made in and of no
213
+ other: with several stacks, give one plan each, and a stack without one keeps the reading of its
214
+ files. A plan finds its directory by what it declares (the directory whose resources and module
215
+ calls are the plan's); when two stacks declare the same, say which it is for with
216
+ `--plan DIR=plan.json`. Even there the files give way only where the plan accounts for them: a
217
+ plan that does not destroy a resource the files remove was made from other files (make it from
218
+ the commit being promoted), and the report keeps the files' reading and says the two disagree.
219
+
220
+ Secrets stay out: values in `.tfvars` are never shown (only that a variable changed); anything
221
+ marked `sensitive`, named like a secret anywhere in its path or inside its value (a `password` key
222
+ in `jsonencode({...})`), held by a resource that is a secret (`azurerm_key_vault_secret`,
223
+ `kubernetes_secret`), or shaped like a credential (a URL with a password in it, a private key, a
224
+ cloud access key) is hidden; and a plan's sensitive marks are respected.
225
+
226
+ ### Settings
227
+
228
+ Environment variables the code **now reads and did not before**, in Python, JavaScript and
229
+ TypeScript, Go, Ruby, Rust, PHP, Java, Kotlin and C#, with whether the code has a fallback.
230
+ A variable the program sets or clears itself is not one somebody has to provide.
231
+ It is a search for the usual ways of reading the environment, not an understanding of the program:
232
+ a list to check. A name counts as new only if nothing in the previous tree mentions it, and test
233
+ files are left out.
234
+
235
+ ### Also changed
236
+
237
+ Dependency manifests and lock files, pipelines, Dockerfiles and deployment manifests are named
238
+ when they change. Add your own groups.
239
+
240
+ ## Configuration
241
+
242
+ Nothing is required. `.whatships.toml`, or `[tool.whatships]` in `pyproject.toml`, is for what
243
+ cannot be guessed:
244
+
245
+ ```toml
246
+ base = "main" # what production runs
247
+ head = "stage" # what gets promoted
248
+ ticket_url = "https://example.atlassian.net/browse/{ticket}"
249
+ ignore = ["vendor/**", "**/*.snap"]
250
+
251
+ [areas] # names for parts of the code, instead of directory names
252
+ Billing = ["apps/billing/**", "apps/invoices/**"]
253
+
254
+ [terraform]
255
+ paths = ["infra/prod"] # only what this promotion applies
256
+
257
+ [watch]
258
+ "Feature flags" = ["config/flags/*.yaml"]
259
+ ```
260
+
261
+ Every key, with its default: [docs/configuration.md](https://github.com/GebleaAlex/whatships/blob/main/docs/configuration.md).
262
+
263
+ ## What it does not do
264
+
265
+ * **It does not connect to your database or your cloud.** It cannot know that a table has two
266
+ hundred million rows, which is why index builds and type changes are "check" and not a verdict.
267
+ * **The Terraform reading from files is a reading of files.** It does not evaluate expressions,
268
+ follow modules into their source, or know the state. For what an apply will do, give it a plan.
269
+ * **Rebase merges leave no trace in git.** Without a token, commits merged by rebase are listed as
270
+ arriving without a pull request. With one, GitHub is asked.
271
+ * **Settings are found by pattern**, so a variable read through a wrapper of your own is missed.
272
+ * **Migrations in Rails and JavaScript are read by name**, not parsed.
273
+ * **A very long range is read from its newest end.** Past 20,000 commits the report says so; a
274
+ promotion is far shorter.
275
+ * **One repository at a time.** A promotion that spans several repositories is several reports.
276
+ * **The comment is for GitHub.** Elsewhere the report is yours to post: Markdown, JSON or Slack.
277
+
278
+ ## Development
279
+
280
+ ```bash
281
+ python -m venv .venv && . .venv/bin/activate # .venv\Scripts\activate on Windows
282
+ pip install -e ".[dev]"
283
+ pytest && ruff check . && ruff format --check . && mypy
284
+ python examples/demo.py # a repository with a promotion in it, and its report
285
+ ```
286
+
287
+ The tests build real repositories with real merges; nothing about git is mocked. See
288
+ [CONTRIBUTING.md](https://github.com/GebleaAlex/whatships/blob/main/CONTRIBUTING.md). Licensed under
289
+ the [MIT License](https://github.com/GebleaAlex/whatships/blob/main/LICENSE).
@@ -0,0 +1,255 @@
1
+ # whatships
2
+
3
+ [![CI](https://github.com/GebleaAlex/whatships/actions/workflows/ci.yml/badge.svg)](https://github.com/GebleaAlex/whatships/actions/workflows/ci.yml)
4
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/GebleaAlex/whatships/blob/main/LICENSE)
5
+ ![Python 3.11+](https://img.shields.io/badge/python-3.11%2B-blue.svg)
6
+
7
+ **What ships with this promotion.** Before `stage` is merged into `main`, whatships reads the
8
+ commits between them and writes down what is about to reach production: the pull requests, the
9
+ database migrations and what each one does, the infrastructure changes, and the settings the new
10
+ code expects. It runs in a second, needs nothing but git, and posts the answer on the pull request.
11
+
12
+ ```console
13
+ $ whatships --base main --head stage
14
+ What ships: stage -> main
15
+ 3 pull requests, 1 commit without one, 2 migrations, 6 infrastructure changes, 2 new settings
16
+
17
+ Needs a look before promoting (2)
18
+ !! apps/orders/migrations/0002_drop_legacy_ref.py: Drops the column of `order.legacy_ref` with its data. Code still running on production from before this promotion fails once the migration has run.
19
+ !! aws_s3_bucket.invoices: Looks renamed to `aws_s3_bucket.invoice_archive` without a moved block: Terraform destroys this one and creates the other. A `moved` block from `aws_s3_bucket.invoices` to `aws_s3_bucket.invoice_archive` keeps it. It holds data.
20
+ ? `main` has 1 commit that `stage` does not (a hotfix, most likely). What was tested on `stage` did not include it: merge `main` back first.
21
+ ? 1 commit reached `stage` without a pull request.
22
+ ...
23
+ ```
24
+
25
+ The same report as the comment it leaves on the pull request
26
+ ([all of it](https://github.com/GebleaAlex/whatships/blob/main/docs/example-report.md)):
27
+
28
+ ![The report as a pull request comment: a warning with two points to look at, the pull requests, and the migrations with what each operation does](https://raw.githubusercontent.com/GebleaAlex/whatships/main/docs/report.png)
29
+
30
+ ## Why
31
+
32
+ A team that promotes to production often stops reading what it promotes. The pull request from
33
+ `stage` to `main` says "47 commits, 212 files changed", and the questions that matter are somewhere
34
+ in there:
35
+
36
+ * **Which changes are these?** Not the commits: the pull requests, with their authors and tickets,
37
+ including the ones that came in through `develop` three merges ago.
38
+ * **Does a migration drop or rename something the running code still uses?** Does one build an index
39
+ on the big table, or run a data fix whose duration nobody measured?
40
+ * **Does the infrastructure change, and does anything get destroyed?**
41
+ * **Does the new code need a setting that production does not have yet?**
42
+ * **Did anything skip review?** Is production ahead of what was tested?
43
+
44
+ Each of these is in the diff for whoever goes looking. whatships goes looking every time.
45
+
46
+ ## Install and run
47
+
48
+ ```bash
49
+ pipx run whatships --base main --head stage # or: uvx whatships ...
50
+ pip install whatships # to keep it
51
+ ```
52
+
53
+ It has no dependencies and reads the repository through the `git` command: nothing is checked out,
54
+ fetched or written. Inside a clone:
55
+
56
+ ```bash
57
+ whatships # the current branch against production
58
+ whatships --base main --head stage # both named
59
+ whatships --last # what the last promotion merged into production shipped
60
+ whatships --merge 4f2a91c # what one merge commit brought in
61
+ whatships --base v1.4.0 --head v1.5.0 # between two tags
62
+ whatships --format markdown -o report.md # also: json, slack, text
63
+ whatships --plan plan.json # with what `terraform show -json` says an apply will do
64
+ whatships --plan envs/prod=prod.json # one plan per stack, each for its own directory
65
+ whatships --fail-on attention # exit 1 when something needs a look
66
+ ```
67
+
68
+ ## On every pull request into production
69
+
70
+ ```yaml
71
+ # .github/workflows/whatships.yml
72
+ name: What ships
73
+ on:
74
+ pull_request:
75
+ branches: [main]
76
+
77
+ permissions:
78
+ contents: read
79
+ pull-requests: write # for the comment
80
+
81
+ jobs:
82
+ report:
83
+ runs-on: ubuntu-latest
84
+ steps:
85
+ - uses: actions/checkout@v7
86
+ with:
87
+ fetch-depth: 0 # the report is made from history: a shallow clone has none
88
+ - uses: GebleaAlex/whatships@v0
89
+ ```
90
+
91
+ The action writes one comment and keeps it up to date as the pull request changes, puts the same
92
+ report in the job summary, and sets outputs (`level`, `pull-requests`, `migrations`, `attention`, …)
93
+ for later steps. Inputs: `base`, `head`, `comment`, `last`, `plan`, `fail-on`, `title`, `config`,
94
+ `token`, `working-directory` ([action.yml](https://github.com/GebleaAlex/whatships/blob/main/action.yml)).
95
+ On a pull request from a fork, where the token may not write, the report goes to the job summary
96
+ and the job still passes.
97
+
98
+ On any other CI, run the command and do what you like with the output; `--format json` has
99
+ everything, and `--format slack` is a ready message for a webhook.
100
+
101
+ ## What it reads
102
+
103
+ ### Pull requests
104
+
105
+ From the commits alone: GitHub merge and squash commits, GitLab merge requests, Bitbucket and Azure
106
+ DevOps merges. No API is needed.
107
+
108
+ * A merge **between long-lived branches** (`develop` into `stage`) is a promotion, not a change. It
109
+ is skipped, and the pull requests it carries are listed. The whole branch name counts: `fix/test`
110
+ is a pull request like any other, and so is `main` from somebody's fork.
111
+ * A commit belongs to the **innermost** pull request that brought it; a pull request merged into
112
+ another one is shown inside it.
113
+ * Commits that reached the branch **without any pull request** are listed apart.
114
+ * A pull request **reverted** inside the same promotion is struck through.
115
+ * **Tickets** named in branches and titles (`ABC-123`) are linked when you say where they live.
116
+ * When production already has some of the work under another commit (a promotion that was
117
+ **squashed**, a cherry-pick), only what still differs between the two branches is reported, and
118
+ the pull requests that bring nothing new are named.
119
+
120
+ With a token (`GITHUB_TOKEN`), GitHub is asked for what git does not record: the title as it is
121
+ now, the author's login, labels, and which pull request a rebased commit came from. What GitHub
122
+ says about a number is used only when it was merged as the very commit that was read: `#12` in a
123
+ commit message can be the number of a pull request somewhere else.
124
+
125
+ ### Database migrations
126
+
127
+ | | Read how | Understood |
128
+ | --- | --- | --- |
129
+ | **Django** | the syntax tree; never imported or run | every built-in operation, `RunSQL`, `RunPython`, `SeparateDatabaseAndState` |
130
+ | **Alembic** | the syntax tree of `upgrade()` and of the functions it calls | `op.*` under any name, batch operations, SQL passed to `execute` as text |
131
+ | **SQL files** | Flyway, dbmate, goose, golang-migrate, Prisma, plain directories | statement by statement |
132
+ | Rails, Knex, Sequelize, TypeORM | by the names of the calls | drops, renames, type changes, indexes, raw SQL |
133
+
134
+ Three levels, and only the first goes to the top of the report:
135
+
136
+ * **Attention**: data goes away or running code breaks. A dropped table or column, a rename, a
137
+ `NOT NULL` column without a default, a `DELETE` without `WHERE`; a migration **edited after it was
138
+ applied**, renamed, or left in **conflict** with another (two migrations ending the same app).
139
+ * **Check**: fine or not depending on something only you know, usually the size of a table. An
140
+ index or constraint built without `CONCURRENTLY`, a type change, `SET NOT NULL`, a data migration.
141
+ * **Note**: for the record. No reverse, runs outside a transaction, a squash.
142
+
143
+ What could not be read is said, not passed over: a migration this Python cannot parse, one that
144
+ is not text or is larger than 2 MB, a list of operations put together at run time, SQL built in
145
+ code, a `DO` block, a stored procedure, a helper imported from another module. Each is a "check"
146
+ that says to open the file. What a procedure, function or trigger *defines* is not what the
147
+ migration runs: statements inside such a body are not reported as if they ran.
148
+
149
+ Two things keep the list honest. For Django, the earlier migrations of the app are replayed, so
150
+ `AlterField` is reported for what it changes: *"choices (no change to the table)"*, or
151
+ *"max_length 100 → 30: fails if a longer value exists"*. And a table **created by the same
152
+ promotion** is empty and unknown to production, so nothing done to it is flagged; "created" is
153
+ judged against what production has, so a squashed migration that creates a table again does not
154
+ make it new.
155
+
156
+ ### Infrastructure
157
+
158
+ Terraform and OpenTofu (`.tf` and `.tofu` files), in two ways.
159
+
160
+ **From the files**, always: which resources, modules, variables, outputs, providers and backend
161
+ settings were added, changed or removed, attribute by attribute (`instance_class: "db.t3.medium" →
162
+ "db.r6g.large"`, `tags.Environment`, `lifecycle.prevent_destroy`). No state, credentials or
163
+ `terraform` binary. It flags what the files alone can show:
164
+
165
+ * a resource **gone from the configuration** (it will be destroyed), louder when it holds data;
166
+ the same for a `removed` block, unless it says `destroy = false`, and for `count = 0`;
167
+ * a resource **renamed without a `moved` block**: same type, same content, new name, which
168
+ Terraform carries out as destroy and create. `moved` blocks are followed, through chains and
169
+ into modules;
170
+ * `prevent_destroy` removed, `count` / `for_each` changed, a module or provider version moved, the
171
+ state's backend moved, a variable that now needs a value in every environment;
172
+ * a file it **could not read**: nothing in that file is compared, and the report says so.
173
+
174
+ What `terraform fmt` does to a file is not a change: spacing, the order of nothing, `:` for `=`.
175
+
176
+ **From a plan**, when you give one (`--plan plan.json`, from `terraform show -json`): what an apply
177
+ will actually do, including what the files cannot know, such as a changed attribute that forces a
178
+ replacement, and drift. A plan stands in for the files of the stack it was made in and of no
179
+ other: with several stacks, give one plan each, and a stack without one keeps the reading of its
180
+ files. A plan finds its directory by what it declares (the directory whose resources and module
181
+ calls are the plan's); when two stacks declare the same, say which it is for with
182
+ `--plan DIR=plan.json`. Even there the files give way only where the plan accounts for them: a
183
+ plan that does not destroy a resource the files remove was made from other files (make it from
184
+ the commit being promoted), and the report keeps the files' reading and says the two disagree.
185
+
186
+ Secrets stay out: values in `.tfvars` are never shown (only that a variable changed); anything
187
+ marked `sensitive`, named like a secret anywhere in its path or inside its value (a `password` key
188
+ in `jsonencode({...})`), held by a resource that is a secret (`azurerm_key_vault_secret`,
189
+ `kubernetes_secret`), or shaped like a credential (a URL with a password in it, a private key, a
190
+ cloud access key) is hidden; and a plan's sensitive marks are respected.
191
+
192
+ ### Settings
193
+
194
+ Environment variables the code **now reads and did not before**, in Python, JavaScript and
195
+ TypeScript, Go, Ruby, Rust, PHP, Java, Kotlin and C#, with whether the code has a fallback.
196
+ A variable the program sets or clears itself is not one somebody has to provide.
197
+ It is a search for the usual ways of reading the environment, not an understanding of the program:
198
+ a list to check. A name counts as new only if nothing in the previous tree mentions it, and test
199
+ files are left out.
200
+
201
+ ### Also changed
202
+
203
+ Dependency manifests and lock files, pipelines, Dockerfiles and deployment manifests are named
204
+ when they change. Add your own groups.
205
+
206
+ ## Configuration
207
+
208
+ Nothing is required. `.whatships.toml`, or `[tool.whatships]` in `pyproject.toml`, is for what
209
+ cannot be guessed:
210
+
211
+ ```toml
212
+ base = "main" # what production runs
213
+ head = "stage" # what gets promoted
214
+ ticket_url = "https://example.atlassian.net/browse/{ticket}"
215
+ ignore = ["vendor/**", "**/*.snap"]
216
+
217
+ [areas] # names for parts of the code, instead of directory names
218
+ Billing = ["apps/billing/**", "apps/invoices/**"]
219
+
220
+ [terraform]
221
+ paths = ["infra/prod"] # only what this promotion applies
222
+
223
+ [watch]
224
+ "Feature flags" = ["config/flags/*.yaml"]
225
+ ```
226
+
227
+ Every key, with its default: [docs/configuration.md](https://github.com/GebleaAlex/whatships/blob/main/docs/configuration.md).
228
+
229
+ ## What it does not do
230
+
231
+ * **It does not connect to your database or your cloud.** It cannot know that a table has two
232
+ hundred million rows, which is why index builds and type changes are "check" and not a verdict.
233
+ * **The Terraform reading from files is a reading of files.** It does not evaluate expressions,
234
+ follow modules into their source, or know the state. For what an apply will do, give it a plan.
235
+ * **Rebase merges leave no trace in git.** Without a token, commits merged by rebase are listed as
236
+ arriving without a pull request. With one, GitHub is asked.
237
+ * **Settings are found by pattern**, so a variable read through a wrapper of your own is missed.
238
+ * **Migrations in Rails and JavaScript are read by name**, not parsed.
239
+ * **A very long range is read from its newest end.** Past 20,000 commits the report says so; a
240
+ promotion is far shorter.
241
+ * **One repository at a time.** A promotion that spans several repositories is several reports.
242
+ * **The comment is for GitHub.** Elsewhere the report is yours to post: Markdown, JSON or Slack.
243
+
244
+ ## Development
245
+
246
+ ```bash
247
+ python -m venv .venv && . .venv/bin/activate # .venv\Scripts\activate on Windows
248
+ pip install -e ".[dev]"
249
+ pytest && ruff check . && ruff format --check . && mypy
250
+ python examples/demo.py # a repository with a promotion in it, and its report
251
+ ```
252
+
253
+ The tests build real repositories with real merges; nothing about git is mocked. See
254
+ [CONTRIBUTING.md](https://github.com/GebleaAlex/whatships/blob/main/CONTRIBUTING.md). Licensed under
255
+ the [MIT License](https://github.com/GebleaAlex/whatships/blob/main/LICENSE).