Skip to content

Commit 08031c5

Browse files
authored
chore: refactor the build workflow for operators (#564)
* chore: refactor the build workflow for operators * linting fixes * add yamllint braces config * update the actions version
1 parent 26d779f commit 08031c5

File tree

10 files changed

+256
-87
lines changed

10 files changed

+256
-87
lines changed

.github/workflows/pr_pre-commit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
with:
1919
persist-credentials: false
2020
fetch-depth: 0
21-
- uses: stackabletech/actions/run-pre-commit@75e0756966dea229d697165bfd06ba79abcda72c # v0.10.3
21+
- uses: stackabletech/actions/run-pre-commit@29bea1b451c0c2e994bd495969286f95bf49ed6a # v0.11.0
2222
with:
2323
python-version: ${{ env.PYTHON_VERSION }}
2424
hadolint: ${{ env.HADOLINT_VERSION }}

.yamllint.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ rules:
1414
comments:
1515
min-spaces-from-content: 1 # Needed due to https://github.com/adrienverge/yamllint/issues/443
1616
comments-indentation: disable # This is generally useless and interferes with commented example values
17+
braces:
18+
max-spaces-inside: 1
19+
max-spaces-inside-empty: 0
1720

1821
yaml-files:
1922
- '*.yaml'

config/retired_files.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33
# This is uncommented as I had issues with everything being deleted when this was just present as an empty key.
44
# May be something to investigate.
55
retired_files:
6-
- .github/ISSUE_TEMPLATE/bug_report.yml
76
- .readme/static/borrowed/sdp_overview.png
8-
- bors.toml
7+
- .github/workflows/build.yml

config/versions.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ python_version: 3.14
3030
# Usually the latest version should just work and as such the version here can
3131
# be bumped without any constraints.
3232
nix_pkg_manager_version: 2.30.0
33+
34+
jinja2_cli_version: 0.8.2
Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
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

template/.github/workflows/integration-test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
# TODO: Enable the scheduled runs which hard-code what profile to use
4242
- name: Run Integration Test
4343
id: test
44-
uses: stackabletech/actions/run-integration-test@75e0756966dea229d697165bfd06ba79abcda72c # v0.10.3
44+
uses: stackabletech/actions/run-integration-test@29bea1b451c0c2e994bd495969286f95bf49ed6a # v0.11.0
4545
with:
4646
replicated-api-token: ${{ secrets.REPLICATED_API_TOKEN }}
4747
test-mode-input: ${{ inputs.test-mode-input }}
@@ -51,7 +51,7 @@ jobs:
5151

5252
- name: Send Notification
5353
if: ${{ failure() || github.run_attempt > 1 }}
54-
uses: stackabletech/actions/send-slack-notification@75e0756966dea229d697165bfd06ba79abcda72c # v0.10.3
54+
uses: stackabletech/actions/send-slack-notification@29bea1b451c0c2e994bd495969286f95bf49ed6a # v0.11.0
5555
with:
5656
slack-token: ${{ secrets.SLACK_INTEGRATION_TEST_TOKEN }}
5757
failed-tests: ${{ steps.test.outputs.failed-tests }}

template/.github/workflows/pr_pre-commit.yaml.j2

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ env:
1111
RUST_TOOLCHAIN_VERSION: "{[ rust_nightly_version }]"
1212
HADOLINT_VERSION: "{[ hadolint_version }]"
1313
PYTHON_VERSION: "{[ python_version }]"
14+
JINJA2_CLI_VERSION: "{[ jinja2_cli_version }]"
1415

1516
jobs:
1617
pre-commit:
@@ -26,10 +27,11 @@ jobs:
2627
persist-credentials: false
2728
submodules: recursive
2829
fetch-depth: 0
29-
- uses: stackabletech/actions/run-pre-commit@75e0756966dea229d697165bfd06ba79abcda72c # v0.10.3
30+
- uses: stackabletech/actions/run-pre-commit@29bea1b451c0c2e994bd495969286f95bf49ed6a # v0.11.0
3031
with:
3132
python-version: ${{ env.PYTHON_VERSION }}
3233
rust: ${{ env.RUST_TOOLCHAIN_VERSION }}
3334
hadolint: ${{ env.HADOLINT_VERSION }}
3435
nix: ${{ env.NIX_PKG_MANAGER_VERSION }}
3536
nix-github-token: ${{ secrets.GITHUB_TOKEN }}
37+
jinja2-cli: ${{ env.JINJA2_CLI_VERSION }}

template/.yamllint.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ rules:
1313
indentation:
1414
indent-sequences: consistent
1515
comments-indentation: disable # This is generally useless and interferes with commented example values
16+
braces:
17+
max-spaces-inside: 1
18+
max-spaces-inside-empty: 0

0 commit comments

Comments
 (0)