File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,12 @@ inputs:
1616 deploy-pr/<environment> branch and open a PR for review
1717 required : false
1818 default : .*(staging|production).*
19+ force-push-on-image-change :
20+ description : |
21+ When true the action will push to the <environment> branch if there
22+ only image changes detected.
23+ required : false
24+ default : false
1925 dry-run :
2026 description : |
2127 On a dry-run only the kustomize build will occur and the built branch will
@@ -175,6 +181,13 @@ runs:
175181 edit-mode : replace
176182 token : ${{ inputs.token }}
177183
184+ - name : Detect pure Image Changes and Force push if true
185+ if : ${{ inputs.force-push-on-image-change == 'true') }
186+ id : detect-image-changes
187+ shell : bash
188+ working-directory : ${{ inputs.working-directory }}
189+ run : sha-change.sh
190+
178191 - name : Commit to ${{ env.PUSH_BRANCH }}
179192 shell : bash
180193 working-directory : ${{ inputs.working-directory }}
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ # Get the git diff output of staged changes
4+
5+ DIFF_OUTPUT=$( git diff " origin/${DIFF_BRANCH} " --unified=0 | grep ' ^[+-]' | grep -Ev ' ^(---|\+\+\+|index)' )
6+
7+ echo " Diff lines:"
8+ echo $DIFF_OUTPUT
9+
10+ # Check if there are any changes
11+ if [[ -z " $DIFF_OUTPUT " ]]; then
12+ echo " No changes found in git diff."
13+ exit 1
14+ fi
15+
16+ # Define the allowed pattern
17+ ALLOWED_PATTERN=' ^[+-][[:space:]]*image:.*'
18+
19+ # Check each line of the diff output
20+ while IFS= read -r line; do
21+ if [[ ! " $line " =~ $ALLOWED_PATTERN ]]; then
22+ echo " Invalid change detected: $line "
23+ exit 1
24+ fi
25+ done <<< " $DIFF_OUTPUT"
26+
27+ echo " All changes match the allowed pattern, Forcing Deploy method to PUSH."
28+ echo " DEPLOY_METHOD=PUSH" >> " ${GITHUB_ENV} "
29+
30+ exit 0
You can’t perform that action at this time.
0 commit comments