Skip to content

Commit

Permalink
Add workflow test hack (#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
jotak authored Apr 20, 2023
1 parent 36de463 commit 949256f
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 9 deletions.
14 changes: 6 additions & 8 deletions .github/workflows/push_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ env:
REGISTRY_PASSWORD: ${{ secrets.QUAY_SECRET }}
REGISTRY: quay.io/netobserv
IMAGE: network-observability-operator
TAGS: main
BUNDLE_VERSION: 0.0.0-main

jobs:
push-image:
Expand All @@ -28,7 +26,7 @@ jobs:
- name: checkout
uses: actions/checkout@v3
- name: build images
run: IMG=${{ env.REGISTRY }}/${{ env.IMAGE }}:${{ env.TAGS }} make ci-images-build
run: IMG=${{ env.REGISTRY }}/${{ env.IMAGE }}:main make ci-images-build
- name: podman login to quay.io
uses: redhat-actions/podman-login@v1
with:
Expand All @@ -42,27 +40,27 @@ jobs:
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ env.IMAGE }}
tags: ${{ env.TAGS }} ${{ env.short_sha }}
tags: main ${{ env.short_sha }}
registry: ${{ env.REGISTRY }}
- name: print image url
run: echo "Image pushed to ${{ steps.push-to-quay.outputs.registry-paths }}"
- name: build bundle
run: VERSION=${{ env.TAGS }} PLG_VERSION=${{ env.TAGS }} FLP_VERSION=${{ env.TAGS }} BPF_VERSION=${{ env.TAGS }} BUNDLE_VERSION=${{ env.BUNDLE_VERSION }} make bundle bundle-build
run: VERSION=main PLG_VERSION=main FLP_VERSION=main BPF_VERSION=main BUNDLE_VERSION=0.0.0-main make bundle bundle-build
- name: push bundle to quay.io
id: push-bundle
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ env.IMAGE }}-bundle
tags: v${{ env.BUNDLE_VERSION }}
tags: v0.0.0-main
registry: ${{ env.REGISTRY }}
- name: build catalog
run: BUNDLE_VERSION=${{ env.BUNDLE_VERSION }} make catalog-build
run: BUNDLE_VERSION=0.0.0-main make catalog-build
- name: push catalog to quay.io
id: push-catalog
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ env.IMAGE }}-catalog
tags: v${{ env.BUNDLE_VERSION }}
tags: v0.0.0-main
registry: ${{ env.REGISTRY }}
- name: print images reference
run: |
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ endif
# https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator
.PHONY: catalog-build
catalog-build: opm ## Build a catalog image.
$(OPM) index add --container-tool ${OCI_BIN} --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)
$(OPM) index add --container-tool ${OCI_BIN} --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT) $(OPM_OPTS)

shortlived-catalog-build: ## Build a temporary catalog image, expiring after 2 weeks on quay
$(MAKE) catalog-build CATALOG_IMG=$(IMAGE_TAG_BASE)-catalog:tmp
Expand All @@ -379,6 +379,10 @@ catalog-undeploy: ## Undeploy a catalog image.

##@ Misc

.PHONY: test-workflow
test-workflow: ## Run some tests on this Makefile and the github workflow
hack/test-workflow.sh

.PHONY: related-release-notes
related-release-notes: ## Grab release notes for related components (to be inserted in operator's release note upstream, cf RELEASE.md)
echo -e "## Related components\n\n" > /tmp/related.md
Expand Down
128 changes: 128 additions & 0 deletions hack/test-workflow.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#!/bin/bash

test_out="test.out"
bundle_csv="bundle/manifests/netobserv-operator.clusterserviceversion.yaml"
short_sha=$(git rev-parse --short HEAD)
fake_tag="1.0.42"

clean_up() {
ARG=$?
rm -r bundle_tmp*
exit $ARG
}
trap clean_up EXIT

run_step() {
file=$1
job=$2
name=$3
opts=$4

step=$(cat .github/workflows/$file | yq ".jobs.$job.steps[] | select(.name==\"$name\").run")
step=$(echo $step | sed -r "s~\\$\{\{ env\.REGISTRY \}\}~quay.io/netobserv~g" | sed -r "s~\\$\{\{ env\.IMAGE \}\}~network-observability-operator~g" | sed -r "s~\\$\{\{ env\.short_sha \}\}~$short_sha~g" | sed -r "s~\\$\{\{ env\.tag \}\}~$fake_tag~g")
step="$opts $step"

echo "↘️ Running step '$name' ($file)"
echo $step
eval $step > $test_out 2>&1

if [ $? -ne 0 ]; then
echo "❌ Step failed"
exit 1
fi
}

expect_image_tagged() {
img=$1
cat $test_out | grep "Successfully tagged $img"
if [ $? -ne 0 ]; then
echo "❌ Failure: expected successful tag $img"
exit 1
fi
}

expect_occurrences() {
file=$1
search=$2
expected=$3
found=$(cat $file | grep -o "$search" | wc -l)
if [ $found -ne $expected ]; then
echo "❌ Failure: expected $expected occurrences of \"$search\" in $file, found $found."
exit 1
fi
}

expect_occurrences_at_least() {
file=$1
search=$2
min=$3
found=$(cat $file | grep -o "$search" | wc -l)
if [ $found -lt $min ]; then
echo "❌ Failure: expected at least $min occurrences of \"$search\" in $file, found $found."
exit 1
fi
}

echo -e "🥁🥁🥁 TESTING push_image_pr.yml 🥁🥁🥁"

run_step "push_image_pr.yml" "push-pr-image" "build images"
expect_image_tagged "quay.io/netobserv/network-observability-operator:$short_sha"

run_step "push_image_pr.yml" "push-pr-image" "build bundle"
expect_image_tagged "quay.io/netobserv/network-observability-operator-bundle:v0.0.0-$short_sha"
expect_occurrences $bundle_csv "quay.io/netobserv/network-observability-operator:$short_sha" 2
expect_occurrences $bundle_csv "quay.io/netobserv/netobserv-ebpf-agent:main" 2
expect_occurrences $bundle_csv "quay.io/netobserv/flowlogs-pipeline:main" 2
expect_occurrences $bundle_csv "quay.io/netobserv/network-observability-console-plugin:main" 2

run_step "push_image_pr.yml" "push-pr-image" "build catalog" "OPM_OPTS=--permissive"
expect_occurrences_at_least $test_out "quay.io/netobserv/network-observability-operator-bundle:v0.0.0-$short_sha" 1
expect_image_tagged "quay.io/netobserv/network-observability-operator-catalog:v0.0.0-$short_sha"

echo -e "✅\n"
echo -e "🥁🥁🥁 TESTING push_image.yml 🥁🥁🥁"

run_step "push_image.yml" "push-image" "build images"
expect_image_tagged "quay.io/netobserv/network-observability-operator:main"

run_step "push_image.yml" "push-image" "build bundle"
expect_image_tagged "quay.io/netobserv/network-observability-operator-bundle:v0.0.0-main"
expect_occurrences $bundle_csv "quay.io/netobserv/network-observability-operator:main" 2
expect_occurrences $bundle_csv "quay.io/netobserv/netobserv-ebpf-agent:main" 2
expect_occurrences $bundle_csv "quay.io/netobserv/flowlogs-pipeline:main" 2
expect_occurrences $bundle_csv "quay.io/netobserv/network-observability-console-plugin:main" 2

run_step "push_image.yml" "push-image" "build catalog" "OPM_OPTS=--permissive"
expect_occurrences_at_least $test_out "quay.io/netobserv/network-observability-operator-bundle:v0.0.0-main" 1
expect_occurrences $test_out "quay.io/netobserv/network-observability-operator-catalog:v0.0.0-main" 2

echo -e "✅\n"
echo -e "🥁🥁🥁 TESTING make update-bundle 🥁🥁🥁"

make update-bundle > $test_out 2>&1
expect_occurrences $bundle_csv "quay.io/netobserv/network-observability-operator:1." 2
expect_occurrences $bundle_csv "quay.io/netobserv/netobserv-ebpf-agent:v0." 2
expect_occurrences $bundle_csv "quay.io/netobserv/flowlogs-pipeline:v0." 2
expect_occurrences $bundle_csv "quay.io/netobserv/network-observability-console-plugin:v0." 2

echo -e "✅\n"
echo -e "🥁🥁🥁 TESTING release.yml 🥁🥁🥁"

run_step "release.yml" "push-image" "build operator"
expect_image_tagged "quay.io/netobserv/network-observability-operator:$fake_tag"

run_step "release.yml" "push-image" "build bundle"
expect_image_tagged "quay.io/netobserv/network-observability-operator-bundle:v$fake_tag"
expect_occurrences $bundle_csv "quay.io/netobserv/network-observability-operator:1." 2
expect_occurrences $bundle_csv "quay.io/netobserv/netobserv-ebpf-agent:v0." 2
expect_occurrences $bundle_csv "quay.io/netobserv/flowlogs-pipeline:v0." 2
expect_occurrences $bundle_csv "quay.io/netobserv/network-observability-console-plugin:v0." 2

run_step "release.yml" "push-image" "build catalog" "OPM_OPTS=--permissive"
expect_occurrences_at_least $test_out "quay.io/netobserv/network-observability-operator-bundle:v$fake_tag" 1
expect_occurrences $test_out "quay.io/netobserv/network-observability-operator-catalog:v$fake_tag" 2

echo -e "\n✅ Looks good to me!"

# Remove output only on success so it's still there for debugging failures
rm $test_out

0 comments on commit 949256f

Please sign in to comment.