Skip to content

Commit 340541f

Browse files
committed
Add github actions for verifying different type input params with go sdk
1 parent bfc6c0c commit 340541f

4 files changed

Lines changed: 673 additions & 3 deletions

File tree

.github/workflows/build.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,20 @@ jobs:
3434
- uses: actions/checkout@v4
3535

3636
- name: Set up Go
37-
uses: actions/setup-go@v4
37+
uses: actions/setup-go@v5
3838
with:
39-
go-version: 1.23
39+
go-version: '1.23'
40+
check-latest: true
41+
42+
- name: Cache Go modules
43+
uses: actions/cache@v4
44+
with:
45+
path: |
46+
~/.cache/go-build
47+
~/go/pkg/mod
48+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
49+
restore-keys: |
50+
${{ runner.os }}-go-
4051
4152
- name: Set up tools
4253
run: |

.github/workflows/ci.yml

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
name: Build Check
19+
20+
on:
21+
push:
22+
branches: ["main"]
23+
pull_request:
24+
branches: ["main"]
25+
26+
permissions:
27+
contents: read
28+
29+
env:
30+
CLOUDSTACK_API_URL: http://localhost:8080/client/api
31+
CLOUDSTACK_USER_ID: 2
32+
33+
jobs:
34+
build:
35+
runs-on: ubuntu-latest
36+
services:
37+
cloudstack-simulator:
38+
image: apache/cloudstack-simulator:4.20.0.0
39+
ports:
40+
- 8080:5050
41+
options: >-
42+
--health-cmd "curl -f http://localhost:5050 || exit 1"
43+
--health-interval 30s
44+
--health-timeout 10s
45+
--health-retries 5
46+
steps:
47+
- uses: actions/checkout@v4
48+
49+
- name: Set up Go
50+
uses: actions/setup-go@v5
51+
with:
52+
go-version: "1.23"
53+
check-latest: true
54+
55+
- name: Cache Go modules
56+
uses: actions/cache@v4
57+
with:
58+
path: |
59+
~/.cache/go-build
60+
~/go/pkg/mod
61+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
62+
restore-keys: |
63+
${{ runner.os }}-go-
64+
65+
- name: Set up tools
66+
run: |
67+
go install golang.org/x/tools/cmd/goimports@latest
68+
go install go.uber.org/mock/mockgen@latest
69+
70+
- name: Build
71+
run: |
72+
export PATH=$PATH:$(go env GOPATH)/bin
73+
make code
74+
make mocks
75+
76+
- name: Set up CloudStack
77+
id: setup-cloudstack
78+
shell: bash
79+
run: |
80+
set -e
81+
82+
# Deploy datacenter configuration
83+
container_id=$(docker container ls --format=json -l | jq -r .ID)
84+
if [ -z "$container_id" ] || [ "$container_id" = "null" ]; then
85+
echo "Failed to get CloudStack container ID"
86+
exit 1
87+
fi
88+
89+
echo "Deploying CloudStack datacenter configuration..."
90+
docker exec "$container_id" python /root/tools/marvin/marvin/deployDataCenter.py -i /root/setup/dev/advanced.cfg
91+
92+
# Login and get API credentials
93+
echo "Logging into CloudStack..."
94+
if ! curl -sf --max-time 30 --location "${CLOUDSTACK_API_URL}" \
95+
--header 'Content-Type: application/x-www-form-urlencoded' \
96+
--data-urlencode 'command=login' \
97+
--data-urlencode 'username=admin' \
98+
--data-urlencode 'password=password' \
99+
--data-urlencode 'response=json' \
100+
--data-urlencode 'domain=/' -j -c cookies.txt --output /dev/null; then
101+
echo "Failed to login to CloudStack"
102+
exit 1
103+
fi
104+
105+
echo "Retrieving API keys..."
106+
api_key=$(curl -s --max-time 30 "${CLOUDSTACK_API_URL}?command=getUserKeys&id=${CLOUDSTACK_USER_ID}&response=json" -b cookies.txt | jq -r '.getuserkeysresponse.userkeys.apikey')
107+
secret_key=$(curl -s --max-time 30 "${CLOUDSTACK_API_URL}?command=getUserKeys&id=${CLOUDSTACK_USER_ID}&response=json" -b cookies.txt | jq -r '.getuserkeysresponse.userkeys.secretkey')
108+
109+
if [ -z "$api_key" ] || [ "$api_key" = "null" ] || [ -z "$secret_key" ] || [ "$secret_key" = "null" ]; then
110+
echo "Failed to retrieve API keys"
111+
exit 1
112+
fi
113+
114+
echo "::add-mask::$api_key"
115+
echo "::add-mask::$secret_key"
116+
117+
echo "CLOUDSTACK_API_KEY=$api_key" >> $GITHUB_OUTPUT
118+
echo "CLOUDSTACK_SECRET_KEY=$secret_key" >> $GITHUB_OUTPUT
119+
120+
- name: Run tests
121+
run: |
122+
go test -v -timeout=30m ./ci/...
123+
env:
124+
CLOUDSTACK_API_URL: ${{ env.CLOUDSTACK_API_URL }}
125+
CLOUDSTACK_API_KEY: ${{ steps.setup-cloudstack.outputs.CLOUDSTACK_API_KEY }}
126+
CLOUDSTACK_SECRET_KEY: ${{ steps.setup-cloudstack.outputs.CLOUDSTACK_SECRET_KEY }}

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ endif
1111
SHELL = /usr/bin/env bash -o pipefail
1212
.SHELLFLAGS = -ec
1313

14+
.PHONY: all code mocks test mockgen
15+
1416
all: code mocks test
1517

1618
code:
@@ -26,6 +28,6 @@ test:
2628
go test -v github.com/apache/cloudstack-go/v2/test
2729

2830
MOCKGEN := mockgen
29-
mockgen: ## Download conversion-gen locally if necessary.
31+
mockgen: ## Download mockgen locally if necessary.
3032
go install go.uber.org/mock/mockgen@latest
3133

0 commit comments

Comments
 (0)