Lock file support for goa
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.
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.
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.