From afe2c37722a9c2cafc8626213f730f65ba6c4b6d Mon Sep 17 00:00:00 2001 From: sahil sharma Date: Wed, 10 Jun 2026 15:56:00 +0100 Subject: [PATCH 1/2] adds reusable work flow on dev for generating config map --- .../dev-build-cm-reusable-workflow.yaml | 154 ++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 .github/workflows/dev-build-cm-reusable-workflow.yaml diff --git a/.github/workflows/dev-build-cm-reusable-workflow.yaml b/.github/workflows/dev-build-cm-reusable-workflow.yaml new file mode 100644 index 00000000..d98cdaf7 --- /dev/null +++ b/.github/workflows/dev-build-cm-reusable-workflow.yaml @@ -0,0 +1,154 @@ +name: Dev Build and Deploy Config Maps (Reusable) + +on: + workflow_call: + inputs: + app-name: + description: 'Human-readable name for commit messages' + required: true + type: string + configmap_file: + description: "Repo-relative path to the ConfigMap manifest" + type: string + required: true + configmap_name: + description: "Name of the Config map" + type: string + required: true + data_key: + description: > + The key under which the file content appears in ConfigMap .data. + type: string + required: true + namespace: + description: "Kubernetes namespace. Defaults to the apps if omitted." + type: string + required: true + gitops-repo: + required: false + type: string + default: 'isisbusapps/gitops' + runner_label: + description: "Self-hosted runner label to target (e.g. 'self-hosted' or 'k8s-prod-runner')" + type: string + required: false + default: "self-hosted" + secrets: + workflow-token: + description: 'PAT with repo+workflow scope for the GitOps repo' + required: true + + outputs: + configmap_output_name: + description: "Name of the ConfigMap that was created/updated" + value: ${{ jobs.generate-configmap.outputs.configmap_name }} + data_key_used: + description: "The .data key the file was stored under" + value: ${{ jobs.generate-configmap.outputs.data_key_used }} + +jobs: + generate-configmap:: + name: Generate & Commit ConfigMap + runs-on: ${{ inputs.runner_label }} + + timeout-minutes: 30 + + permissions: + packages: write + + configmap_name: ${{ steps.resolve.outputs.configmap_name }} + + steps: + - name: Checkout source repository + uses: actions/checkout@v6 + + - name: Validate source file + run: | + FILE="${{ inputs.configmap_file }}" + + if [[ ! -f "${FILE}" ]]; then + echo "::error file=${FILE}::Source file not found: ${FILE}" + exit 1 + fi + + # Basic sanity — reject empty files + if [[ ! -s "${FILE}" ]]; then + echo "::error file=${FILE}::Source file is empty: ${FILE}" + exit 1 + fi + echo "Source file found: ${FILE} ($(wc -l < "${FILE}") lines)" + + - name: Resolve parameters + id: resolve + run: | + # Namespace + if [[ -n "${{ inputs.namespace }}" ]]; then + NS="${{ inputs.namespace }}" + else + echo "::error::The namespace input cannot be empty!" + exit 1 + fi + + # Data key + if [[ -n "${{ inputs.data_key }}" ]]; then + KEY="${{ inputs.data_key }}" + else + echo "::error::The data key input cannot be empty!" + exit 1 + fi + + # Config Map + if [[ -n "${{ inputs.configmap_name }}" ]]; then + CM="${{ inputs.configmap_name }}" + else + echo "::error::The configmap name cannot be empty!" + exit 1 + fi + + echo "namespace=${NS}" >> "$GITHUB_OUTPUT" + echo "data_key=${KEY}" >> "$GITHUB_OUTPUT" + echo "configmap_name=${CM}" >> "$GITHUB_OUTPUT" + + echo "ConfigMap name : ${CM}" + echo "Namespace : ${NS}" + echo "Data key : ${KEY}" + + - name: Generate ConfigMap manifest + id: generate + run: | + NS="${{ steps.resolve.outputs.namespace }}" + CM="${{ steps.resolve.outputs.configmap_name }}" + KEY="${{ steps.resolve.outputs.data_key }}" + FILE="${{ inputs.yaml_file }}" + + echo "🔧 Generating ConfigMap manifest..." + + kubectl create configmap "${CM}" \ + --from-file="${KEY}=${FILE}" \ + --namespace "${NS}" \ + --dry-run=client \ + -o yaml > /tmp/configmap-generated.yaml + + echo "============= Generated manifest===================" + cat /tmp/configmap-generated.yaml + echo "===================================================" + + update_gitops: + name: Update GitOps Repository + runs-on: self-hosted + timeout-minutes: 10 + needs: build_and_push + if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' + steps: + - name: Checkout GitOps repository + uses: actions/checkout@v6 + with: + repository: ${{ inputs.gitops-repo }} + token: ${{ secrets.workflow-token }} + + - name: Commit and push changes + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git commit -am "[CD] Update ${{ inputs.app-name }} with this commit ${{ github.event.head_commit.url }}" + git push \ No newline at end of file From 1e8ff5e6888e6e2cc79b26d76b443f74aba5b224 Mon Sep 17 00:00:00 2001 From: sahil sharma Date: Wed, 10 Jun 2026 16:13:47 +0100 Subject: [PATCH 2/2] Addressed review comments --- .../dev-build-cm-reusable-workflow.yaml | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/.github/workflows/dev-build-cm-reusable-workflow.yaml b/.github/workflows/dev-build-cm-reusable-workflow.yaml index d98cdaf7..2c1e1ac2 100644 --- a/.github/workflows/dev-build-cm-reusable-workflow.yaml +++ b/.github/workflows/dev-build-cm-reusable-workflow.yaml @@ -8,20 +8,19 @@ on: required: true type: string configmap_file: - description: "Repo-relative path to the ConfigMap manifest" + description: 'Repo-relative path to the ConfigMap manifest' type: string required: true configmap_name: - description: "Name of the Config map" + description: 'Name of the Config map' type: string required: true data_key: - description: > - The key under which the file content appears in ConfigMap .data. + description: 'The key under which the file content appears in ConfigMap .data.' type: string required: true namespace: - description: "Kubernetes namespace. Defaults to the apps if omitted." + description: 'Kubernetes namespace. Defaults to the apps if omitted.' type: string required: true gitops-repo: @@ -29,10 +28,10 @@ on: type: string default: 'isisbusapps/gitops' runner_label: - description: "Self-hosted runner label to target (e.g. 'self-hosted' or 'k8s-prod-runner')" + description: 'Self-hosted runner label to target e.g. self-hosted or k8s-prod-runner)' type: string required: false - default: "self-hosted" + default: 'self-hosted' secrets: workflow-token: description: 'PAT with repo+workflow scope for the GitOps repo' @@ -40,10 +39,10 @@ on: outputs: configmap_output_name: - description: "Name of the ConfigMap that was created/updated" + description: 'Name of the ConfigMap that was created/updated' value: ${{ jobs.generate-configmap.outputs.configmap_name }} data_key_used: - description: "The .data key the file was stored under" + description: 'The .data key the file was stored under' value: ${{ jobs.generate-configmap.outputs.data_key_used }} jobs: @@ -121,7 +120,7 @@ jobs: KEY="${{ steps.resolve.outputs.data_key }}" FILE="${{ inputs.yaml_file }}" - echo "🔧 Generating ConfigMap manifest..." + echo "Generating ConfigMap manifest..." kubectl create configmap "${CM}" \ --from-file="${KEY}=${FILE}" \