Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 153 additions & 0 deletions .github/workflows/dev-build-cm-reusable-workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
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 }}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think we should use GitHubs public runners. And use the azure/setup-kubetcl / install kubectl as part of the workflow.

However we have kubectl on the self hosted runners now so it will work.


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}"
Comment on lines +111 to +113

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is GH displaying it oddly, but this looks like it is being interpreted differently to the rest of the run: | block..


- 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