From ba6da23323e942c96dc6320bd48a2cbf8d8f8f48 Mon Sep 17 00:00:00 2001
From: Hidde Beydals <hello@hidde.co>
Date: Mon, 8 Mar 2021 17:17:53 +0100
Subject: [PATCH] Make manifests dir `bundle.sh` configurable

There was an assumption in this script that it is always executed in Git
repository/directory, this is however not always true, for example when
one downloads the `.tar.gz` that is made available for every release
by GitHub (and used in one of our AUR packages).

This commit changes this, and makes the first argument of `bundle.sh`
configurable, so a custom manifests directory can always be defined
_without_ relying on Git.

Omitting it, or passing an empty string, will still fall back to the
previous behavior of using `git rev-parse --show-toplevel`.

Signed-off-by: Hidde Beydals <hello@hidde.co>
---
 .github/workflows/release.yaml |  2 +-
 manifests/scripts/bundle.sh    | 14 +++++++-------
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml
index 0a920706..3629109c 100644
--- a/.github/workflows/release.yaml
+++ b/.github/workflows/release.yaml
@@ -31,7 +31,7 @@ jobs:
       - name: Generate manifests
         run: |
           make cmd/flux/manifests
-          ./manifests/scripts/bundle.sh ./output manifests.tar.gz
+          ./manifests/scripts/bundle.sh "" ./output manifests.tar.gz
           kustomize build ./manifests/install > ./output/install.yaml
       - name: Run GoReleaser
         uses: goreleaser/goreleaser-action@v1
diff --git a/manifests/scripts/bundle.sh b/manifests/scripts/bundle.sh
index b5f89607..31babc7c 100755
--- a/manifests/scripts/bundle.sh
+++ b/manifests/scripts/bundle.sh
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 
-# Copyright 2020 The Flux authors. All rights reserved.
+# Copyright 2020, 2021 The Flux authors. All rights reserved.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -16,9 +16,9 @@
 
 set -e
 
-REPO_ROOT=$(git rev-parse --show-toplevel)
-OUT_PATH=${1:-"${REPO_ROOT}/cmd/flux/manifests"}
-TAR=${2}
+IN_PATH=${1:-"$(git rev-parse --show-toplevel)/manifests"}
+OUT_PATH=${2:-"$(git rev-parse --show-toplevel)/cmd/flux/manifests"}
+TAR=${3}
 
 info() {
     echo '[INFO] ' "$@"
@@ -45,20 +45,20 @@ files=""
 info using "$(kustomize version --short)"
 
 # build controllers
-for controller in ${REPO_ROOT}/manifests/bases/*/; do
+for controller in ${IN_PATH}/bases/*/; do
     output_path="${OUT_PATH}/$(basename $controller).yaml"
     build $controller $output_path
     files+=" $(basename $output_path)"
 done
 
 # build rbac
-rbac_path="${REPO_ROOT}/manifests/rbac"
+rbac_path="${IN_PATH}/rbac"
 rbac_output_path="${OUT_PATH}/rbac.yaml"
 build $rbac_path $rbac_output_path
 files+=" $(basename $rbac_output_path)"
 
 # build policies
-policies_path="${REPO_ROOT}/manifests/policies"
+policies_path="${IN_PATH}/policies"
 policies_output_path="${OUT_PATH}/policies.yaml"
 build $policies_path $policies_output_path
 files+=" $(basename $policies_output_path)"
-- 
GitLab