Skip to content

Commit

Permalink
Merge pull request #36 from ydb-platform/RELEASES
Browse files Browse the repository at this point in the history
Scripts and files to build releases
  • Loading branch information
shmel1k authored Oct 9, 2024
2 parents c61e18a + f0c9636 commit c8ce2f6
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 7 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Go

on:
push:
tags:
- 'v*'

jobs:

build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@master

- name: Build
run: |
make build-in-docker
- name: Generate Changelog
run: |
VERSION=$(cicd/version.sh)
cicd/changelog.sh $VERSION > bin/CHANGELOG.md
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
body_path: bin/CHANGELOG.md
files: bin/ydbops*
env:
GITHUB_TOKEN: ${{ github.token }}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog

## 0.0.9
+ Information about version in help output
+ Scripts for build release
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
FROM golang:1.22 as builder
COPY go /go/pkg/mod
RUN mkdir /app
WORKDIR /app
COPY . /app
RUN cd /app && make build
RUN cd /app && make all
33 changes: 30 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,40 @@
APP_VERSION=$(shell cicd/version.sh)
BINARY_NAME=ydbops
BUILD_DIR=bin
TODAY=$(shell date --iso=minutes)

build:
go get -u
CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -ldflags='-X main.buildInfo=${TODAY}' -o bin/${BINARY_NAME} main.go
all: build build-macos

lint:
@echo "Linting code..."
@go vet ./...

pre-build:
@mkdir -p $(BUILD_DIR)

build-macos: lint pre-build
GOOS=darwin GOARCH=amd64 go build -ldflags='-X github.com/ydb-platform/ydbops/cmd.buildVersion=${APP_VERSION}' -o ${BUILD_DIR}/${BINARY_NAME}_darwin_amd64 main.go
GOOS=darwin GOARCH=arm64 go build -ldflags='-X github.com/ydb-platform/ydbops/cmd.buildVersion=${APP_VERSION}' -o ${BUILD_DIR}/${BINARY_NAME}_darwin_arm64 main.go

build: lint pre-build
CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -ldflags='-X github.com/ydb-platform/ydbops/cmd.buildVersion=${APP_VERSION}' -o ${BUILD_DIR}/${BINARY_NAME} main.go
strip bin/${BINARY_NAME}

clear:
rm -rf bin/${BINARY_NAME}

dep:
go mod download

docker:
docker build --force-rm -t $(BINARY_NAME) .

build-in-docker: docker
docker rm -f $(BINARY_NAME) || true
docker create --name $(BINARY_NAME) $(BINARY_NAME)
docker cp '$(BINARY_NAME):/app/bin/' $(BUILD_DIR)
docker rm -f $(BINARY_NAME)

clean:
@echo "Cleaning..."
@rm -Rf $(BUILD_DIR)
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ For now, please use the below info for reference only, it might be slightly outd
Execute build.sh
Also Dockerfile can be used as a part of other multi-stage dockerfiles.

## How to run tests:
## How to run tests

Ginkgo testing library is used. Do:

Expand Down Expand Up @@ -80,3 +80,18 @@ ydbops restart --storage \
--availability-mode strong --verbose --hosts=7,8 \
--user jorres --kubeconfig ~/.kube/config
```

## How to create a new version
### In Github
1. Define new version number, like 1.1.0
2. Update CHANGELOG.md with proper information about new version
3. Push changes into the repository (git push)
4. Add tag v{VERSION}, like v1.1.0 (git tag v1.1.0)
5. Push tag into the repository (git push --tags)
6. Github will create a new release

## Localy
1. Define new version number, like 1.1.0
2. Update CHANGELOG.md with proper information about new version
4. Add tag v{VERSION}, like v1.1.0 (git tag v1.1.0)
5. make build-in-docker
27 changes: 27 additions & 0 deletions cicd/changelog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/sh

MARKER_PREFIX="##"
VERSION=$(echo "$1" | sed 's/^v//g')

IFS=''
found=0

cat CHANGELOG.md | while read "line"; do

# If not found and matching heading
if [ $found -eq 0 ] && echo "$line" | grep -q "^$MARKER_PREFIX $VERSION$"; then
found=1
continue
fi

# If needed version if found, and reaching next delimter - stop
if [ $found -eq 1 ] && echo "$line" | grep -q -E "^$MARKER_PREFIX [[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+"; then
found=0
break
fi

# Keep printing out lines as no other version delimiter found
if [ $found -eq 1 ]; then
echo "$line"
fi
done
14 changes: 14 additions & 0 deletions cicd/version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
LATEST_TAG_REV=$(git rev-list --tags --max-count=1)
LATEST_COMMIT_REV=$(git rev-list HEAD --max-count=1)

if [ -n "$LATEST_TAG_REV" ]; then
LATEST_TAG=$(git describe --tags "$(git rev-list --tags --max-count=1)")
else
LATEST_TAG="v0.0.0"
fi

if [ "$LATEST_TAG_REV" != "$LATEST_COMMIT_REV" ]; then
echo "$LATEST_TAG+$(git rev-list HEAD --max-count=1 --abbrev-commit)"
else
echo "$LATEST_TAG"
fi
4 changes: 3 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
"github.com/ydb-platform/ydbops/pkg/options"
)

var buildVersion = "v0.0.0"

var RootCommandDescription = command.NewDescription(
"ydbops",
"ydbops: a CLI tool for performing YDB cluster maintenance operations",
Expand Down Expand Up @@ -46,7 +48,7 @@ func NewRootCommand(
cmd := &cobra.Command{
Use: RootCommandDescription.GetUse(),
Short: RootCommandDescription.GetShortDescription(),
Long: RootCommandDescription.GetLongDescription(),
Long: RootCommandDescription.GetLongDescription() + " (" + buildVersion + ")",
// hide --completion for more compact --help
CompletionOptions: cobra.CompletionOptions{
DisableDefaultCmd: true,
Expand Down

0 comments on commit c8ce2f6

Please sign in to comment.