feat(ci): add Kubernetes deployment toggle and update conditions for deployment steps
All checks were successful
CI / lint (push) Successful in 16s
CI / test (push) Successful in 1m3s
CI / build (push) Successful in 1m53s
CI / lint (pull_request) Successful in 16s
CI / test (pull_request) Successful in 1m3s
CI / build (pull_request) Successful in 1m51s

This commit is contained in:
2025-11-14 20:14:53 +01:00
parent 839399363e
commit dae3b59af9

View File

@@ -140,6 +140,7 @@ jobs:
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
STAGING_KUBE_CONFIG: ${{ secrets.STAGING_KUBE_CONFIG }}
PROD_KUBE_CONFIG: ${{ secrets.PROD_KUBE_CONFIG }}
K8S_DEPLOY_ENABLED: ${{ secrets.K8S_DEPLOY_ENABLED }}
steps:
- name: Checkout
uses: actions/checkout@v4
@@ -159,6 +160,16 @@ jobs:
echo "REGISTRY_HOST=${registry_host}" >> "$GITHUB_ENV"
echo "REGISTRY_REPOSITORY=${registry_repository}" >> "$GITHUB_ENV"
- name: Report Kubernetes deployment toggle
run: |
set -euo pipefail
enabled="${K8S_DEPLOY_ENABLED:-}"
if [ "${enabled}" = "true" ]; then
echo "Kubernetes deployment is enabled for this run."
else
echo "::notice::Kubernetes deployment steps are disabled (set secrets.K8S_DEPLOY_ENABLED to 'true' to enable)."
fi
- name: Capture commit metadata
id: commit_meta
run: |
@@ -167,21 +178,21 @@ jobs:
echo "message=$message" >> "$GITHUB_OUTPUT"
- name: Set up kubectl for staging
if: contains(steps.commit_meta.outputs.message, '[deploy staging]')
if: env.K8S_DEPLOY_ENABLED == 'true' && contains(steps.commit_meta.outputs.message, '[deploy staging]')
uses: azure/k8s-set-context@v3
with:
method: kubeconfig
kubeconfig: ${{ env.STAGING_KUBE_CONFIG }}
- name: Set up kubectl for production
if: contains(steps.commit_meta.outputs.message, '[deploy production]')
if: env.K8S_DEPLOY_ENABLED == 'true' && contains(steps.commit_meta.outputs.message, '[deploy production]')
uses: azure/k8s-set-context@v3
with:
method: kubeconfig
kubeconfig: ${{ env.PROD_KUBE_CONFIG }}
- name: Deploy to staging
if: contains(steps.commit_meta.outputs.message, '[deploy staging]')
if: env.K8S_DEPLOY_ENABLED == 'true' && contains(steps.commit_meta.outputs.message, '[deploy staging]')
run: |
kubectl set image deployment/calminer-app calminer=${REGISTRY_REPOSITORY}:latest
kubectl apply -f k8s/configmap.yaml
@@ -189,7 +200,7 @@ jobs:
kubectl rollout status deployment/calminer-app
- name: Collect staging deployment logs
if: contains(steps.commit_meta.outputs.message, '[deploy staging]')
if: env.K8S_DEPLOY_ENABLED == 'true' && contains(steps.commit_meta.outputs.message, '[deploy staging]')
run: |
mkdir -p logs/deployment/staging
kubectl get pods -o wide > logs/deployment/staging/pods.txt
@@ -197,7 +208,7 @@ jobs:
kubectl logs deployment/calminer-app --all-containers=true --tail=500 > logs/deployment/staging/calminer-app.log
- name: Deploy to production
if: contains(steps.commit_meta.outputs.message, '[deploy production]')
if: env.K8S_DEPLOY_ENABLED == 'true' && contains(steps.commit_meta.outputs.message, '[deploy production]')
run: |
kubectl set image deployment/calminer-app calminer=${REGISTRY_REPOSITORY}:latest
kubectl apply -f k8s/configmap.yaml
@@ -205,7 +216,7 @@ jobs:
kubectl rollout status deployment/calminer-app
- name: Collect production deployment logs
if: contains(steps.commit_meta.outputs.message, '[deploy production]')
if: env.K8S_DEPLOY_ENABLED == 'true' && contains(steps.commit_meta.outputs.message, '[deploy production]')
run: |
mkdir -p logs/deployment/production
kubectl get pods -o wide > logs/deployment/production/pods.txt