# Maintain a golden test of your package's API with \`diff-package-api\` and \`print-api\`

**URL:** https://discourse.haskell.org/t/maintain-a-golden-test-of-your-packages-api-with-diff-package-api-and-print-api/9997
**Category:** Announcements
**Created:** [July 21, 2024, 9:40pm UTC](https://discourse.haskell.org/t/maintain-a-golden-test-of-your-packages-api-with-diff-package-api-and-print-api/9997 "2024-07-21T21:40:15Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![Kleidukos](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/kleidukos/32/1213_2.png) [@Kleidukos](https://discourse.haskell.org/u/Kleidukos)
#### Post date: [July 21, 2024, 9:40pm UTC](https://discourse.haskell.org/t/maintain-a-golden-test-of-your-packages-api-with-diff-package-api-and-print-api/9997/1 "2024-07-21T21:40:15Z")

</div>

The machine never stops.

Joining the publication of [get-tested](http://discourse.haskell.org/t/go-get-tested-test-your-supported-ghc-versions-in-github-actions/8483), I have the pleasure to welcome [`diff-package-api`](https://github.com/marketplace/actions/package-interface-diff) to the suite of CI tools that power my continuous integration setups.

[`diff-package-api`](https://github.com/Kleidukos/diff-package-api/) is a GitHub Action workflow that runs against your Haskell package and compares the API it exposes against a file tracked in your repository that contains the _expected_ API exposed by your package.

It is powered by [`print-api`](https://github.com/Kleidukos/print-api), which is adapted from the [`dump-decls`](https://gitlab.haskell.org/ghc/ghc/-/tree/master/utils/dump-decls?ref_type=heads) tool created by @bgamari for the benefit of the GHC release engineering team.

It’s still fresh from the oven, so you are highly encouraged to try it out for your projects and give usability feedback. Some aspects of its usage are a bit annoying, like the need to have one golden file per GHC version, but this is due to the very precise level of details regarding the provenance of the identifiers. For instance, between GHC 9.8.2 and GHC 9.10.1, the switch to `ghc-internal` has changed the provenance of `TypeError`:

```diff
 module Data.Text.Display.Generic where
- type Assert :: GHC.Types.Bool -> GHC.TypeError.ErrorMessage -> Constraint
+ type Assert :: GHC.Types.Bool -> GHC. **Internal**.TypeError.ErrorMessage -> Constraint

```

(emphasis mine)

While I’m opening a bottle to celebrate, I will also produce an architecture document that ought to answer a lot of questions about the precise details of how it all works and when it stops working.

This is not a PVP compliance checker (although perhaps it could?). For the moment it forces you to stay honest on the changes of your packages’ API.

* * *

Here a few screenshots from a [PR on text-display](https://github.com/haskell-text/text-display/pull/71/files). You can go there to see (or hear) by yourself if the screenshots are not convenient.

## The updated API interface file in a pull request

 ![image](https://us1.discourse-cdn.com/flex002/uploads/haskell/original/2X/3/3d7f480d884b30731c2efbc38adfa48c6f6dc051.png)

## When `diff-package-api` complains

 ![image](https://us1.discourse-cdn.com/flex002/uploads/haskell/original/2X/a/acceeb58410054096cd0a4cd8fc04dc36c8e78eb.png)

## Me when I can keep trace of potentially breaking API changes

> **dope.**
>
> ![dope](https://us1.discourse-cdn.com/flex002/uploads/haskell/original/2X/e/e694d01f100788d2437cabd6690bc6fd4963bf2e.gif)

* * *

My warmest thanks to @bgamari, @TeofilC and @mpickering for their help, both direct and indirect.

---

<div class="post-metadata">

### Author: ![Vlix](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/vlix/32/1551_2.png) [@Vlix](https://discourse.haskell.org/u/Vlix)
#### Post date: [July 22, 2024, 12:51pm UTC](https://discourse.haskell.org/t/maintain-a-golden-test-of-your-packages-api-with-diff-package-api-and-print-api/9997/2 "2024-07-22T12:51:52Z")

</div>

Love hearing about developments regarding stability and backwards compatibility ❤

---

<div class="post-metadata">

### Author: ![Kleidukos](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/kleidukos/32/1213_2.png) [@Kleidukos](https://discourse.haskell.org/u/Kleidukos)
#### Post date: [July 22, 2024, 12:56pm UTC](https://discourse.haskell.org/t/maintain-a-golden-test-of-your-packages-api-with-diff-package-api-and-print-api/9997/3 "2024-07-22T12:56:42Z")

</div>

Cheers, I have to admit that the zeitgeist of the Haskell community encouraged me, with the importance given to Stability and its working group.

---

<div class="post-metadata">

### Author: ![arianvp](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/arianvp/32/2077_2.png) [@arianvp](https://discourse.haskell.org/u/arianvp)
#### Post date: [July 22, 2024, 7:34pm UTC](https://discourse.haskell.org/t/maintain-a-golden-test-of-your-packages-api-with-diff-package-api-and-print-api/9997/4 "2024-07-22T19:34:52Z")

</div>

This is cool! I wonder if we can go a bit further and implement something like [gorelease command - golang.org/x/exp/cmd/gorelease - Go Packages](https://pkg.go.dev/golang.org/x/exp/cmd/gorelease)

which automatically suggests semver bumps based on the API diff. Always dreamt of something like that

---

<div class="post-metadata">

### Author: ![jaror](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/jaror/32/3271_2.png) [@jaror](https://discourse.haskell.org/u/jaror)
#### Post date: [July 22, 2024, 7:38pm UTC](https://discourse.haskell.org/t/maintain-a-golden-test-of-your-packages-api-with-diff-package-api-and-print-api/9997/5 "2024-07-22T19:38:53Z")

</div>

There is a prototype: [policeman :: Kowainik](https://kowainik.github.io/projects/policeman), but it is not maintained. Maybe it would be easy to revive using `diff-package-api`.

---

<div class="post-metadata">

### Author: ![andreabedini](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/andreabedini/32/2201_2.png) [@andreabedini](https://discourse.haskell.org/u/andreabedini)
#### Post date: [July 26, 2024, 1:51am UTC](https://discourse.haskell.org/t/maintain-a-golden-test-of-your-packages-api-with-diff-package-api-and-print-api/9997/6 "2024-07-26T01:51:30Z")

</div>

Wow this is fantastic @Kleidukos!! I had played with the same idea and I’m very happy to see you deliver it!

We struggled with noticing API changes in cabal, so let’s start using it there right away (or you opened a PR already? 🙂)

---

<div class="post-metadata">

### Author: ![harendra](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/harendra/32/1143_2.png) [@harendra](https://discourse.haskell.org/u/harendra)
#### Post date: [July 26, 2024, 8:09am UTC](https://discourse.haskell.org/t/maintain-a-golden-test-of-your-packages-api-with-diff-package-api-and-print-api/9997/7 "2024-07-26T08:09:55Z")

</div>

We are using a similar tool in our CIs which diffs API based on the haddock generated hoogle file. We also generate a API changelog using this tool. I updated the following in another thread:

> We use packdiff ([GitHub - composewell/packdiff](https://github.com/composewell/packdiff)) to find the complete API diff from a previous release/commit. In fact we have it integrated in our CI to report API changes in each PR, the output looks like this: [Multiple issue resolution targeting the 0.11 release · composewell/streamly@ed72f22 · GitHub](https://github.com/composewell/streamly/actions/runs/9998145946/job/27636362257) (check out the “run packdiff on streamly-core” section).

---

<div class="post-metadata">

### Author: ![Kleidukos](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/kleidukos/32/1213_2.png) [@Kleidukos](https://discourse.haskell.org/u/Kleidukos)
#### Post date: [July 26, 2024, 9:09am UTC](https://discourse.haskell.org/t/maintain-a-golden-test-of-your-packages-api-with-diff-package-api-and-print-api/9997/8 "2024-07-26T09:09:48Z")

</div>

Not yet, I am taking some vacations right now but it would be grand to have it indeed. 🙂

---

<div class="post-metadata">

### Author: ![Kleidukos](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/kleidukos/32/1213_2.png) [@Kleidukos](https://discourse.haskell.org/u/Kleidukos)
#### Post date: [July 26, 2024, 9:11am UTC](https://discourse.haskell.org/t/maintain-a-golden-test-of-your-packages-api-with-diff-package-api-and-print-api/9997/9 "2024-07-26T09:11:11Z")

</div>

Nice, that’s perhaps a less involved solution 🙂 I’d be interested in providing it as a backend for the diff-package-api Workflow

---

<div class="post-metadata">

### Author: ![harendra](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/harendra/32/1143_2.png) [@harendra](https://discourse.haskell.org/u/harendra)
#### Post date: [July 26, 2024, 10:13am UTC](https://discourse.haskell.org/t/maintain-a-golden-test-of-your-packages-api-with-diff-package-api-and-print-api/9997/10 "2024-07-26T10:13:22Z")

</div>

Sure, we will be happy to help if it is useful.

---

<div class="post-metadata">

### Author: ![geekosaur](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/geekosaur/32/2128_2.png) [@geekosaur](https://discourse.haskell.org/u/geekosaur)
#### Post date: [July 28, 2024, 12:56am UTC](https://discourse.haskell.org/t/maintain-a-golden-test-of-your-packages-api-with-diff-package-api-and-print-api/9997/11 "2024-07-28T00:56:47Z")

</div>

It’s on my list. I’ve been somewhat busy with medical things of late, so we’ll see when I get to it. (@Kleidukos: Is the action you show available in general?)

---

<div class="post-metadata">

### Author: ![Kleidukos](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/kleidukos/32/1213_2.png) [@Kleidukos](https://discourse.haskell.org/u/Kleidukos)
#### Post date: [July 28, 2024, 6:57am UTC](https://discourse.haskell.org/t/maintain-a-golden-test-of-your-packages-api-with-diff-package-api-and-print-api/9997/12 "2024-07-28T06:57:55Z")

</div>

It’s available for all GitHub Actions workflows to re-use, yes! 🙂
