-
Notifications
You must be signed in to change notification settings - Fork 0
adds reusable work flow on dev for generating config map #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Sahil-STFC
merged 2 commits into
main
from
#32-Create-reusable-workflows-for-generating-configmaps
Jun 11, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 }} | ||
|
|
||
| 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.