ci: switch to commit-back GitOps (update values.yaml)
Some checks failed
Build & Deploy Go API / build (push) Failing after 16s

This commit is contained in:
Joe
2026-07-19 20:23:41 +08:00
parent ee87c20649
commit b85d618f91

View File

@@ -12,7 +12,7 @@ jobs:
runs-on: self-hosted
steps:
- name: Install build tools
run: apk add --no-cache curl git docker-cli jq 2>/dev/null || true
run: apk add --no-cache curl git docker-cli 2>/dev/null || true
- name: Clone + prepare
run: |
@@ -42,22 +42,21 @@ jobs:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
REGISTRY: ${{ env.REGISTRY }}
- name: Update ArgoCD
- name: Update image tag in values.yaml (commit-back GitOps)
run: |
WORK=/root/.cache/demo-go-api
cd $WORK
SHORT=${GITHUB_SHA::8}
# Wait for ArgoCD to be ready
for i in {1..10}; do
if kubectl -n cicd get application demo-go-api &>/dev/null; then
break
fi
echo "Waiting for ArgoCD application..."
sleep 3
done
# Patch using JSON
PATCH=$(jq -n --arg tag "$SHORT" --arg reg "$REGISTRY" \
'{"spec":{"source":{"helm":{"parameters":[{"name":"image.registry","value":$reg},{"name":"image.tag","value":$tag}]}}}}')
kubectl -n cicd patch application demo-go-api --type=merge -p "$PATCH"
echo "✓ ArgoCD updated with tag ${SHORT}"
# Use sed to update image.tag in helm values.yaml
sed -i "s/^ tag:.*/ tag: \"${SHORT}\"/" deploy/helm/values.yaml
# Show the diff
git diff deploy/helm/values.yaml
# Commit and push
git config user.email "ci@local"
git config user.name "gitea-ci"
git add deploy/helm/values.yaml
git commit -m "ci: update image tag to ${SHORT}"
git push origin main
env:
GITHUB_SHA: ${{ github.sha }}
REGISTRY: ${{ env.REGISTRY }}
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}