Ensure that package.yaml and *.cabal are Synchronized in a Github Workflow

Thanks for this link!

I have no idea. I just copy and pasted that snippet :joy: into my workflow.

You can get this feature with some cabal formatters: cabal-fmt has an expand pragma and gild has a discover pragma.

3 Likes

My workflow is: I have a ./Shake cabalfiles script I can run any time, which runs hpack to update cabal files as needed and then commits the cabal files if they changed. (I like to commit these separate from other changes, reducing version control conflicts.)

Some notes from the comments there,

  • I used hpack’s --no-hash flag to avoid adding the hash header to the cabal files, reducing conflicts. I think this is the default behaviour in hpack nowadays.

  • As previously mentioned, use the same hpack version shown by stack --version, reducing conflicts.

  • I used to use stack build --dry-run for this, but that behaviour was dropped from stack some time ago, and it also returned a misleading exit code requiring a workaround. Though I see it’s still recommended elsewhere in this thread, so YMMV.

This is a really great tool! I am deleting my package.yaml files now.

PreferNoHash was introduced with Hpack 0.34.0, and incorporated into Stack 2.9.1 (September 2022).

I could not identify stack build --dry-run as having been dropped and later restored, but it is part of modern Stack. The Stack project uses it to re-create stack.cabal for package distribution when its package.yaml is updated.

I meant, stack build --dry-run stopped regenerating cabal files at some point - or so I thought.

1 Like