Skip to content

Commit bc9abac

Browse files
authored
enable golang e2e test in CI (#85)
Signed-off-by: Yingchun Guo <yingchun.guo@intel.com>
1 parent 04d7f24 commit bc9abac

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed

.github/workflows/go-e2e.yaml

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
name: Golang E2e Tests
5+
6+
on:
7+
pull_request:
8+
branches: [main]
9+
types: [opened, reopened, ready_for_review, synchronize] # added `ready_for_review` since draft is skipped
10+
paths:
11+
- microservices-connector/**
12+
workflow_dispatch:
13+
14+
# If there is a new commit, the previous jobs will be canceled
15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
17+
cancel-in-progress: true
18+
19+
env:
20+
GOSRC_DIR: "microservices-connector"
21+
22+
jobs:
23+
go-e2e:
24+
runs-on: k8s
25+
steps:
26+
- name: Checkout out Repo
27+
uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 0
30+
31+
- name: Set variables
32+
run: |
33+
echo "SYSTEM_NAMESPACE=opea-system-$(date +%Y%m%d%H%M%S)" >> $GITHUB_ENV
34+
echo "APP_NAMESPACE=chatqna-$(date +%Y%m%d%H%M%S)" >> $GITHUB_ENV
35+
echo "DOCKER_REGISTRY=$OPEA_IMAGE_REPO/opea" >> $GITHUB_ENV
36+
echo "VERSION=${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV
37+
echo "should_cleanup=false" >> $GITHUB_ENV
38+
echo "skip_validate=false" >> $GITHUB_ENV
39+
40+
- name: Build image and push
41+
run: |
42+
cd $GOSRC_DIR
43+
make docker.build
44+
make docker.push
45+
46+
- name: Install modules
47+
run: |
48+
echo "should_cleanup=true" >> $GITHUB_ENV
49+
.github/workflows/scripts/e2e/go_test.sh install_gmc
50+
exit_status=$$?$$
51+
if [ $$exit_status -ne 0 ]; then
52+
echo "Failed to install modules"
53+
echo "skip_validate=true" >> $GITHUB_ENV
54+
fi
55+
56+
- name: Run e2e tests
57+
run: |
58+
# export DOCKER_REGISTRY={{ env.DOCKER_REGISTRY }}
59+
# export VERSION={{ env.VERSION }}
60+
if $skip_validate; then
61+
echo "Skip validate"
62+
else
63+
.github/workflows/scripts/e2e/go_test.sh validate_gmc
64+
fi
65+
66+
- name: Cleanup modules
67+
if: always()
68+
run: |
69+
if $should_cleanup; then
70+
.github/workflows/scripts/e2e/go_test.sh cleanup_gmc
71+
fi
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
# Copyright (C) 2024 Intel Corporation
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
set -xe
6+
USER_ID=$(whoami)
7+
LOG_PATH=/home/$(whoami)/logs
8+
MOUNT_DIR=/home/$USER_ID/charts-mnt
9+
IMAGE_REPO=${OPEA_IMAGE_REPO:-docker.io}
10+
11+
function install_gmc() {
12+
# Make sure you have to use image tag $VERSION for microservice-connector installation
13+
echo "install microservice-connector, using repo $DOCKER_REGISTRY and tag $VERSION"
14+
echo "using namespace $SYSTEM_NAMESPACE and $APP_NAMESPACE"
15+
}
16+
17+
function validate_gmc() {
18+
echo "validate microservice-connector"
19+
}
20+
21+
function cleanup_gmc() {
22+
echo "clean up microservice-connector"
23+
# clean up the images
24+
docker rmi $DOCKER_REGISTRY/gmcrouter:$VERSION
25+
docker rmi $DOCKER_REGISTRY/gmcmanager:$VERSION
26+
}
27+
28+
if [ $# -eq 0 ]; then
29+
echo "Usage: $0 <function_name>"
30+
exit 1
31+
fi
32+
33+
case "$1" in
34+
install_gmc)
35+
install_gmc
36+
;;
37+
validate_gmc)
38+
validate_gmc
39+
;;
40+
cleanup_gmc)
41+
cleanup_gmc
42+
;;
43+
*)
44+
echo "Unknown function: $1"
45+
;;
46+
esac

0 commit comments

Comments
 (0)