|
| 1 | +name: Release SUSE AI Operator [Container and Helm Chart] |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + tags: |
| 8 | + - suse-ai-operator-* |
| 9 | + |
| 10 | +env: |
| 11 | + CONTAINER_REGISTRY: ghcr.io/leooamaral/suse-ai-operator |
| 12 | + CHART_PATH: deploy/charts/suse-ai-operator |
| 13 | + CHART_REGISTRY: oci://ghcr.io/leooamaral/chart |
| 14 | +jobs: |
| 15 | + container: |
| 16 | + outputs: |
| 17 | + VERSION: ${{ steps.tags.outputs.VERSION }} |
| 18 | + CHART_VERSION: ${{ steps.tags.outputs.CHART_VERSION }} |
| 19 | + PUBLISH: ${{ steps.tags.outputs.PUBLISH }} |
| 20 | + METADATA_TAGS: ${{ steps.tags.outputs.METADATA_TAGS }} |
| 21 | + NOTES_START_TAG: ${{ steps.tags.outputs.NOTES_START_TAG }} |
| 22 | + permissions: |
| 23 | + contents: read |
| 24 | + packages: write |
| 25 | + runs-on: ubuntu-latest |
| 26 | + steps: |
| 27 | + - name: Checkout |
| 28 | + uses: actions/checkout@v4 |
| 29 | + |
| 30 | + - name: Calculate tags |
| 31 | + id: tags |
| 32 | + shell: bash |
| 33 | + run: | |
| 34 | + ref=${{ github.ref }} |
| 35 | + case "$ref" in |
| 36 | + refs/heads/main) |
| 37 | + BASE_VERSION=$(cat VERSION) |
| 38 | + |
| 39 | + git fetch --tags |
| 40 | +
|
| 41 | + LAST_DEV=$(git tag \ |
| 42 | + --list "suse-ai-operator-${BASE_VERSION}-dev.*" \ |
| 43 | + --sort=-v:refname \ |
| 44 | + | head -n 1) |
| 45 | +
|
| 46 | + if [[ -z "$LAST_DEV" ]]; then |
| 47 | + DEV_NUM=1 |
| 48 | + NOTES_START_TAG=$(git tag --list "suse-ai-operator-*" --sort=-v:refname | grep -v "\-dev" | head -n 1) |
| 49 | + else |
| 50 | + DEV_NUM="${LAST_DEV##*.}" |
| 51 | + DEV_NUM=$((DEV_NUM + 1)) |
| 52 | + NOTES_START_TAG="$LAST_DEV" |
| 53 | + fi |
| 54 | +
|
| 55 | + VERSION="${BASE_VERSION}-dev.${DEV_NUM}" |
| 56 | + IMAGE_TAGS="$VERSION" |
| 57 | + CHART_VERSION="$VERSION" |
| 58 | +
|
| 59 | + { |
| 60 | + echo "METADATA_TAGS<<EOF" |
| 61 | + echo "$VERSION" |
| 62 | + echo "EOF" |
| 63 | + } >> "$GITHUB_OUTPUT" |
| 64 | +
|
| 65 | + PUBLISH=true |
| 66 | + ;; |
| 67 | + refs/tags/suse-ai-operator-*) |
| 68 | + VERSION="${ref#refs/tags/suse-ai-operator-}" |
| 69 | + IMAGE_TAGS="$VERSION" |
| 70 | + CHART_VERSION="$VERSION" |
| 71 | + NOTES_START_TAG="" |
| 72 | +
|
| 73 | + { |
| 74 | + echo "METADATA_TAGS<<EOF" |
| 75 | + echo "$VERSION" |
| 76 | + if [[ "$VERSION" != *"-"* ]]; then |
| 77 | + echo "latest" |
| 78 | + fi |
| 79 | + echo "EOF" |
| 80 | + } >> "$GITHUB_OUTPUT" |
| 81 | +
|
| 82 | + PUBLISH=true |
| 83 | + ;; |
| 84 | + *) |
| 85 | + VERSION="${{ github.sha }}" |
| 86 | + IMAGE_TAGS="$VERSION" |
| 87 | + CHART_VERSION="$VERSION" |
| 88 | + NOTES_START_TAG="" |
| 89 | +
|
| 90 | + { |
| 91 | + echo "METADATA_TAGS<<EOF" |
| 92 | + echo "$VERSION" |
| 93 | + echo "EOF" |
| 94 | + } >> "$GITHUB_OUTPUT" |
| 95 | +
|
| 96 | + PUBLISH=false |
| 97 | + ;; |
| 98 | + esac |
| 99 | +
|
| 100 | + echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT" |
| 101 | + echo "IMAGE_TAGS=$IMAGE_TAGS" >> "$GITHUB_OUTPUT" |
| 102 | + echo "PUBLISH=$PUBLISH" >> "$GITHUB_OUTPUT" |
| 103 | + echo "CHART_VERSION=$CHART_VERSION" >> "$GITHUB_OUTPUT" |
| 104 | + echo "NOTES_START_TAG=$NOTES_START_TAG" >> "$GITHUB_OUTPUT" |
| 105 | +
|
| 106 | + - name: Login to GHCR |
| 107 | + if: steps.tags.outputs.PUBLISH == 'true' |
| 108 | + uses: docker/login-action@v3 |
| 109 | + with: |
| 110 | + registry: ghcr.io |
| 111 | + username: ${{ github.repository_owner }} |
| 112 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 113 | + |
| 114 | + - name: Set up QEMU |
| 115 | + if: steps.tags.outputs.PUBLISH == 'true' |
| 116 | + uses: docker/setup-qemu-action@v3 |
| 117 | + |
| 118 | + - name: Setup Docker Buildx |
| 119 | + if: steps.tags.outputs.PUBLISH == 'true' |
| 120 | + uses: docker/setup-buildx-action@v3 |
| 121 | + |
| 122 | + - name: Get Docker Metadata |
| 123 | + id: meta |
| 124 | + if: steps.tags.outputs.PUBLISH == 'true' |
| 125 | + uses: docker/metadata-action@v5 |
| 126 | + with: |
| 127 | + images: ${{ env.CONTAINER_REGISTRY }} |
| 128 | + tags: | |
| 129 | + ${{ steps.tags.outputs.METADATA_TAGS }} |
| 130 | +
|
| 131 | + - name: Build Docker Container |
| 132 | + id: push |
| 133 | + if: steps.tags.outputs.PUBLISH == 'true' |
| 134 | + uses: docker/build-push-action@v6 |
| 135 | + with: |
| 136 | + context: . |
| 137 | + labels: ${{ steps.meta.outputs.labels }} |
| 138 | + tags: ${{ steps.meta.outputs.tags }} |
| 139 | + push: true |
| 140 | + platforms: linux/arm64,linux/amd64 |
| 141 | + |
| 142 | + helm: |
| 143 | + needs: container |
| 144 | + if: needs.container.outputs.PUBLISH == 'true' |
| 145 | + permissions: |
| 146 | + contents: write |
| 147 | + packages: write |
| 148 | + runs-on: ubuntu-latest |
| 149 | + steps: |
| 150 | + - name: Checkout |
| 151 | + uses: actions/checkout@v4 |
| 152 | + with: |
| 153 | + fetch-depth: 0 |
| 154 | + |
| 155 | + - name: Login to GHCR |
| 156 | + uses: docker/login-action@v3 |
| 157 | + with: |
| 158 | + registry: ghcr.io |
| 159 | + username: ${{ github.repository_owner }} |
| 160 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 161 | + |
| 162 | + - name: Update Chart.yaml |
| 163 | + run: | |
| 164 | + yq -i '.version = "${{ needs.container.outputs.CHART_VERSION }}"' $CHART_PATH/Chart.yaml |
| 165 | + yq -i '.appVersion = "${{ needs.container.outputs.VERSION }}"' $CHART_PATH/Chart.yaml |
| 166 | +
|
| 167 | + - name: Update image annotations |
| 168 | + run: | |
| 169 | + yq -i ' |
| 170 | + .annotations."helm.sh/images" = |
| 171 | + "- image: ghcr.io/leooamaral/suse-ai-operator:${{ needs.container.outputs.VERSION }}\n name: suse-ai-operator" |
| 172 | + ' $CHART_PATH/Chart.yaml |
| 173 | +
|
| 174 | + - name: Package Helm Chart |
| 175 | + id: package |
| 176 | + run: | |
| 177 | + chart_package=$(helm package $CHART_PATH --destination . | awk '{print $NF}') |
| 178 | + echo "chart_package=$chart_package" >> $GITHUB_OUTPUT |
| 179 | +
|
| 180 | + - name: Publish Helm Chart |
| 181 | + run: | |
| 182 | + helm push ${{ steps.package.outputs.chart_package }} \ |
| 183 | + $CHART_REGISTRY |
| 184 | +
|
| 185 | + - name: Create dev git tag |
| 186 | + if: needs.container.outputs.PUBLISH == 'true' && github.ref == 'refs/heads/main' |
| 187 | + run: | |
| 188 | + git config user.name "github-actions" |
| 189 | + git config user.email "github-actions@github.com" |
| 190 | +
|
| 191 | + TAG="suse-ai-operator-${{ needs.container.outputs.VERSION }}" |
| 192 | + git checkout -b release/${TAG} |
| 193 | +
|
| 194 | + git add $CHART_PATH/Chart.yaml |
| 195 | + git commit -m "chore(release): ${TAG}" |
| 196 | +
|
| 197 | + git tag "$TAG" |
| 198 | + git push origin "$TAG" |
| 199 | +
|
| 200 | + - name: Create pre-release and release notes for dev |
| 201 | + env: |
| 202 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 203 | + START_TAG: ${{ needs.container.outputs.NOTES_START_TAG }} |
| 204 | + if: needs.container.outputs.PUBLISH == 'true' && github.ref == 'refs/heads/main' |
| 205 | + run: | |
| 206 | + TAG="suse-ai-operator-${{ needs.container.outputs.VERSION }}" |
| 207 | +
|
| 208 | + NOTES_ARG="" |
| 209 | + if [[ -n "$START_TAG" ]]; then |
| 210 | + NOTES_ARG="--notes-start-tag $START_TAG" |
| 211 | + fi |
| 212 | +
|
| 213 | + gh release create "${TAG}" \ |
| 214 | + --title "${TAG}" \ |
| 215 | + --prerelease --fail-on-no-commits \ |
| 216 | + --generate-notes $NOTES_ARG |
0 commit comments