Skip to content

Commit a5ae6c3

Browse files
authored
Merge pull request #118 from theBeginner86/thebeginner86/e2e
[CI] Add E2E Test
2 parents fab4b8d + 6874e76 commit a5ae6c3

File tree

7 files changed

+80
-170
lines changed

7 files changed

+80
-170
lines changed

.github/workflows/e2e-test.yaml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: E2E Test
2+
on:
3+
pull_request:
4+
types:
5+
- opened
6+
- synchronize
7+
- edited
8+
9+
jobs:
10+
e2e-test:
11+
runs-on: ubuntu-24.04
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
- name: Set up Go
16+
uses: actions/setup-go@v5
17+
with:
18+
go-version: "1.23"
19+
- name: Install Helm
20+
run: |
21+
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
22+
helm version
23+
- name: Build and Install Plugin
24+
run: |
25+
./scripts/e2e.sh
26+
env:
27+
PROVIDER_TOKEN: ${{ secrets.PROVIDER_TOKEN }}
28+
WORKFLOW_ACCESS_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
29+
- name: Snapshot Meshery Helm Chart
30+
run: |
31+
helm plugin list
32+
helm helm-kanvas-snapshot -f https://meshery.io/charts/meshery-v0.8.12.tgz --name meshery-chart
33+
34+

Makefile

+8-9
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,17 @@ endif
7171
help: ## Prints help (only for targets with comments)
7272
@grep -E '^[a-zA-Z0-9._-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
7373

74-
local.fmt: ## Lints all the Go code in the application.
75-
@gofmt -w $(GOFMT_FILES)
76-
$(GOBIN)/goimports -w $(GOFMT_FILES)
77-
$(GOBIN)/gofumpt -l -w $(GOFMT_FILES)
78-
$(GOBIN)/gci write $(GOFMT_FILES) --skip-generated
74+
# local.fmt: ## Lints all the Go code in the application.
75+
# @gofmt -w $(GOFMT_FILES)
76+
# $(GOBIN)/goimports -w $(GOFMT_FILES)
77+
# $(GOBIN)/gofumpt -l -w $(GOFMT_FILES)
78+
# $(GOBIN)/gci write $(GOFMT_FILES) --skip-generated
7979

80-
local.check: local.fmt ## Loads all dependencies
80+
local.check: ## Loads all dependencies
8181
@go mod tidy
8282

83-
local.build: local.check ## Generates the artifact with 'go build'
84-
@go build -o $(APP_NAME) -ldflags="-s -w -X 'main.providerToken=$(PROVIDER_TOKEN)' -X 'main.mesheryCloudAPIBaseURL=$(MESHERY_CLOUD_API_BASE_URL)' -X 'main.mesheryAPIBaseURL=$(MESHERY_API_BASE_URL)'"
85-
83+
local.build: local.check ## Generates the artifact with 'go build'
84+
@go build -o $(APP_NAME) -ldflags="-s -w -X 'main.providerToken=$(PROVIDER_TOKEN)' -X 'main.workflowAccessToken=$(WORKFLOW_ACCESS_TOKEN)' -X 'main.mesheryCloudAPIBaseURL=$(MESHERY_CLOUD_API_BASE_URL)' -X 'main.mesheryAPIBaseURL=$(MESHERY_API_BASE_URL)'"
8685

8786
local.snapshot: local.check ## Generates the artifact with 'go build'
8887
GOVERSION=${GOVERSION} BUILD_ENVIRONMENT=${BUILD_ENVIRONMENT} goreleaser build --snapshot --clean

cmd/kanvas-snapshot/cmd.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ func CreateMesheryDesign(uri, name, email string) (string, error) {
154154
}
155155

156156
fullURL := fmt.Sprintf("%s/api/pattern/import", MesheryAPIBaseURL)
157-
158157
// Create the request
159158
req, err := http.NewRequest("POST", fullURL, bytes.NewBuffer(payloadBytes))
160159
if err != nil {
@@ -204,7 +203,7 @@ func CreateMesheryDesign(uri, name, email string) (string, error) {
204203

205204
func GenerateSnapshot(contentID, assetLocation, email string, ghAccessToken string) error {
206205
payload := fmt.Sprintf(`{"ref":"master","inputs":{"contentID":"%s","assetLocation":"%s", "email":"%s"}}`, contentID, assetLocation, email)
207-
req, err := http.NewRequest("POST", "https://api.github.com/repos/meshery/helm-kanvas-snapshot/actions/workflows/kanvas.yaml/dispatches", bytes.NewBuffer([]byte(payload)))
206+
req, err := http.NewRequest("POST", "https://api.github.com/repos/meshery-extensions/helm-kanvas-snapshot/actions/workflows/kanvas.yaml/dispatches", bytes.NewBuffer([]byte(payload)))
208207
if err != nil {
209208
return err
210209
}

plugin.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ useTunnel: true
66
command: "$HELM_PLUGIN_DIR/bin/helm-kanvas-snapshot"
77
hooks:
88
install: |
9-
$HELM_PLUGIN_DIR/install-binary.sh
9+
$HELM_PLUGIN_DIR/scripts/install-binary.sh
1010
update: |
11-
$HELM_PLUGIN_DIR/install-binary.sh
11+
$HELM_PLUGIN_DIR/scripts/install-binary.sh
1212
uninstall: |
1313
echo "Snapshot plugin uninstalled."

scripts/e2e.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
source scripts/utils.sh
4+
5+
trap "fail_trap" EXIT
6+
make PROVIDER_TOKEN=$PROVIDER_TOKEN WORKFLOW_ACCESS_TOKEN=$WORKFLOW_ACCESS_TOKEN local.build
7+
installFileFromLocal
8+
echo
9+
echo "helm-kanvas-snapshot is installed at ${HELM_PLUGIN_DIR}/bin/helm-kanvas-snapshot"
10+
echo
11+
echo "See https://github.com/$PROJECT_GH#readme for more information on getting started."

scripts/install-binary.sh

+8-137
Original file line numberDiff line numberDiff line change
@@ -12,143 +12,9 @@
1212
# // See the License for the specific language governing permissions and
1313
# // limitations under the License.
1414

15-
# This script installs the Helm Kanvas Snapshot plugin.
15+
#!/usr/bin/env bash
1616

17-
#!/usr/bin/env sh
18-
19-
echo "Installing Helm Kanvas Snapshot plugin..."
20-
21-
CLI="kanvas-snapshot"
22-
REPO_NAME="helm-kanvas-snapshot"
23-
PROJECT_ORG="${PROJECT_ORG:-meshery}"
24-
PROJECT_GH="$PROJECT_ORG/$REPO_NAME"
25-
HELM_BIN="/usr/local/bin/helm"
26-
export GREP_COLOR="never"
27-
28-
HELM_MAJOR_VERSION=$("${HELM_BIN}" version --client --short | awk -F '.' '{print $1}')
29-
30-
# : ${HELM_PLUGIN_DIR:="$("${HELM_BIN}" home --debug=false)/plugins/helm-diff"}
31-
32-
# Handle HELM_PLUGIN_DIR filepath based on OS. Use *nix-based filepathing
33-
34-
if type cygpath >/dev/null 2>&1; then
35-
HELM_PLUGIN_DIR=$(cygpath -u $HELM_PLUGIN_DIR)
36-
fi
37-
38-
if [ "$SKIP_BIN_INSTALL" = "1" ]; then
39-
echo "Skipping binary install"
40-
exit
41-
fi
42-
43-
# Identify systm architecture
44-
initArch() {
45-
ARCH=$(uname -m)
46-
case $ARCH in
47-
armv5*) ARCH="armv5" ;;
48-
armv6*) ARCH="armv6" ;;
49-
armv7*) ARCH="armv7" ;;
50-
aarch64) ARCH="arm64" ;;
51-
x86) ARCH="386" ;;
52-
x86_64) ARCH="x86_64" ;;
53-
i686) ARCH="386" ;;
54-
i386) ARCH="386" ;;
55-
esac
56-
echo "ARCH: $ARCH"
57-
}
58-
59-
# Identify operating system
60-
initOS() {
61-
OS=$(uname | tr '[:upper:]' '[:lower:]')
62-
63-
case "$OS" in
64-
# Msys support
65-
msys*) OS='windows' ;;
66-
# Minimalist GNU for Windows
67-
mingw*) OS='windows' ;;
68-
darwin) OS='darwin' ;;
69-
esac
70-
echo "OS: $OS"
71-
}
72-
73-
# verifySupported checks that the os/arch combination is supported for
74-
# binary builds.
75-
verifySupported() {
76-
supported="linux_amd64\ndarwin_x86_64\nlinux_arm64\ndarwin_arm64\nwindows_amd64"
77-
if ! echo "${supported}" | grep -q "${OS}_${ARCH}"; then
78-
echo "No prebuilt binary for ${OS}_${ARCH}."
79-
exit 1
80-
fi
81-
82-
if ! type "curl" >/dev/null && ! type "wget" >/dev/null; then
83-
echo "Either curl or wget is required"
84-
exit 1
85-
fi
86-
}
87-
88-
# getDownloadURL checks the latest available version.
89-
getDownloadURL() {
90-
#version=$(git -C "$HELM_PLUGIN_DIR" describe --tags --exact-match 2>/dev/null || :)
91-
echo "OS: $OS"
92-
93-
version="$(cat $HELM_PLUGIN_DIR/plugin.yaml | grep "version" | cut -d '"' -f 2)"
94-
if [ -n "$version" ]; then
95-
DOWNLOAD_URL="https://github.com/$PROJECT_GH/releases/download/v$version/$CLI_$version_$OS_$ARCH.tar.gz"
96-
echo "DOWNLOAD_URL1: $DOWNLOAD_URL"
97-
# https://github.com/meshery/helm-kanvas-snapshot/releases/download/v0.2.0/kanvas-snapshot_0.2.0_Darwin_x86_64.tar.gz
98-
else
99-
# Use the GitHub API to find the download url for this project.
100-
url="https://api.github.com/repos/$PROJECT_GH/releases/latest"
101-
if type "curl" >/dev/null; then
102-
DOWNLOAD_URL=$(curl -s $url | grep $OS_$ARCH\" | awk '/\"browser_download_url\":/{gsub( /[,\"]/,"", $2); print $2}')
103-
echo "DOWNLOAD_URL2: $DOWNLOAD_URL"
104-
105-
elif type "wget" >/dev/null; then
106-
DOWNLOAD_URL=$(wget -q -O - $url | grep $OS_$ARCH\" | awk '/\"browser_download_url\":/{gsub( /[,\"]/,"", $2); print $2}')
107-
echo "DOWNLOAD_URL3: $DOWNLOAD_URL"
108-
109-
fi
110-
fi
111-
112-
}
113-
114-
# downloadFile downloads the latest binary package and also the checksum
115-
# for that binary.
116-
downloadFile() {
117-
BINDIR="$HELM_PLUGIN_DIR/bin"
118-
rm -rf "$BINDIR"
119-
mkdir -p "$BINDIR"
120-
echo "Downloading $DOWNLOAD_URL"
121-
if type "curl" >/dev/null; then
122-
HTTP_CODE=$(curl -sL --write-out "%{http_code}" "$DOWNLOAD_URL" --output "$BINDIR/$CLI")
123-
if [ ${HTTP_CODE} -ne 200 ]; then
124-
exit 1
125-
fi
126-
elif type "wget" >/dev/null; then
127-
wget -q -O "$BINDIR/$CLI" "$DOWNLOAD_URL"
128-
fi
129-
130-
chmod +x "$BINDIR/$CLI"
131-
132-
}
133-
134-
# fail_trap is executed if an error occurs.
135-
fail_trap() {
136-
result=$?
137-
if [ "$result" != "0" ]; then
138-
echo "Failed to install $CLI"
139-
printf "\tFor support, go to https://discuss.layer5.io.\n"
140-
fi
141-
exit $result
142-
}
143-
144-
# testVersion tests the installed client to make sure it is working.
145-
testVersion() {
146-
set +e
147-
echo "$CLI installed into $HELM_PLUGIN_DIR/$CLI"
148-
"${HELM_PLUGIN_DIR}/bin/$CLI" version
149-
echo "`helm $CLI --help` to get started."
150-
set -e
151-
}
17+
source scripts/utils.sh
15218

15319

15420
# Execution
@@ -161,4 +27,9 @@ initOS
16127
verifySupported
16228
getDownloadURL
16329
downloadFile
164-
testVersion
30+
installFileFromZip
31+
echo
32+
echo "helm-kanvas-snapshot is installed at ${HELM_PLUGIN_DIR}/bin/helm-kanvas-snapshot"
33+
echo
34+
echo "See https://github.com/$PROJECT_GH#readme for more information on getting started."
35+

install-binary.sh renamed to scripts/utils.sh

+16-20
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ fi
1717
[ -z "$HELM_HOME" ] && HELM_HOME=$(helm env | grep 'HELM_DATA_HOME' | cut -d '=' -f2 | tr -d '"')
1818

1919
mkdir -p "$HELM_HOME"
20-
2120
: "${HELM_PLUGIN_DIR:="$HELM_HOME/plugins/$PROJECT_NAME"}"
2221

2322
if [ "$SKIP_BIN_INSTALL" = "1" ]; then
@@ -104,7 +103,7 @@ downloadFile() {
104103

105104
# installFile verifies the SHA256 for the file, then unpacks and
106105
# installs it.
107-
installFile() {
106+
installFileFromZip() {
108107
HELM_TMP="/tmp/$PROJECT_NAME"
109108
HELM_TMP_BIN="/tmp/$PROJECT_NAME/$PROJECT_NAME_WITH_VERSION/$PROJECT_NAME"
110109
mkdir -p "$HELM_TMP"
@@ -117,6 +116,20 @@ installFile() {
117116
cp "$HELM_TMP_BIN" "$HELM_PLUGIN_DIR/bin"
118117
}
119118

119+
installFileFromLocal() {
120+
echo "Preparing to install into ${HELM_PLUGIN_DIR}"
121+
cwd=$(pwd)
122+
if [ -z "$cwd" ]; then
123+
echo "Failed to get current working directory"
124+
exit 1
125+
fi
126+
mkdir -p "$HELM_PLUGIN_DIR"
127+
echo "Current working directory: $cwd"
128+
cp -r $cwd/. "$HELM_PLUGIN_DIR"
129+
mkdir -p "$HELM_PLUGIN_DIR/bin"
130+
cp "$PROJECT_NAME" "$HELM_PLUGIN_DIR/bin"
131+
}
132+
120133
# fail_trap is executed if an error occurs.
121134
fail_trap() {
122135
result=$?
@@ -125,21 +138,4 @@ fail_trap() {
125138
echo "\tFor support, open issue at https://github.com/$PROJECT_GH."
126139
fi
127140
exit $result
128-
}
129-
130-
# Execution
131-
132-
#Stop execution on any error
133-
trap "fail_trap" EXIT
134-
set -e
135-
initArch
136-
initOS
137-
verifySupported
138-
getDownloadURL
139-
downloadFile
140-
installFile
141-
echo
142-
echo "helm-kanvas-snapshot is installed at ${HELM_PLUGIN_DIR}/bin/helm-kanvas-snapshot"
143-
echo
144-
echo "See https://github.com/$PROJECT_GH#readme for more information on getting started."
145-
141+
}

0 commit comments

Comments
 (0)