Skip to content

Commit

Permalink
Go: CD pipeline (#3062)
Browse files Browse the repository at this point in the history
Go CD

---------

Signed-off-by: James Xin <[email protected]>
  • Loading branch information
jamesx-improving authored Feb 7, 2025
1 parent c6c4c45 commit e651fdb
Show file tree
Hide file tree
Showing 47 changed files with 322 additions and 76 deletions.
6 changes: 3 additions & 3 deletions .github/json_matrices/build-matrix.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"RUNNER": "ubuntu-latest",
"ARCH": "x64",
"TARGET": "x86_64-unknown-linux-gnu",
"PACKAGE_MANAGERS": ["pypi", "npm", "maven"],
"PACKAGE_MANAGERS": ["pypi", "npm", "maven", "pkg_go_dev"],
"run": "always",
"languages": ["python", "node", "java", "go", "dotnet"]
},
Expand All @@ -15,7 +15,7 @@
"RUNNER": ["self-hosted", "Linux", "ARM64", "ephemeral"],
"ARCH": "arm64",
"TARGET": "aarch64-unknown-linux-gnu",
"PACKAGE_MANAGERS": ["pypi", "npm", "maven"],
"PACKAGE_MANAGERS": ["pypi", "npm", "maven", "pkg_go_dev"],
"languages": ["python", "node", "java", "go", "dotnet"]
},
{
Expand All @@ -24,7 +24,7 @@
"RUNNER": "macos-14",
"ARCH": "arm64",
"TARGET": "aarch64-apple-darwin",
"PACKAGE_MANAGERS": ["pypi", "npm", "maven"],
"PACKAGE_MANAGERS": ["pypi", "npm", "maven", "pkg_go_dev"],
"languages": ["python", "node", "java", "go", "dotnet"]
},
{
Expand Down
207 changes: 207 additions & 0 deletions .github/workflows/go-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
name: Go - Continuous Deployment

on:
workflow_dispatch:
inputs:
version:
description: "The release version of GLIDE, formatted as v*.*.* or v*.*.*-rc*"
required: true
pkg_go_dev_publish:
description: "Publish to pkg.go.dev"
required: true
type: boolean
default: false

concurrency:
group: go-cd-${{ github.head_ref || github.ref }}
cancel-in-progress: true

permissions:
id-token: write

jobs:
load-platform-matrix:
runs-on: ubuntu-latest
outputs:
PLATFORM_MATRIX: ${{ steps.load-platform-matrix.outputs.PLATFORM_MATRIX }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: load-platform-matrix
id: load-platform-matrix
shell: bash
run: |
# Get the matrix from the matrix.json file, without the object that has the IMAGE key
export "PLATFORM_MATRIX=$(jq 'map(select(.PACKAGE_MANAGERS | contains(["pkg_go_dev"])))' < .github/json_matrices/build-matrix.json | jq -c .)"
echo "PLATFORM_MATRIX=${PLATFORM_MATRIX}" >> $GITHUB_OUTPUT
validate-release-version:
if: ${{ github.event.inputs.pkg_go_dev_publish }}
runs-on: ubuntu-latest
outputs:
RELEASE_VERSION: ${{ steps.release-tag.outputs.RELEASE_VERSION }}
env:
INPUT_VERSION: ${{ github.event.inputs.version }}
steps:
- name: Validate Version Against RegEx
run: |
echo "input version is: ${{ env.INPUT_VERSION }}"
if ! echo "${{ env.INPUT_VERSION }}" | grep -Pq '^v\d+\.\d+\.\d+(-rc\d+)?$'; then
echo "Version is not valid, must be v*.*.* or v*.*.*-rc*"
exit 1
fi
- name: Checkout for tag check
uses: actions/checkout@v4

- name: Validate version agaisnt tags
run: |
git fetch --tags
if git tag | grep -q "^go/${{ env.INPUT_VERSION }}$"; then
echo "Version ${{ env.INPUT_VERSION }} already exists."
exit 1
fi
- name: Output release tag
id: release-tag
run: |
echo "RELEASE_VERSION=${{ env.INPUT_VERSION }}" >> $GITHUB_OUTPUT
create-binaries:
needs: [load-platform-matrix]
if: success() && github.repository_owner == 'valkey-io'
strategy:
fail-fast: false
matrix:
host: ${{ fromJson(needs.load-platform-matrix.outputs.PLATFORM_MATRIX) }}
runs-on: ${{ matrix.host.RUNNER }}
steps:
- name: Setup self-hosted runner access
run: |
GHA_HOME=/home/ubuntu/actions-runner/_work/valkey-glide
if [ -d $GHA_HOME ]; then
sudo chown -R $USER:$USER $GHA_HOME
sudo rm -rf $GHA_HOME
mkdir -p $GHA_HOME/valkey-glide
else
echo "No cleaning needed"
fi
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "^1.22.0"
- name: Install shared software dependencies
uses: ./.github/workflows/install-shared-dependencies
with:
os: ${{ matrix.host.OS }}
target: ${{ matrix.host.TARGET }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Build Go client
working-directory: go
run: |
make install-build-tools
make build-glide-client
# TODO: move generation of protobuf and header file to a non-matrix step
make generate-protobuf
- name: Upload artifacts
continue-on-error: true
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.host.TARGET }}
path: |
go/target/release/libglide_rs.a
go/lib.h
go/protobuf/
commit-auto-gen-files-with-tag:
if: ${{ github.event.inputs.pkg_go_dev_publish }}
needs: [validate-release-version, create-binaries]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
path: artifacts
- name: Copy generated files to repo
run: |
cd artifacts
for dir in */; do
target_name=${dir%/}
mkdir -p $GITHUB_WORKSPACE/go/rustbin/${target_name}
cp ${target_name}/target/release/libglide_rs.a $GITHUB_WORKSPACE/go/rustbin/${target_name}/
done
# TODO: move generation of protobuf and header file to a non-matrix step
cd x86_64-unknown-linux-gnu
cp lib.h $GITHUB_WORKSPACE/go/
mkdir -p $GITHUB_WORKSPACE/go/protobuf
cp protobuf/* $GITHUB_WORKSPACE/go/protobuf/
- name: Commit and push tag
run: |
git config user.name github-actions
git config user.email [email protected]
git add -f .
git commit -m "Automated commit from GitHub Actions"
git tag go/${{ needs.validate-release-version.outputs.RELEASE_VERSION }}
git push origin go/${{ needs.validate-release-version.outputs.RELEASE_VERSION }}
GOPROXY=proxy.golang.org go list -m github.com/valkey-io/valkey-glide/go@${{ needs.validate-release-version.outputs.RELEASE_VERSION }}
extra-post-commit-test:
needs:
[
load-platform-matrix,
validate-release-version,
commit-auto-gen-files-with-tag,
]
strategy:
fail-fast: false
matrix:
host: ${{ fromJson(needs.load-platform-matrix.outputs.PLATFORM_MATRIX) }}
runs-on: ${{ matrix.host.RUNNER }}
steps:
- name: Setup self-hosted runner access
run: |
GHA_HOME=/home/ubuntu/actions-runner/_work/valkey-glide
if [ -d $GHA_HOME ]; then
sudo chown -R $USER:$USER $GHA_HOME
sudo rm -rf $GHA_HOME
mkdir -p $GHA_HOME/valkey-glide
else
echo "No cleaning needed"
fi
- uses: actions/checkout@v4
with:
ref: "go/${{ needs.validate-release-version.outputs.RELEASE_VERSION }}"
- uses: actions/setup-go@v5
with:
go-version: "^1.22.0"
- name: Install shared software dependencies
uses: ./.github/workflows/install-shared-dependencies
with:
os: ${{ matrix.host.OS }}
target: ${{ matrix.host.TARGET }}
github-token: ${{ secrets.GITHUB_TOKEN }}
engine-version: "8.0"
- name: Start standalone Valkey server
working-directory: utils
id: start-server
run: |
PORT=$(python3 ./cluster_manager.py start -r 0 2>&1 | grep CLUSTER_NODES | cut -d = -f 2 | cut -d , -f 1 | cut -d : -f 2)
echo "PORT=$PORT" >> $GITHUB_OUTPUT
- name: test newly released go client
env:
PORT: ${{ steps.start-server.outputs.PORT }}
working-directory: go/benchmarks
run: |
# change go/benchmarks/go.mod on the fly
export ESCAPED_VERSION=$(echo "${{ needs.validate-release-version.outputs.RELEASE_VERSION }}" | sed 's/\./\\./g')
if [[ "${{ matrix.host.OS }}" == "macos" ]]; then
sed -i '' '/replace github\.com\/valkey-io\/valkey-glide\/go/d' go.mod
sed -i '' "s/github\.com\/valkey-io\/valkey-glide\/go v0\.0\.0/github.com\/valkey-io\/valkey-glide\/go $ESCAPED_VERSION/g" go.mod
else
sed -i '/replace github\.com\/valkey-io\/valkey-glide\/go/d' go.mod
sed -i "s/github\.com\/valkey-io\/valkey-glide\/go v0\.0\.0/github.com\/valkey-io\/valkey-glide\/go $ESCAPED_VERSION/g" go.mod
fi
go mod tidy
go run . -minimal -clients glide -concurrentTasks 10 -port ${{ env.PORT }}
3 changes: 3 additions & 0 deletions go/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ lib.h
benchmarks/results/**
benchmarks/gobenchmarks.json
benchmarks/benchmarks

# compiled static library file
*.a
2 changes: 1 addition & 1 deletion go/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ license = "Apache-2.0"
authors = ["Valkey GLIDE Maintainers"]

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

[dependencies]
redis = { path = "../glide-core/redis-rs/redis", features = ["aio", "tokio-comp", "connection-manager", "tokio-rustls-comp"] }
Expand Down
18 changes: 12 additions & 6 deletions go/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,17 @@ clean:

build-glide-client:
cargo build --release
cbindgen --config cbindgen.toml --crate glide-rs --output lib.h
cbindgen --config cbindgen.toml --crate glide-rs --output lib.h --lang c
if [ "$$(uname)" = "Darwin" ]; then \
strip -x target/release/libglide_rs.a; \
else \
strip --strip-unneeded target/release/libglide_rs.a; \
fi


build-glide-client-debug:
cargo build
cbindgen --config cbindgen.toml --crate glide-rs --output lib.h
cbindgen --config cbindgen.toml --crate glide-rs --output lib.h --lang c

generate-protobuf:
rm -rf protobuf
Expand Down Expand Up @@ -81,9 +87,9 @@ format:
unit-test:
mkdir -p reports
set -o pipefail; \
LD_LIBRARY_PATH=$(shell find . -name libglide_rs.so|grep -w release|tail -1|xargs dirname|xargs readlink -f):${LD_LIBRARY_PATH} \
LD_LIBRARY_PATH=$(shell find . -name libglide_rs.a|grep -w release|tail -1|xargs dirname|xargs readlink -f):${LD_LIBRARY_PATH} \
go test -v -race ./... -skip TestGlideTestSuite $(if $(test-filter), -testify.m $(test-filter)) \
| tee >(go tool test2json -t -p github.com/valkey-io/valkey-glide/go/glide/utils | go-test-report -o reports/unit-tests.html -t unit-test > /dev/null)
| tee >(go tool test2json -t -p github.com/valkey-io/valkey-glide/go/utils | go-test-report -o reports/unit-tests.html -t unit-test > /dev/null)

# integration tests - run subtask with skipping modules tests
integ-test: export TEST_FILTER = -skip TestGlideTestSuite/TestModule $(if $(test-filter), -testify.m $(test-filter))
Expand All @@ -96,12 +102,12 @@ modules-test: __it
__it:
mkdir -p reports
set -o pipefail; \
LD_LIBRARY_PATH=$(shell find . -name libglide_rs.so|grep -w release|tail -1|xargs dirname|xargs readlink -f):${LD_LIBRARY_PATH} \
LD_LIBRARY_PATH=$(shell find . -name libglide_rs.a|grep -w release|tail -1|xargs dirname|xargs readlink -f):${LD_LIBRARY_PATH} \
go test -v -race ./integTest/... \
$(TEST_FILTER) \
$(if $(filter true, $(tls)), --tls,) \
$(if $(standalone-endpoints), --standalone-endpoints=$(standalone-endpoints)) \
$(if $(cluster-endpoints), --cluster-endpoints=$(cluster-endpoints)) \
| tee >(go tool test2json -t -p github.com/valkey-io/valkey-glide/go/glide/integTest | go-test-report -o reports/integ-tests.html -t integ-test > /dev/null)
| tee >(go tool test2json -t -p github.com/valkey-io/valkey-glide/go/integTest | go-test-report -o reports/integ-tests.html -t integ-test > /dev/null)
# code above ^ is similar to `go test .... -json | go-test-report ....`, but it also prints plain text output to stdout
# `go test` prints plain text, tee duplicates it to stdout and to `test2json` which is coupled with `go-test-report` to generate the report
18 changes: 12 additions & 6 deletions go/api/base_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

package api

// #cgo LDFLAGS: -L../target/release -lglide_rs
// #cgo LDFLAGS: -lglide_rs
// #cgo !windows LDFLAGS: -lm
// #cgo darwin LDFLAGS: -framework Security
// #cgo linux,amd64 LDFLAGS: -L${SRCDIR}/../rustbin/x86_64-unknown-linux-gnu
// #cgo linux,arm64 LDFLAGS: -L${SRCDIR}/../rustbin/aarch64-unknown-linux-gnu
// #cgo darwin,arm64 LDFLAGS: -L${SRCDIR}/../rustbin/aarch64-apple-darwin
// #cgo LDFLAGS: -L../target/release
// #include "../lib.h"
//
// void successCallback(void *channelPtr, struct CommandResponse *message);
Expand All @@ -15,11 +21,11 @@ import (
"strconv"
"unsafe"

"github.com/valkey-io/valkey-glide/go/glide/api/config"
"github.com/valkey-io/valkey-glide/go/glide/api/errors"
"github.com/valkey-io/valkey-glide/go/glide/api/options"
"github.com/valkey-io/valkey-glide/go/glide/protobuf"
"github.com/valkey-io/valkey-glide/go/glide/utils"
"github.com/valkey-io/valkey-glide/go/api/config"
"github.com/valkey-io/valkey-glide/go/api/errors"
"github.com/valkey-io/valkey-glide/go/api/options"
"github.com/valkey-io/valkey-glide/go/protobuf"
"github.com/valkey-io/valkey-glide/go/utils"
"google.golang.org/protobuf/proto"
)

Expand Down
2 changes: 1 addition & 1 deletion go/api/bitmap_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

package api

import "github.com/valkey-io/valkey-glide/go/glide/api/options"
import "github.com/valkey-io/valkey-glide/go/api/options"

// Supports commands and transactions for the "Bitmap" group of commands for standalone and cluster clients.
//
Expand Down
6 changes: 3 additions & 3 deletions go/api/command_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ package api
import (
"strconv"

"github.com/valkey-io/valkey-glide/go/glide/api/config"
"github.com/valkey-io/valkey-glide/go/glide/api/errors"
"github.com/valkey-io/valkey-glide/go/glide/utils"
"github.com/valkey-io/valkey-glide/go/api/config"
"github.com/valkey-io/valkey-glide/go/api/errors"
"github.com/valkey-io/valkey-glide/go/utils"
)

// SetOptions represents optional arguments for the [api.StringCommands.SetWithOptions] command.
Expand Down
2 changes: 1 addition & 1 deletion go/api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

package api

import "github.com/valkey-io/valkey-glide/go/glide/protobuf"
import "github.com/valkey-io/valkey-glide/go/protobuf"

const (
defaultHost = "localhost"
Expand Down
4 changes: 2 additions & 2 deletions go/api/config/request_routing_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"strconv"
"strings"

"github.com/valkey-io/valkey-glide/go/glide/api/errors"
"github.com/valkey-io/valkey-glide/go/glide/protobuf"
"github.com/valkey-io/valkey-glide/go/api/errors"
"github.com/valkey-io/valkey-glide/go/protobuf"
)

// Request routing basic interface. Please use one of the following:
Expand Down
2 changes: 1 addition & 1 deletion go/api/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/valkey-io/valkey-glide/go/glide/protobuf"
"github.com/valkey-io/valkey-glide/go/protobuf"
)

func TestDefaultStandaloneConfig(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion go/api/connection_management_cluster_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

package api

import "github.com/valkey-io/valkey-glide/go/glide/api/options"
import "github.com/valkey-io/valkey-glide/go/api/options"

// Supports commands and transactions for the "Connection Management" group of commands for cluster client.
//
Expand Down
2 changes: 1 addition & 1 deletion go/api/connection_management_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

package api

import "github.com/valkey-io/valkey-glide/go/glide/api/options"
import "github.com/valkey-io/valkey-glide/go/api/options"

// Supports commands and transactions for the "Connection Management" group of commands for standalone client.
//
Expand Down
Loading

0 comments on commit e651fdb

Please sign in to comment.