Skip to content

Commit e3cc8e6

Browse files
committed
Added PR tag to script
1 parent b1e5487 commit e3cc8e6

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ VERSION ?= 0.0.1
77
OPERATOR_NAME ?= uptimeguardian
88
CATALOG_DIR_PATH ?= catalog
99
DOCKER_REPO_BASE ?= ghcr.io/stakater
10+
PR_TAG ?= PR
1011

1112
# CHANNELS define the bundle channels used in the bundle.
1213
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
@@ -337,7 +338,7 @@ endif
337338
# Render bundle to the catalog index.
338339
.PHONY: catalog-render
339340
catalog-render: opm yq ## Render bundle to catalog index.
340-
sh generate-catalog-index.sh $(DOCKER_REPO_BASE) $(OPERATOR_NAME) $(CATALOG_DIR_PATH)
341+
sh generate-catalog-index.sh $(DOCKER_REPO_BASE) $(OPERATOR_NAME) $(CATALOG_DIR_PATH) $(VERSION) $(PR_TAG)
341342
.PHONY: catalog-build
342343
catalog-build: opm ## Build a catalog image.
343344
$(CONTAINER_TOOL) build -f catalog.Dockerfile -t $(CATALOG_IMG) .

generate-catalog-index.sh

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,46 @@
11
DOCKER_REPO=$1
22
OPERATOR_NAME=$2
33
CATALOG_DIR_PATH=$3
4+
VERSION=$4
5+
PR_TAG=$5
46

57
# Get entries and iterate
6-
CHANNEL_BUNDLES=$(yq eval-all 'select(.schema == "olm.channel") | .entries[].name' $CATALOG_DIR_PATH/channels.yaml | grep -v '^---$' | sort | uniq)
8+
CHANNEL_BUNDLES=$(yq eval-all 'select(.schema == "olm.channel") | .entries[].name' "$CATALOG_DIR_PATH"/channels.yaml | grep -v '^---$' | sort | uniq)
79
# Render all required bundles
8-
rm -rf $CATALOG_DIR_PATH/bundles.yaml
10+
rm -rf "$CATALOG_DIR_PATH"/bundles.yaml
11+
912
echo " catalog build start"
13+
SHOULD_RELEASE="false"
1014
for item in $CHANNEL_BUNDLES; do
11-
bundle="${item//${OPERATOR_NAME}./${OPERATOR_NAME}-bundle:}"
12-
opm render "$DOCKER_REPO/$bundle" --output=yaml >> $CATALOG_DIR_PATH/bundles.yaml
15+
# Setup bundle from entries
16+
if [ -n "$PR_TAG" ]; then
17+
bundle="${item//${OPERATOR_NAME}./${OPERATOR_NAME}-bundle:}-${PR_TAG}"
18+
release="${OPERATOR_NAME}-bundle:v${VERSION}-${PR_TAG}"
19+
else
20+
bundle="${item//${OPERATOR_NAME}./${OPERATOR_NAME}-bundle:}"
21+
release="${OPERATOR_NAME}-bundle:v${VERSION}"
22+
fi
23+
24+
# Check if next release is defined in any channel
25+
if [ "${bundle}" == "${release}" ]; then
26+
SHOULD_RELEASE="true"
27+
else
28+
SHOULD_RELEASE="false"
29+
fi
30+
31+
opm render "$DOCKER_REPO/$bundle" --output=yaml >> "$CATALOG_DIR_PATH"/bundles.yaml
1332
echo " >> rendered $bundle >> $CATALOG_DIR_PATH/bundles.yaml"
1433
done
1534

16-
# Build catalog index
17-
yq eval-all '.' $CATALOG_DIR_PATH/package.yaml $CATALOG_DIR_PATH/channels.yaml $CATALOG_DIR_PATH/bundles.yaml > $CATALOG_DIR_PATH/release/index.yaml
18-
echo " >> created index >> $CATALOG_DIR_PATH/release/index.yaml"
35+
# Build catalog index if there should be a release
36+
if [ ${SHOULD_RELEASE} = "true" ]; then
37+
yq eval-all '.' "$CATALOG_DIR_PATH"/package.yaml "$CATALOG_DIR_PATH"/channels.yaml "$CATALOG_DIR_PATH"/bundles.yaml > "$CATALOG_DIR_PATH"/release/index.yaml
38+
echo " >> created index >> $CATALOG_DIR_PATH/release/index.yaml"
39+
else
40+
echo " >> release is not defined in ${CATALOG_DIR_PATH}/channels.yaml, will not create catalog index"
41+
fi
1942

20-
rm -rf $CATALOG_DIR_PATH/bundles.yaml
43+
rm -rf "$CATALOG_DIR_PATH"/bundles.yaml
2144
echo " catalog build done!"
2245

2346
## Delete entries

0 commit comments

Comments
 (0)