Skip to content

Create lock file with checksums of files generated by goa

License

Notifications You must be signed in to change notification settings

benschoch/goa-lock-plugin

Repository files navigation

Lock file support for goa


Description

This is a plugin for goa that provides a similar concept of lock file creation, that you might already know from package managers such as npm or composer.

The idea behind this concept is to ensure that the code that is not part of your repository, is still in the expected state and does not change in your CI/CD process.

By enabling this plugin within your goa setup, you will get a file created in your output directory, called goa.lock when you execute the goa gen command.
That file can be used in your CI/CD to validate that the generated code didn't change accidentally.


How to enable the plugin?

Plugins for goa are enabled via import for side effects, which should look something like this:

package mygoadesigns
    
import (
    // import plugin for side effects on `goa gen`
    _ "github.com/benschoch/goa-lock-plugin"
)

Please refer to the goa docs for more details.


How to use in CI/CD?

TL;DR: identify changes in the lock file: git diff --exit-code gen/goa.lock

Probably the easiest way to include the lock file validation into your pipeline is via git diff.
First of all, you have to include the goa.lock file into your repository and exclude all other files generated by goa gen.

For example, if your project structure looks like this:

my-app/
├─ gen/
│  ├─ ...       <- all the generated files
│  ├─ goa.lock  <- the lock file
├─ design/
│  ├─ api.go
├─ .gitignore
├─ go.mod
├─ ...

You could have a .gitignore similar to this:

/gen/*
!/gen/goa.lock

And now you could run git diff --exit-code gen/goa.lock which returns an exit code 0 if the file didn't change and otherwise 1.

That exit code can then be used accordingly within your preferred CI pipeline tool.

About

Create lock file with checksums of files generated by goa

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published