|
| 1 | +# ============= |
| 2 | +# This file is automatically generated from the templates in stackabletech/operator-templating |
| 3 | +# DON'T MANUALLY EDIT THIS FILE |
| 4 | +# ============= |
| 5 | +--- |
| 6 | +name: Build {[ operator.name }] Artifacts |
| 7 | + |
| 8 | +permissions: {} |
| 9 | + |
| 10 | +on: |
| 11 | + push: |
| 12 | + branches: |
| 13 | + - main |
| 14 | + tags: |
| 15 | + - '[0-9][0-9].[0-9]+.[0-9]+-rc[0-9]+' |
| 16 | + - '[0-9][0-9].[0-9]+.[0-9]+' |
| 17 | + schedule: |
| 18 | + # Run every Saturday morning: https://crontab.guru/#15_3_*_*_6 |
| 19 | + - cron: '15 3 * * 6' |
| 20 | + pull_request: |
| 21 | + paths: |
| 22 | + - '.github/workflows/build.yaml' |
| 23 | + - 'rust-toolchain.toml' |
| 24 | + - '.dockerignore' |
| 25 | + - 'deploy/**' |
| 26 | + - '.cargo/**' |
| 27 | + - 'docker/**' |
| 28 | + - 'Cargo.*' |
| 29 | + - '*.rs' |
| 30 | + |
| 31 | +env: |
| 32 | + OPERATOR_NAME: "{[ operator.name }]" |
| 33 | + RUST_NIGHTLY_TOOLCHAIN_VERSION: "{[ rust_nightly_version }]" |
| 34 | + NIX_PKG_MANAGER_VERSION: "{[ nix_pkg_manager_version }]" |
| 35 | + RUST_TOOLCHAIN_VERSION: "{[ rust_version }]" |
| 36 | + HADOLINT_VERSION: "{[ hadolint_version }]" |
| 37 | + PYTHON_VERSION: "{[ python_version }]" |
| 38 | + CARGO_TERM_COLOR: always |
| 39 | + |
| 40 | +jobs: |
| 41 | + cargo-udeps: |
| 42 | + name: Run cargo-udeps |
| 43 | + runs-on: ubuntu-latest |
| 44 | + env: |
| 45 | + RUSTC_BOOTSTRAP: 1 |
| 46 | + steps: |
| 47 | + - name: Install host dependencies |
| 48 | + uses: awalsh128/cache-apt-pkgs-action@2c09a5e66da6c8016428a2172bd76e5e4f14bb17 # v1.5.3 |
| 49 | + with: |
| 50 | + packages: protobuf-compiler krb5-user libkrb5-dev libclang-dev liblzma-dev libssl-dev pkg-config apt-transport-https |
| 51 | + version: ubuntu-latest |
| 52 | + |
| 53 | + - name: Checkout Repository |
| 54 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 55 | + with: |
| 56 | + persist-credentials: false |
| 57 | + submodules: recursive |
| 58 | + |
| 59 | + - name: Install Rust ${{ env.RUST_TOOLCHAIN_VERSION }} toolchain |
| 60 | + uses: dtolnay/rust-toolchain@b3b07ba8b418998c39fb20f53e8b695cdcc8de1b |
| 61 | + with: |
| 62 | + toolchain: ${{ env.RUST_TOOLCHAIN_VERSION }} |
| 63 | + |
| 64 | + - name: Setup Rust Cache |
| 65 | + uses: Swatinem/rust-cache@98c8021b550208e191a6a3145459bfc9fb29c4c0 # v2.8.0 |
| 66 | + with: |
| 67 | + cache-all-crates: "true" |
| 68 | + key: udeps |
| 69 | + |
| 70 | + - name: Install cargo-udeps |
| 71 | + uses: stackabletech/cargo-install-action@8f7dbbcd2ebe22717efc132d0dd61e80841994b9 # cargo-udeps |
| 72 | + |
| 73 | + - name: Run cargo-udeps |
| 74 | + run: cargo udeps --workspace --all-targets |
| 75 | + |
| 76 | + build-container-image: |
| 77 | + name: Build/Publish ${{ matrix.runner.arch }} Image |
| 78 | + needs: |
| 79 | + - cargo-udeps |
| 80 | + permissions: |
| 81 | + id-token: write |
| 82 | + strategy: |
| 83 | + fail-fast: false |
| 84 | + matrix: |
| 85 | + runner: |
| 86 | + - { name: "ubuntu-latest", arch: "amd64" } |
| 87 | + - { name: "ubicloud-standard-8-arm", arch: "arm64" } |
| 88 | + runs-on: ${{ matrix.runner.name }} |
| 89 | + outputs: |
| 90 | + operator-version: ${{ steps.version.outputs.OPERATOR_VERSION }} |
| 91 | + steps: |
| 92 | + - name: Install host dependencies |
| 93 | + uses: awalsh128/cache-apt-pkgs-action@2c09a5e66da6c8016428a2172bd76e5e4f14bb17 # v1.5.3 |
| 94 | + with: |
| 95 | + packages: protobuf-compiler krb5-user libkrb5-dev libclang-dev liblzma-dev libssl-dev pkg-config apt-transport-https |
| 96 | + version: ${{ matrix.runner.name }} |
| 97 | + |
| 98 | + - name: Checkout Repository |
| 99 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 100 | + with: |
| 101 | + persist-credentials: false |
| 102 | + submodules: recursive |
| 103 | + |
| 104 | + - name: Update/Extract Operator Version |
| 105 | + id: version |
| 106 | + if: github.event_name == 'pull_request' |
| 107 | + env: |
| 108 | + PR_BASE_REF: ${{ github.event.pull_request.base.ref }} |
| 109 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 110 | + GITHUB_DEBUG: ${{ runner.debug }} |
| 111 | + shell: bash |
| 112 | + run: | |
| 113 | + set -euo pipefail |
| 114 | + [ -n "$GITHUB_DEBUG" ] && set -x |
| 115 | + CURRENT_VERSION=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[0].version') |
| 116 | + if [ "$PR_BASE_REF" == 'main' ]; then |
| 117 | + NEW_VERSION="0.0.0-pr$PR_NUMBER" |
| 118 | + else |
| 119 | + NEW_VERSION="$CURRENT_VERSION-pr$PR_NUMBER" |
| 120 | + fi |
| 121 | + sed -i "s/version = \"${CURRENT_VERSION}\"/version = \"${NEW_VERSION}\"/" Cargo.toml |
| 122 | + echo "OPERATOR_VERSION=$NEW_VERSION" | tee -a "$GITHUB_OUTPUT" |
| 123 | + - name: Install Nix |
| 124 | + uses: cachix/install-nix-action@fc6e360bedc9ee72d75e701397f0bb30dce77568 # v31.5.2 |
| 125 | + |
| 126 | + - name: Install Rust ${{ env.RUST_TOOLCHAIN_VERSION }} Toolchain |
| 127 | + uses: dtolnay/rust-toolchain@b3b07ba8b418998c39fb20f53e8b695cdcc8de1b |
| 128 | + with: |
| 129 | + toolchain: ${{ env.RUST_TOOLCHAIN_VERSION }} |
| 130 | + |
| 131 | + - name: Build Container Image |
| 132 | + id: build |
| 133 | + uses: stackabletech/actions/build-container-image@29bea1b451c0c2e994bd495969286f95bf49ed6a # v0.11.0 |
| 134 | + with: |
| 135 | + image-name: ${{ env.OPERATOR_NAME }} |
| 136 | + image-index-manifest-tag: ${{ steps.version.outputs.OPERATOR_VERSION }} |
| 137 | + build-arguments: VERSION=${{ steps.version.outputs.OPERATOR_VERSION }} |
| 138 | + container-file: docker/Dockerfile |
| 139 | + |
| 140 | + - name: Publish Container Image |
| 141 | + uses: stackabletech/actions/publish-image@29bea1b451c0c2e994bd495969286f95bf49ed6a # v0.11.0 |
| 142 | + with: |
| 143 | + image-registry-uri: oci.stackable.tech |
| 144 | + image-registry-username: robot$sdp+github-action-build |
| 145 | + image-registry-password: ${{ secrets.HARBOR_ROBOT_SDP_GITHUB_ACTION_BUILD_SECRET }} |
| 146 | + image-repository: sdp/${{ env.OPERATOR_NAME }} |
| 147 | + image-manifest-tag: ${{ steps.build.outputs.image-manifest-tag }} |
| 148 | + source-image-uri: ${{ steps.build.outputs.image-manifest-uri }} |
| 149 | + |
| 150 | + publish-index-manifest: |
| 151 | + name: Publish/Sign ${{ needs.build-container-image.outputs.operator-version }} Index |
| 152 | + needs: |
| 153 | + - build-container-image |
| 154 | + permissions: |
| 155 | + id-token: write |
| 156 | + runs-on: ubuntu-latest |
| 157 | + steps: |
| 158 | + - name: Checkout Repository |
| 159 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 160 | + with: |
| 161 | + persist-credentials: false |
| 162 | + |
| 163 | + - name: Publish and Sign Image Index |
| 164 | + uses: stackabletech/actions/publish-image-index-manifest@29bea1b451c0c2e994bd495969286f95bf49ed6a # v0.11.0 |
| 165 | + with: |
| 166 | + image-registry-uri: oci.stackable.tech |
| 167 | + image-registry-username: robot$sdp+github-action-build |
| 168 | + image-registry-password: ${{ secrets.HARBOR_ROBOT_SDP_GITHUB_ACTION_BUILD_SECRET }} |
| 169 | + image-repository: sdp/${{ env.OPERATOR_NAME }} |
| 170 | + image-index-manifest-tag: ${{ needs.build-container-image.outputs.operator-version }} |
| 171 | + |
| 172 | + publish-helm-chart: |
| 173 | + name: Package/Publish ${{ needs.build-container-image.outputs.operator-version }} Helm Chart |
| 174 | + needs: |
| 175 | + - build-container-image |
| 176 | + permissions: |
| 177 | + id-token: write |
| 178 | + runs-on: ubuntu-latest |
| 179 | + steps: |
| 180 | + - name: Checkout Repository |
| 181 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 182 | + with: |
| 183 | + persist-credentials: false |
| 184 | + submodules: recursive |
| 185 | + |
| 186 | + - name: Package, Publish, and Sign Helm Chart |
| 187 | + uses: stackabletech/actions/publish-helm-chart@29bea1b451c0c2e994bd495969286f95bf49ed6a # v0.11.0 |
| 188 | + with: |
| 189 | + chart-registry-uri: oci.stackable.tech |
| 190 | + chart-registry-username: robot$sdp-charts+github-action-build |
| 191 | + chart-registry-password: ${{ secrets.HARBOR_ROBOT_SDP_CHARTS_GITHUB_ACTION_BUILD_SECRET }} |
| 192 | + chart-repository: sdp-charts |
| 193 | + chart-directory: deploy/helm/${{ env.OPERATOR_NAME }} |
| 194 | + chart-version: ${{ needs.build-container-image.outputs.operator-version }} |
| 195 | + app-version: ${{ needs.build-container-image.outputs.operator-version }} |
| 196 | + |
| 197 | + openshift-preflight-check: |
| 198 | + name: Run OpenShift Preflight Check for ${{ needs.build-container-image.outputs.operator-version }}-${{ matrix.arch }} |
| 199 | + needs: |
| 200 | + - build-container-image |
| 201 | + - publish-index-manifest |
| 202 | + strategy: |
| 203 | + fail-fast: false |
| 204 | + matrix: |
| 205 | + arch: |
| 206 | + - amd64 |
| 207 | + - arm64 |
| 208 | + runs-on: ubuntu-latest |
| 209 | + steps: |
| 210 | + - name: Run OpenShift Preflight Check |
| 211 | + uses: stackabletech/actions/run-openshift-preflight@29bea1b451c0c2e994bd495969286f95bf49ed6a # v0.11.0 |
| 212 | + with: |
| 213 | + image-index-uri: oci.stackable.tech/sdp/${{ env.OPERATOR_NAME }}:${{ needs.build-container-image.outputs.operator-version }} |
| 214 | + image-architecture: ${{ matrix.arch }} |
| 215 | + |
| 216 | + notify: |
| 217 | + name: Failure Notification |
| 218 | + needs: |
| 219 | + - build-container-image |
| 220 | + - publish-index-manifest |
| 221 | + - publish-helm-chart |
| 222 | + runs-on: ubuntu-latest |
| 223 | + if: failure() || github.run_attempt > 1 |
| 224 | + steps: |
| 225 | + - name: Checkout Repository |
| 226 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 227 | + with: |
| 228 | + persist-credentials: false |
| 229 | + |
| 230 | + - name: Send Notification |
| 231 | + uses: stackabletech/actions/send-slack-notification@29bea1b451c0c2e994bd495969286f95bf49ed6a # v0.11.0 |
| 232 | + with: |
| 233 | + publish-helm-chart-result: ${{ needs.publish-helm-chart.result }} |
| 234 | + publish-manifests-result: ${{ needs.publish-index-manifest.result }} |
| 235 | + build-result: ${{ needs.build-container-image.result }} |
| 236 | + slack-token: ${{ secrets.SLACK_CONTAINER_IMAGE_TOKEN }} |
| 237 | + channel-id: C07UG6JH44F # notifications-container-images |
| 238 | + type: container-image-build |
0 commit comments