diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f8943376..7930c9ef 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -59,6 +59,11 @@ jobs: - name: Upload Coverage Report uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + file: ./coverage.txt + name: coverage-$(date +%s) + flags: unittests provisioner-localpv: runs-on: ubuntu-latest @@ -189,4 +194,3 @@ jobs: - name: Integration test run: | make integration-test - diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 1045d589..ca69278c 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -43,11 +43,11 @@ jobs: go-version: 1.19.13 cache: false - - name: Lint Check - uses: golangci/golangci-lint-action@v4 - with: - version: v1.56.2 - args: -E exportloopref,dupl,revive,bodyclose,goconst,misspell -D structcheck --timeout 5m0s + # - name: Lint Check + # uses: golangci/golangci-lint-action@v4 + # with: + # version: v1.56.2 + # args: -E exportloopref,dupl,revive,bodyclose,goconst,misspell -D structcheck --timeout 5m0s - name: Check if the chart follows a valid semver version run: | @@ -78,6 +78,11 @@ jobs: - name: Upload Coverage Report uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + file: ./coverage.txt + name: coverage-$(date +%s) + flags: unittests provisioner-localpv: runs-on: ubuntu-latest @@ -148,19 +153,4 @@ jobs: run: | make integration-test - localpv-e2e: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Build the localpv-e2e image - uses: docker/build-push-action@v4 - with: - file: ./e2e-tests/Dockerfile - push: false - load: false - platforms: linux/amd64 - tags: | - openebs/localpv-e2e:ci diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 104080ff..3a48948b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -48,11 +48,11 @@ jobs: go-version: 1.19.13 cache: false - - name: Lint Check - uses: golangci/golangci-lint-action@v4 - with: - version: v1.56.2 - args: -E exportloopref,dupl,revive,bodyclose,goconst,misspell -D structcheck --timeout 5m0s + # - name: Lint Check + # uses: golangci/golangci-lint-action@v4 + # with: + # version: v1.56.2 + # args: -E exportloopref,dupl,revive,bodyclose,goconst,misspell -D structcheck --timeout 5m0s - name: Check if the chart follows a valid semver version run: | @@ -87,6 +87,11 @@ jobs: - name: Upload Coverage Report uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + file: ./coverage.txt + name: coverage-$(date +%s) + flags: unittests integration-test: runs-on: ubuntu-latest @@ -208,3 +213,4 @@ jobs: DBUILD_REPO_URL=https://github.com/openebs/dynamic-localpv-provisioner DBUILD_SITE_URL=https://openebs.io RELEASE_TAG=${{ env.RELEASE_TAG }} + diff --git a/ct.yaml b/ct.yaml index 86949033..a646494f 100644 --- a/ct.yaml +++ b/ct.yaml @@ -5,4 +5,4 @@ chart-dirs: - deploy/helm helm-extra-args: --timeout=500s validate-maintainers: false -check-version-increment: false \ No newline at end of file +check-version-increment: false diff --git a/nix/sources.json b/nix/sources.json index dc4bfb25..9faedce3 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -11,4 +11,4 @@ "url": "https://github.com/NixOS/nixpkgs/archive/9a333eaa80901efe01df07eade2c16d183761fa3.tar.gz", "url_template": "https://github.com///archive/.tar.gz" } -} \ No newline at end of file +} diff --git a/nix/sources.nix b/nix/sources.nix index 0b645c28..fe3dadf7 100644 --- a/nix/sources.nix +++ b/nix/sources.nix @@ -195,4 +195,4 @@ let }; in -mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); } \ No newline at end of file +mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/scripts/update-chart-version.sh b/scripts/update-chart-version.sh new file mode 100644 index 00000000..90cfb017 --- /dev/null +++ b/scripts/update-chart-version.sh @@ -0,0 +1,224 @@ +#!/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}" +} + +help() { + cat < Name of the target branch. + --tag Release tag. + --type Which branch to modify. + --chart-version Version of the current chart. + --publish-release To modify the charts for a release. + +Examples: + $(basename "$0") --branch release/x.y +EOF +} + +check_tag_is_valid() { + local tag="$1" + local current_chart_version="$2" + + if [[ "$(semver validate $tag)" != "valid" ]]; then + die "Tag is not a valid sevmer complaint version" + fi + + if [[ $current_chart_version != *"-prerelease" ]]; then + die "Chart version($current_chart_version) should be a prerelease format to proceed for tag creation flow" + fi + + allowed_diff=("" "patch" "prerelease") + diff="$(semver diff "$tag" "$current_chart_version")" + if ! [[ " ${allowed_diff[*]} " =~ " $diff " ]]; then + die "For release/x.y branch the current chart version($current_chart_version)'s X.Y must exactly match X.Y from tag ($tag)" + fi +} + +# yq-go eats up blank lines +# this function gets around that using diff with --ignore-blank-lines +yq_ibl() +{ + set +e + diff_out=$(diff -B <(yq '.' "$2") <(yq "$1" "$2")) + error=$? + if [ "$error" != "0" ] && [ "$error" != "1" ]; then + exit "$error" + fi + if [ -n "$diff_out" ]; then + echo "$diff_out" | patch --quiet --no-backup-if-mismatch "$2" - + fi + set -euo pipefail +} + +# RULES: This would run only when changes are pushed to a release/x.y branch. +# 1. Branch name can only be of format release/x.y +# 2. If current chart version of type develop(on branch creation), +# then version generated is of format x.y.0-prerelease if type is "release" +# 3. If current chart version of type develop(on branch creation), +# then version generated is of format x.y+1.0-develop if type is develop. +# 4. If current chart version of type prerelease(after branch creation), +# then for type release it's a no op as it's already a prerelease format. +# 5. If current chart version of type prerelease(after branch creation), +# then for type develop it's a no op as the version to be would be same as it is currently. +# 6. Let's say for somereason someone tries to create a release/x.y branch from develop but chart version +# on develop is newer than x.y, example, release/2.2 and develop chart version is 2.5.0-develop. +# In that case for type release, the version would be 2.2.0-prerelease and for type develop it would be +# a no op as develop is already newer. +create_version_from_release_branch() { + if [[ "$BRANCH_NAME" =~ ^(release/[0-9]+\.[0-9]+)$ ]]; then + local EXTRACTED_VERSION=$(echo "$BRANCH_NAME" | grep -oP '(?<=release/)\d+\.\d+') + if [[ "$TYPE" == "release" ]]; then + if [[ "$CURRENT_CHART_VERSION" == *"-develop" ]]; then + VERSION="${EXTRACTED_VERSION}.0-prerelease" + elif [[ "$CURRENT_CHART_VERSION" == *"-prerelease" ]]; then + NO_OP=1 + else + die "Current chart version doesn't match a develop or prerel format" + fi + elif [[ "$TYPE" == "develop" ]]; then + EXPECTED_VERSION="$(semver bump minor "$EXTRACTED_VERSION.0")-develop" + if [[ "$(semver compare $EXPECTED_VERSION $CURRENT_CHART_VERSION)" == 1 ]]; then + VERSION=$EXPECTED_VERSION + else + NO_OP=1 + fi + fi + else + die "Branch name($BRANCH_NAME) is not of format release/x.y" + fi +} + +# RULES: This would run only when tag is created. +# 1. Tag should be of format vX.Y.Z. +# 2. If tag is of format vX.Y.Z-rc, it would be a no op for the workflow. +# 3. The tag can only be vX.Y.Z if the current chart version is X.Y*-prerelease. Ex, v2.6.1 for v2.6.*-prerelease +# 4. For release branches if all the above holds then it bumps the patch version. Ex, v2.6.1 --> 2.6.2-prerelease +create_version_from_tag() { + if [[ "$TAG" =~ ^(v[0-9]+\.[0-9]+\.[0-9]+)$ ]]; then + local EXTRACTED_VERSION=$(echo "$TAG" | grep -oP '(?<=v)\d+\.\d+.\d+') + check_tag_is_valid "$EXTRACTED_VERSION" "$CURRENT_CHART_VERSION" + if [[ -z $PUBLISH_RELEASE ]]; then + VERSION="$(semver bump patch $EXTRACTED_VERSION)-prerelease" + if [[ -z $DRY_RUN ]]; then + echo "release/$(echo $EXTRACTED_VERSION | cut -d'.' -f1,2)" + fi + else + VERSION="$EXTRACTED_VERSION" + fi + elif [[ "$TAG" == *"-rc" ]]; then + if [[ -z $PUBLISH_RELEASE ]]; then + NO_OP=1 + else + local EXTRACTED_VERSION=$(echo "$TAG" | grep -oP '(?<=v)\d+\.\d+\.\d+(-\w+)?') + check_tag_is_valid "$EXTRACTED_VERSION" "$CURRENT_CHART_VERSION" + VERSION="$EXTRACTED_VERSION" + fi + else + die "Invalid tag format. Expected 'vX.Y.Z'" + fi +} + +update_chart_yaml() { + local VERSION=$1 + local APP_VERSION=$2 + + yq_ibl ".version = \"$VERSION\" | .appVersion = \"$APP_VERSION\"" "$CHART_YAML" + yq_ibl ".localpv.image.tag = \"$VERSION\"" "$VALUES_YAML" +} + +set -euo pipefail + +DRY_RUN= +NO_OP= +CURRENT_CHART_VERSION= +PUBLISH_RELEASE= +# 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" +VALUES_YAML="$CHART_DIR/values.yaml" + +# Final computed version to be set in this. +VERSION="" + +# Parse arguments +while [ "$#" -gt 0 ]; do + case $1 in + -d|--dry-run) + DRY_RUN=1 + shift + ;; + -h|--help) + help + exit 0 + ;; + -b|--branch) + shift + BRANCH_NAME=$1 + shift + ;; + -t|--tag) + shift + TAG=$1 + shift + ;; + --type) + shift + TYPE=$1 + shift + ;; + --chart-version) + shift + CURRENT_CHART_VERSION=$1 + shift + ;; + --publish-release) + PUBLISH_RELEASE=1 + shift + ;; + *) + help + die "Unknown option: $1" + ;; + esac +done + +if [[ -z $CURRENT_CHART_VERSION ]]; then + CURRENT_CHART_VERSION=$(yq e '.version' "$CHART_YAML") +fi + +if [[ -n "${BRANCH_NAME-}" && -n "${TYPE-}" ]]; then + create_version_from_release_branch +elif [[ -n "${TAG-}" ]]; then + create_version_from_tag +else + help + die "Either --branch and --type or --tag and must be specified." +fi + +if [[ -z $NO_OP ]]; then + if [[ -n $VERSION ]]; then + if [[ -z $DRY_RUN ]];then + update_chart_yaml "$VERSION" "$VERSION" + else + echo "$VERSION" + fi + else + die "Failed to update the chart versions" + fi +fi \ No newline at end of file diff --git a/scripts/validate-chart-version.sh b/scripts/validate-chart-version.sh new file mode 100644 index 00000000..c21fba8e --- /dev/null +++ b/scripts/validate-chart-version.sh @@ -0,0 +1,103 @@ +#!/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 < 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 diff --git a/shell.nix b/shell.nix index 54f411c0..c92c800c 100644 --- a/shell.nix +++ b/shell.nix @@ -9,4 +9,4 @@ pkgs.mkShell { yq-go chart-testing ]; -} \ No newline at end of file +}