# Release

## Preparing release version

1. Update the `version` defined in the code to the new version number.
   As of the time of writing, the version is defined in `pkg/buildinfo/version.go`.

## Kubernetes release
Is there a Kubernetes release since the last Sonobuoy release? If so, apply the following steps:

### Conformance images
Ensure the upstream conformance script is working appropriately:
  * Update the `kind-config.yaml` file with the new image version [here](https://github.com/vmware-tanzu/sonobuoy/blob/main/kind-config.yaml).
  * Run conformance tests

## Updating the versioned docs
Explicit doc changes (if any) should be made to the appropriate files in directory `site/docs/main`.

Next, generate a set of versioned docs for v0.x.y. For instance, the new docs be generated by running the command:

```
./scripts/update_docs.sh v0.20.0
```

This will copy the current `main` docs into the version given and update
a few of the links in the README to be correct. It will also update
the website config to add the new version and consider it the newest
version of the docs.

## Create PR
1. Commit previous changes and open a new PR
2. Ensure your commits signed
3. Follow PR build progress in circleci.com
4. Once all checks passes, merge accordingly

## Tag release
This step will tag the code and triggers a release.

1. From your local branch, create an annotated `tag` for the commit that was merged:

    ```
    git tag -a v0.x.y -m "Release v0.x.y"
    ```

    > NOTE: Tag the new tip of `main`, not the branch you just merged.

1. Push the `tag` to the [`github.com/vmware-tanzu/sonobuoy`](https://github.com/vmware-tanzu/sonobuoy/) repository.
2. To ensure that the tag is pushed to the correct repository, check which remote corresponds to that repository using the following command:

     ```
     git remote -v
     ```
     The output of this command should include at least two configured remotes, typically `origin`, which refers to your personal fork, and `upstream` which refers to the upstream Sonobuoy repository.
     For example:

     ```
     origin	git@github.com:<username>/sonobuoy.git (fetch)
     origin	git@github.com:<username>/sonobuoy.git (push)
     upstream	https://github.com/vmware-tanzu/sonobuoy (fetch)
     upstream	https://github.com/vmware-tanzu/sonobuoy (push)
     ```
     For the following steps, use the remote configured for the `vmware-tanzu/sonobuoy` repository.
     The following instructions will use `upstream`.
1. Push the tag with the following command.
     > NOTE: This will push all tags.

     ```
     git push upstream --tags
     ```
     To push just one tag, use the following command format (replacing `v0.x.y` with the tag created in the previous step):

     ```
     git push upstream refs/tags/v0.x.y
     ```
     If there is a problem and you need to remove the tag, run the following commands:

     ```
     git tag -d v0.x.y
     git push upstream :refs/tags/v0.x.y
     ```
     > NOTE: The `:` preceding the tag ref is necessary to delete the tag from the remote repository.
     > Git refspecs have the format `<+><src>:<dst>`.
     > By pushing an empty `src` to the remote `dst`, it makes the destination ref empty, effectively deleting it.
     > For more details, see the [`git push` documentation](https://git-scm.com/docs/git-push) or [this concise explanation on Stack Overflow](https://stackoverflow.com/a/7303710).


## Release Validation
1. Open a browser tab and go to: https://https://github.com/vmware-tanzu/sonobuoy/actions and verify go releaser for tag v0.x.y completes successfully.
1. Upon successful completion of build job above, check the [releases tab of Sonobuoy](https://github.com/vmware-tanzu/sonobuoy/releases) and verify the artifacts and changelog were published correctly.
1. Run the following command to make sure the image was pushed correctly to [Docker Hub][dockerhub]:

   ```
   docker run -it sonobuoy/sonobuoy:v0.x.y /sonobuoy version
   ```
   The `Sonobuoy Version` in the output should match the release tag above.
1. Go to the [GitHub release page](https://github.com/vmware-tanzu/sonobuoy/releases) and download the release binaries and make sure the version matches the expected values.
2. Run a [Kind](https://github.com/kubernetes-sigs/kind) cluster locally and ensure that you can run `sonobuoy run --mode quick`.
   If this release corresponds to a new Kubernetes release as well, ensure:

    * you're using the correct Kubernetes context by checking the output from:

      ```
      kubectl config current-context
      ```

      and verifying that it is set to the context for the Kind cluster just created (`kind-kind` or `kind-<custom_cluster_name>`)
    * you're testing with the new Kind images by checking the output from:

      ```
      kubectl version --short
      ```

      and verifying that the server version matches the intended Kubernetes version.
    * you can run `sonobuoy images` and get a list of test images as expected
2. Update the release notes if desired on GitHub by editing the newly created release.

### Notes
1. Before releasing, ensure all parties are available to resolve any issues that come up. If not, just bump the release.

[gendocs]: #generating-a-new-set-of-versioned-docs
[dockerhub]: https://cloud.docker.com/u/sonobuoy/repository/docker/sonobuoy/sonobuoy/tags
