@@ -125,6 +125,15 @@ runs:
125125 - name : Update Docker Image in Repository
126126 shell : bash
127127 run : |
128+ commit_changes () {
129+ if [[ ${{ steps.preparation.outputs.push }} == "true" ]]; then
130+ git add . && git commit -m "Release ${{ inputs.dockerregistry }}/${{ inputs.dockerimage }}:${{ steps.preparation.outputs.tag }}"
131+ # In case there was another push in the meantime, we pull it again
132+ git pull --rebase https://${{ inputs.gitopsuser }}:${{ inputs.gitopstoken }}@github.com/${{ inputs.gitopsorganization }}/${{ inputs.gitopsrepository }}.git
133+ git push https://${{ inputs.gitopsuser }}:${{ inputs.gitopstoken }}@github.com/${{ inputs.gitopsorganization }}/${{ inputs.gitopsrepository }}.git
134+ fi
135+ }
136+
128137 if [[ ${{ inputs.gitopsenabled }} == "true" ]]; then
129138 git config --global user.email "${{ inputs.gitopsemail }}" && git config --global user.name "${{ inputs.gitopsuser }}"
130139
@@ -140,6 +149,8 @@ runs:
140149 echo "Run update $line ${{ inputs.dockerregistry }}/${{ inputs.dockerimage }}:${{ steps.preparation.outputs.tag }}"
141150 ../gitops/yq w -i $line ${{ inputs.dockerregistry }}/${{ inputs.dockerimage }}:${{ steps.preparation.outputs.tag }}
142151 done <<< "${{ inputs.gitopsstage }}"
152+ commit_changes
153+
143154 elif [[ $GITHUB_REF == refs/heads/dev && -n "${{ inputs.gitopsdev }}" ]]; then
144155 echo "Run update for DEV"
145156 while IFS= read -r line; do
@@ -148,6 +159,8 @@ runs:
148159 echo "Run update $line ${{ inputs.dockerregistry }}/${{ inputs.dockerimage }}:${{ steps.preparation.outputs.tag }}"
149160 ../gitops/yq w -i $line ${{ inputs.dockerregistry }}/${{ inputs.dockerimage }}:${{ steps.preparation.outputs.tag }}
150161 done <<< "${{ inputs.gitopsdev }}"
162+ commit_changes
163+
151164 elif [[ $GITHUB_REF == refs/tags/* && -n "${{ inputs.gitopsprod }}" ]]; then
152165 echo "Run update for PROD"
153166 while IFS= read -r line; do
@@ -156,6 +169,8 @@ runs:
156169 echo "Run update $line ${{ inputs.dockerregistry }}/${{ inputs.dockerimage }}:${{ steps.preparation.outputs.tag }}"
157170 ../gitops/yq w -i $line ${{ inputs.dockerregistry }}/${{ inputs.dockerimage }}:${{ steps.preparation.outputs.tag }}
158171 done <<< "${{ inputs.gitopsprod }}"
172+ commit_changes
173+
159174 elif [[ -n "${{ inputs.gitopsdev }}" ]]; then
160175 echo "Simulate update for DEV"
161176 while IFS= read -r line; do
@@ -164,11 +179,6 @@ runs:
164179 echo "Run update $line ${{ inputs.dockerregistry }}/${{ inputs.dockerimage }}:${{ steps.preparation.outputs.tag }}"
165180 ../gitops/yq w -i $line ${{ inputs.dockerregistry }}/${{ inputs.dockerimage }}:${{ steps.preparation.outputs.tag }}
166181 done <<< "${{ inputs.gitopsdev }}"
167- fi
168-
169- if [[ ${{ steps.preparation.outputs.push }} == "true" ]]; then
170- git add . && git commit -m "Release ${{ inputs.dockerregistry }}/${{ inputs.dockerimage }}:${{ steps.preparation.outputs.tag }}"
171- git pull --rebase https://${{ inputs.gitopsuser }}:${{ inputs.gitopstoken }}@github.com/${{ inputs.gitopsorganization }}/${{ inputs.gitopsrepository }}.git # in case there was another push in the meantime
172- git push https://${{ inputs.gitopsuser }}:${{ inputs.gitopstoken }}@github.com/${{ inputs.gitopsorganization }}/${{ inputs.gitopsrepository }}.git
182+ commit_changes
173183 fi
174184 fi
0 commit comments