|
33 | 33 | - uses: actions/setup-node@1a4442cacd436585916779262731d5b162bc6ec7 # v3.8.2 |
34 | 34 | with: |
35 | 35 | node-version: 20.x |
| 36 | + - name: Check if sha256 lines changed in this PR for verifying image digest changes |
| 37 | + id: check-sha |
| 38 | + if: github.event_name == 'pull_request' |
| 39 | + run: | |
| 40 | + set -euo pipefail |
| 41 | +
|
| 42 | + echo "Checking only Dockerfile and Dockerfile.plugins for sha256 changes" |
| 43 | +
|
| 44 | + # Prefer the base SHA from the PR event, which works for both forks and same-repo branches. |
| 45 | + BASE_SHA="${{ github.event.pull_request.base.sha }}" |
| 46 | + echo "Initial diff target from PR base SHA: $BASE_SHA" |
| 47 | +
|
| 48 | + # If the base SHA is not present in the local clone (e.g., shallow fetch), try fetching the base ref. |
| 49 | + if ! git cat-file -e "$BASE_SHA^{commit}" 2>/dev/null; then |
| 50 | + echo "Base SHA not found locally, trying to fetch base ref" |
| 51 | + BASE_REF="${{ github.event.pull_request.base.ref }}" |
| 52 | + git fetch origin "$BASE_REF" --depth=5000 || git fetch origin "$BASE_REF" || true |
| 53 | + if git show-ref --verify --quiet "refs/remotes/origin/${BASE_REF}"; then |
| 54 | + BASE_SHA="origin/${BASE_REF}" |
| 55 | + echo "Using origin/${BASE_REF} as diff target" |
| 56 | + else |
| 57 | + echo "Warning: could not fetch base ref; falling back to PR base SHA (may fail if missing)" |
| 58 | + fi |
| 59 | + fi |
| 60 | +
|
| 61 | + # Try three-dot first; if there is no merge base (e.g., unrelated histories), |
| 62 | + # fall back to a simple two-dot diff which doesn't require a merge base. |
| 63 | + if git merge-base "$BASE_SHA" HEAD >/dev/null 2>&1; then |
| 64 | + DIFF_RANGE="${BASE_SHA}...HEAD" |
| 65 | + else |
| 66 | + echo "No merge-base between $BASE_SHA and HEAD; using two-dot diff" |
| 67 | + DIFF_RANGE="${BASE_SHA}..HEAD" |
| 68 | + fi |
| 69 | +
|
| 70 | + if git diff -U0 "$DIFF_RANGE" -- Dockerfile Dockerfile.plugins | grep -E '^[+-].*sha256:' >/dev/null; then |
| 71 | + echo "sha_changed=true" |
| 72 | + echo "sha_changed=true" >> "$GITHUB_OUTPUT" |
| 73 | + else |
| 74 | + echo "sha_changed=false" |
| 75 | + echo "sha_changed=false" >> "$GITHUB_OUTPUT" |
| 76 | + fi |
36 | 77 | - name: Verify container image digests |
| 78 | + if: github.event_name == 'pull_request' && steps.check-sha.outputs.sha_changed == 'true' |
37 | 79 | run: npm run image:verify-image-digests |
38 | 80 | - name: Start Cluster 1 |
39 | 81 | uses: helm/kind-action@0025e74a8c7512023d06dc019c617aa3cf561fde # v1.0.0 |
|
0 commit comments