Skip to content

Latest commit

 

History

History
118 lines (97 loc) · 5.63 KB

CONTRIBUTING.md

File metadata and controls

118 lines (97 loc) · 5.63 KB

Contributing

Contributions should roughly follow the uber style guide

Adding a new Go Module

If you need to make a new go module, here are the steps to follow:

  1. Create a new directory in the right sub-directory. If the file tree already has a go.mod or a go.sum file, you don't need a new module, you're just creating a package. *Note: the packages directory is for javascript and should not be used.

  2. Create a go.mod file in the new directory. You'll want the module name to match the directory path and the package name to be part of go.mod file. The go version should match the version in the root go.work file unless there's a good reaon for it no to.

    module github.com/synapsecns/sanguine/path/to/your/module
    
    go 1.19 // or whatever the version is in go.work

    Any local dependencies should use replaces like this:

    module github.com/synapsecns/sanguine/path/to/your/module
    
    go 1.19 // or whatever the version is in go.work
    
    require (
        github.com/synapsecns/sanguine/core v0.0.1
    )
    
    replace (
          github.com/synapsecns/sanguine/core => ../path/to/core
    )

    In so far as you have issues running go mod tidy, you may need to add additional replace directives. If you can't figure out what these are, please look at other requires of the module you're trying to link to

  3. Add the module to the go.work file. The path should be in alphabetical order.

    go 1.19
    use (
    ./a_module
    ./another_module
    ./path/to/your/module
    )
  4. Add the module to the .codecov.yml file under flags in alphabetical order . This allows codecov to re-use old coverage information if no changes have been made, which speeds up testing. For an explanation of when changes are ran please see this post , the go workflow and the git-changes-action. For an explanation of the carryforward flag, please see the codecov docs:

      # Lots of other stuff....
    
      # from the go.work file
      flags:
        # other flags...
    
        your-module-name: # in the case of github.com/synapsecns/sanguine/path/to/your/module, this would be module
          path: path/to/your/module/
          carryforward: true

    Note: The codecov.yaml used in ci will not be updated until your branch is merged to master. This is expected

  5. Create a Makefile. If your makefile has no custom commands (it shouldn't if you're just starting), simply create a symlink to the go.Makefile by running ln -sv ../path/to/repo/root/make/go.Makefile Makefile. Otherwise, create the makefile in $REPO_ROOT/make/[module_name].Makefile with the following text:

    include ../path/to/go.Makefile # this is the path to the go.Makefile from the module directory
    
    
    custom command:
      @eval $(echo "do something new!")

    then symlink it like above. Note: please do your best to make Makefile commands as portable as possible. For example, this installs tfenv for testing the terraform modules on osx and linux:

    tfenv-install:
      @#Brew - MacOS
      @if [ "$(shell which tflint)" = "" ] && [ "$(shell which brew)" != "" ]; then brew install rflint; fi;
      # default
      @if [ "$(shell which tflint)" = "" ]; then curl -s https://raw.githubusercontent.com/terraform-linters/tflint/master/install_linux.sh | bash; fi;
  6. Add a .goreleaser.yml file. If you're just starting the directory, it's likely you don't have a binary/Dockerfile yet so it can look something like this:

    project_name: your-module-name
    
    monorepo:
      tag_prefix: path/from/repo/root/to/module
      dir: path/from/repo/root/to/module
    
    # for now, this is a library release
    builds:
      - skip: true
    
    # add a source archive at release time
    source:
      enabled: true
    
    # Archives
    archives:
      - format: tar.gz
        wrap_in_directory: true
        format_overrides:
          - goos: windows
            format: zip
        name_template: '{{.ProjectName}}-{{.Version}}_{{.Os}}_{{.Arch}}'
        replacements:
          amd64: x86_64
          arm64: ARM64
          darwin: macOS
          linux: Linux
          windows: Windows
        files:
          - README.md
    
    checksum:
      name_template: checksums.txt
    
    # Add a changelog
    changelog:
      sort: asc

    If this is not a library release, please see any other .goreleaser.yml file for an example. It is important the production docker files are put in the docker/ directory and named [module_name].Dockerfile so that others can find them.

  7. Create a README.md file in the directory. This should include a description of the module and a link to the godoc page and go report card . If you're not sure what to put in the readme, look at the other modules for inspiration. If the module is on the more complex side, consider including a directory tree like we have here. If the application is runnable, instructions on running should be present.

  8. Add the new directory and description to the Directory Structure section of this README in alphabetical order.