Skip to content

Commit

Permalink
Merge pull request #9 from splitio/release_action
Browse files Browse the repository at this point in the history
add release action + some more UT coverage
  • Loading branch information
mredolatti authored Sep 5, 2023
2 parents 7a2d364 + 4be9a8d commit a94ac91
Show file tree
Hide file tree
Showing 84 changed files with 3,819 additions and 1,205 deletions.
87 changes: 41 additions & 46 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
name: ci

on:
pull_request:
branches:
- dev
- main
push:
branches:
- dev
- main

concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'push' && github.run_number || github.event.pull_request.number }}
Expand All @@ -16,16 +17,20 @@ jobs:
name: Run unit tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set VERSION env
run: echo "VERSION=$(cat splitio/version.go | grep 'Version =' | awk '{print $3}' | tr -d '"')" >> $GITHUB_ENV
run: echo "VERSION=$(cat splitio/version.go | grep 'Version =' | awk '{print $4}' | tr -d '"')" >> $GITHUB_ENV

- name: Version validation
if: ${{ github.event_name == 'pull_request' }}
uses: mukunku/[email protected]
id: checkTag
with:
tag: ${{ env.VERSION }}
tag: v${{ env.VERSION }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand All @@ -35,56 +40,46 @@ jobs:
with:
script: core.setFailed('[ERROR] Tag already exists.')

- name: Git tag
if: ${{ github.event_name == 'push' }}
uses: mathieudutour/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
custom_tag: ${{ env.VERSION }}
tag_prefix: ''

- name: Setup Go version
uses: actions/setup-go@v4
with:
go-version: '^1.19.1'

- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
go-version: '^1.20.7'

- name: Build binaries for host machine
run: make splitd splitcli

- name: Run tests
run: make test

- name: Cross build for GNU Linux & Darwin x amd64 & arm64
run: make binaries_release

- name: Run tests
run: make test
- name: SonarQube Scan
uses: SonarSource/[email protected]
env:
SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
projectBaseDir: .
args: >
-Dsonar.host.url=${{ secrets.SONARQUBE_HOST }}
-Dsonar.projectVersion=${{ env.VERSION }}
- name: Git tag
if: ${{ github.event_name == 'push' }}
uses: mathieudutour/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
custom_tag: ${{ env.VERSION }}
tag_prefix: 'v'

# - name: SonarQube Scan (Push)
# if: matrix.version == '8.2' && github.event_name == 'push'
# uses: SonarSource/[email protected]
# env:
# SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }}
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# projectBaseDir: .
# args: >
# -Dsonar.host.url=${{ secrets.SONARQUBE_HOST }}
# -Dsonar.projectVersion=${{ env.VERSION }}
#
# - name: SonarQube Scan (Pull Request)
# if: matrix.version == '8.2' && github.event_name == 'pull_request'
# uses: SonarSource/[email protected]
# env:
# SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }}
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# projectBaseDir: .
# args: >
# -Dsonar.host.url=${{ secrets.SONARQUBE_HOST }}
# -Dsonar.projectVersion=${{ env.VERSION }}
# -Dsonar.pullrequest.key=${{ github.event.pull_request.number }}
# -Dsonar.pullrequest.branch=${{ github.event.pull_request.head.ref }}
# -Dsonar.pullrequest.base=${{ github.event.pull_request.base.ref }}
- name: Release
uses: softprops/action-gh-release@v1
if: ${{ github.event_name == 'push' }}
with:
name: splitd-${{ env.VERSION }}
files: |
splitd-darwin-amd64-${{ env.VERSION }}.bin
splitd-darwin-arm-${{ env.VERSION }}.bin
splitd-linux-amd64-${{ env.VERSION }}.bin
splitd-linux-arm-${{ env.VERSION }}.bin
32 changes: 6 additions & 26 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,30 @@ name: docker
on:
push:
branches:
- dev
- main
pull_request:
branches:
- dev
- main

concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'push' && github.run_number || github.event.pull_request.number }}

jobs:
build-docker-image:
name: Build and push Docker image
runs-on: ubuntu-latest

steps:
- name: Login to Artifactory
if: ${{ github.event_name == 'push' }}
uses: docker/login-action@v2
with:
registry: splitio-docker.jfrog.io
username: ${{ secrets.ARTIFACTORY_DOCKER_USER }}
password: ${{ secrets.ARTIFACTORY_DOCKER_PASS }}

- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set VERSION env
run: echo "VERSION=$(cat splitio/version.go | grep 'Version =' | awk '{print $4}' | tr -d '"')" >> $GITHUB_ENV

- name: Docker build and push
uses: docker/build-push-action@v4
with:
context: .
file: "infra/sidecar.Dockerfile"
push: ${{ github.event_name == 'push' }}
tags: splitio-docker.jfrog.io/${{ github.event.repository.name }}/sidecar:${{ github.sha }}

deploy:
name: Deploy to testing
if: ${{ github.event_name == 'push' }}
runs-on: ubuntu-latest
needs: build-docker-image
steps:
- name: Deploy to testing
run: |
curl --header "Content-Type: application/json" \
--request PUT \
--data '{ "service": "${{ github.event.repository.name }}", "environment": "testing", "tag": "${{ github.sha }}", "token": "${{ secrets.R2D2_SLACK_TOKEN_STAGE }}"}' \
https://r2d2.split-stage.io/deployment
push: true
tags: splitio-docker.jfrog.io/splitd/sidecar:latest,splitio-docker.jfrog.io/splitd/sidecar:${{ env.VERSION }}
31 changes: 31 additions & 0 deletions .github/workflows/unstable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: unstable
on:
push:
branches-ignore:
- main

jobs:
push-docker-image:
name: Build and Push Docker Image
runs-on: ubuntu-latest
steps:
- name: Login to Artifactory
uses: docker/login-action@v2
with:
registry: splitio-docker-dev.jfrog.io
username: ${{ secrets.ARTIFACTORY_DOCKER_USER }}
password: ${{ secrets.ARTIFACTORY_DOCKER_PASS }}

- name: Checkout code
uses: actions/checkout@v4

- name: Get short hash
run: echo "SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV

- name: Docker Build and Push
uses: docker/build-push-action@v4
with:
context: .
file: "infra/sidecar.Dockerfile"
push: true
tags: splitio-docker-dev.jfrog.io/splitd/sidecar:${{ env.SHORT_SHA }}
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,16 @@

/splitd
/splitcli
/sdhelper
/splitd.yaml
testcfg
shared

splitd.darwin.*
splitd.linux.*

# Sonarqube files
.scannerwork

# DS Store
.DS_Store
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-added-large-files
- id: check-shebang-scripts-are-executable
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
5 changes: 5 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1.0.1 (Sep 5, 2023):
- Add support for .track
- Fixed issue where impressions could take too long to evict even with the queue full
- Fixed eviction on shutdown
- Internal: bumped test covereage, bumped CI configuration & automated release logic, module configuration cleanup
64 changes: 44 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
.PHONY: clean build test sidecar_image unit-tests entrypoint-test
.PHONY: clean build test sidecar_image unit-tests entrypoint-test splitio/commitsha.go

# Setup defaults
GO ?=go
DOCKER ?= docker
SHELL = /usr/bin/env bash -o pipefail

# setup platform specific docker image builds
PLATFORM ?=
PLATFORM_STR := $(if $(PLATFORM),--platform=$(PLATFORM),)

VERSION := $(shell cat splitio/version.go | grep 'const Version' | sed 's/const Version = //' | tr -d '"')
COMMIT_SHA := $(shell git rev-parse --short HEAD)
COMMIT_SHA_FILE := splitio/commitsha.go

GO_FILES := $(shell find . -name "*.go" -not -name "$(COMMIT_SHA_FILE)") go.sum

CONFIG_TEMPLATE ?= splitd.yaml.tpl
COVERAGE_FILE ?= coverage.out

GO_FILES := $(shell find . -name "*.go") go.sum

default: help

Expand All @@ -19,23 +29,29 @@ go.sum: go.mod
clean:
rm -Rf splitcli \
splitd \
splitd.linux.amd64.$(VERSION).bin \
splitd.darwin.amd64.$(VERSION).bin \
splitd.linux.arm.$(VERSION).bin \
splitd.darwin.arm.$(VERSION).bin
splitd-linux-amd64-$(VERSION).bin \
splitd-darwin-amd64-$(VERSION).bin \
splitd-linux-arm-$(VERSION).bin \
splitd-darwin-arm-$(VERSION).bin

## build binaries for this platform
build: splitd splitcli
build: splitd splitcli sdhelper



## run all tests
test: unit-tests entrypoint-test

## run go unit tests
unit-tests:
$(GO) test ./... -count=1 -race
$(GO) test ./... -count=1 -race -coverprofile=$(COVERAGE_FILE)

## display unit test coverage derived from last test run (use `make test display-coverage` for up-to-date results)
display-coverage: coverage.out
go tool cover -html=coverage.out

## run bash entrypoint tests
entrypoint-test:
entrypoint-test: splitd # requires splitd binary to generate a config and validate env var forwarding
bash infra/test/test_entrypoint.sh

## build splitd for local machine
Expand All @@ -46,34 +62,42 @@ splitd: $(GO_FILES)
splitcli: $(GO_FILES)
go build -o splitcli cmd/splitcli/main.go

## regenerate config file template with defaults
$(CONFIG_TEMPLATE): $(SOURCES) sdhelper
./sdhelper -command="gen-config-template" > $(CONFIG_TEMPLATE)
## build splitd helper (for code/doc generation purposes only)
sdhelper: $(GO_FILES)
go build -o sdhelper cmd/sdhelper/main.go

## build docker images for sidecar
images_release: # entrypoints
$(DOCKER) build $(platform_str) -t splitsoftware/splitd-sidecar:latest -t splitsoftware/splitd-sidecar:$(VERSION) -f infra/sidecar.Dockerfile .
$(DOCKER) build $(PLATFORM_STR) -t splitsoftware/splitd-sidecar:latest -t splitsoftware/splitd-sidecar:$(VERSION) -f infra/sidecar.Dockerfile .
@echo "Image created. Make sure everything works ok, and then run the following commands to push them."
@echo "$(DOCKER) push splitsoftware/splitd-sidecar:latest"
@echo "$(DOCKER) push splitsoftware/splitd-sidecar:$(VERSION)"

## build release for binaires
binaries_release: splitd.linux.amd64.$(VERSION).bin splitd.darwin.amd64.$(VERSION).bin splitd.linux.arm.$(VERSION).bin splitd.darwin.arm.$(VERSION).bin
binaries_release: splitd-linux-amd64-$(VERSION).bin splitd-darwin-amd64-$(VERSION).bin splitd-linux-arm-$(VERSION).bin splitd-darwin-arm-$(VERSION).bin

$(COVERAGE_FILE): unit-tests

$(COMMIT_SHA_FILE):
@echo "package splitio" > $(COMMIT_SHA_FILE)
@echo "" >> $(COMMIT_SHA_FILE)
@echo "const CommitSHA = \"$(COMMIT_SHA)\"" >> $(COMMIT_SHA_FILE)

splitd.linux.amd64.$(VERSION).bin: $(GO_FILES)
splitd-linux-amd64-$(VERSION).bin: $(GO_FILES)
GOARCH=amd64 GOOS=linux $(GO) build -o $@ cmd/splitd/main.go

splitd.darwin.amd64.$(VERSION).bin: $(GO_FILES)
splitd-darwin-amd64-$(VERSION).bin: $(GO_FILES)
GOARCH=amd64 GOOS=darwin $(GO) build -o $@ cmd/splitd/main.go

splitd.linux.arm.$(VERSION).bin: $(GO_FILES)
splitd-linux-arm-$(VERSION).bin: $(GO_FILES)
GOARCH=arm64 GOOS=linux $(GO) build -o $@ cmd/splitd/main.go

splitd.darwin.arm.$(VERSION).bin: $(GO_FILES)
splitd-darwin-arm-$(VERSION).bin: $(GO_FILES)
GOARCH=arm64 GOOS=darwin $(GO) build -o $@ cmd/splitd/main.go

binaries_release: splitd

# helper macros
platform_str = $(if $(PLATFORM),--platform=$(PLATFORM),)

# Help target borrowed from: https://docs.cloudposse.com/reference/best-practices/make-best-practices/
## This help screen
help:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# splitd
# splitd
Loading

0 comments on commit a94ac91

Please sign in to comment.