From 9f7df0c6129e467f247f831912f0292c987d8987 Mon Sep 17 00:00:00 2001 From: Harry Gogonis Date: Wed, 13 Nov 2024 10:40:59 -0500 Subject: [PATCH 1/2] WIP: new folders --- .github/workflows/test.yml | 1 + testdata/new/README.md | 2 ++ testdata/new/kustomization.yml | 4 ++++ 3 files changed, 7 insertions(+) create mode 100644 testdata/new/README.md create mode 100644 testdata/new/kustomization.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 59f4f48..b61d378 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,6 +19,7 @@ jobs: kustomizations: |- testdata/prod testdata/stage + testdata/new - uses: mshick/add-pr-comment@v2 with: message: ${{ steps.test-action.outputs.diff }} diff --git a/testdata/new/README.md b/testdata/new/README.md new file mode 100644 index 0000000..e901c93 --- /dev/null +++ b/testdata/new/README.md @@ -0,0 +1,2 @@ +The point of this folder is to test that if the base commit does not contain this folder, +the action is still successful \ No newline at end of file diff --git a/testdata/new/kustomization.yml b/testdata/new/kustomization.yml new file mode 100644 index 0000000..27bb5cb --- /dev/null +++ b/testdata/new/kustomization.yml @@ -0,0 +1,4 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - ../base From 366e0da8c8ae3bdd00cc9e895440ef40c4d175e0 Mon Sep 17 00:00:00 2001 From: Harry Gogonis Date: Wed, 13 Nov 2024 10:50:58 -0500 Subject: [PATCH 2/2] update code --- .github/workflows/test.yml | 2 +- entrypoint.sh | 28 ++++++++++++++++++++++------ testdata/new/README.md | 3 +-- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b61d378..0d3f5cc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,7 +15,7 @@ jobs: uses: ./ with: base_ref: 027b33661ae3211230e8cd03d19df49ba620b379 - head_ref: 182a672418c5bae4d6b7ca1244da5f28bf5ff6f0 + head_ref: ${{ github.sha }} kustomizations: |- testdata/prod testdata/stage diff --git a/entrypoint.sh b/entrypoint.sh index 67f1486..e334fe4 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -4,12 +4,28 @@ set -eux build_dir=$(mktemp -d) -build() { - ref="$1" - git checkout "$1" --quiet +build_base() { + ref="$INPUT_BASE_REF" + git checkout "$ref" --quiet for target in $INPUT_KUSTOMIZATIONS; do - echo "Building $target" to "$build_dir/$ref/$target" + echo "Building base $target" to "$build_dir/$ref/$target" + mkdir -p "$build_dir/$ref/$target" + if [ ! -d "$target" ]; then + echo "Base $target does not exist. Treating it as an empty dir" + mkdir -p "$target" + else + kustomize build "$target" -o "$build_dir/$ref/$target/" + fi + done +} + +build_head() { + ref="$INPUT_HEAD_REF" + git checkout "$ref" --quiet + + for target in $INPUT_KUSTOMIZATIONS; do + echo "Building head $target" to "$build_dir/$ref/$target" mkdir -p "$build_dir/$ref/$target" kustomize build "$target" -o "$build_dir/$ref/$target/" done @@ -17,8 +33,8 @@ build() { git config --global --add safe.directory "$GITHUB_WORKSPACE" -build "$INPUT_BASE_REF" -build "$INPUT_HEAD_REF" +build_base +build_head base_ref_build_dir="$build_dir/$INPUT_BASE_REF" head_ref_build_dir="$build_dir/$INPUT_HEAD_REF" diff --git a/testdata/new/README.md b/testdata/new/README.md index e901c93..14d024d 100644 --- a/testdata/new/README.md +++ b/testdata/new/README.md @@ -1,2 +1 @@ -The point of this folder is to test that if the base commit does not contain this folder, -the action is still successful \ No newline at end of file +The point of this folder is to test that if the base commit does not contain this folder, the action is still successful \ No newline at end of file