Skip to content

Commit 14cd204

Browse files
authored
chore: moves workflow crd helper structs to this repo (#123)
* chore: moves workflow crd helper structs to this repo Signed-off-by: Amit Singh <singhamitch@outlook.com> * chore: adds workflow to ensure source branch is clean Signed-off-by: Amit Singh <singhamitch@outlook.com> * chore: adds const mk file Signed-off-by: Amit Singh <singhamitch@outlook.com> * chore: adds dependecy mk file Signed-off-by: Amit Singh <singhamitch@outlook.com> --------- Signed-off-by: Amit Singh <singhamitch@outlook.com>
1 parent a91fd1f commit 14cd204

10 files changed

Lines changed: 493 additions & 10 deletions

File tree

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Kubevela Test Environment Setup Action
2+
3+
A GitHub Actions composite action that sets up a complete testing environment for Kubevela projects with Go, Kubernetes tools, and the Ginkgo testing framework.
4+
5+
## Features
6+
7+
- 🛠️ **System Dependencies**: Installs essential build tools (make, gcc, jq, curl, etc.)
8+
- ☸️ **Kubernetes Tools**: Sets up kubectl and Helm for cluster operations
9+
- 🐹 **Go Environment**: Configurable Go version with module caching
10+
- 📦 **Dependency Management**: Downloads and verifies Go module dependencies
11+
- 🧪 **Testing Framework**: Installs Ginkgo v2 for BDD-style testing
12+
13+
## Usage
14+
15+
```yaml
16+
- name: Setup Kubevela Test Environment
17+
uses: ./path/to/this/action
18+
with:
19+
go-version: '1.23.8' # Optional: Go version (default: 1.23.8)
20+
```
21+
22+
### Example Workflow
23+
24+
```yaml
25+
name: Kubevela Tests
26+
on: [push, pull_request]
27+
28+
jobs:
29+
test:
30+
runs-on: ubuntu-latest
31+
steps:
32+
- uses: actions/checkout@v4
33+
34+
- name: Setup Test Environment
35+
uses: ./path/to/this/action
36+
with:
37+
go-version: '1.21'
38+
39+
- name: Run Tests
40+
run: |
41+
ginkgo -r ./tests/e2e/
42+
```
43+
44+
## Inputs
45+
46+
| Input | Description | Required | Default | Usage |
47+
|-------|-------------|----------|---------|-------|
48+
| `go-version` | Go version to install and use | No | `1.23.8` | Specify Go version for your project |
49+
50+
## What This Action Installs
51+
52+
### System Tools
53+
- **make**: Build automation tool
54+
- **gcc**: GNU Compiler Collection
55+
- **jq**: JSON processor for shell scripts
56+
- **ca-certificates**: SSL/TLS certificates
57+
- **curl**: HTTP client for downloads
58+
- **gnupg**: GNU Privacy Guard for security
59+
60+
### Kubernetes Ecosystem
61+
- **kubectl**: Kubernetes command-line tool (latest stable)
62+
- **helm**: Kubernetes package manager (latest stable)
63+
64+
### Go Development
65+
- **Go Runtime**: Specified version with module caching enabled
66+
- **Go Modules**: Downloaded and verified dependencies
67+
- **Ginkgo v2.14.0**: BDD testing framework for Go
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: 'Kubevela Test Environment Setup'
2+
description: 'Sets up complete testing environment for Kubevela with Go, Kubernetes tools, and Ginkgo framework for E2E testing.'
3+
4+
inputs:
5+
go-version:
6+
description: 'Go version to use for testing'
7+
required: false
8+
default: '1.23.8'
9+
10+
11+
runs:
12+
using: 'composite'
13+
steps:
14+
# ========================================================================
15+
# Environment Setup
16+
# ========================================================================
17+
- name: Install system dependencies
18+
shell: bash
19+
run: |
20+
# Update package manager and install essential tools
21+
sudo apt-get update
22+
sudo apt-get install -y \
23+
make \
24+
gcc \
25+
jq \
26+
ca-certificates \
27+
curl \
28+
gnupg
29+
30+
- name: Install kubectl and helm
31+
shell: bash
32+
run: |
33+
# Detect architecture
34+
ARCH=$(uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/')
35+
36+
# Install kubectl
37+
echo "Installing kubectl for architecture: $ARCH"
38+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/${ARCH}/kubectl"
39+
chmod +x kubectl
40+
sudo mv kubectl /usr/local/bin/
41+
42+
# Install helm using the official script (more reliable)
43+
echo "Installing Helm using official script..."
44+
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
45+
chmod 700 get_helm.sh
46+
./get_helm.sh
47+
rm get_helm.sh
48+
49+
# Verify installations
50+
echo "Verifying installations..."
51+
kubectl version --client
52+
helm version
53+
54+
55+
- name: Setup Go environment
56+
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32
57+
with:
58+
go-version: ${{ inputs.go-version }}
59+
cache: true
60+
61+
- name: Download Go dependencies
62+
shell: bash
63+
run: |
64+
# Download and cache Go module dependencies
65+
go mod download
66+
go mod verify
67+
68+
- name: Install Ginkgo testing framework
69+
shell: bash
70+
run: |
71+
echo "Installing Ginkgo testing framework..."
72+
go install github.com/onsi/ginkgo/v2/ginkgo@v2.14.0

‎.github/workflows/clean-branch.yml‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Clean Branch Check
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- release-*
8+
workflow_dispatch: {}
9+
pull_request:
10+
branches:
11+
- main
12+
- release-*
13+
14+
permissions:
15+
contents: read
16+
17+
jobs:
18+
detect-noop:
19+
runs-on: ubuntu-22.04
20+
outputs:
21+
noop: ${{ steps.noop.outputs.should_skip }}
22+
permissions:
23+
actions: write
24+
steps:
25+
- name: Detect No-op Changes
26+
id: noop
27+
uses: fkirc/skip-duplicate-actions@f75f66ce1886f00957d99748a42c724f4330bdcf
28+
with:
29+
github_token: ${{ secrets.GITHUB_TOKEN }}
30+
paths_ignore: '["**.md", "**.mdx", "**.png", "**.jpg"]'
31+
do_not_skip: '["workflow_dispatch", "schedule", "push"]'
32+
continue-on-error: true
33+
34+
check-diff:
35+
runs-on: ubuntu-22.04
36+
needs: detect-noop
37+
if: needs.detect-noop.outputs.noop != 'true'
38+
steps:
39+
- name: Checkout
40+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
41+
with:
42+
submodules: true
43+
44+
- name: Setup Env
45+
uses: ./.github/actions/env-setup
46+
47+
- name: Check Diff
48+
run: make check-diff

‎Makefile‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
include makefiles/const.mk
2+
include makefiles/dependency.mk
3+
14
LOCALBIN ?= $(shell pwd)/bin
25
$(LOCALBIN):
36
mkdir -p $(LOCALBIN)
@@ -19,7 +22,7 @@ tidy:
1922
unit-test: envtest
2023
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test -v -coverpkg=./... -coverprofile=coverage.txt ./...
2124

22-
lint:
25+
lint: golangci
2326
golangci-lint run ./...
2427

2528
reviewable: generate fmt vet tidy lint
@@ -28,3 +31,9 @@ reviewable: generate fmt vet tidy lint
2831
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
2932
$(ENVTEST): $(LOCALBIN)
3033
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
34+
35+
# check-diff: Execute auto-gen code commands and ensure branch is clean.
36+
check-diff: reviewable
37+
git --no-pager diff
38+
git diff --quiet || ($(ERR) please run 'make reviewable' to include all changes && false)
39+
@$(OK) branch is clean

‎apis/oam/v1alpha1/workflow_types.go‎

Lines changed: 75 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ package v1alpha1
22

33
import (
44
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5-
6-
workflowv1alpha1 "github.com/kubevela/workflow/api/v1alpha1"
5+
"k8s.io/apimachinery/pkg/runtime"
76
)
87

98
// +kubebuilder:object:root=true
@@ -17,8 +16,8 @@ type Workflow struct {
1716
metav1.TypeMeta `json:",inline"`
1817
metav1.ObjectMeta `json:"metadata,omitempty"`
1918

20-
Mode *workflowv1alpha1.WorkflowExecuteMode `json:"mode,omitempty"`
21-
workflowv1alpha1.WorkflowSpec `json:",inline"`
19+
Mode *WorkflowExecuteMode `json:"mode,omitempty"`
20+
WorkflowSpec `json:",inline"`
2221
}
2322

2423
// +kubebuilder:object:root=true
@@ -30,3 +29,75 @@ type WorkflowList struct {
3029
metav1.ListMeta `json:"metadata,omitempty"`
3130
Items []Workflow `json:"items"`
3231
}
32+
33+
// InputItem defines an input variable of WorkflowStep
34+
type InputItem struct {
35+
ParameterKey string `json:"parameterKey,omitempty"`
36+
From string `json:"from"`
37+
}
38+
39+
// OutputItem defines an output variable of WorkflowStep
40+
type OutputItem struct {
41+
ValueFrom string `json:"valueFrom"`
42+
Name string `json:"name"`
43+
}
44+
45+
// StepOutputs defines output variable of WorkflowStep
46+
type StepOutputs []OutputItem
47+
48+
// StepInputs defines variable input of WorkflowStep
49+
type StepInputs []InputItem
50+
51+
// WorkflowStepMeta contains the meta data of a workflow step
52+
type WorkflowStepMeta struct {
53+
Alias string `json:"alias,omitempty"`
54+
}
55+
56+
// WorkflowStepBase defines the workflow step base
57+
type WorkflowStepBase struct {
58+
// Name is the unique name of the workflow step.
59+
Name string `json:"name,omitempty"`
60+
// Type is the type of the workflow step.
61+
Type string `json:"type"`
62+
// Meta is the meta data of the workflow step.
63+
Meta *WorkflowStepMeta `json:"meta,omitempty"`
64+
// If is the if condition of the step
65+
If string `json:"if,omitempty"`
66+
// Timeout is the timeout of the step
67+
Timeout string `json:"timeout,omitempty"`
68+
// DependsOn is the dependency of the step
69+
DependsOn []string `json:"dependsOn,omitempty"`
70+
// Inputs is the inputs of the step
71+
Inputs StepInputs `json:"inputs,omitempty"`
72+
// Outputs is the outputs of the step
73+
Outputs StepOutputs `json:"outputs,omitempty"`
74+
75+
// Properties is the properties of the step
76+
// +kubebuilder:pruning:PreserveUnknownFields
77+
Properties *runtime.RawExtension `json:"properties,omitempty"`
78+
}
79+
80+
// WorkflowStep defines how to execute a workflow step.
81+
type WorkflowStep struct {
82+
WorkflowStepBase `json:",inline"`
83+
// Mode is only valid for sub steps, it defines the mode of the sub steps
84+
// +nullable
85+
Mode WorkflowMode `json:"mode,omitempty"`
86+
SubSteps []WorkflowStepBase `json:"subSteps,omitempty"`
87+
}
88+
89+
// WorkflowSpec defines workflow steps and other attributes
90+
type WorkflowSpec struct {
91+
Steps []WorkflowStep `json:"steps,omitempty"`
92+
}
93+
94+
// WorkflowMode describes the mode of workflow
95+
type WorkflowMode string
96+
97+
// WorkflowExecuteMode defines the mode of workflow execution
98+
type WorkflowExecuteMode struct {
99+
// Steps is the mode of workflow steps execution
100+
Steps WorkflowMode `json:"steps,omitempty"`
101+
// SubSteps is the mode of workflow sub steps execution
102+
SubSteps WorkflowMode `json:"subSteps,omitempty"`
103+
}

0 commit comments

Comments
 (0)