|
| 1 | +name: Helm OCI Chart Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + oci_registry: |
| 7 | + description: 'OCI registry URL (e.g., ghcr.io/comet-ml)' |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + chart_path: |
| 11 | + description: 'Path to the chart directory (default: repository root)' |
| 12 | + required: false |
| 13 | + type: string |
| 14 | + default: '.' |
| 15 | + mark_as_latest: |
| 16 | + description: 'Mark the GitHub release as latest' |
| 17 | + required: false |
| 18 | + type: boolean |
| 19 | + default: true |
| 20 | + skip_existing: |
| 21 | + description: 'Skip release if tag already exists' |
| 22 | + required: false |
| 23 | + type: boolean |
| 24 | + default: true |
| 25 | + secrets: |
| 26 | + oci_password: |
| 27 | + description: 'Password for OCI registry authentication' |
| 28 | + required: true |
| 29 | + outputs: |
| 30 | + chart_name: |
| 31 | + description: 'The name of the released chart' |
| 32 | + value: ${{ jobs.release.outputs.chart_name }} |
| 33 | + chart_version: |
| 34 | + description: 'The version of the released chart' |
| 35 | + value: ${{ jobs.release.outputs.chart_version }} |
| 36 | + released: |
| 37 | + description: 'Whether a release was created' |
| 38 | + value: ${{ jobs.release.outputs.released }} |
| 39 | + |
| 40 | +jobs: |
| 41 | + release: |
| 42 | + runs-on: ubuntu-latest |
| 43 | + outputs: |
| 44 | + chart_name: ${{ steps.chart_info.outputs.name }} |
| 45 | + chart_version: ${{ steps.chart_info.outputs.version }} |
| 46 | + released: ${{ steps.release.outputs.released }} |
| 47 | + steps: |
| 48 | + - name: Checkout |
| 49 | + uses: actions/checkout@v4 |
| 50 | + |
| 51 | + - name: Extract chart info |
| 52 | + id: chart_info |
| 53 | + working-directory: ${{ inputs.chart_path }} |
| 54 | + run: | |
| 55 | + if [[ ! -f "Chart.yaml" ]]; then |
| 56 | + echo "::error::Chart.yaml not found in ${{ inputs.chart_path }}" |
| 57 | + exit 1 |
| 58 | + fi |
| 59 | +
|
| 60 | + name=$(yq '.name' Chart.yaml) |
| 61 | + version=$(yq '.version' Chart.yaml) |
| 62 | + description=$(yq '.description' Chart.yaml) |
| 63 | +
|
| 64 | + echo "name=$name" >> $GITHUB_OUTPUT |
| 65 | + echo "version=$version" >> $GITHUB_OUTPUT |
| 66 | + echo "description=$description" >> $GITHUB_OUTPUT |
| 67 | +
|
| 68 | + echo "Chart: $name" |
| 69 | + echo "Version: $version" |
| 70 | + echo "Description: $description" |
| 71 | +
|
| 72 | + - name: Check if release exists |
| 73 | + id: check_release |
| 74 | + env: |
| 75 | + GH_TOKEN: ${{ github.token }} |
| 76 | + run: | |
| 77 | + tag="${{ steps.chart_info.outputs.name }}-${{ steps.chart_info.outputs.version }}" |
| 78 | + echo "tag=$tag" >> $GITHUB_OUTPUT |
| 79 | +
|
| 80 | + if gh release view "$tag" &>/dev/null; then |
| 81 | + echo "exists=true" >> $GITHUB_OUTPUT |
| 82 | + echo "Release $tag already exists" |
| 83 | + else |
| 84 | + echo "exists=false" >> $GITHUB_OUTPUT |
| 85 | + echo "Release $tag does not exist" |
| 86 | + fi |
| 87 | +
|
| 88 | + - name: Skip if release exists |
| 89 | + if: steps.check_release.outputs.exists == 'true' && inputs.skip_existing |
| 90 | + run: | |
| 91 | + echo "::notice::Release ${{ steps.check_release.outputs.tag }} already exists. Skipping." |
| 92 | + echo "released=false" >> $GITHUB_OUTPUT |
| 93 | +
|
| 94 | + - name: Install Helm |
| 95 | + if: steps.check_release.outputs.exists != 'true' || !inputs.skip_existing |
| 96 | + uses: azure/setup-helm@v4 |
| 97 | + with: |
| 98 | + version: 'v3.14.0' |
| 99 | + |
| 100 | + - name: Login to OCI registry |
| 101 | + if: steps.check_release.outputs.exists != 'true' || !inputs.skip_existing |
| 102 | + run: | |
| 103 | + registry="${{ inputs.oci_registry }}" |
| 104 | + # Remove oci:// prefix if present |
| 105 | + registry="${registry#oci://}" |
| 106 | + # Extract host from registry URL |
| 107 | + host="${registry%%/*}" |
| 108 | +
|
| 109 | + echo "${{ secrets.oci_password }}" | helm registry login "$host" \ |
| 110 | + --username ${{ github.actor }} \ |
| 111 | + --password-stdin |
| 112 | +
|
| 113 | + - name: Package chart |
| 114 | + if: steps.check_release.outputs.exists != 'true' || !inputs.skip_existing |
| 115 | + id: package |
| 116 | + working-directory: ${{ inputs.chart_path }} |
| 117 | + run: | |
| 118 | + helm dependency update |
| 119 | + helm package . --destination /tmp/helm-packages |
| 120 | +
|
| 121 | + package_file="/tmp/helm-packages/${{ steps.chart_info.outputs.name }}-${{ steps.chart_info.outputs.version }}.tgz" |
| 122 | + echo "package_file=$package_file" >> $GITHUB_OUTPUT |
| 123 | +
|
| 124 | + echo "Packaged chart: $package_file" |
| 125 | + ls -la /tmp/helm-packages/ |
| 126 | +
|
| 127 | + - name: Push chart to OCI registry |
| 128 | + if: steps.check_release.outputs.exists != 'true' || !inputs.skip_existing |
| 129 | + run: | |
| 130 | + registry="${{ inputs.oci_registry }}" |
| 131 | + # Remove oci:// prefix if present |
| 132 | + registry="${registry#oci://}" |
| 133 | +
|
| 134 | + helm push "${{ steps.package.outputs.package_file }}" "oci://${registry}" |
| 135 | +
|
| 136 | + echo "Pushed chart to oci://${registry}/${{ steps.chart_info.outputs.name }}:${{ steps.chart_info.outputs.version }}" |
| 137 | +
|
| 138 | + - name: Create GitHub release |
| 139 | + if: steps.check_release.outputs.exists != 'true' || !inputs.skip_existing |
| 140 | + id: release |
| 141 | + env: |
| 142 | + GH_TOKEN: ${{ github.token }} |
| 143 | + run: | |
| 144 | + tag="${{ steps.check_release.outputs.tag }}" |
| 145 | +
|
| 146 | + # Determine latest flag |
| 147 | + latest_flag="" |
| 148 | + if [[ "${{ inputs.mark_as_latest }}" == "true" ]]; then |
| 149 | + latest_flag="--latest" |
| 150 | + fi |
| 151 | +
|
| 152 | + # Create release |
| 153 | + gh release create "$tag" \ |
| 154 | + --title "$tag" \ |
| 155 | + --notes "${{ steps.chart_info.outputs.description }}" \ |
| 156 | + $latest_flag |
| 157 | +
|
| 158 | + # Upload chart package to release |
| 159 | + gh release upload "$tag" "${{ steps.package.outputs.package_file }}" --clobber |
| 160 | +
|
| 161 | + echo "released=true" >> $GITHUB_OUTPUT |
| 162 | + echo "Created release: $tag" |
| 163 | +
|
| 164 | + - name: Generate summary |
| 165 | + if: always() |
| 166 | + run: | |
| 167 | + echo "## Helm Chart Release Summary" >> $GITHUB_STEP_SUMMARY |
| 168 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 169 | + echo "| Property | Value |" >> $GITHUB_STEP_SUMMARY |
| 170 | + echo "|----------|-------|" >> $GITHUB_STEP_SUMMARY |
| 171 | + echo "| Chart | ${{ steps.chart_info.outputs.name }} |" >> $GITHUB_STEP_SUMMARY |
| 172 | + echo "| Version | ${{ steps.chart_info.outputs.version }} |" >> $GITHUB_STEP_SUMMARY |
| 173 | + echo "| Tag | ${{ steps.check_release.outputs.tag }} |" >> $GITHUB_STEP_SUMMARY |
| 174 | + echo "| Registry | ${{ inputs.oci_registry }} |" >> $GITHUB_STEP_SUMMARY |
| 175 | +
|
| 176 | + if [[ "${{ steps.check_release.outputs.exists }}" == "true" && "${{ inputs.skip_existing }}" == "true" ]]; then |
| 177 | + echo "| Status | Skipped (release exists) |" >> $GITHUB_STEP_SUMMARY |
| 178 | + elif [[ "${{ steps.release.outputs.released }}" == "true" ]]; then |
| 179 | + echo "| Status | Released |" >> $GITHUB_STEP_SUMMARY |
| 180 | + else |
| 181 | + echo "| Status | Failed |" >> $GITHUB_STEP_SUMMARY |
| 182 | + fi |
0 commit comments