Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CI for Go #77

Merged
merged 17 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
177 changes: 177 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
name: Go CI

on:
push:
aaron-congo marked this conversation as resolved.
Show resolved Hide resolved
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: 25
aaron-congo marked this conversation as resolved.
Show resolved Hide resolved
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 }}

- 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-dependencies

- name: Build client
working-directory: ./go
run: |
go mod edit -go=${{ matrix.go }}
make build

- name: Run go vet linter
working-directory: ./go
run: go vet .

- name: Run staticcheck linter
working-directory: ./go
run: staticcheck .

- 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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you use actions/setup-go there?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe? I saw that Java uses setup-java for ubuntu/macos but not for amazon linux so I assumed setup-java did not work on amazon linux and that if it doesn't work for java that it wouldn't for go. But my assumption may be wrong

run: |
wget https://go.dev/dl/go${{ matrix.go }}.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go${{ matrix.go }}.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin

- name: Build client
working-directory: ./go
run: |
cargo build --release
go mod edit -go=${{ matrix.go }}
make build

- 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

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"
aaron-congo marked this conversation as resolved.
Show resolved Hide resolved
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
31 changes: 31 additions & 0 deletions go/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
install-dependencies:
go install github.com/DarkDrim/[email protected]
go install google.golang.org/protobuf/cmd/[email protected]
go install honnef.co/go/tools/cmd/[email protected]

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:
aaron-congo marked this conversation as resolved.
Show resolved Hide resolved
go vet ./...
staticcheck ./...

unit-test-report:
mkdir -p reports
go test ./... -json | go-test-report -o reports/unit-test-report.html
1 change: 1 addition & 0 deletions go/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.21
aaron-congo marked this conversation as resolved.
Show resolved Hide resolved

require (
github.com/DarkDrim/go-test-report v1.5.0
google.golang.org/protobuf v1.32.0
honnef.co/go/tools v0.4.6
)

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
)
28 changes: 28 additions & 0 deletions go/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/DarkDrim/go-test-report v1.5.0 h1:KBItzAYuvgjUvMhfiM2KmSuXFV2zbK/E9SwsFSbp4mU=
github.com/DarkDrim/go-test-report v1.5.0/go.mod h1:b3M6oZDGdKEuWjHYQDzDP70nzr/DOqZPFjwaFdQGhp8=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a h1:Jw5wfR+h9mnIYH+OtGT2im5wV1YGGDora5vTv/aa5bE=
golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk=
golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/tools v0.12.1-0.20230825192346-2191a27a6dc5 h1:Vk4mysSz+GqQK2eqgWbo4zEO89wkeAjJiFIr9bpqa8k=
golang.org/x/tools v0.12.1-0.20230825192346-2191a27a6dc5/go.mod h1:Sc0INKfu04TlqNoRA1hgpFZbhYXHPr4V5DzpSBTPqQM=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.4.6 h1:oFEHCKeID7to/3autwsWfnuv69j3NsfcXbvJKuIcep8=
honnef.co/go/tools v0.4.6/go.mod h1:+rnGS1THNh8zMwnd2oVOTL9QF6vmfyG6ZXBULae2uc0=
9 changes: 9 additions & 0 deletions go/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0
*/
use std::ffi::c_void;

#[no_mangle]
pub extern "C" fn create_connection() -> *const c_void {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I needed to add some arbitrary code here so that lint-rust had something to run against. I tried only adding the copyright, with no actual code, but the lint-rust workflow failed, I think because it wants their to be logic in this file

todo!()
}
13 changes: 13 additions & 0 deletions go/tests/glide_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package tests

import (
"testing"
)

// TODO: Replace this test with real tests when glide client implementation is started
func TestArbitraryLogic(t *testing.T) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also added this arbitrary test so that the unit test workflow had something to run against

someVar := true
if !someVar {
t.Fatalf("Expected someVar to be true, but was false.")
}
}
10 changes: 10 additions & 0 deletions go/tools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//go:build tools
// +build tools

package main

import (
_ "github.com/DarkDrim/go-test-report"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently this file is recommended to specify ci dependencies (ie dependencies that are not directly required by your code). These dependencies are specified here and in go.mod. If you remove this file the dependencies in go.mod are removed when you run go mod tidy because go detects that they aren't directly required by your code. More info about this here

_ "google.golang.org/protobuf/cmd/protoc-gen-go"
_ "honnef.co/go/tools/cmd/staticcheck"
)
Loading