From 29a97fa09db6191c9df42662d6f264dd38726bc0 Mon Sep 17 00:00:00 2001 From: itaydj Date: Sun, 1 Mar 2026 12:11:32 +0200 Subject: [PATCH 1/3] created a build and publish pipeline --- .github/workflows/pr-version-check.yml | 148 +++++++++++++++++++++++++ .github/workflows/release.yml | 50 ++++++++- 2 files changed, 192 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/pr-version-check.yml diff --git a/.github/workflows/pr-version-check.yml b/.github/workflows/pr-version-check.yml new file mode 100644 index 0000000..95d665b --- /dev/null +++ b/.github/workflows/pr-version-check.yml @@ -0,0 +1,148 @@ +name: PR Version Check + +on: + pull_request: + branches: + - main + types: [opened, synchronize, reopened, ready_for_review] + +permissions: + contents: read + pull-requests: write + +jobs: + check_version_bump: + runs-on: ubuntu-latest + steps: + - name: Checkout PR branch + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Auth GH CLI + run: gh auth setup-git + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Check Chart.yaml version bump + id: version_check + run: | + set -euo pipefail + + # Get current version from PR's Chart.yaml + if [ ! -f "Chart.yaml" ]; then + echo "❌ Chart.yaml not found" + exit 1 + fi + + pr_version=$(grep '^version:' Chart.yaml | awk '{print $2}') + echo "📄 PR Chart.yaml version: $pr_version" + + # Get latest release/tag version + latest_tag=$(gh api repos/${{ github.repository }}/tags --jq '.[0].name' 2>/dev/null || echo "") + + if [ -z "$latest_tag" ]; then + echo "â„šī¸ No existing releases found" + echo "✅ This will be the first release with version: $pr_version" + echo "status=success" >> $GITHUB_OUTPUT + echo "message=✅ First release - version $pr_version will be used" >> $GITHUB_OUTPUT + exit 0 + fi + + # Remove 'v' prefix and chart name prefix if present + # Handles both "v0.1.32" and "webrix-postgres-0.1.32" formats + latest_version=$(echo "$latest_tag" | sed -E 's/^v//;s/^[a-zA-Z-]+-//') + echo "đŸ“Ļ Latest release version: $latest_version" + + # Compare versions + if [ "$pr_version" = "$latest_version" ]; then + echo "❌ Version not bumped!" + echo "status=failure" >> $GITHUB_OUTPUT + echo "message=❌ Chart.yaml version ($pr_version) must be bumped from latest release ($latest_version)" >> $GITHUB_OUTPUT + exit 1 + fi + + # Validate version is greater than latest + IFS='.' read -r pr_major pr_minor pr_patch <<< "$pr_version" + IFS='.' read -r latest_major latest_minor latest_patch <<< "$latest_version" + + # Remove any non-numeric suffixes (e.g., -alpha, -beta) + pr_major=${pr_major%%[^0-9]*} + pr_minor=${pr_minor%%[^0-9]*} + pr_patch=${pr_patch%%[^0-9]*} + latest_major=${latest_major%%[^0-9]*} + latest_minor=${latest_minor%%[^0-9]*} + latest_patch=${latest_patch%%[^0-9]*} + + version_greater=false + + if [ "$pr_major" -gt "$latest_major" ]; then + version_greater=true + bump_type="major" + elif [ "$pr_major" -eq "$latest_major" ] && [ "$pr_minor" -gt "$latest_minor" ]; then + version_greater=true + bump_type="minor" + elif [ "$pr_major" -eq "$latest_major" ] && [ "$pr_minor" -eq "$latest_minor" ] && [ "$pr_patch" -gt "$latest_patch" ]; then + version_greater=true + bump_type="patch" + fi + + if [ "$version_greater" = false ]; then + echo "❌ Version is not greater than latest release!" + echo "status=failure" >> $GITHUB_OUTPUT + echo "message=❌ Chart.yaml version ($pr_version) must be greater than latest release ($latest_version)" >> $GITHUB_OUTPUT + exit 1 + fi + + echo "✅ Version bump detected: $latest_version → $pr_version ($bump_type)" + echo "status=success" >> $GITHUB_OUTPUT + echo "message=✅ Version bumped: $latest_version → $pr_version ($bump_type)" >> $GITHUB_OUTPUT + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Comment on PR + if: always() && github.event_name == 'pull_request' + uses: actions/github-script@v7 + with: + script: | + const status = '${{ steps.version_check.outputs.status }}'; + const message = '${{ steps.version_check.outputs.message }}'; + + const commentBody = status === 'success' + ? `## ✅ Version Check Passed\n\n${message}\n\nThis PR can be merged.` + : `## ❌ Version Check Failed\n\n${message}\n\n### Required Action\n\nPlease update the \`version\` field in \`Chart.yaml\` to be greater than the latest release.\n\n**Tip**: Use semantic versioning:\n- **Patch** (x.y.Z): Bug fixes, small changes\n- **Minor** (x.Y.0): New features, backward compatible\n- **Major** (X.0.0): Breaking changes`; + + // Find existing bot comment + const { data: comments } = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + }); + + const botComment = comments.find(comment => + comment.user.type === 'Bot' && + comment.body.includes('Version Check') + ); + + // Update or create comment + if (botComment) { + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: botComment.id, + body: commentBody + }); + } else { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body: commentBody + }); + } + + - name: Set check status + if: steps.version_check.outputs.status == 'failure' + run: | + echo "::error::Chart.yaml version must be bumped before merging" + exit 1 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3acca92..a5063c5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -37,10 +37,10 @@ jobs: run: | chart_name=$(grep '^name:' Chart.yaml | awk '{print $2}') chart_version=$(grep '^version:' Chart.yaml | awk '{print $2}') - + echo "📋 Chart: $chart_name" echo "đŸ“Ļ Version: $chart_version" - + echo "name=$chart_name" >> $GITHUB_OUTPUT echo "version=$chart_version" >> $GITHUB_OUTPUT @@ -57,9 +57,16 @@ jobs: env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Helm Lint + - name: Build chart dependencies if: steps.check_release.outputs.exists == 'false' - run: helm lint . + run: | + echo "🔨 Building chart dependencies..." + if [ -f "Chart.lock" ]; then + helm dependency build + echo "✅ Dependencies built" + else + echo "â„šī¸ No dependencies to build" + fi - name: Package Helm chart if: steps.check_release.outputs.exists == 'false' @@ -68,6 +75,7 @@ jobs: mkdir -p .cr-release-packages helm package . --destination .cr-release-packages echo "✅ Chart packaged" + ls -lh .cr-release-packages/ - name: Create GitHub Release if: steps.check_release.outputs.exists == 'false' @@ -94,21 +102,30 @@ jobs: git add index.yaml git commit -m "Initialize gh-pages" fi + # Clean up the package directory from the previous branch + rm -rf .cr-release-packages - name: Update Helm repository index if: steps.check_release.outputs.exists == 'false' run: | echo "📝 Updating repository index..." + + # Download the packaged chart from the release mkdir -p .cr-release-packages gh release download "v${{ steps.chart_version.outputs.version }}" \ --pattern "*.tgz" \ --dir .cr-release-packages - + + # Move the chart to root for indexing (so URL doesn't include .cr-release-packages/) mv .cr-release-packages/*.tgz . + + # Generate/update index.yaml helm repo index . --url https://github.com/${{ github.repository }}/releases/download/v${{ steps.chart_version.outputs.version }} --merge index.yaml - + + # Clean up the .tgz file (we don't need it in gh-pages, it's in the GitHub release) rm -f *.tgz rm -rf .cr-release-packages + echo "✅ Index updated" env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -120,3 +137,24 @@ jobs: git commit -m "Update index for v${{ steps.chart_version.outputs.version }}" git push origin gh-pages echo "✅ Index pushed to gh-pages" + + - name: Release summary + run: | + if [ "${{ steps.check_release.outputs.exists }}" == "true" ]; then + echo "## â„šī¸ Release Already Exists" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "Version **v${{ steps.chart_version.outputs.version }}** was already released." >> $GITHUB_STEP_SUMMARY + else + echo "## 🎉 Helm Chart Released!" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "**Chart:** ${{ steps.chart_version.outputs.name }}" >> $GITHUB_STEP_SUMMARY + echo "**Version:** v${{ steps.chart_version.outputs.version }}" >> $GITHUB_STEP_SUMMARY + echo "**Repository:** https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "### đŸ“Ļ Installation" >> $GITHUB_STEP_SUMMARY + echo '```bash' >> $GITHUB_STEP_SUMMARY + echo "helm repo add ${{ steps.chart_version.outputs.name }} https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}" >> $GITHUB_STEP_SUMMARY + echo "helm repo update" >> $GITHUB_STEP_SUMMARY + echo "helm install my-release ${{ steps.chart_version.outputs.name }}/${{ steps.chart_version.outputs.name }}" >> $GITHUB_STEP_SUMMARY + echo '```' >> $GITHUB_STEP_SUMMARY + fi From 0911a5b79dfd966939311be2439a58294594edab Mon Sep 17 00:00:00 2001 From: itaydj Date: Sun, 1 Mar 2026 12:15:57 +0200 Subject: [PATCH 2/3] created a build and publish pipeline --- .github/workflows/release.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a5063c5..2b8b21c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -119,8 +119,12 @@ jobs: # Move the chart to root for indexing (so URL doesn't include .cr-release-packages/) mv .cr-release-packages/*.tgz . - # Generate/update index.yaml - helm repo index . --url https://github.com/${{ github.repository }}/releases/download/v${{ steps.chart_version.outputs.version }} --merge index.yaml + # Generate/update index.yaml (only use --merge if index.yaml is non-empty) + if [ -s index.yaml ]; then + helm repo index . --url https://github.com/${{ github.repository }}/releases/download/v${{ steps.chart_version.outputs.version }} --merge index.yaml + else + helm repo index . --url https://github.com/${{ github.repository }}/releases/download/v${{ steps.chart_version.outputs.version }} + fi # Clean up the .tgz file (we don't need it in gh-pages, it's in the GitHub release) rm -f *.tgz From 4ec704761097a32833c052f7a0fe7e758832eba5 Mon Sep 17 00:00:00 2001 From: itaydj Date: Mon, 2 Mar 2026 08:39:07 +0200 Subject: [PATCH 3/3] aligned service names with out current bitnami deployment --- templates/_helpers.tpl | 2 ++ templates/service.yaml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl index af9cf43..acc9ed1 100644 --- a/templates/_helpers.tpl +++ b/templates/_helpers.tpl @@ -16,6 +16,8 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this {{- $name := default .Chart.Name .Values.nameOverride }} {{- if contains $name .Release.Name }} {{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else if contains .Release.Name $name }} +{{- $name | trunc 63 | trimSuffix "-" }} {{- else }} {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} {{- end }} diff --git a/templates/service.yaml b/templates/service.yaml index f910b84..1eadc3c 100644 --- a/templates/service.yaml +++ b/templates/service.yaml @@ -2,7 +2,7 @@ apiVersion: v1 kind: Service metadata: - name: {{ include "postgresql.primary.svcName" . }} + name: {{ .Release.Name }}-postgresql namespace: {{ .Release.Namespace | quote }} labels: {{- include "postgresql.labels" . | nindent 4 }}