Skip to content

Commit ad98e7f

Browse files
committed
Refine run-name logic and enhance environment handling in CI/CD workflow
1 parent 6e69bc7 commit ad98e7f

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

.github/workflows/infrastructure-ci-cd.yml

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Helm Chart CI/CD
22
permissions: read-all
33
# [Deploying/Linting for] [<chart>/all charts] in [dev/test/prod/all environments]
4-
run-name: ${{ inputs.run_cd && 'Deploying ' || 'Linting for' }} ${{ github.event_name =='workflow_dispatch' && (inputs.chart == 'all' && 'all charts' || inputs.chart) || 'changed files'}} in ${{ inputs.environment == 'all' && 'all environments' || inputs.environment }}
4+
run-name: ${{ ((inputs.run_cd && github.event_name == 'workflow_dispatch') || github.event_name == 'push') && 'Deploying ' || 'Linting for' }} ${{ github.event_name =='workflow_dispatch' && (inputs.chart == 'all' && 'all charts' || inputs.chart) || 'changed files'}} in ${{ inputs.environment == 'all' && 'all environments' || inputs.environment }}
55
on:
66
push:
77
branches: [main]
@@ -75,16 +75,19 @@ jobs:
7575
# Default environments
7676
environments=("${{ inputs.environment }}")
7777
78-
# Handle "all" case
79-
if [[ "${{ inputs.environment }}" == "all" ]]; then
78+
# If "all" is selected or we are linting a PR, we include all environments
79+
if [[ "${{ inputs.environment }}" == "all" || "${{ github.event_name }}" == "pull_request" ]]; then
80+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
81+
echo "Linting this PR. All environments will be included." >> $GITHUB_STEP_SUMMARY
82+
fi
8083
environments=("dev" "test" "prod")
8184
fi
8285
8386
# Convert to compact JSON array
8487
environments_json=$(printf '%s\n' "${environments[@]}" | jq -R . | jq -s -c .)
8588
8689
echo "environments=${environments_json}" >> $GITHUB_OUTPUT
87-
echo -e "#Environments to process: \n```json\n${environments_json}\n```" >> $GITHUB_STEP_SUMMARY
90+
echo -e "#Environments to process: \n\`\`\`json\n${environments_json}\n\`\`\`" >> $GITHUB_STEP_SUMMARY
8891
8992
- name: Set matrix for changed charts
9093
id: set-chart-matrix
@@ -132,23 +135,28 @@ jobs:
132135
fi
133136
fi
134137
135-
# If no charts selected, default to all
138+
# If no charts selected, skip the rest of the steps
136139
if [[ ${#charts[@]} -eq 0 ]]; then
137-
for chart_name in "${!chart_dirs[@]}"; do
138-
charts+=("{\"name\":\"$chart_name\",\"dir\":\"${chart_dirs[$chart_name]}\"}")
139-
done
140+
echo "No charts eligible for processing." >> $GITHUB_STEP_SUMMARY
141+
echo "charts=[]" >> $GITHUB_OUTPUT
142+
exit 0
140143
fi
141144
142145
# Convert to JSON array
143146
charts_json=$(printf '%s\n' "${charts[@]}" | jq -s -c '.')
144147
145148
echo "charts=${charts_json}" >> $GITHUB_OUTPUT
146-
echo -e "#Charts to process: \n```json\n${charts_json}\n```" >> $GITHUB_STEP_SUMMARY
149+
echo -e "#Charts to process: \n\`\`\`json\n${charts_json}\n\`\`\`" >> $GITHUB_STEP_SUMMARY
147150
148151
lint-and-test:
149152
needs: setup
150153
runs-on: ubuntu-latest
154+
if: needs.setup.outputs.charts != '[]'
155+
concurrency:
156+
group: ${{ github.ref }}
157+
cancel-in-progress: true
151158
strategy:
159+
fail-fast: false
152160
matrix:
153161
chart: ${{ fromJson(needs.setup.outputs.charts) }}
154162
environment: ${{ fromJson(needs.setup.outputs.environments) }}

0 commit comments

Comments
 (0)