|
| 1 | +name: Release operator bundle |
| 2 | + |
| 3 | +# Build and publish the OLM operator bundle for a release, and (optionally) open |
| 4 | +# the version PR to k8s-operatorhub/community-operators. The committed bundle |
| 5 | +# under deploy/olm/bundle is the 0.4.0 base; this workflow rewrites it to the |
| 6 | +# release version in a throwaway workspace, validates it, pushes the bundle |
| 7 | +# image, and prepares the community-operators contribution. |
| 8 | +# |
| 9 | +# Prerequisites and notes: |
| 10 | +# * Images must already be published to ghcr.io/mitos-run for the version. |
| 11 | +# * The first community-operators listing is still a manual PR; this automates |
| 12 | +# subsequent versions once a fork and token exist. |
| 13 | +# * To open the PR automatically, set the COMMUNITY_OPERATORS_TOKEN secret to a |
| 14 | +# PAT (repo scope) whose account has a fork of k8s-operatorhub/community- |
| 15 | +# operators. Without it, the versioned bundle is uploaded as an artifact. |
| 16 | +# * Pass `previous` so the bundle gets a spec.replaces upgrade edge. |
| 17 | + |
| 18 | +on: |
| 19 | + release: |
| 20 | + types: [published] |
| 21 | + workflow_dispatch: |
| 22 | + inputs: |
| 23 | + version: |
| 24 | + description: "Bundle version without leading v, for example 0.4.1" |
| 25 | + required: true |
| 26 | + previous: |
| 27 | + description: "Previous bundle version for spec.replaces, for example 0.4.0" |
| 28 | + required: false |
| 29 | + |
| 30 | +permissions: |
| 31 | + contents: read |
| 32 | + |
| 33 | +jobs: |
| 34 | + bundle: |
| 35 | + runs-on: ubuntu-latest |
| 36 | + permissions: |
| 37 | + contents: read |
| 38 | + packages: write |
| 39 | + id-token: write |
| 40 | + env: |
| 41 | + BUNDLE_IMAGE: ghcr.io/mitos-run/mitos-operator-bundle |
| 42 | + steps: |
| 43 | + - uses: actions/checkout@v6 |
| 44 | + |
| 45 | + - name: Derive version |
| 46 | + id: ver |
| 47 | + run: | |
| 48 | + set -euo pipefail |
| 49 | + if [ "${{ github.event_name }}" = "release" ]; then |
| 50 | + v="${GITHUB_REF_NAME#v}" |
| 51 | + else |
| 52 | + v="${{ inputs.version }}" |
| 53 | + fi |
| 54 | + [ -n "$v" ] || { echo "no version resolved"; exit 1; } |
| 55 | + echo "version=$v" >> "$GITHUB_OUTPUT" |
| 56 | + echo "previous=${{ inputs.previous }}" >> "$GITHUB_OUTPUT" |
| 57 | +
|
| 58 | + - name: Install yq and operator-sdk |
| 59 | + run: | |
| 60 | + set -euo pipefail |
| 61 | + sudo curl -fsSL -o /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 |
| 62 | + sudo chmod +x /usr/local/bin/yq |
| 63 | + sudo curl -fsSL -o /usr/local/bin/operator-sdk \ |
| 64 | + https://github.com/operator-framework/operator-sdk/releases/latest/download/operator-sdk_linux_amd64 |
| 65 | + sudo chmod +x /usr/local/bin/operator-sdk |
| 66 | +
|
| 67 | + - name: Rewrite the bundle to the release version |
| 68 | + env: |
| 69 | + VERSION: ${{ steps.ver.outputs.version }} |
| 70 | + PREVIOUS: ${{ steps.ver.outputs.previous }} |
| 71 | + run: | |
| 72 | + set -euo pipefail |
| 73 | + csv=deploy/olm/bundle/manifests/mitos.clusterserviceversion.yaml |
| 74 | + BASE="$(yq '.spec.version' "$csv")" |
| 75 | + export BASE |
| 76 | + echo "rewriting bundle ${BASE} -> ${VERSION}" |
| 77 | + yq -i '.metadata.name = "mitos.v" + strenv(VERSION)' "$csv" |
| 78 | + yq -i '.spec.version = strenv(VERSION)' "$csv" |
| 79 | + yq -i '.metadata.annotations.createdAt = (now | format_datetime("2006-01-02T15:04:05Z"))' "$csv" |
| 80 | + # rewrite the controller image tag, the containerImage annotation, and |
| 81 | + # the husk-stub image arg from :v$BASE to :v$VERSION. |
| 82 | + yq -i '.metadata.annotations.containerImage |= sub(":v" + strenv(BASE), ":v" + strenv(VERSION))' "$csv" |
| 83 | + yq -i '(.spec.install.spec.deployments[].spec.template.spec.containers[].image) |= sub(":v" + strenv(BASE), ":v" + strenv(VERSION))' "$csv" |
| 84 | + yq -i '(.spec.install.spec.deployments[].spec.template.spec.containers[].args[]) |= sub(":v" + strenv(BASE), ":v" + strenv(VERSION))' "$csv" |
| 85 | + if [ -n "${PREVIOUS}" ]; then |
| 86 | + yq -i '.spec.replaces = "mitos.v" + strenv(PREVIOUS)' "$csv" |
| 87 | + fi |
| 88 | +
|
| 89 | + - name: Validate the bundle |
| 90 | + run: | |
| 91 | + set -euo pipefail |
| 92 | + operator-sdk bundle validate ./deploy/olm/bundle |
| 93 | + operator-sdk bundle validate ./deploy/olm/bundle --select-optional suite=operatorframework |
| 94 | +
|
| 95 | + - name: Log in to GHCR |
| 96 | + uses: docker/login-action@v4 |
| 97 | + with: |
| 98 | + registry: ghcr.io |
| 99 | + username: ${{ secrets.GHCR_WRITE_USER || github.actor }} |
| 100 | + password: ${{ secrets.GHCR_WRITE_TOKEN || secrets.GITHUB_TOKEN }} |
| 101 | + |
| 102 | + - name: Build and push the bundle image |
| 103 | + id: push |
| 104 | + env: |
| 105 | + VERSION: ${{ steps.ver.outputs.version }} |
| 106 | + run: | |
| 107 | + set -euo pipefail |
| 108 | + docker build -f deploy/olm/bundle/bundle.Dockerfile -t "${BUNDLE_IMAGE}:${VERSION}" deploy/olm/bundle |
| 109 | + docker push "${BUNDLE_IMAGE}:${VERSION}" |
| 110 | + digest="$(docker inspect --format='{{index .RepoDigests 0}}' "${BUNDLE_IMAGE}:${VERSION}" | cut -d@ -f2)" |
| 111 | + echo "digest=${digest}" >> "$GITHUB_OUTPUT" |
| 112 | +
|
| 113 | + - name: Install cosign |
| 114 | + uses: sigstore/cosign-installer@v3 |
| 115 | + |
| 116 | + - name: Cosign keyless sign the bundle image |
| 117 | + env: |
| 118 | + DIGEST: ${{ steps.push.outputs.digest }} |
| 119 | + run: cosign sign --yes "${BUNDLE_IMAGE}@${DIGEST}" |
| 120 | + |
| 121 | + - name: Stage the community-operators contribution |
| 122 | + env: |
| 123 | + VERSION: ${{ steps.ver.outputs.version }} |
| 124 | + run: | |
| 125 | + set -euo pipefail |
| 126 | + dst="contribution/operators/mitos/${VERSION}" |
| 127 | + mkdir -p "$dst" |
| 128 | + cp -r deploy/olm/bundle/manifests "$dst/manifests" |
| 129 | + cp -r deploy/olm/bundle/metadata "$dst/metadata" |
| 130 | + echo "staged $dst" |
| 131 | +
|
| 132 | + - name: Upload the versioned bundle artifact |
| 133 | + uses: actions/upload-artifact@v7 |
| 134 | + with: |
| 135 | + name: community-operators-mitos-${{ steps.ver.outputs.version }} |
| 136 | + path: contribution/ |
| 137 | + |
| 138 | + - name: Open the community-operators PR |
| 139 | + env: |
| 140 | + VERSION: ${{ steps.ver.outputs.version }} |
| 141 | + CO_TOKEN: ${{ secrets.COMMUNITY_OPERATORS_TOKEN }} |
| 142 | + run: | |
| 143 | + set -euo pipefail |
| 144 | + if [ -z "${CO_TOKEN}" ]; then |
| 145 | + echo "COMMUNITY_OPERATORS_TOKEN not set; skipping PR. The bundle is in the uploaded artifact." |
| 146 | + exit 0 |
| 147 | + fi |
| 148 | + export GH_TOKEN="${CO_TOKEN}" |
| 149 | + owner="$(gh api user -q .login)" |
| 150 | + # ensure the fork exists under the token owner. |
| 151 | + gh repo fork k8s-operatorhub/community-operators --clone=false || true |
| 152 | + git clone "https://x-access-token:${CO_TOKEN}@github.com/${owner}/community-operators" co |
| 153 | + cd co |
| 154 | + git remote add upstream https://github.com/k8s-operatorhub/community-operators |
| 155 | + git fetch -q upstream |
| 156 | + branch="mitos-${VERSION}" |
| 157 | + git checkout -q -b "$branch" upstream/main |
| 158 | + mkdir -p "operators/mitos/${VERSION}" |
| 159 | + cp -r "../contribution/operators/mitos/${VERSION}/." "operators/mitos/${VERSION}/" |
| 160 | + git config user.name "mitos-run" |
| 161 | + git config user.email "maintainers@mitos.run" |
| 162 | + git add "operators/mitos/${VERSION}" |
| 163 | + # community-operators requires a DCO sign-off. |
| 164 | + git commit -s -q -m "operator mitos (${VERSION})" |
| 165 | + git push -q origin "$branch" |
| 166 | + gh pr create --repo k8s-operatorhub/community-operators \ |
| 167 | + --base main --head "${owner}:${branch}" \ |
| 168 | + --title "operator mitos (${VERSION})" \ |
| 169 | + --body "Adds mitos ${VERSION}. Snapshot-fork sandboxes for AI agents on Kubernetes. https://mitos.run" |
0 commit comments