Skip to content

Commit

Permalink
Go: Add CI (valkey-io#946)
Browse files Browse the repository at this point in the history
* Add CI for Go

* Add command to install wget to amazon linux workflow

* Remove sudo from the amazon linux tar command

* Add command to install tar on amazon linux

* Change command so that the Go path is updated for all amazon linux steps

* Remove command to list Go version

* Fix missing steps, go mod command

* Remove redundant step

* Add Go bin to path, remove patch version from go mod command

* Update amazon linux test name

* Increase timeout

* Specify minimum go version as 1.18, remove dependency requiring Go 1.21, fix yml formatting, fix setup-go cache
  • Loading branch information
aaron-congo authored Feb 14, 2024
1 parent 8466748 commit ace0786
Show file tree
Hide file tree
Showing 11 changed files with 605 additions and 0 deletions.
178 changes: 178 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
name: Go CI

on:
workflow_dispatch:
push:
branches: [ "main" ]
paths:
- glide-core/**
- submodules/**
- go/**
- .github/workflows/go.yml
pull_request:
paths:
- glide-core/**
- submodules/**
- go/**
- .github/workflows/go.yml

# Run only the latest job on a branch and cancel previous ones
concurrency:
group: ${{ github.head_ref || github.ref }}
cancel-in-progress: true

jobs:
build-and-test-go-client:
timeout-minutes: 20
strategy:
# Run all jobs
fail-fast: false
matrix:
go:
- '1.18'
- '1.21'
redis:
- 6.2.14
- 7.2.3
os:
- ubuntu-latest
- macos-latest

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Set up Go ${{ matrix.go }}
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
cache-dependency-path: go/go.sum

- name: Install shared software dependencies
uses: ./.github/workflows/install-shared-dependencies
with:
os: ${{ matrix.os }}
target: ${{ matrix.os == 'ubuntu-latest' && 'x86_64-unknown-linux-gnu' || 'x86_64-apple-darwin' }}
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Install redis
# TODO: make this step macos compatible: https://github.com/aws/glide-for-redis/issues/781
if: ${{ matrix.os == 'ubuntu-latest' }}
uses: ./.github/workflows/install-redis
with:
redis-version: ${{ matrix.redis }}

- name: Install client dependencies
working-directory: ./go
run: make install-tools

- name: Build client
working-directory: ./go
run: make build

- name: Run linters
working-directory: ./go
run: make lint

- name: Run unit tests
working-directory: ./go
run: make unit-test-report

- name: Upload test reports
if: always()
continue-on-error: true
uses: actions/upload-artifact@v4
with:
name: test-reports-go-${{ matrix.go }}-redis-${{ matrix.redis }}-${{ matrix.os }}
path: |
go/reports/unit-test-report.html
build-amazonlinux-latest:
if: github.repository_owner == 'aws'
strategy:
# Run all jobs
fail-fast: false
matrix:
go:
- 1.18.10
- 1.21.6
runs-on: ubuntu-latest
container: amazonlinux:latest
timeout-minutes: 15
steps:
- name: Install git
run: |
yum -y remove git
yum -y remove git-*
yum -y install https://packages.endpointdev.com/rhel/7/os/x86_64/endpoint-repo.x86_64.rpm
yum update
yum install -y git
git --version
- uses: actions/checkout@v4

- name: Checkout submodules
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE"
git submodule update --init --recursive
- name: Install shared software dependencies
uses: ./.github/workflows/install-shared-dependencies
with:
os: "amazon-linux"
target: "x86_64-unknown-linux-gnu"
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Create a symbolic Link for redis6 binaries
run: |
ln -s /usr/bin/redis6-server /usr/bin/redis-server
ln -s /usr/bin/redis6-cli /usr/bin/redis-cli
- name: Install Go
run: |
yum -y install wget
yum -y install tar
wget https://go.dev/dl/go${{ matrix.go }}.linux-amd64.tar.gz
tar -C /usr/local -xzf go${{ matrix.go }}.linux-amd64.tar.gz
echo "/usr/local/go/bin" >> $GITHUB_PATH
echo "$HOME/go/bin" >> $GITHUB_PATH
- name: Install client dependencies
working-directory: ./go
run: make install-tools

- name: Build client
working-directory: ./go
run: make build

- name: Run linters
working-directory: ./go
run: make lint

- name: Run unit tests
working-directory: ./go
run: make unit-test-report

- name: Upload test reports
if: always()
continue-on-error: true
uses: actions/upload-artifact@v4
with:
name: test-reports-go-${{ matrix.go }}-amazon-linux-latest
path: go/reports/unit-test-report.html

lint-rust:
timeout-minutes: 15
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- uses: ./.github/workflows/lint-rust
with:
cargo-toml-folder: ./go
name: lint go rust
3 changes: 3 additions & 0 deletions go/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[env]
GLIDE_NAME = { value = "GlideGo", force = true }
GLIDE_VERSION = "0.1.0"
4 changes: 4 additions & 0 deletions go/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Go compilation files
*.pb.go

reports
19 changes: 19 additions & 0 deletions go/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "glide-rs"
version = "0.1.0"
edition = "2021"
license = "Apache-2.0"
authors = ["Amazon Web Services"]

[lib]
crate-type = ["cdylib"]

[dependencies]
redis = { path = "../submodules/redis-rs/redis", features = ["aio", "tokio-comp", "tls", "tokio-native-tls-comp", "tls-rustls-insecure"] }
glide-core = { path = "../glide-core" }
tokio = { version = "^1", features = ["rt", "macros", "rt-multi-thread", "time"] }
protobuf = { version = "3.3.0", features = [] }

[profile.release]
lto = true
debug = true
29 changes: 29 additions & 0 deletions go/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
install-tools:
@cat tools.go | grep _ | awk -F'"' '{print $$2}' | xargs -tI % go install %

build: build-glide-core build-glide-client generate-protobuf
go build ./...

build-glide-core:
cd ../glide-core; cargo build --release

build-glide-client:
cargo build --release

generate-protobuf:
mkdir -p protobuf
protoc --proto_path=../glide-core/src/protobuf \
--go_opt=Mconnection_request.proto=github.com/aws/glide-for-redis/go/protobuf \
--go_opt=Mredis_request.proto=github.com/aws/glide-for-redis/go/protobuf \
--go_opt=Mresponse.proto=github.com/aws/glide-for-redis/go/protobuf \
--go_out=./protobuf \
--go_opt=paths=source_relative \
../glide-core/src/protobuf/*.proto

lint:
go vet ./...
staticcheck ./...

unit-test-report:
mkdir -p reports
go test -race ./... -json | go-test-report -o reports/unit-test-report.html
1 change: 1 addition & 0 deletions go/glide/glide.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package glide
21 changes: 21 additions & 0 deletions go/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module github.com/aws/glide-for-redis/go/glide

go 1.18

require (
github.com/vakenbolt/go-test-report v0.9.3
google.golang.org/protobuf v1.32.0
honnef.co/go/tools v0.3.3
)

require (
github.com/BurntSushi/toml v1.2.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/spf13/cobra v1.8.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/tools v0.12.1-0.20230825192346-2191a27a6dc5 // indirect
)
Loading

0 comments on commit ace0786

Please sign in to comment.