Skip to content

Commit f578488

Browse files
committed
sed compatibility for non-GNU systems in ci-test
sed behaves differently depending on if it is the GNU version or the BSD version In the BSD version, using sed -i requires setting a backup (which can be empty) Signed-off-by: Tomáš Nevrlka <[email protected]>
1 parent d02a861 commit f578488

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

ci-test.sh

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@ source setup-local-dev-repos.sh
33
source init-tas-vars.sh
44
eval "$(hack/get-trustification-env.sh)"
55

6+
# sed behaves differently on different platforms
7+
# sed --version is not valid on BSD, while it is valid on the GNU version
8+
SED_CMD() {
9+
if sed --version > /dev/null 2>&1; then
10+
# GNU version
11+
sed -i "$@"
12+
else
13+
# BSD version
14+
sed -i "" "$@"
15+
fi
16+
}
17+
618
# setting secrets for the dev repos is slow
719
# after the first setting, you can skip this step
820
# warning, if your secrets are stale, do not skip this step
@@ -34,9 +46,9 @@ function updateGitAndQuayRefs() {
3446
echo "USE_RHTAP_IMAGES is set to $USE_RHTAP_IMAGES"
3547
echo "images or Jenkins references patched to quay.io/$MY_QUAY_USER and github.com/$MY_GITHUB_USER"
3648
if [ -f "$1" ]; then
37-
sed -i "s!quay.io/redhat-appstudio/rhtap-task-runner.*!quay.io/$MY_QUAY_USER/rhtap-task-runner:dev!g" "$1"
38-
sed -i "s!https://github.com/redhat-appstudio!https://github.com/$MY_GITHUB_USER!g" "$1"
39-
sed -i "s!RHTAP_Jenkins@.*'!RHTAP_Jenkins@dev'!g" "$1"
49+
SED_CMD "s!quay.io/redhat-appstudio/rhtap-task-runner.*!quay.io/$MY_QUAY_USER/rhtap-task-runner:dev!g" "$1"
50+
SED_CMD "s!https://github.com/redhat-appstudio!https://github.com/$MY_GITHUB_USER!g" "$1"
51+
SED_CMD "s!RHTAP_Jenkins@.*'!RHTAP_Jenkins@dev'!g" "$1"
4052
fi
4153
fi
4254
}
@@ -47,14 +59,14 @@ function updateBuild() {
4759
mkdir -p "$REPO/rhtap"
4860
SETUP_ENV=$REPO/rhtap/env.sh
4961
cp rhtap/env.template.sh "$SETUP_ENV"
50-
sed -i "s!\${{ values.image }}!$IMAGE_TO_BUILD!g" "$SETUP_ENV"
51-
sed -i "s!\${{ values.dockerfile }}!Dockerfile!g" "$SETUP_ENV"
52-
sed -i "s!\${{ values.buildContext }}!.!g" "$SETUP_ENV"
53-
sed -i "s!\${{ values.repoURL }}!$GITOPS_REPO_UPDATE!g" "$SETUP_ENV"
62+
SED_CMD "s!\${{ values.image }}!$IMAGE_TO_BUILD!g" "$SETUP_ENV"
63+
SED_CMD "s!\${{ values.dockerfile }}!Dockerfile!g" "$SETUP_ENV"
64+
SED_CMD "s!\${{ values.buildContext }}!.!g" "$SETUP_ENV"
65+
SED_CMD "s!\${{ values.repoURL }}!$GITOPS_REPO_UPDATE!g" "$SETUP_ENV"
5466
# Update REKOR_HOST and TUF_MIRROR values directly
55-
sed -i '/export REKOR_HOST=/d' "$SETUP_ENV"
56-
sed -i '/export TUF_MIRROR=/d' "$SETUP_ENV"
57-
sed -i '/export IGNORE_REKOR=/d' "$SETUP_ENV"
67+
SED_CMD '/export REKOR_HOST=/d' "$SETUP_ENV"
68+
SED_CMD '/export TUF_MIRROR=/d' "$SETUP_ENV"
69+
SED_CMD '/export IGNORE_REKOR=/d' "$SETUP_ENV"
5870

5971
{
6072
echo ""
@@ -66,7 +78,7 @@ function updateBuild() {
6678

6779
if [[ "$TEST_PRIVATE_REGISTRY" == "true" ]]; then
6880
echo "WARNING Due to private repos, disabling ACS"
69-
sed -i '/export DISABLE_ACS=/d' "$SETUP_ENV"
81+
SED_CMD '/export DISABLE_ACS=/d' "$SETUP_ENV"
7082
echo "export DISABLE_ACS=true" >> "$SETUP_ENV"
7183
fi
7284

0 commit comments

Comments
 (0)