Skip to content

Commit

Permalink
ci: enhance pull_request workflow
Browse files Browse the repository at this point in the history
Signed-off-by: Diwakar Sharma <[email protected]>
  • Loading branch information
dsharma-dc committed Jul 23, 2024
1 parent ea480b6 commit 99a4ef4
Show file tree
Hide file tree
Showing 15 changed files with 374 additions and 62 deletions.
56 changes: 28 additions & 28 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,14 @@
# Copyright 2020 The OpenEBS Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: ci
name: Pull Request CI

on:
pull_request:
branches:
- 'develop'
- 'v*'
- release/**'
paths-ignore:
- '*.md'
- 'BUILDMETA'
- 'changelogs/**'
- 'deploy/helm/**'
- 'docs/**'
- 'design/**'
- 'LICENSE'
Expand All @@ -35,6 +20,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Go 1.19
uses: actions/setup-go@v5
Expand Down Expand Up @@ -62,7 +49,19 @@ jobs:
path: '.'
pattern: '*.sh'

unit-test:
- uses: cachix/install-nix-action@v22
- uses: rrbutani/[email protected]
with:
file: shell.nix
- name: Check if the chart follows a valid semver version
run: |
branch_name="${{ github.event.pull_request.base.ref }}"
./scripts/validate-chart-version.sh --branch $branch_name
- name: Run chart-testing lint
run: |
ct lint --config ct.yaml
unit-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -85,8 +84,8 @@ jobs:
name: coverage-$(date +%s)
flags: unittests

bdd-test:
needs: ['unit-test']
bdd-tests:
needs: ['unit-tests']
runs-on: ubuntu-latest
strategy:
fail-fast: true
Expand All @@ -95,13 +94,21 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4

- uses: cachix/install-nix-action@v22
- uses: rrbutani/[email protected]
with:
file: shell.nix

- name: Set up Go 1.19
uses: actions/setup-go@v5
with:
go-version: 1.19.9
cache: false

- name: Build images locally
run: make lvm-driver-image || exit 1;

- name: Setup Minikube-Kubernetes
uses: medyagh/setup-minikube@latest
with:
Expand All @@ -112,9 +119,6 @@ jobs:
cni: calico
start-args: '--install-addons=false'

- name: Build images locally
run: make lvm-driver-image || exit 1;

- name: bootstrap
run: make bootstrap

Expand All @@ -131,7 +135,7 @@ jobs:

csi-driver:
runs-on: ubuntu-latest
needs: ['lint', 'unit-test', 'bdd-test']
needs: ['lint', 'unit-tests', 'bdd-tests']
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -144,8 +148,6 @@ jobs:
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
with:
version: v0.13.1

- name: Build
uses: docker/build-push-action@v5
Expand All @@ -154,5 +156,3 @@ jobs:
file: ./buildscripts/lvm-driver/Dockerfile.buildx
push: false
platforms: linux/amd64, linux/arm64
tags: |
openebs/lvm-driver:ci
12 changes: 6 additions & 6 deletions .github/workflows/release-charts.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: Release Charts

on:
push:
paths:
- 'deploy/helm/**'
branches:
- develop
#on:
# push:
# paths:
# - 'deploy/helm/**'
# branches:
# - develop

jobs:
release:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ tags
*.swo
*.swn
*.idea
*.test
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ ifeq (${DBUILD_SITE_URL}, )
export DBUILD_SITE_URL
endif

# Set the path to the Chart.yaml file
ROOT_DIR:=$(dir $(realpath $(firstword $(MAKEFILE_LIST))))
CHART_YAML:=${ROOT_DIR}/deploy/helm/charts/Chart.yaml

ifeq (${IMAGE_TAG}, )
IMAGE_TAG = ci
IMAGE_TAG := $(shell awk -F': ' '/^version:/ {print $$2}' $(CHART_YAML))
export IMAGE_TAG
endif

Expand Down
20 changes: 2 additions & 18 deletions ci/ci-test.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,12 @@
#!/usr/bin/env bash
# Copyright 2021 The OpenEBS Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


set -e

LVM_OPERATOR="$(realpath deploy/lvm-operator.yaml)"
SNAP_CLASS="$(realpath deploy/sample/lvmsnapclass.yaml)"

export LVM_NAMESPACE="openebs"
export TEST_DIR="tests"
export NAMESPACE="kube-system"
export NAMESPACE="openebs"

# allow override
if [ -z "${KUBECONFIG}" ]
Expand Down Expand Up @@ -60,7 +45,6 @@ cleanup() {

kubectl delete pvc -n openebs lvmpv-pvc
kubectl delete -f "${SNAP_CLASS}"
kubectl delete -f "${LVM_OPERATOR}"

# always return true
return 0
Expand All @@ -87,7 +71,7 @@ sudo sed -i '/^[^#]*thin_pool_autoextend_percent/ s/= .*/= 20/' /etc/lvm/lvm.con

# Prepare env for running BDD tests
# Minikube is already running
kubectl apply -f "${LVM_OPERATOR}"
helm install lvm-localpv ./deploy/helm/charts -n "$OPENEBS_NAMESPACE" --create-namespace --set lvmPlugin.pullPolicy=Never --set analytics.enabled=false
kubectl apply -f "${SNAP_CLASS}"

dumpAgentLogs() {
Expand Down
1 change: 1 addition & 0 deletions ct.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ chart-dirs:
- deploy/helm
helm-extra-args: --timeout=500s
validate-maintainers: false
check-version-increment: false
6 changes: 3 additions & 3 deletions deploy/helm/charts/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apiVersion: v2
name: lvm-localpv
description: CSI Driver for dynamic provisioning of LVM Persistent Local Volumes.
version: 1.6.0
appVersion: 1.6.0
version: 1.7.0-develop
appVersion: 1.7.0-develop
icon: https://raw.githubusercontent.com/cncf/artwork/master/projects/openebs/icon/color/openebs-icon-color.png
home: https://openebs.io/
keywords:
Expand All @@ -16,5 +16,5 @@ sources:
- https://github.com/openebs/lvm-localpv
dependencies:
- name: crds
version: 1.6.0
version: 1.7.0-develop
condition: crds.enabled
2 changes: 1 addition & 1 deletion deploy/helm/charts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ helm install openebs-lvmlocalpv openebs-lvmlocalpv/lvm-localpv --namespace opene
| `lvmPlugin.image.registry` | Registry for openebs-lvm-plugin image | `""` |
| `lvmPlugin.image.repository` | Image repository for openebs-lvm-plugin | `openebs/lvm-driver` |
| `lvmPlugin.image.pullPolicy` | Image pull policy for openebs-lvm-plugin | `IfNotPresent` |
| `lvmPlugin.image.tag` | Image tag for openebs-lvm-plugin | `1.6.0` |
| `lvmPlugin.image.tag` | Image tag for openebs-lvm-plugin | `1.7.0-develop` |
| `lvmPlugin.metricsPort` | The TCP port number used for exposing lvm-metrics | `9500` |
| `lvmPlugin.allowedTopologies` | The comma seperated list of allowed node topologies | `kubernetes.io/hostname,` |
| `lvmNode.driverRegistrar.image.registry` | Registry for csi-node-driver-registrar image | `registry.k8s.io/` |
Expand Down
2 changes: 1 addition & 1 deletion deploy/helm/charts/charts/crds/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: v2
name: crds
version: 1.6.0
version: 1.7.0-develop
description: A Helm chart that collects CustomResourceDefinitions (CRDs) from lvm-localpv.
2 changes: 1 addition & 1 deletion deploy/helm/charts/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Define meta labels for openebs lvm-localpv components
{{- define "lvmlocalpv.common.metaLabels" -}}
chart: {{ template "lvmlocalpv.chart" . }}
heritage: {{ .Release.Service }}
openebs.io/version: {{ .Values.release.version | quote }}
openebs.io/version: {{ .Chart.AppVersion | quote }}
role: {{ .Values.role | quote }}
{{- end -}}

Expand Down
4 changes: 1 addition & 3 deletions deploy/helm/charts/values.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Default values for openebs-lvmlocalpv.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
release:
version: "1.6.0"

imagePullSecrets:
# - name: "image-pull-secret"
Expand Down Expand Up @@ -151,7 +149,7 @@ lvmPlugin:
repository: openebs/lvm-driver
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: 1.6.0
tag: 1.7.0-develop
ioLimits:
enabled: false
containerRuntime: containerd
Expand Down
101 changes: 101 additions & 0 deletions deploy/scripts/validate-chart-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/usr/bin/env bash

# Write output to error output stream.
echo_stderr() {
echo -e "${1}" >&2
}

die()
{
local _return="${2:-1}"
echo_stderr "$1"
exit "${_return}"
}

set -euo pipefail

# Set the path to the Chart.yaml file
SCRIPT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]:-"$0"}")")"
ROOT_DIR="$SCRIPT_DIR/.."
CHART_DIR="$ROOT_DIR/deploy/helm/charts"
CHART_YAML="$CHART_DIR/Chart.yaml"

# Check if the Chart.yaml file exists
if [ ! -f "$CHART_YAML" ]; then
die "Chart.yaml file not found in $CHART_YAML"
fi

# Extract the chart version and app version using yq
CHART_VERSION=$(yq e '.version' "$CHART_YAML")
APP_VERSION=$(yq e '.appVersion' "$CHART_YAML")

# Check if extraction was successful
if [ -z "$CHART_VERSION" ] || [ -z "$APP_VERSION" ]; then
die "Failed to extract versions from Chart.yaml"
fi

# Print the extracted versions
echo "Chart Version: $CHART_VERSION"
echo "App Version: $APP_VERSION"

# Validate that the versions are valid semver
if [ "$(semver validate "$CHART_VERSION")" != "valid" ]; then
die "Invalid chart version: $CHART_VERSION"
fi

if [ "$(semver validate "$APP_VERSION")" != "valid" ]; then
die "Invalid app version: $APP_VERSION"
fi

help() {
cat <<EOF
Usage: $(basename "$0") [OPTIONS]
Options:
--branch <branch name> Name of the branch on which this workflow is running.
Examples:
$(basename "$0") --branch develop
EOF
}

# Parse arguments
while [ "$#" -gt 0 ]; do
case $1 in
-b|--branch)
BRANCH_NAME=$2
shift
;;
-h|--help)
help
exit 0
;;
*)
help
die "Unknown option: $1"
;;
esac
shift
done

# Extract major and minor version from the branch name
extract_major_minor() {
echo "$1" | awk -F/ '{print $2}'
}

if [[ "$BRANCH_NAME" == "develop" ]]; then
if [[ "$CHART_VERSION" != *"-develop" ]]; then
die "Chart version must include '-develop' for develop branch"
fi
if [[ "$APP_VERSION" != *"-develop" ]]; then
die "App version must include '-develop' for develop branch"
fi
elif [[ "$BRANCH_NAME" =~ ^(release/[0-9]+\.[0-9]+)$ ]]; then
RELEASE_VERSION=$(extract_major_minor "$BRANCH_NAME")
if [[ "$CHART_VERSION" != "$RELEASE_VERSION."*"-prerelease" ]]; then
die "Chart version must be in format $RELEASE_VERSION.X-prerelease for release branch"
fi
if [[ "$APP_VERSION" != "$RELEASE_VERSION."*"-prerelease" ]]; then
die "App version must be in format $RELEASE_VERSION.X-prerelease for release branch"
fi
else
die "Unknown branch name: $BRANCH_NAME"
fi
14 changes: 14 additions & 0 deletions nix/sources.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"nixpkgs": {
"branch": "release-23.05",
"description": "A read-only mirror of NixOS/nixpkgs tracking the released channels. Send issues and PRs to",
"homepage": "https://github.com/NixOS/nixpkgs",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "9a333eaa80901efe01df07eade2c16d183761fa3",
"sha256": "0xhqjli4m9wkzv7xhs6fr1iajdjbv7xnj0bwvwldq9s6arlwkhj3",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/9a333eaa80901efe01df07eade2c16d183761fa3.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
}
}
Loading

0 comments on commit 99a4ef4

Please sign in to comment.