|
| 1 | +name: Release Charts |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - develop |
| 7 | + |
| 8 | +jobs: |
| 9 | + package-helm-chart: |
| 10 | + name: Package helm chart |
| 11 | + runs-on: ubuntu-latest |
| 12 | + permissions: |
| 13 | + contents: read |
| 14 | + packages: read |
| 15 | + outputs: |
| 16 | + has_artifacts: ${{ steps.check-artifacts.outputs.has_artifacts }} |
| 17 | + steps: |
| 18 | + - name: Checkout |
| 19 | + uses: actions/checkout@v4 |
| 20 | + with: |
| 21 | + fetch-depth: 0 |
| 22 | + |
| 23 | + - name: Install helm |
| 24 | + uses: azure/setup-helm@v4 |
| 25 | + |
| 26 | + - name: Install Oras |
| 27 | + uses: oras-project/setup-oras@v1 |
| 28 | + |
| 29 | + - name: Login to GitHub Container Registry |
| 30 | + uses: docker/login-action@v3 |
| 31 | + with: |
| 32 | + registry: ghcr.io |
| 33 | + username: ${{ github.actor }} |
| 34 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 35 | + |
| 36 | + - name: Package helm charts |
| 37 | + run: | |
| 38 | + mkdir -p ./.cr-release-packages |
| 39 | + for chart_path in ./charts/*; do |
| 40 | + if [ -d "$chart_path" ] && [ -f "$chart_path/Chart.yaml" ]; then |
| 41 | + chart_name=$(grep '^name:' "$chart_path/Chart.yaml" | awk '{print $2}') |
| 42 | + # get current version |
| 43 | + current_version=$(grep '^version:' "$chart_path/Chart.yaml" | awk '{print $2}') |
| 44 | + # try to get current release version |
| 45 | + set +e |
| 46 | + oras discover ghcr.io/${GITHUB_REPOSITORY@L}/${chart_name}:${current_version} |
| 47 | + oras_exit_code=$? |
| 48 | + set -e |
| 49 | +
|
| 50 | + if [ $oras_exit_code -ne 0 ]; then |
| 51 | + helm dependency build "$chart_path" |
| 52 | + helm package "$chart_path" --destination ./.cr-release-packages |
| 53 | + else |
| 54 | + echo "No version change for $chart_name. Skipping." |
| 55 | + fi |
| 56 | + else |
| 57 | + echo "Skipping $chart_name: Not a valid Helm chart" |
| 58 | + fi |
| 59 | + done |
| 60 | +
|
| 61 | + - name: Check if artifacts exist |
| 62 | + id: check-artifacts |
| 63 | + run: | |
| 64 | + if ls .cr-release-packages/* >/dev/null 2>&1; then |
| 65 | + echo "has_artifacts=true" >> $GITHUB_OUTPUT |
| 66 | + else |
| 67 | + echo "has_artifacts=false" >> $GITHUB_OUTPUT |
| 68 | + fi |
| 69 | +
|
| 70 | + - name: Upload artifacts |
| 71 | + uses: actions/upload-artifact@v4 |
| 72 | + if: steps.check-artifacts.outputs.has_artifacts == 'true' |
| 73 | + with: |
| 74 | + name: artifacts |
| 75 | + include-hidden-files: true |
| 76 | + path: .cr-release-packages/ |
| 77 | + |
| 78 | + publish: |
| 79 | + name: Publish to ghcr.io |
| 80 | + runs-on: ubuntu-latest |
| 81 | + permissions: |
| 82 | + packages: write # needed for pushing to github registry |
| 83 | + id-token: write # needed for signing the images with GitHub OIDC Token |
| 84 | + needs: [package-helm-chart] |
| 85 | + if: needs.package-helm-chart.outputs.has_artifacts == 'true' |
| 86 | + steps: |
| 87 | + - name: Checkout |
| 88 | + uses: actions/checkout@v4 |
| 89 | + with: |
| 90 | + fetch-depth: 0 |
| 91 | + |
| 92 | + - name: Install helm |
| 93 | + uses: azure/setup-helm@v4 |
| 94 | + |
| 95 | + - name: Install Oras |
| 96 | + uses: oras-project/setup-oras@v1 |
| 97 | + |
| 98 | + - name: Install Cosign |
| 99 | + uses: sigstore/cosign-installer@v3 |
| 100 | + |
| 101 | + - name: Downloads artifacts |
| 102 | + uses: actions/download-artifact@v4 |
| 103 | + with: |
| 104 | + name: artifacts |
| 105 | + path: .cr-release-packages/ |
| 106 | + |
| 107 | + - name: Login to GitHub Container Registry |
| 108 | + uses: docker/login-action@v3 |
| 109 | + with: |
| 110 | + registry: ghcr.io |
| 111 | + username: ${{ github.actor }} |
| 112 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 113 | + |
| 114 | + - name: Push charts to GHCR |
| 115 | + env: |
| 116 | + COSIGN_YES: true |
| 117 | + run: | |
| 118 | + for chart_path in `find .cr-release-packages -name '*.tgz' -print`; do |
| 119 | + # push chart to OCI |
| 120 | + chart_release_file=$(basename "$chart_path") |
| 121 | + chart_name=${chart_release_file%-*} |
| 122 | + helm push ${chart_path} oci://ghcr.io/${GITHUB_REPOSITORY@L} |& tee helm-push-output.log |
| 123 | + chart_digest=$(awk -F "[, ]+" '/Digest/{print $NF}' < helm-push-output.log) |
| 124 | + # sign chart |
| 125 | + cosign sign "ghcr.io/${GITHUB_REPOSITORY@L}/${chart_name}@${chart_digest}" |
| 126 | + # push artifacthub-repo.yml to OCI |
| 127 | + oras push \ |
| 128 | + ghcr.io/${GITHUB_REPOSITORY@L}/${chart_name}:artifacthub.io \ |
| 129 | + --config /dev/null:application/vnd.cncf.artifacthub.config.v1+yaml \ |
| 130 | + charts/$chart_name/artifacthub-repo.yml:application/vnd.cncf.artifacthub.repository-metadata.layer.v1.yaml \ |
| 131 | + |& tee oras-push-output.log |
| 132 | + artifacthub_digest=$(grep "Digest:" oras-push-output.log | awk '{print $2}') |
| 133 | + # sign artifacthub-repo.yml |
| 134 | + cosign sign "ghcr.io/${GITHUB_REPOSITORY@L}/${chart_name}:artifacthub.io@${artifacthub_digest}" |
| 135 | + done |
0 commit comments