goa

package module
v0.0.0-...-d58e6b1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 27, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

README

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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(_ string, _ []eval.Root, files []*codegen.File) ([]*codegen.File, error)

Generate applies finalization functions to all files in order to put their checksums into the lock file

Types

type Locker

type Locker struct {
	// contains filtered or unexported fields
}

func NewLocker

func NewLocker(files []*codegen.File) (*Locker, error)

func (*Locker) Lock

func (l *Locker) Lock() (lockFilename []byte, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL