Skip to content

Commit 496e0eb

Browse files
author
Kevin Li
committed
Merge branch 'main' of github.com:apache/cloudstack-go into modify_post_request
2 parents bfde559 + f4febd1 commit 496e0eb

File tree

5 files changed

+693
-11
lines changed

5 files changed

+693
-11
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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: 'Setup Go Environment'
19+
description: 'Set up Go with caching and install required tools'
20+
21+
inputs:
22+
go-version:
23+
description: 'Go version to use'
24+
required: false
25+
default: '1.23'
26+
27+
runs:
28+
using: 'composite'
29+
steps:
30+
- name: Set up Go
31+
uses: actions/setup-go@v5
32+
with:
33+
go-version: ${{ inputs.go-version }}
34+
check-latest: true
35+
36+
- name: Cache Go modules
37+
uses: actions/cache@v4
38+
with:
39+
path: |
40+
~/.cache/go-build
41+
~/go/pkg/mod
42+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
43+
restore-keys: |
44+
${{ runner.os }}-go-
45+
46+
- name: Set up tools
47+
shell: bash
48+
run: |
49+
go install golang.org/x/tools/cmd/goimports@latest
50+
go install go.uber.org/mock/mockgen@latest
51+
52+
53+
- name: Build
54+
shell: bash
55+
run: |
56+
export PATH=$PATH:$(go env GOPATH)/bin
57+
make code
58+
make mocks

.github/workflows/build.yml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,8 @@ jobs:
3333
steps:
3434
- uses: actions/checkout@v4
3535

36-
- name: Set up Go
37-
uses: actions/setup-go@v4
38-
with:
39-
go-version: 1.23
40-
41-
- name: Set up tools
42-
run: |
43-
go install golang.org/x/tools/cmd/goimports@latest
44-
go install go.uber.org/mock/mockgen@latest
36+
- name: Setup Go Environment
37+
uses: ./.github/actions/setup-go-and-build
4538

4639
- name: Build
4740
run: |
@@ -50,4 +43,4 @@ jobs:
5043
make mocks
5144
5245
- name: Test
53-
run: go test -v ./...
46+
run: go test -v ./test/... ./examples/...

.github/workflows/ci.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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: CI
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+
32+
jobs:
33+
build:
34+
runs-on: ubuntu-latest
35+
services:
36+
cloudstack-simulator:
37+
image: apache/cloudstack-simulator:4.20.0.0
38+
ports:
39+
- 8080:5050
40+
options: >-
41+
--health-cmd "curl -f http://localhost:5050 || exit 1"
42+
--health-interval 30s
43+
--health-timeout 10s
44+
--health-retries 5
45+
steps:
46+
- uses: actions/checkout@v4
47+
48+
- name: Setup Go Environment & build code & mocks
49+
uses: ./.github/actions/setup-go-and-build
50+
51+
- name: Set up CloudStack
52+
id: setup-cloudstack
53+
shell: bash
54+
run: |
55+
set -e
56+
57+
# Deploy datacenter configuration
58+
container_id=$(docker container ls --format=json -l | jq -r .ID)
59+
if [ -z "$container_id" ] || [ "$container_id" = "null" ]; then
60+
echo "Failed to get CloudStack container ID"
61+
exit 1
62+
fi
63+
64+
echo "Deploying CloudStack datacenter configuration..."
65+
docker exec "$container_id" python /root/tools/marvin/marvin/deployDataCenter.py -i /root/setup/dev/advanced.cfg
66+
67+
# Login and get API credentials
68+
echo "Logging into CloudStack..."
69+
session_key=$(curl -sf --location "${CLOUDSTACK_API_URL}" \
70+
--header 'Content-Type: application/x-www-form-urlencoded' \
71+
--data-urlencode 'command=login' \
72+
--data-urlencode 'username=admin' \
73+
--data-urlencode 'password=password' \
74+
--data-urlencode 'response=json' \
75+
--data-urlencode 'domain=/' -j -c cookies.txt | jq -r ".loginresponse.sessionkey")
76+
77+
78+
echo "::add-mask::$session_key" # Mask the session key
79+
80+
echo "Retrieving API keys..."
81+
CLOUDSTACK_USER_ID=$(curl -fs "${CLOUDSTACK_API_URL}?command=listUsers&response=json&sessionkey=${session_key}" -b cookies.txt | jq -r '.listusersresponse.user[0].id')
82+
api_key=$(curl -s "${CLOUDSTACK_API_URL}?command=getUserKeys&id=${CLOUDSTACK_USER_ID}&response=json&sessionkey=${session_key}" -b cookies.txt | jq -r '.getuserkeysresponse.userkeys.apikey')
83+
secret_key=$(curl -fs "${CLOUDSTACK_API_URL}?command=getUserKeys&id=${CLOUDSTACK_USER_ID}&response=json&sessionkey=${session_key}" -b cookies.txt | jq -r '.getuserkeysresponse.userkeys.secretkey')
84+
85+
86+
echo "::add-mask::$api_key" # Mask the API key
87+
echo "::add-mask::$secret_key" # Mask the secret key
88+
89+
echo "CLOUDSTACK_API_KEY=$api_key" >> $GITHUB_OUTPUT
90+
echo "CLOUDSTACK_SECRET_KEY=$secret_key" >> $GITHUB_OUTPUT
91+
92+
- name: Run tests
93+
run: |
94+
go test -v -timeout=30m ./ci/...
95+
env:
96+
CLOUDSTACK_API_URL: ${{ env.CLOUDSTACK_API_URL }}
97+
CLOUDSTACK_API_KEY: ${{ steps.setup-cloudstack.outputs.CLOUDSTACK_API_KEY }}
98+
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: ## Install mockgen locally via go install.
3032
go install go.uber.org/mock/mockgen@latest
3133

0 commit comments

Comments
 (0)