diff --git a/.github/workflows/chart-push-release.yaml b/.github/workflows/chart-push-release.yaml new file mode 100644 index 0000000..a5db450 --- /dev/null +++ b/.github/workflows/chart-push-release.yaml @@ -0,0 +1,33 @@ +name: "Push helm chart on release" + +env: + IMAGE_NAME: ghcr.io/${{ github.repository }} + +on: + push: + tags: + - v* +jobs: + package-and-push-helm-chart: + runs-on: ubuntu-22.04 + steps: + - name: install helm + uses: azure/setup-helm@v4.2.0 + with: + version: latest + + - name: Check out the repo + uses: actions/checkout@v4 + + - name: update chart + env: + GITHUB_TAG: ${{ github.ref_name }} + GITHUB_REPO_OWNER: ${{ github.repository_owner }} + run: make chart-prepare-release + + - name: push chart + env: + GITHUB_TAG: ${{ github.ref_name }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_REPO_OWNER: ${{ github.repository_owner }} + run: make chart-push-release \ No newline at end of file diff --git a/Makefile b/Makefile index 3197654..978e822 100644 --- a/Makefile +++ b/Makefile @@ -273,6 +273,14 @@ catalog-build: opm ## Build a catalog image. catalog-push: ## Push a catalog image. $(MAKE) docker-push IMG=$(CATALOG_IMG) +.PHONY: chart-prepare-release +chart-prepare-release: | $(YQ) ; ## prepare helm chart for release + @GITHUB_TAG=$(GITHUB_TAG) GITHUB_REPO_OWNER=$(GITHUB_REPO_OWNER) hack/release/chart-update.sh + +.PHONY: chart-push-release +chart-push-release: | $(HELM) ## push release helm chart + @GITHUB_TAG=$(GITHUB_TAG) GITHUB_TOKEN=$(GITHUB_TOKEN) GITHUB_REPO_OWNER=$(GITHUB_REPO_OWNER) hack/release/chart-push.sh + ##@ Binary Dependencies download MOCKERY ?= $(LOCALBIN)/mockery @@ -378,6 +386,13 @@ $(HELM): | $(LOCALBIN) rm -f $(LOCALBIN)/get_helm.sh; \ } +YQ := $(abspath $(LOCALBIN)/yq) +YQ_VERSION=v4.44.1 +.PHONY: yq +yq: $(YQ) ## Download yq locally if necessary. +$(YQ): | $(LOCALBIN) + @curl -fsSL -o $(YQ) https://github.com/mikefarah/yq/releases/download/$(YQ_VERSION)/yq_linux_amd64 && chmod +x $(YQ) + ##@ Dev TEST_CLUSTER_NAME = mn-op diff --git a/hack/release/chart-push.sh b/hack/release/chart-push.sh new file mode 100644 index 0000000..9eb3105 --- /dev/null +++ b/hack/release/chart-push.sh @@ -0,0 +1,34 @@ +#!/bin/bash +set -ex + +# github repo owner: e.g mellanox +GITHUB_REPO_OWNER=${GITHUB_REPO_OWNER:-} +# github api token with package:write permissions +GITHUB_TOKEN=${GITHUB_TOKEN:-} +# github tag e.g v1.2.3 +GITHUB_TAG=${GITHUB_TAG:-} + +BASE=${PWD} +HELM_CMD="${BASE}/bin/helm" +HELM_CHART=${BASE}/deployment/maintenance-operator-chart +HELM_CHART_VERSION=${GITHUB_TAG#"v"} +HELM_CHART_TARBALL="maintenance-operator-chart-${HELM_CHART_VERSION}.tgz" + +if [ -z "$GITHUB_REPO_OWNER" ]; then + echo "ERROR: GITHUB_REPO_OWNER must be provided as env var" + exit 1 +fi + +if [ -z "$GITHUB_TOKEN" ]; then + echo "ERROR: GITHUB_TOKEN must be provided as env var" + exit 1 +fi + +if [ -z "$GITHUB_TAG" ]; then + echo "ERROR: GITHUB_TAG must be provided as env var" + exit 1 +fi + +$HELM_CMD package ${HELM_CHART} +$HELM_CMD registry login ghcr.io -u ${GITHUB_REPO_OWNER} -p ${GITHUB_TOKEN} +$HELM_CMD push ${HELM_CHART_TARBALL} oci://ghcr.io/${GITHUB_REPO_OWNER} diff --git a/hack/release/chart-update.sh b/hack/release/chart-update.sh new file mode 100644 index 0000000..20d266e --- /dev/null +++ b/hack/release/chart-update.sh @@ -0,0 +1,37 @@ +#!/bin/bash +set -ex + +# github tag e.g v1.2.3 +GITHUB_TAG=${GITHUB_TAG:-} +# github repo owner e.g mellanox +GITHUB_REPO_OWNER=${GITHUB_REPO_OWNER:-} + +BASE=${PWD} +YQ_CMD="${BASE}/bin/yq" +HELM_VALUES=${BASE}/deployment/maintenance-opeator-chart/values.yaml +HELM_CHART=${BASE}/deployment/maintenance-opeator-chart/Chart.yaml + + +if [ -z "$GITHUB_TAG" ]; then + echo "ERROR: GITHUB_TAG must be provided as env var" + exit 1 +fi + +if [ -z "$GITHUB_REPO_OWNER" ]; then + echo "ERROR: GITHUB_REPO_OWNER must be provided as env var" + exit 1 +fi + +# tag provided via env var +OPERATOR_TAG=${GITHUB_TAG} + +# patch values.yaml in-place + +# maintenance-operator image: +OPERATOR_REPO=${GITHUB_REPO_OWNER} # this is used to allow to release maintenance-operator from forks +$YQ_CMD -i ".operator.image.repository = \"ghcr.io/${OPERATOR_REPO}/maintenance-operator\"" ${HELM_VALUES} +$YQ_CMD -i ".operator.image.tag = \"${OPERATOR_TAG}\"" ${HELM_VALUES} + +# patch Chart.yaml in-place +$YQ_CMD -i ".version = \"${OPERATOR_TAG#"v"}\"" ${HELM_CHART} +$YQ_CMD -i ".appVersion = \"${OPERATOR_TAG}\"" ${HELM_CHART}