Skip to content

Commit

Permalink
make md5 logic centralised (#5248)
Browse files Browse the repository at this point in the history
  • Loading branch information
pdabelf5 authored Mar 14, 2024
1 parent 01ef65f commit 079a935
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
29 changes: 29 additions & 0 deletions .github/scripts/variables.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

if [ "$1" = "" ]; then
echo "ERROR: paramater needed"
exit 2
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 . -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 . -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
3 changes: 1 addition & 2 deletions .github/workflows/build-base-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cache-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/update-docker-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 079a935

Please sign in to comment.