Skip to content

Commit 68be98b

Browse files
Refactor GitHub Actions workflow for updating Kustomize overlay
1 parent f85bc07 commit 68be98b

File tree

1 file changed

+25
-42
lines changed

1 file changed

+25
-42
lines changed

.github/workflows/kustomize-ci.yaml

Lines changed: 25 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -57,55 +57,38 @@ jobs:
5757
5858
sed -i.bak -E "s|image:.*|image: ${IMAGE_NAME}:${IMAGE_TAG}|" "$FILE"
5959
60-
- name: Commit and push changes
61-
env:
62-
TOKEN: ${{ secrets.GH_PAT }}
63-
IMAGE_TAG: ${{ env.IMAGE_TAG }}
64-
run: |
65-
git config --global user.name "${{ secrets.GIT_USER_NAME }}"
66-
git config --global user.email "${{ secrets.GIT_USER_EMAIL }}"
67-
68-
git remote set-url origin https://x-access-token:${{ secrets.GH_PAT }}@github.com/${{ github.repository }}.git
69-
git remote set-url origin https://x-access-token:${{ secrets.GH_PAT }}@github.com/${{ github.repository }}.git
70-
71-
72-
git add kustomize/overlays/dev/patch-deployment-image.yaml
73-
git commit -m "Update latest image tag to $IMAGE_TAG"
74-
git push
7560
61+
update-kustomize:
62+
name: Update Kustomize Overlay
63+
needs: build-and-push
64+
runs-on: ubuntu-latest
7665

77-
# update-kustomize:
78-
# name: Update Kustomize Overlay
79-
# needs: build-and-push
80-
# runs-on: ubuntu-latest
66+
env:
67+
IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/springboot-postgres
68+
IMAGE_TAG: ${{ needs.build-and-push.outputs.image-tag }}
8169

82-
# env:
83-
# IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/springboot-postgres
84-
# IMAGE_TAG: ${{ needs.build-and-push.outputs.image-tag }}
70+
steps:
71+
- name: Checkout code
72+
uses: actions/checkout@v4
8573

86-
# steps:
87-
# - name: Checkout code
88-
# uses: actions/checkout@v4
89-
90-
# - name: Update image tag in dev overlay
91-
# run: |
92-
# FILE="kustomize/overlays/dev/patch-deployment-image.yaml"
74+
- name: Update image tag in dev overlay
75+
run: |
76+
FILE="kustomize/overlays/dev/patch-deployment-image.yaml"
9377
94-
# echo "Updating $FILE with image: $IMAGE_NAME:$IMAGE_TAG"
78+
echo "Updating $FILE with image: $IMAGE_NAME:$IMAGE_TAG"
9579
96-
# sed -i.bak -E "s|image:.*|image: ${IMAGE_NAME}:${IMAGE_TAG}|" "$FILE"
80+
sed -i.bak -E "s|image:.*|image: ${IMAGE_NAME}:${IMAGE_TAG}|" "$FILE"
9781
98-
# - name: Commit and push changes
99-
# env:
100-
# TOKEN: ${{ secrets.GH_PAT }}
101-
# IMAGE_TAG: ${{ env.IMAGE_TAG }}
102-
# run: |
103-
# git config --global user.name ${{ secrets.GIT_USER_EMAIL }}
104-
# git config --global user.email ${{ secrets.GIT_USER_NAME }}
82+
- name: Commit and push changes
83+
run: |
84+
git config --global user.name "${{ secrets.GIT_USER_NAME }}"
85+
git config --global user.email "${{ secrets.GIT_USER_EMAIL }}"
10586
106-
# git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }}.git
10787
88+
git remote set-url origin https://x-access-token:${{ secrets.GH_PAT }}@github.com/${{ github.repository }}.git
10889
109-
# git add kustomize/overlays/dev/patch-deployment-image.yaml
110-
# git commit -m "Update latest image tag to $IMAGE_TAG"
111-
# git push
90+
git add kustomize/overlays/dev/patch-deployment-image.yaml
91+
git commit -m "Update latest image tag to $IMAGE_TAG" || echo "No changes to commit"
92+
git push
93+
env:
94+
IMAGE_TAG: ${{ github.sha }}

0 commit comments

Comments
 (0)