|
| 1 | +# List available commands |
| 2 | +[private] |
| 3 | +default: |
| 4 | + just --justfile {{justfile()}} --list chart |
| 5 | + |
| 6 | +# Publish the packaged chart to an OCI registry. |
| 7 | +# Registry URL is resolved in the script from env, not from Justfile interpolation. |
| 8 | +# Defaults to ghcr.io/<owner>/charts, which results in charts at ghcr.io/<owner>/charts/<chartname> |
| 9 | +publish registry="": |
| 10 | + #!/usr/bin/env bash |
| 11 | + set -e |
| 12 | + |
| 13 | + cd {{justfile_directory()}} |
| 14 | + |
| 15 | + echo "🔐 Logging in to Helm registry..." |
| 16 | + # Resolve full registry path: |
| 17 | + # 1. CLI arg: `just chart publish registry="ghcr.io/org/charts"` |
| 18 | + # 2. Env: HELM_REGISTRY (e.g. "ghcr.io/hotosm/charts") |
| 19 | + # 3. Default: ghcr.io/<owner>/charts |
| 20 | + REGISTRY="{{ registry }}" |
| 21 | + if [ -z "$REGISTRY" ]; then |
| 22 | + if [ -n "${HELM_REGISTRY:-}" ]; then |
| 23 | + REGISTRY="${HELM_REGISTRY}" |
| 24 | + else |
| 25 | + OWNER="${HELM_REGISTRY_OWNER:-${GITHUB_REPOSITORY_OWNER:-}}" |
| 26 | + if [ -z "$OWNER" ]; then |
| 27 | + echo "❌ Unable to determine chart registry owner." |
| 28 | + echo " Provide one of:" |
| 29 | + echo " - just chart publish registry=\"ghcr.io/<owner>/charts\"" |
| 30 | + echo " - HELM_REGISTRY=\"ghcr.io/<owner>/charts\"" |
| 31 | + echo " - HELM_REGISTRY_OWNER or GITHUB_REPOSITORY_OWNER" |
| 32 | + exit 1 |
| 33 | + fi |
| 34 | + REGISTRY="ghcr.io/${OWNER}/charts" |
| 35 | + fi |
| 36 | + fi |
| 37 | + |
| 38 | + REGISTRY_HOST="$(printf '%s\n' "$REGISTRY" | cut -d/ -f1)" |
| 39 | + echo "REGISTRY: ${REGISTRY}" |
| 40 | + echo "REGISTRY_HOST: ${REGISTRY_HOST}" |
| 41 | + |
| 42 | + # Prefer explicit Helm registry creds, fall back to GitHub defaults in CI |
| 43 | + USERNAME="${HELM_REGISTRY_USERNAME:-${GITHUB_ACTOR:-}}" |
| 44 | + PASSWORD="${HELM_REGISTRY_PASSWORD:-${GITHUB_TOKEN:-}}" |
| 45 | + |
| 46 | + if [ -z "$USERNAME" ] || [ -z "$PASSWORD" ]; then |
| 47 | + echo "❌ Missing registry credentials." |
| 48 | + echo " Set HELM_REGISTRY_USERNAME / HELM_REGISTRY_PASSWORD" |
| 49 | + echo " or rely on GITHUB_ACTOR / GITHUB_TOKEN in GitHub Actions." |
| 50 | + exit 1 |
| 51 | + fi |
| 52 | + |
| 53 | + echo "$PASSWORD" | helm registry login "$REGISTRY_HOST" \ |
| 54 | + --username "$USERNAME" \ |
| 55 | + --password-stdin |
| 56 | + |
| 57 | + just chart build |
| 58 | + |
| 59 | + CHART_FILE=$(ls -t xlsform-builder-*.tgz | head -1) |
| 60 | + if [ -z "$CHART_FILE" ]; then |
| 61 | + echo "❌ No chart file found. Run build first" |
| 62 | + exit 1 |
| 63 | + fi |
| 64 | + |
| 65 | + echo "🚀 Publishing chart to OCI registry..." |
| 66 | + echo "📦 Chart file: $CHART_FILE" |
| 67 | + |
| 68 | + echo "🔎 Checking if chart version already exists in registry..." |
| 69 | + CHART_VERSION=$(helm show chart "$CHART_FILE" | grep '^version:' | awk '{ print $2 }') |
| 70 | + if helm show chart "oci://$REGISTRY/xlsform-builder" --version "$CHART_VERSION" >/dev/null 2>&1; then |
| 71 | + echo "ℹ️ Chart version $CHART_VERSION already exists in OCI registry." |
| 72 | + echo " Skipping push." |
| 73 | + exit 0 |
| 74 | + fi |
| 75 | + |
| 76 | + echo "📤 Pushing to: oci://$REGISTRY" |
| 77 | + helm push "$CHART_FILE" "oci://$REGISTRY" |
| 78 | + |
| 79 | + echo "✅ Chart published!" |
| 80 | + |
| 81 | +# Build the Helm chart: lint, update deps, test, and package |
| 82 | +build: |
| 83 | + #!/usr/bin/env bash |
| 84 | + set -e |
| 85 | + |
| 86 | + # Ensure Helm is available (works locally and in CI) |
| 87 | + just _install-helm |
| 88 | + |
| 89 | + cd {{justfile_directory()}} |
| 90 | + |
| 91 | + echo "🔨 Building Helm chart..." |
| 92 | + echo "" |
| 93 | + |
| 94 | + just chart lint |
| 95 | + just chart dependencies |
| 96 | + just chart validate |
| 97 | + just chart package |
| 98 | + |
| 99 | +# Lint the Helm chart |
| 100 | +lint: |
| 101 | + #!/usr/bin/env sh |
| 102 | + set -e |
| 103 | + |
| 104 | + cd {{justfile_directory()}} |
| 105 | + echo "🔍 Linting chart..." |
| 106 | + helm lint ./chart |
| 107 | + echo "✓ Lint passed" |
| 108 | + echo "" |
| 109 | + |
| 110 | +# Update chart dependences |
| 111 | +dependencies: |
| 112 | + #!/usr/bin/env sh |
| 113 | + set -e |
| 114 | + |
| 115 | + cd {{justfile_directory()}}/chart |
| 116 | + echo "📥 Updating dependencies..." |
| 117 | + helm dependency update |
| 118 | + cd .. |
| 119 | + echo "✓ Dependencies updated" |
| 120 | + echo "" |
| 121 | + |
| 122 | +# Validate chart templates |
| 123 | +validate: |
| 124 | + #!/usr/bin/env sh |
| 125 | + set -e |
| 126 | + |
| 127 | + cd {{justfile_directory()}} |
| 128 | + echo "🧪 Testing chart (dry-run)..." |
| 129 | + helm install xlsform-builder-test ./chart --dry-run=client --take-ownership --debug > /dev/null |
| 130 | + echo "✓ Test passed" |
| 131 | + echo "" |
| 132 | + |
| 133 | +# Package the Helm chart |
| 134 | +package: |
| 135 | + #!/usr/bin/env bash |
| 136 | + set -e |
| 137 | + |
| 138 | + cd {{justfile_directory()}} |
| 139 | + echo "📦 Packaging chart..." |
| 140 | + helm package ./chart |
| 141 | + PACKAGE=$(ls -t xlsform-builder-*.tgz | head -1) |
| 142 | + echo "✓ Chart packaged: $PACKAGE" |
| 143 | + echo "" |
| 144 | + echo "✅ Build complete!" |
| 145 | + |
| 146 | +# Render chart templates |
| 147 | +template: |
| 148 | + #!/usr/bin/env bash |
| 149 | + set -e |
| 150 | + cd {{justfile_directory()}} |
| 151 | + helm template xlsform-builder ./chart |
| 152 | + |
| 153 | +# Show chart information |
| 154 | +show: |
| 155 | + #!/usr/bin/env bash |
| 156 | + set -e |
| 157 | + cd {{justfile_directory()}} |
| 158 | + helm show all ./chart |
| 159 | + |
| 160 | +# Clean up packaged charts |
| 161 | +clean: |
| 162 | + #!/usr/bin/env bash |
| 163 | + set -e |
| 164 | + |
| 165 | + cd {{justfile_directory()}} |
| 166 | + rm -f xlsform-builder-*.tgz |
| 167 | + rm -rf chart/charts/ |
| 168 | + echo "✓ Cleaned up chart artifacts" |
0 commit comments