Skip to content

Commit

Permalink
New release pipeline in operator (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorres authored Nov 5, 2024
1 parent 5744c87 commit 3a88507
Show file tree
Hide file tree
Showing 20 changed files with 154 additions and 150 deletions.
1 change: 1 addition & 0 deletions .changes/header.tpl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Changelog
Empty file added .changes/unreleased/.gitkeep
Empty file.
3 changes: 3 additions & 0 deletions .changes/v0.5.31.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## v0.5.31 - 2024-11-04
### Added
* Initialized a changelog
26 changes: 26 additions & 0 deletions .changie.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
changesDir: .changes
unreleasedDir: unreleased
headerPath: header.tpl.md
changelogPath: CHANGELOG.md
versionExt: md
versionFormat: '## {{.Version}} - {{.Time.Format "2006-01-02"}}'
kindFormat: '### {{.Kind}}'
changeFormat: '* {{.Body}}'
kinds:
- label: Added
auto: minor
- label: Changed
auto: major
- label: Deprecated
auto: minor
- label: Removed
auto: major
- label: Fixed
auto: patch
- label: Security
auto: patch
newlines:
afterChangelogHeader: 1
beforeChangelogVersion: 1
endOfVersion: 1
envPrefix: CHANGIE_
11 changes: 0 additions & 11 deletions .github/scripts/check-work-copy-equals-to-committed.sh

This file was deleted.

22 changes: 0 additions & 22 deletions .github/scripts/format-all-go-code.sh

This file was deleted.

13 changes: 0 additions & 13 deletions .github/scripts/format-go-code.sh

This file was deleted.

10 changes: 0 additions & 10 deletions .github/scripts/is_autogenerated_file.sh

This file was deleted.

58 changes: 58 additions & 0 deletions .github/workflows/create-release-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: create-release-pr

on:
workflow_dispatch:

jobs:
create-release-pr:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4

- name: batch-changes
uses: miniscruff/changie-action@v2
with:
version: latest
args: batch patch

- name: merge-changes
uses: miniscruff/changie-action@v2
with:
version: latest
args: merge

- name: print the latest version
id: latest
uses: miniscruff/changie-action@v2
with:
version: latest
args: latest

- name: print the latest version without "v"
id: latest-no-v
uses: miniscruff/changie-action@v2
with:
version: latest
args: latest --remove-prefix

- name: check-chart-version
run: |
VERSION=${{ steps.latest-no-v.outputs.output }}
APP_VERSION=$(grep '^appVersion:' ./deploy/ydb-operator/Chart.yaml | awk '{print $2}' | tr -d '"')
CHART_VERSION=$(grep '^version:' ./deploy/ydb-operator/Chart.yaml | awk '{print $2}' | tr -d '"')
if [ "$APP_VERSION" != "$VERSION" ] || [ "$CHART_VERSION" != "$VERSION" ]; then
echo "Version mismatch: appVersion ($APP_VERSION) or version ($CHART_VERSION) does not match expected version ($VERSION). You most likely forgot to bump the version in Chart.yaml, please do so."
exit 1
else
echo "Version matches: appVersion ($APP_VERSION) and version ($CHART_VERSION) are both $VERSION."
fi
- name: Create Pull Request
uses: peter-evans/create-pull-request@v7
with:
title: Release ${{ steps.latest.outputs.output }}
branch: release/${{ steps.latest.outputs.output }}
commit-message: Release ${{ steps.latest.outputs.output }}
token: ${{ github.token }}
30 changes: 3 additions & 27 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v3
- name: setup-go
uses: actions/setup-go@v3
with:
go-version: '1.20'
uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.58.1
code-format-check:
concurrency:
group: lint-autoformat-${{ github.head_ref || github.ref_name }}
cancel-in-progress: true
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v3
- name: setup-go
uses: actions/setup-go@v3
uses: golangci/golangci-lint-action@v6
with:
go-version: '1.20'
- name: install-utilities
run: |
go install mvdan.cc/[email protected]
go install github.com/rinchsan/gosimports/cmd/[email protected]
- name: format all files with auto-formatter
run: bash ./.github/scripts/format-all-go-code.sh "$PWD"
- name: check-repository-diff
run: bash ./.github/scripts/check-work-copy-equals-to-committed.sh "auto-format broken"
version: v1.61.0
run-unit-tests:
concurrency:
group: run-unit-tests-${{ github.head_ref || github.ref_name }}
Expand Down
50 changes: 33 additions & 17 deletions .github/workflows/upload-artifacts.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,45 @@
name: upload-artifacts

on:
push:
branches:
- master
paths:
- 'CHANGELOG.md'
workflow_dispatch:

jobs:
tag-job:
tag-and-release:
runs-on: ubuntu-latest
outputs:
tagcreated: ${{steps.tag-step.outputs.tagcreated}}
steps:
- uses: actions/checkout@v3
- id: tag-step
uses: butlerlogic/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v4

- name: get-latest-version
uses: miniscruff/changie-action@v2
with:
strategy: regex
root: "./deploy/ydb-operator/Chart.yaml"
regex_pattern: 'version:[\s]*(["]?[0-9\.]{3,}["]?)'
upload-artifacts:
runs-on: ubuntu-latest
needs: tag-job
if: ${{ needs.tag-job.outputs.tagcreated == 'yes' }}
steps:
- uses: actions/checkout@v3
version: latest
args: latest
- name: get-latest-no-v-version
uses: miniscruff/changie-action@v2
with:
version: latest
# Echoes the same version as previous step, but without "v" prefix.
# Is used as a docker image tag in the release step.
# E.g. "v0.5.31" -> "0.5.31"
args: latest --remove-prefix

- name: update-chart-version-with-release-version
run: |
RELEASE_VERSION=${{ steps.get-latest-no-v-version.outputs.output }}
sed -i 's/<IS_SUBSTITUTED_IN_CI_RELEASE_JOB>/'"$RELEASE_VERSION"'/g' ./deploy/ydb-operator/Chart.yaml
- name: create-tag
uses: mathieudutour/[email protected]
with:
tag_prefix: ""
custom_tag: ${{ steps.get-latest-version.outputs.output }}
github_token: ${{ github.token }}

- name: install-dependencies
run: |
HELM_PKG="helm-v3.10.3-linux-amd64.tar.gz"
Expand Down
5 changes: 4 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ linters-settings:
check-blank: false
govet:
# report about shadowed variables
check-shadowing: true
shadow: true
fieldalignment: true
golint:
# minimal confidence for issues, default is 0.8
Expand All @@ -76,6 +76,7 @@ linters-settings:
gosec:
excludes:
- G101
- G115
fieldalignment:
# print struct with more effective memory layout or not, false by default
suggest-new: true
Expand Down Expand Up @@ -129,6 +130,8 @@ linters-settings:
linters:
disable-all: true
enable:
# - cyclop
# - depguardgolang
- dogsled
- errcheck
- errorlint
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Changelog


## v0.5.31 - 2024-11-04
### Added
* Initialized a changelog
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![check-pr](https://github.com/ydb-platform/ydb-kubernetes-operator/actions/workflows/check-pr.yml/badge.svg)](https://github.com/ydb-platform/ydb-kubernetes-operator/actions/workflows/check-pr.yml)
[![run-tests](https://github.com/ydb-platform/ydb-kubernetes-operator/actions/workflows/run-tests.yml/badge.svg)](https://github.com/ydb-platform/ydb-kubernetes-operator/actions/workflows/run-tests.yml)
[![upload-artifacts](https://github.com/ydb-platform/ydb-kubernetes-operator/actions/workflows/upload-artifacts.yml/badge.svg)](https://github.com/ydb-platform/ydb-kubernetes-operator/actions/workflows/upload-artifacts.yml)

# YDB Kubernetes Operator
Expand Down
4 changes: 2 additions & 2 deletions deploy/ydb-operator/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.5.30
version: "0.5.31"

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "0.5.30"
appVersion: "0.5.31"
16 changes: 4 additions & 12 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
This document attempts to be some sort of a table of contents:

## Operator release flow

See [here](./release-flow.md).
## Working on a feature

## Writing and running tests

See [here](./tests.md).

## Storage

#### [Storage state machine schema](./storage-state-machine-schema.md)

This describes which states the Storage object has and in what order they are
traversed.
- don't forget to use `changie` to generate a changelog entry, whenever you complete a feature
- see [here](./tests.md) to learn how to run tests
- see [here](./tests.md) to learn how to release a new version
43 changes: 12 additions & 31 deletions docs/release-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,15 @@

#### How and when the operator version is changed

The single source of truth is the version number in
[Chart.yaml](https://github.com/ydb-platform/ydb-kubernetes-operator/blob/master/deploy/ydb-operator/Chart.yaml#L18)
file.

It is incremented according to semver practices. Essentially, it is incremented every
time any change is made into either chart or the operator code.

For the contrast, changing some details of Github workflows or rewriting the docs
does not initiate a new release.

#### What the CI does

When you increment the version in `Chart.yaml` and your PR is merged into master, tag
is automatically extracted from the Chart like this:

```
"version: 0.4.22" -> "0.4.22"
```

If the version is new (no previous commit was tagged with this version), then:

- this merge commit gets tagged with version extracted from `Chart.yaml`;
- new docker image is built and uploaded to `cr.yandex/yc/ydb-kubernetes-operator`;
- new chart version is uploaded to https://charts.ydb.tech.

#### What if I forget to bump up the chart version?

Then these changes won't get automatically tagged, new version won't be built and
uploaded and you most likely will notice it immediately when you'll want to use an
updated version. Then you make another PR with a chart version bump and get your
changes rebuilt.
The single source of truth is the changelog.

Currently, version is updated when a developer decides to release a new version by manually invoking
`create-release-pr` workflow in Github Actions:

- invoke `create-release-pr` workflow
- `changie` tool automatically bumps the version and generates an updated CHANGELOG.md
- if a generated `CHANGELOG.md` looks okay, just merge it
- the `upload-artifacts` workflow will:
- substitute the latest version in `Chart.yaml`
- build artifacts (docker image and helm chart) and upload them to all configured registries
- create a new Github release
Binary file removed docs/storage-state-machine-schema.drawio.png
Binary file not shown.
3 changes: 0 additions & 3 deletions docs/storage-state-machine-schema.md

This file was deleted.

1 change: 1 addition & 0 deletions internal/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func InPod(
if err != nil {
return stdout.String(), stderr.String(), errors.Wrapf(
err,
//nolint:govet // TODO @jorres figure out why non-const error messages are not recommended
fmt.Sprintf("failed to stream execution results back, stdout:\n\"%s\"stderr:\n\"%s\"", stdout.String(), stderr.String()),
)
}
Expand Down

0 comments on commit 3a88507

Please sign in to comment.