From dc221fafdf9dc10b697111fefd97552b62cd04e3 Mon Sep 17 00:00:00 2001
From: Paul Abel
Date: Thu, 14 Mar 2024 11:50:31 +0000
Subject: [PATCH 1/2] make md5 logic centralised
---
.github/scripts/variables.sh | 25 ++++++++++++++++++++++
.github/workflows/build-base-images.yml | 3 +--
.github/workflows/cache-update.yml | 2 +-
.github/workflows/ci.yml | 5 ++---
.github/workflows/update-docker-images.yml | 8 ++++++-
5 files changed, 36 insertions(+), 7 deletions(-)
create mode 100755 .github/scripts/variables.sh
diff --git a/.github/scripts/variables.sh b/.github/scripts/variables.sh
new file mode 100755
index 0000000000..88cc3f4200
--- /dev/null
+++ b/.github/scripts/variables.sh
@@ -0,0 +1,25 @@
+#!/usr/bin/env bash
+
+if [ "$1" = "" ]; then
+ echo "ERROR: paramater needed"
+ exit 2
+fi
+
+INPUT=$1
+ROOTDIR=$(git rev-parse --show-toplevel || echo ".")
+
+case $INPUT in
+ docker_md5)
+ docker_md5=$(find "$ROOTDIR" -type f \( -name "Dockerfile" -o -name version.txt \) -not -path "./tests*" -exec md5sum {} + | LC_ALL=C sort | md5sum | awk '{ print $1 }')
+ echo "docker_md5=${docker_md5:0:8}"
+ ;;
+
+ go_code_md5)
+ echo "go_code_md5=$(find "$ROOTDIR" -type f \( -name "*.go" -o -name go.mod -o -name go.sum -o -name "*.tmpl" \) -not -path "./docs*" -exec md5sum {} + | LC_ALL=C sort | md5sum | awk '{ print $1 }')"
+ ;;
+
+ *)
+ echo "ERROR: option not found"
+ exit 2
+ ;;
+esac
diff --git a/.github/workflows/build-base-images.yml b/.github/workflows/build-base-images.yml
index a92cd044f9..b63e79e381 100644
--- a/.github/workflows/build-base-images.yml
+++ b/.github/workflows/build-base-images.yml
@@ -32,8 +32,7 @@ jobs:
- name: Output Variables
id: vars
run: |
- docker_md5=$(find . -type f \( -name "Dockerfile" -o -name version.txt \) -not -path "./tests*" -exec md5sum {} + | LC_ALL=C sort | md5sum | awk '{ print $1 }')
- echo "docker_md5=${docker_md5:0:8}" >> $GITHUB_OUTPUT
+ ./.github/scripts/variables.sh docker_md5 >> $GITHUB_OUTPUT
source .github/data/version.txt
echo "ic_version=${IC_VERSION}" >> $GITHUB_OUTPUT
cat $GITHUB_OUTPUT
diff --git a/.github/workflows/cache-update.yml b/.github/workflows/cache-update.yml
index 37e4e1d5de..17dc021df4 100644
--- a/.github/workflows/cache-update.yml
+++ b/.github/workflows/cache-update.yml
@@ -28,7 +28,7 @@ jobs:
- name: Output Variables
id: vars
run: |
- echo go_code_md5=$(find . -type f \( -name "*.go" -o -name go.mod -o -name go.sum -o -name "*.tmpl" -o -name .goreleaser.yml -o -name .github/data/version.txt \) -not -path "./docs*" -exec md5sum {} + | LC_ALL=C sort | md5sum | awk '{ print $1 }') >> $GITHUB_OUTPUT
+ ./.github/scripts/variables.sh go_code_md5 >> $GITHUB_OUTPUT
source .github/data/version.txt
echo "chart_version=${HELM_CHART_VERSION}" >> $GITHUB_OUTPUT
cat $GITHUB_OUTPUT
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index d540d9beee..19a9149673 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -81,7 +81,6 @@ jobs:
| jq -R -s -c 'split("\n")[:-1]')
echo "latest_kindest_node_versions=$kindest_versions" >> $GITHUB_OUTPUT
echo "go_path=$(go env GOPATH)" >> $GITHUB_OUTPUT
- echo go_code_md5=$(find . -type f \( -name "*.go" -o -name go.mod -o -name go.sum -o -name "*.tmpl" -o -name .goreleaser.yml -o -name .github/data/version.txt \) -not -path "./docs*" -exec md5sum {} + | LC_ALL=C sort | md5sum | awk '{ print $1 }') >> $GITHUB_OUTPUT
source .github/data/version.txt
echo "ic_version=${IC_VERSION}" >> $GITHUB_OUTPUT
echo "chart_version=${HELM_CHART_VERSION}" >> $GITHUB_OUTPUT
@@ -94,8 +93,8 @@ jobs:
publish=true
fi
echo "publish=$publish" >> $GITHUB_OUTPUT
- docker_md5=$(find . -type f \( -name "Dockerfile" -o -name version.txt \) -not -path "./tests*" -exec md5sum {} + | LC_ALL=C sort | md5sum | awk '{ print $1 }')
- echo "docker_md5=${docker_md5:0:8}" >> $GITHUB_OUTPUT
+ ./.github/scripts/variables.sh go_code_md5 >> $GITHUB_OUTPUT
+ ./.github/scripts/variables.sh docker_md5 >> $GITHUB_OUTPUT
cat $GITHUB_OUTPUT
- name: Fetch Cached Binary Artifacts
diff --git a/.github/workflows/update-docker-images.yml b/.github/workflows/update-docker-images.yml
index 1fbf07ccde..5a6d63fe58 100644
--- a/.github/workflows/update-docker-images.yml
+++ b/.github/workflows/update-docker-images.yml
@@ -30,6 +30,7 @@ jobs:
versions: ${{ steps.versions.outputs.matrix }}
go-md5: ${{ steps.md5.outputs.go_code_md5 }}
binary-cache-hit: ${{ steps.binary-cache.outputs.cache-hit }}
+ base-image-md5: ${{ steps.md5.outputs.docker_md5 }}
steps:
- name: Checkout Repository
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
@@ -57,7 +58,9 @@ jobs:
- name: Set Go MD5sums
id: md5
- run: echo go_code_md5=$(find . -type f \( -name "*.go" -o -name go.mod -o -name go.sum -o -name "*.tmpl" \) -not -path "./docs*" -exec md5sum {} + | LC_ALL=C sort | md5sum | awk '{ print $1 }') >> $GITHUB_OUTPUT
+ run: |
+ ./.github/scripts/variables.sh go_code_md5 >> $GITHUB_OUTPUT
+ ./.github/scripts/variables.sh docker_md5 >> $GITHUB_OUTPUT
- name: Fetch Cached Binary Artifacts
id: binary-cache
@@ -144,6 +147,7 @@ jobs:
image: debian
tag: ${{ needs.variables.outputs.kic-tag }}
go-md5: ${{ needs.variables.outputs.go-md5 }}
+ base-image-md5: ${{ needs.variables.outputs.base-image-md5 }}
permissions:
contents: read
actions: read
@@ -162,6 +166,7 @@ jobs:
image: alpine
tag: ${{ needs.variables.outputs.kic-tag }}
go-md5: ${{ needs.variables.outputs.go-md5 }}
+ base-image-md5: ${{ needs.variables.outputs.base-image-md5 }}
permissions:
contents: read
actions: read
@@ -180,6 +185,7 @@ jobs:
image: ubi
tag: ${{ needs.variables.outputs.kic-tag }}
go-md5: ${{ needs.variables.outputs.go-md5 }}
+ base-image-md5: ${{ needs.variables.outputs.base-image-md5 }}
permissions:
contents: read
actions: read
From 45999a3c9cd2a431b54a46c25e1360a71ba88e05 Mon Sep 17 00:00:00 2001
From: Paul Abel
Date: Thu, 14 Mar 2024 12:17:41 +0000
Subject: [PATCH 2/2] change directory to root of git project
---
.github/scripts/variables.sh | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/.github/scripts/variables.sh b/.github/scripts/variables.sh
index 88cc3f4200..ba31016b2d 100755
--- a/.github/scripts/variables.sh
+++ b/.github/scripts/variables.sh
@@ -7,15 +7,19 @@ fi
INPUT=$1
ROOTDIR=$(git rev-parse --show-toplevel || echo ".")
+if [ "$PWD" != "$ROOTDIR" ]; then
+ # shellcheck disable=SC2164
+ cd "$ROOTDIR";
+fi
case $INPUT in
docker_md5)
- docker_md5=$(find "$ROOTDIR" -type f \( -name "Dockerfile" -o -name version.txt \) -not -path "./tests*" -exec md5sum {} + | LC_ALL=C sort | md5sum | awk '{ print $1 }')
+ docker_md5=$(find . -type f \( -name "Dockerfile" -o -name version.txt \) -not -path "./tests*" -exec md5sum {} + | LC_ALL=C sort | md5sum | awk '{ print $1 }')
echo "docker_md5=${docker_md5:0:8}"
;;
go_code_md5)
- echo "go_code_md5=$(find "$ROOTDIR" -type f \( -name "*.go" -o -name go.mod -o -name go.sum -o -name "*.tmpl" \) -not -path "./docs*" -exec md5sum {} + | LC_ALL=C sort | md5sum | awk '{ print $1 }')"
+ echo "go_code_md5=$(find . -type f \( -name "*.go" -o -name go.mod -o -name go.sum -o -name "*.tmpl" \) -not -path "./docs*" -exec md5sum {} + | LC_ALL=C sort | md5sum | awk '{ print $1 }')"
;;
*)