diff --git a/.github/workflows/chart-lint-test.yml b/.github/workflows/chart-lint-test.yml deleted file mode 100644 index 94e438686..000000000 --- a/.github/workflows/chart-lint-test.yml +++ /dev/null @@ -1,53 +0,0 @@ -name: Chart Lint and Test - -on: - push: - paths: - - 'deploy/helm/**' - branches: - - develop - pull_request: - paths: - - 'deploy/helm/**' - branches: - - develop - -jobs: - lint-test: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Set up Helm - uses: azure/setup-helm@v4 - with: - version: v3.14.3 - - - uses: actions/setup-python@v5 - with: - python-version: '3.10' - check-latest: true - - - name: Set up chart-testing - uses: helm/chart-testing-action@v2.6.1 - - - name: Run chart-testing (list-changed) - id: list-changed - run: | - changed=$(ct list-changed --config ct.yaml) - if [[ -n "$changed" ]]; then - echo "changed=true" >> $GITHUB_OUTPUT - fi - - - name: Run chart-testing (lint) - run: ct lint --config ct.yaml - - - name: Create kind cluster - uses: helm/kind-action@v1.9.0 - if: steps.list-changed.outputs.changed == 'true' - - - name: Run chart-testing (install) - run: ct install --config ct.yaml diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 48ec98f92..b3b6a35ba 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -1,31 +1,16 @@ -# 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: paths-ignore: - - 'deploy/helm/**' - 'docs/**' - 'design/**' - 'changelogs/**' - '*.md' + - 'MAINTAINERS' branches: - # on pull requests to develop and release branches - develop - - 'v*' + - 'release/**' jobs: lint: @@ -33,6 +18,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Shellcheck uses: reviewdog/action-shellcheck@v1 @@ -41,9 +28,21 @@ jobs: reporter: github-pr-review path: '.' pattern: '*.sh' + + - uses: cachix/install-nix-action@v22 + - uses: rrbutani/use-nix-shell-action@v1.1.0 + 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-test: + unit-tests: runs-on: ubuntu-latest steps: - name: Checkout @@ -60,9 +59,9 @@ jobs: name: coverage-$(date +%s) flags: unittests - bdd-test: - needs: ['unit-test'] + bdd-tests: runs-on: ubuntu-latest + needs: ['unit-tests'] strategy: fail-fast: true matrix: @@ -71,12 +70,10 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Installation - run: | - sudo apt-get update -qq - sudo apt-get install -y zfsutils-linux - truncate -s 100G /tmp/disk.img - sudo zpool create zfspv-pool `sudo losetup -f /tmp/disk.img --show` + - uses: cachix/install-nix-action@v22 + - uses: rrbutani/use-nix-shell-action@v1.1.0 + with: + file: shell.nix - name: Set up Go 1.19 uses: actions/setup-go@v4 @@ -84,6 +81,15 @@ jobs: go-version: 1.19.9 cache: false + - name: Build images locally + run: make zfs-driver-image || exit 1; + + - name: Setup zfs pools + run: | + sudo apt-get install zfsutils-linux -y + truncate -s 100G /tmp/disk.img + sudo zpool create zfspv-pool $(sudo losetup -f /tmp/disk.img --show) + - name: Setup Minikube-Kubernetes uses: medyagh/setup-minikube@latest with: @@ -99,9 +105,6 @@ jobs: echo "KUBECONFIG=$HOME/.kube/config" >> $GITHUB_ENV echo "OPENEBS_NAMESPACE=openebs" >> $GITHUB_ENV - - name: Build images locally - run: make zfs-driver-image || exit 1; - - name: bootstrap run: make bootstrap @@ -120,7 +123,7 @@ jobs: csi-driver: runs-on: ubuntu-latest - needs: ['lint', 'bdd-test'] + needs: ['lint', 'bdd-tests'] steps: - name: Checkout uses: actions/checkout@v4 @@ -133,8 +136,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 @@ -143,6 +144,3 @@ jobs: file: ./buildscripts/zfs-driver/zfs-driver.Dockerfile push: false platforms: linux/amd64, linux/arm64 - tags: | - openebs/zfs-driver:ci - diff --git a/.github/workflows/release-charts.yml b/.github/workflows/release-charts.yml index 9ab123cd9..a90a61ec5 100644 --- a/.github/workflows/release-charts.yml +++ b/.github/workflows/release-charts.yml @@ -1,11 +1,12 @@ name: Release Charts -on: - push: - paths: - - 'deploy/helm/**' - branches: - - develop +# Disable the workflow till we have the proper CI setup +# on: +# push: +# paths: +# - 'deploy/helm/**' +# branches: +# - develop jobs: release: diff --git a/.gitignore b/.gitignore index c095246ea..f7a3fb154 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ tags *.swo *.swn *.idea +*.test \ No newline at end of file diff --git a/Makefile b/Makefile index c7e59caaa..00e5ed44e 100644 --- a/Makefile +++ b/Makefile @@ -53,8 +53,12 @@ ifeq (${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 diff --git a/ci/ci-test.sh b/ci/ci-test.sh index 024c68a63..c8cba6a89 100755 --- a/ci/ci-test.sh +++ b/ci/ci-test.sh @@ -1,58 +1,42 @@ #!/usr/bin/env bash -# Copyright 2019 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 -ZFS_OPERATOR=deploy/zfs-operator.yaml SNAP_CLASS=deploy/sample/zfssnapclass.yaml - TEST_DIR="tests" - -# Prepare env for runnging BDD tests +# Prepare env for running BDD tests # Minikube is already running -kubectl apply -f $ZFS_OPERATOR -kubectl apply -f $SNAP_CLASS +helm install zfs-localpv ./deploy/helm/charts -n "$OPENEBS_NAMESPACE" --create-namespace --set zfsPlugin.pullPolicy=Never --set analytics.enabled=false +kubectl apply -f "$SNAP_CLASS" dumpAgentLogs() { NR=$1 - AgentPOD=$(kubectl get pods -l app=openebs-zfs-node -o jsonpath='{.items[0].metadata.name}' -n kube-system) - kubectl describe po $AgentPOD -n kube-system + AgentPOD=$(kubectl get pods -l app=openebs-zfs-node -o jsonpath='{.items[0].metadata.name}' -n openebs) + kubectl describe po "$AgentPOD" -n openebs printf "\n\n" - kubectl logs --tail=${NR} $AgentPOD -n kube-system -c openebs-zfs-plugin + kubectl logs --tail="${NR}" "$AgentPOD" -n openebs -c openebs-zfs-plugin printf "\n\n" } dumpControllerLogs() { NR=$1 - ControllerPOD=$(kubectl get pods -l app=openebs-zfs-controller -o jsonpath='{.items[0].metadata.name}' -n kube-system) - kubectl describe po $ControllerPOD -n kube-system + ControllerPOD=$(kubectl get pods -l app=openebs-zfs-controller -o jsonpath='{.items[0].metadata.name}' -n openebs) + kubectl describe po "$ControllerPOD" -n openebs printf "\n\n" - kubectl logs --tail=${NR} $ControllerPOD -n kube-system -c openebs-zfs-plugin + kubectl logs --tail="${NR}" "$ControllerPOD" -n openebs -c openebs-zfs-plugin printf "\n\n" } isPodReady(){ - [ "$(kubectl get po "$1" -o 'jsonpath={.status.conditions[?(@.type=="Ready")].status}' -n kube-system)" = 'True' ] + [ "$(kubectl get po "$1" -o 'jsonpath={.status.conditions[?(@.type=="Ready")].status}' -n openebs)" = 'True' ] } isDriverReady(){ for pod in $zfsDriver;do - isPodReady $pod || return 1 + isPodReady "$pod" || return 1 done } @@ -63,8 +47,8 @@ waitForZFSDriver() { i=0 while [ "$i" -le "$period" ]; do - zfsDriver="$(kubectl get pods -l role=openebs-zfs -o 'jsonpath={.items[*].metadata.name}' -n kube-system)" - if isDriverReady $zfsDriver; then + zfsDriver="$(kubectl get pods -l role=openebs-zfs -o 'jsonpath={.items[*].metadata.name}' -n openebs)" + if isDriverReady "$zfsDriver"; then return 0 fi @@ -82,7 +66,7 @@ waitForZFSDriver cd $TEST_DIR -kubectl get po -n kube-system +kubectl get po -n openebs set +e @@ -123,4 +107,5 @@ kubectl get zfssnapshots.zfs.openebs.io -n openebs -oyaml exit 1 fi -echo "\n\n######### All test cases passed #########\n\n" +printf "\n\n" +echo "######### All test cases passed #########" diff --git a/ci/sanity.sh b/ci/sanity.sh index 5c47837e1..ae505f34a 100755 --- a/ci/sanity.sh +++ b/ci/sanity.sh @@ -1,37 +1,23 @@ #!/bin/bash -# Copyright 2020 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 -ex test_repo="kubernetes-csi" dumpAgentLogs() { NR=$1 - AgentPOD=$(kubectl get pods -l app=openebs-zfs-node -o jsonpath='{.items[0].metadata.name}' -n kube-system) - kubectl describe po "$AgentPOD" -n kube-system + AgentPOD=$(kubectl get pods -l app=openebs-zfs-node -o jsonpath='{.items[0].metadata.name}' -n openebs) + kubectl describe po "$AgentPOD" -n openebs printf "\n\n" - kubectl logs --tail="${NR}" "$AgentPOD" -n kube-system -c openebs-zfs-plugin + kubectl logs --tail="${NR}" "$AgentPOD" -n openebs -c openebs-zfs-plugin printf "\n\n" } dumpControllerLogs() { NR=$1 - ControllerPOD=$(kubectl get pods -l app=openebs-zfs-controller -o jsonpath='{.items[0].metadata.name}' -n kube-system) - kubectl describe po "$ControllerPOD" -n kube-system + ControllerPOD=$(kubectl get pods -l app=openebs-zfs-controller -o jsonpath='{.items[0].metadata.name}' -n openebs) + kubectl describe po "$ControllerPOD" -n openebs printf "\n\n" - kubectl logs --tail="${NR}" "$ControllerPOD" -n kube-system -c openebs-zfs-plugin + kubectl logs --tail="${NR}" "$ControllerPOD" -n openebs -c openebs-zfs-plugin printf "\n\n" } @@ -66,7 +52,7 @@ EOT make clean make - UUID=$(kubectl get pod -n kube-system -l "openebs.io/component-name=openebs-zfs-controller" -o 'jsonpath={.items[0].metadata.uid}') + UUID=$(kubectl get pod -n openebs -l "openebs.io/component-name=openebs-zfs-controller" -o 'jsonpath={.items[0].metadata.uid}') SOCK_PATH=/var/lib/kubelet/pods/"$UUID"/volumes/kubernetes.io~empty-dir/socket-dir/csi.sock sudo chmod -R 777 /var/lib/kubelet diff --git a/ct.yaml b/ct.yaml index 91f9bd031..a646494ff 100644 --- a/ct.yaml +++ b/ct.yaml @@ -4,4 +4,5 @@ target-branch: develop chart-dirs: - deploy/helm helm-extra-args: --timeout=500s -validate-maintainers: false \ No newline at end of file +validate-maintainers: false +check-version-increment: false diff --git a/deploy/helm/charts/Chart.yaml b/deploy/helm/charts/Chart.yaml index 208e134bd..f27acaee8 100644 --- a/deploy/helm/charts/Chart.yaml +++ b/deploy/helm/charts/Chart.yaml @@ -1,8 +1,8 @@ apiVersion: v2 name: zfs-localpv description: Helm chart for CSI Driver for dynamic provisioning of ZFS Persistent Local Volumes. For instructions on how to use this helm chart, see - https://openebs.github.io/zfs-localpv/ -version: 2.6.0 -appVersion: 2.6.0 +version: 2.7.0-develop +appVersion: 2.7.0-develop icon: https://raw.githubusercontent.com/cncf/artwork/master/projects/openebs/icon/color/openebs-icon-color.png home: https://openebs.io/ keywords: @@ -16,5 +16,5 @@ sources: - https://github.com/openebs/zfs-localpv dependencies: - name: crds - version: 2.6.0 + version: 2.7.0-develop condition: crds.enabled diff --git a/deploy/helm/charts/README.md b/deploy/helm/charts/README.md index 56c5e0113..409f589d2 100644 --- a/deploy/helm/charts/README.md +++ b/deploy/helm/charts/README.md @@ -69,7 +69,7 @@ The following table lists the configurable parameters of the OpenEBS ZFS Localpv | `zfsPlugin.image.registry`| Registry for openebs-zfs-plugin image| `""`| | `zfsPlugin.image.repository`| Image repository for openebs-zfs-plugin| `openebs/zfs-driver`| | `zfsPlugin.image.pullPolicy`| Image pull policy for openebs-zfs-plugin| `IfNotPresent`| -| `zfsPlugin.image.tag`| Image tag for openebs-zfs-plugin| `2.6.0`| +| `zfsPlugin.image.tag`| Image tag for openebs-zfs-plugin| `2.7.0-develop`| | `zfsNode.allowedTopologyKeys`| Custom topology keys required for provisioning| `"kubernetes.io/hostname,"`| | `zfsNode.driverRegistrar.image.registry`| Registry for csi-node-driver-registrar image| `registry.k8s.io/`| | `zfsNode.driverRegistrar.image.repository`| Image repository for csi-node-driver-registrar| `sig-storage/csi-node-driver-registrar`| diff --git a/deploy/helm/charts/charts/crds/Chart.yaml b/deploy/helm/charts/charts/crds/Chart.yaml index 7fec42129..a26a92fd6 100644 --- a/deploy/helm/charts/charts/crds/Chart.yaml +++ b/deploy/helm/charts/charts/crds/Chart.yaml @@ -1,4 +1,4 @@ apiVersion: v2 name: crds -version: 2.6.0 +version: 2.7.0-develop description: A Helm chart that collects CustomResourceDefinitions (CRDs) from zfs-localpv. diff --git a/deploy/helm/charts/templates/_helpers.tpl b/deploy/helm/charts/templates/_helpers.tpl index 66b8dcfab..95b4443c4 100644 --- a/deploy/helm/charts/templates/_helpers.tpl +++ b/deploy/helm/charts/templates/_helpers.tpl @@ -60,7 +60,7 @@ Define meta labels for openebs zfs-localpv components {{- define "zfslocalpv.common.metaLabels" -}} chart: {{ template "zfslocalpv.chart" . }} heritage: {{ .Release.Service }} -openebs.io/version: {{ .Values.release.version | quote }} +openebs.io/version: {{ .Chart.AppVersion | quote }} role: {{ .Values.role | quote }} {{- end -}} diff --git a/deploy/helm/charts/values.yaml b/deploy/helm/charts/values.yaml index 7dc0f5ef1..9e561f6ca 100644 --- a/deploy/helm/charts/values.yaml +++ b/deploy/helm/charts/values.yaml @@ -1,9 +1,6 @@ # Default values for openebs-zfslocalpv. # This is a YAML-formatted file. # Declare variables to be passed into your templates. -release: - version: "2.6.0" - imagePullSecrets: # - name: "image-pull-secret" @@ -146,7 +143,7 @@ zfsPlugin: repository: openebs/zfs-driver pullPolicy: IfNotPresent # Overrides the image tag whose default is the chart appVersion. - tag: 2.6.0 + tag: 2.7.0-develop role: openebs-zfs diff --git a/nix/sources.json b/nix/sources.json new file mode 100644 index 000000000..9faedce33 --- /dev/null +++ b/nix/sources.json @@ -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///archive/.tar.gz" + } +} diff --git a/nix/sources.nix b/nix/sources.nix new file mode 100644 index 000000000..fe3dadf7e --- /dev/null +++ b/nix/sources.nix @@ -0,0 +1,198 @@ +# This file has been generated by Niv. + +let + + # + # The fetchers. fetch_ fetches specs of type . + # + + fetch_file = pkgs: name: spec: + let + name' = sanitizeName name + "-src"; + in + if spec.builtin or true then + builtins_fetchurl { inherit (spec) url sha256; name = name'; } + else + pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; + + fetch_tarball = pkgs: name: spec: + let + name' = sanitizeName name + "-src"; + in + if spec.builtin or true then + builtins_fetchTarball { name = name'; inherit (spec) url sha256; } + else + pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; + + fetch_git = name: spec: + let + ref = + spec.ref or ( + if spec ? branch then "refs/heads/${spec.branch}" else + if spec ? tag then "refs/tags/${spec.tag}" else + abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!" + ); + submodules = spec.submodules or false; + submoduleArg = + let + nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0; + emptyArgWithWarning = + if submodules + then + builtins.trace + ( + "The niv input \"${name}\" uses submodules " + + "but your nix's (${builtins.nixVersion}) builtins.fetchGit " + + "does not support them" + ) + { } + else { }; + in + if nixSupportsSubmodules + then { inherit submodules; } + else emptyArgWithWarning; + in + builtins.fetchGit + ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); + + fetch_local = spec: spec.path; + + fetch_builtin-tarball = name: throw + ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=tarball -a builtin=true''; + + fetch_builtin-url = name: throw + ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=file -a builtin=true''; + + # + # Various helpers + # + + # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695 + sanitizeName = name: + ( + concatMapStrings (s: if builtins.isList s then "-" else s) + ( + builtins.split "[^[:alnum:]+._?=-]+" + ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name) + ) + ); + + # The set of packages used when specs are fetched using non-builtins. + mkPkgs = sources: system: + let + sourcesNixpkgs = + import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; }; + hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; + hasThisAsNixpkgsPath = == ./.; + in + if builtins.hasAttr "nixpkgs" sources + then sourcesNixpkgs + else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then + import { } + else + abort + '' + Please specify either (through -I or NIX_PATH=nixpkgs=...) or + add a package called "nixpkgs" to your sources.json. + ''; + + # The actual fetching function. + fetch = pkgs: name: spec: + + if ! builtins.hasAttr "type" spec then + abort "ERROR: niv spec ${name} does not have a 'type' attribute" + else if spec.type == "file" then fetch_file pkgs name spec + else if spec.type == "tarball" then fetch_tarball pkgs name spec + else if spec.type == "git" then fetch_git name spec + else if spec.type == "local" then fetch_local spec + else if spec.type == "builtin-tarball" then fetch_builtin-tarball name + else if spec.type == "builtin-url" then fetch_builtin-url name + else + abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; + + # If the environment variable NIV_OVERRIDE_${name} is set, then use + # the path directly as opposed to the fetched source. + replace = name: drv: + let + saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; + ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; + in + if ersatz == "" then drv else + # this turns the string into an actual Nix path (for both absolute and + # relative paths) + if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; + + # Ports of functions for older nix versions + + # a Nix version of mapAttrs if the built-in doesn't exist + mapAttrs = builtins.mapAttrs or ( + f: set: with builtins; + listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) + ); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 + range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 + stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 + stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); + concatMapStrings = f: list: concatStrings (map f list); + concatStrings = builtins.concatStringsSep ""; + + # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 + optionalAttrs = cond: as: if cond then as else { }; + + # fetchTarball version that is compatible between all the versions of Nix + builtins_fetchTarball = { url, name ? null, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchTarball; + in + if lessThan nixVersion "1.12" then + fetchTarball ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchTarball attrs; + + # fetchurl version that is compatible between all the versions of Nix + builtins_fetchurl = { url, name ? null, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchurl; + in + if lessThan nixVersion "1.12" then + fetchurl ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchurl attrs; + + # Create the final "sources" from the config + mkSources = config: + mapAttrs + ( + name: spec: + if builtins.hasAttr "outPath" spec + then + abort + "The values in sources.json should not have an 'outPath' attribute" + else + spec // { outPath = replace name (fetch config.pkgs name spec); } + ) + config.sources; + + # The "config" used by the fetchers + mkConfig = + { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null + , sources ? if sourcesFile == null then { } else builtins.fromJSON (builtins.readFile sourcesFile) + , system ? builtins.currentSystem + , pkgs ? mkPkgs sources system + }: rec { + # The sources, i.e. the attribute set of spec name to spec + inherit sources; + + # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers + inherit pkgs; + }; + +in +mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/scripts/validate-chart-version.sh b/scripts/validate-chart-version.sh new file mode 100755 index 000000000..c21fba8e6 --- /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 new file mode 100644 index 000000000..c92c800cc --- /dev/null +++ b/shell.nix @@ -0,0 +1,12 @@ +let + sources = import ./nix/sources.nix; + pkgs = import sources.nixpkgs {}; +in +pkgs.mkShell { + name = "scripts-shell"; + buildInputs = with pkgs; [ + semver-tool + yq-go + chart-testing + ]; +} diff --git a/tests/tests.test b/tests/tests.test deleted file mode 100755 index ea1dff21a..000000000 Binary files a/tests/tests.test and /dev/null differ