github.com/kaisawind/go-swagger@v0.19.0/docs/guidelines/README.md (about)

     1  # Guidelines to maintainers
     2  
     3  A quick guide on how to contribute to `go-swagger` and the other `go-openapi` repos.
     4  
     5  ### Getting started
     6  
     7  Repos follow standard go building and testing rules.
     8  
     9  Cloning `go-swagger`:
    10  ```bash
    11  mkdir -p $GOPATH/src/github.com/go-swagger
    12  cd $GOPATH/src/github.com/go-swagger
    13  git clone https://github.com/go-swagger/go-swagger
    14  ```
    15  
    16  All dependencies are available in the checked out `vendor` directory.
    17  
    18  Building and installing go-swagger from source on your system:
    19  ```
    20  go install github.com/go-swagger/go-swagger/cmd/swagger
    21  ```
    22  
    23  Running standard unit tests:
    24  ```bash
    25  go test ./...
    26  ```
    27  
    28  More advanced tests are run by CI. See [below](#continuous-integration).
    29  
    30  ### Generally accepted rules for pull requests
    31  
    32  All PR's are welcome and generally accepted (so far, 95% were accepted...).
    33  There are just a few common sense rules to be followed.
    34  
    35  1. PRs which are not ready to merge should be prefixed with `WIP:`
    36  2. Generally, contributors should squash their commits (use `git rebase -i master`)
    37  3. Provide sufficient test coverage with changes
    38  4. Do not bring in uncontrolled dependencies, including from fixtures or examples
    39  Adding dependencies is possible with a vendor update (`dep ensure -update`)
    40  5. Use the `fixes #xxx` github feature in PR to automate issue closing
    41  6. Sign-off commits with `git commit -s`. PGP-signed commits with verified signatures are not mandatory (but much appreciated)
    42  
    43  ### Go environment
    44  
    45  We want to always support the **two most recent go versions**.
    46  
    47  However, we try to avoid introducing breaking changes, especially on the more
    48  stable `go-openapi` repos. We manage this with build tags. Notice the very
    49  important blank line after your build tag comment line.
    50  
    51  Example (from `go-openapi/swag`):
    52  ```go
    53  // +build !go1.8
    54  
    55  package swag
    56  
    57  import "net/url"
    58  
    59  func pathUnescape(path string) (string, error) {
    60  	return url.QueryUnescape(path)
    61  }
    62  ```
    63  
    64  All repos should remain go-gettable (i.e. available with the `go get ./...` command)
    65  and testable with `go test ./...`
    66  
    67  ### Continuous integration
    68  
    69  All PR's require a review by a team member, whatever the CI engines tell.
    70  
    71  ##### go-swagger/go-swagger
    72  
    73  Enabled CI engines and bots:
    74  - CircleCI (linux)
    75  - Appveyor (windows)
    76  - GolangCI
    77  - Codecov
    78  - DCO (enfore signed-off commits)
    79  - WIP (blocks PRs with title WIP/do not merge, etc...)
    80  
    81  Codecov results are not blocking.
    82  
    83  CI runs description/configuration:
    84  
    85  | CI engine | Test type     | Configuration             | Comment |
    86  |---        |---            |---                        |---      |
    87  | CircleCI  | unit test     | .circleci/config.yml      |         |
    88  |           | build test (1)| ./hack/codegen-nonreg.sh  | Codegen and build test on many (~ 80) specs in `fixtures/codegen` and `fixtures/bugs``|
    89  |           | build test (2)| ./hack/run-canary.sh      | Codegen and build test on (large) specs in fixtures/canary`|
    90  | Appveyor  | unit test     | appveyor.yml              | `go test -v ./...` |
    91  | GolangCI  | linting       | .golangci.yml             | equ. `golangci-lint run` |
    92  | Codecov   | test coverage | -                         | project test coverage and PR diff coverage|
    93  | DCO       | commit signed | -                         | https://probot.github.io/apps/dco|
    94  | WIP       | PR title      | -                         | https://github.com/apps/wip|
    95  
    96  Deprecated engines:
    97  - hound (`.hound.yml`): previous linting checker before we moved to golangCI
    98  
    99  > **NOTE on Appveyor**:
   100  > Appveyor runs our UT on Windows. This makes sure everything works fine
   101  > on this platform as well.
   102  > The peculiarity with this CI is that it does not tolerate output to `stderr`
   103  > from test programs (this is actually a Powershell limitation).
   104  > Therefore, please make sure your UT remain mute on stderr or capture the
   105  > output if you need to assert something from the output.
   106  
   107  The script `./hack/codegen-nonreg.sh` runs on CI with a single generation option.
   108  You may run it manually to explore more generation options (expand spec, flatten, etc...).
   109  
   110  CircleCI has a separate CI workflow to build releases, baking and checking newly released docker
   111  images.
   112  
   113  ##### go-openapi repos
   114  
   115  Enabled CI engines:
   116  - Travis (linux)
   117  - GolangCI
   118  - Codecov
   119  
   120  > **NOTE**: setting up Appveyor on go-openapi/spec and validate is on the todo list.
   121  
   122  | CI engine | Test type     | Configuration             | Comment |
   123  |---        |---            |---                        |---      |
   124  | Travis    | unit test     | .travis.yml               | `go test -v ./...` |
   125  | GolangCI  | linting       | .golangci.yml             | equ. `golangci-lint run` |
   126  
   127  ### Vendoring
   128  
   129  `go-swagger/go-swagger` repo comes with a vendor directory. This is because
   130  we release binary distributions (docker, debian...).
   131  
   132  The `go-openapi` packages are **not** vendored.
   133  
   134  Vendoring is managed using the current _official_ `dep` tool.
   135  Configuration is in `Gopkg.toml`.
   136  
   137  Run `dep ensure -update` to update dependencies. Please do not cherry-pick
   138  updates manually.
   139  
   140  > **NOTE**: since there are many dependencies, running an update may update
   141  > many things.
   142  > We prefer to get vendor updates as separate commits with changes to vendor only.
   143  
   144  ##### Testing PRs requiring integration of a dependency (e.g. another pending PR on `go-openapi`)
   145  
   146  This happens for instance whenever you want to test the full integration in `go-swagger` of an unmerged PR
   147  in one of the `go-openapi` repos.
   148  
   149  With `go-swagger` (vendored):
   150  - prepare a "WIP" PR with a temporary vendor update commit
   151  - this vendor update temporarily alters the `branch` and `source` in `Gopkg.toml`
   152  to get the proper version of the required dependency from the unmerged branch (e.g. from your fork)
   153  
   154  With `go-openapi` (non vendored):
   155  - for your "WIP" PR, temporarily alter the CI config script (e.g. `.travis.yml`) and
   156  replace the `go get` requirements to build your CI with the adequate `git clone`
   157  pointing to the required branches
   158  
   159  ### Update templates
   160  
   161  `go-swagger` is built with an in-memory image of templates.
   162  
   163  Binary encoded assets are auto-generated from the `generator/templates` directory using `bindata`
   164  (the result is `generator/bindata.go`).
   165  
   166  While developing, you may work with dynamically updated templates (i.e. no need to rebuild)
   167  using `bindata.go` generated in debug mode (use script: `./generator/gen-debug.sh`).
   168  
   169  There is a `.githook` script configured as pre-commit: every time you commit to the repo, `generator/bindata.go`
   170  is regenerated and added to the current commit (without debug mode).
   171  
   172  For `bindata` please use the fork found at: `github.com/kevinburke/go-bindata`.
   173  
   174  > **NOTE**: we are carrying out unit tests on codegen mostly by asserting lines in generated code.
   175  > There is a bunch of test utility functions for this. See `generator/*_test.go`.
   176  > If you want to bring in more advanced testing go programs with your fixtures, please tag
   177  > those so they don't affect the `go ./...` command (e.g. with `// +build +integration`).
   178  
   179  ### Updating examples
   180  
   181  Whenever code generation rules change, we feel it is important to maintain
   182  consistency with the generated code provided as examples.
   183  
   184  The script `./hack/regen-samples.sh` does just that.
   185  
   186  Do not forget to update this script when you add a new example.
   187  
   188  ### Writing documentation
   189  
   190  ##### go-swagger/go-swagger
   191  
   192  The `go-swagger` documentation site (`goswagger.io`) is built with GitBooks.
   193  Configuration is in `book.json`. The documents root is in `./docs`
   194  
   195  We systematically copy the repository main `README.md` to `docs/README.md`.
   196  Please make sure links work both from github and gitbook.
   197  
   198  There is also a minimal godoc for goswagger.
   199  
   200  Please make sure new CLI options remain well documented in `./docs/usage` and `./docs/generate`.
   201  
   202  ##### go-openapi repos
   203  
   204  Documentation is limited to the repo's README.md and godoc, published on godoc.org.