Skip to content

Commit ef1098c

Browse files
committed
Update determine-matrix and deploy action to accept multiple branches
1 parent 4769c11 commit ef1098c

4 files changed

Lines changed: 67 additions & 29 deletions

File tree

.github/actions/determine-matrix/README.md

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ This action reads project configuration from `config/projects.json` in the sprin
2424
| `repository` | Repository name in format `org/repo-name` | Yes | - |
2525
| `event-name` | GitHub event name (schedule, push, workflow_dispatch, etc.) | Yes | - |
2626
| `ref-name` | Git ref name (branch name) | Yes | - |
27-
| `branch` | Optional branch override for single-branch builds | No | `''` |
27+
| `branches` | Optional branch override (single branch or comma-separated list) for builds | No | `''` |
2828
| `config-ref` | Git ref for spring-cloud-github-actions config | No | `main` |
2929

3030
## Outputs
@@ -56,7 +56,7 @@ jobs:
5656
repository: ${{ github.repository }}
5757
event-name: ${{ github.event_name }}
5858
ref-name: ${{ github.ref_name }}
59-
branch: ${{ inputs.branch }}
59+
branches: ${{ inputs.branches }}
6060

6161
build:
6262
needs: setup
@@ -86,9 +86,32 @@ Other Spring Cloud repositories can reference this action:
8686
repository: ${{ github.repository }}
8787
event-name: ${{ github.event_name }}
8888
ref-name: ${{ github.ref_name }}
89-
branch: ${{ inputs.branch }}
89+
branches: ${{ inputs.branches }}
9090
```
9191
92+
### Using Comma-Separated Branches
93+
94+
You can specify multiple branches using a comma-separated list. This is useful for manual workflow dispatches or when you want to build specific branches:
95+
96+
```yaml
97+
- name: Determine build matrix
98+
id: determine-matrix
99+
uses: spring-cloud/spring-cloud-github-actions/.github/actions/determine-matrix@main
100+
with:
101+
repository: ${{ github.repository }}
102+
event-name: ${{ github.event_name }}
103+
ref-name: ${{ github.ref_name }}
104+
branches: "main,3.3.x,3.2.x" # Build multiple branches
105+
```
106+
107+
**Note**: Comma-separated branch input is ignored for scheduled events, which always use the `branches.scheduled` configuration from `projects.json`.
108+
109+
**Examples**:
110+
- Single branch: `branches: "main"` → builds only `main`
111+
- Multiple branches: `branches: "main,3.3.x,3.2.x"` → builds all three branches
112+
- With whitespace: `branches: "main, 3.3.x , 3.2.x"` → automatically trims whitespace
113+
- Empty input: `branches: ""` → falls back to `ref-name`
114+
92115
### Using Additional Outputs
93116

94117
```yaml
@@ -99,7 +122,7 @@ Other Spring Cloud repositories can reference this action:
99122
repository: ${{ github.repository }}
100123
event-name: ${{ github.event_name }}
101124
ref-name: ${{ github.ref_name }}
102-
branch: ${{ inputs.branch }}
125+
branches: ${{ inputs.branches }}
103126
104127
- name: Display build info
105128
run: |
@@ -117,7 +140,7 @@ Other Spring Cloud repositories can reference this action:
117140
repository: ${{ github.repository }}
118141
event-name: ${{ github.event_name }}
119142
ref-name: ${{ github.ref_name }}
120-
branch: ${{ inputs.branch }}
143+
branches: ${{ inputs.branches }}
121144
config-ref: 'feature/new-config-structure' # Use feature branch config
122145
```
123146

@@ -162,8 +185,11 @@ The action reads configuration from `config/projects.json` in the spring-cloud-g
162185
1. **Repository Detection**: Extracts repository name and detects commercial vs OSS variant
163186
2. **Config Loading**: Checks out spring-cloud-github-actions repo and reads `config/projects.json`
164187
3. **Branch Determination**:
165-
- For scheduled runs: builds multiple branches from config
166-
- For other events: builds single branch (from input or ref-name)
188+
- For scheduled runs: builds multiple branches from config (ignores branch input)
189+
- For other events:
190+
- If `branch` input is provided and contains commas: parses comma-separated list
191+
- If `branch` input is provided (single branch): uses that branch
192+
- Otherwise: uses `ref-name` (the triggering branch)
167193
4. **JDK Mapping**: Maps each branch to its configured JDK versions
168194
5. **Matrix Generation**: Creates matrix entries for each branch + JDK combination
169195
6. **Additional Outputs**: Generates branches list and branch-jdk-mapping
@@ -189,8 +215,8 @@ on:
189215
- cron: '0 2 * * *'
190216
workflow_dispatch:
191217
inputs:
192-
branch:
193-
description: 'Branch to build'
218+
branches:
219+
description: 'Branch(es) to build - single branch or comma-separated list'
194220
required: false
195221
196222
jobs:
@@ -210,7 +236,7 @@ jobs:
210236
repository: ${{ github.repository }}
211237
event-name: ${{ github.event_name }}
212238
ref-name: ${{ github.ref_name }}
213-
branch: ${{ inputs.branch }}
239+
branches: ${{ inputs.branches }}
214240
215241
build:
216242
name: Build ${{ matrix.branch }} (JDK ${{ matrix.java-version }})

.github/actions/determine-matrix/action.yml

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ inputs:
1212
ref-name:
1313
description: 'Git ref name (branch name)'
1414
required: true
15-
branch:
16-
description: 'Optional branch override for single-branch builds'
15+
branches:
16+
description: 'Optional branch override (single branch or comma-separated list) for builds'
1717
required: false
1818
default: ''
1919
config-ref:
@@ -50,7 +50,7 @@ runs:
5050
echo "Event name: ${{ inputs.event-name }}"
5151
echo "Ref name: ${{ inputs.ref-name }}"
5252
echo "Repository: ${{ inputs.repository }}"
53-
echo "Branch input: ${{ inputs.branch }}"
53+
echo "Branch input: ${{ inputs.branches }}"
5454
echo ""
5555
5656
# Extract repository name (without org)
@@ -92,20 +92,29 @@ runs:
9292
CONFIG_PATH=".defaults.$CONFIG_SECTION"
9393
fi
9494
95-
# Determine the branch to use
96-
BRANCH="${{ inputs.branch }}"
97-
if [[ -z "$BRANCH" ]]; then
98-
BRANCH="${{ inputs.ref-name }}"
99-
fi
100-
echo "Target branch: $BRANCH"
101-
10295
# Determine which branches to build based on event type
10396
if [[ "${{ inputs.event-name }}" == "schedule" ]]; then
104-
echo "Trigger: Scheduled run - building multiple branches"
97+
echo "Trigger: Scheduled run - building multiple branches from config"
10598
BRANCHES=$(jq -r "$CONFIG_PATH.branches.scheduled // .defaults.$CONFIG_SECTION.branches.scheduled" "$CONFIG_FILE" | jq -r '.[]')
10699
else
107-
echo "Trigger: ${{ inputs.event-name }} - building single branch"
108-
BRANCHES="$BRANCH"
100+
# Non-scheduled event: check branch input
101+
BRANCH_INPUT="${{ inputs.branches }}"
102+
if [[ -n "$BRANCH_INPUT" ]]; then
103+
# Check if comma-separated
104+
if [[ "$BRANCH_INPUT" == *","* ]]; then
105+
echo "Trigger: ${{ inputs.event-name }} - building multiple branches from comma-separated input"
106+
# Parse comma-separated branches: split, trim whitespace, filter empty
107+
BRANCHES=$(echo "$BRANCH_INPUT" | tr ',' '\n' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//' | grep -v '^$')
108+
BRANCH_COUNT=$(echo "$BRANCHES" | wc -l | tr -d ' ')
109+
echo "Detected $BRANCH_COUNT branch(es) in comma-separated input: $(echo "$BRANCHES" | tr '\n' ',' | sed 's/,$//')"
110+
else
111+
echo "Trigger: ${{ inputs.event-name }} - building single branch from input"
112+
BRANCHES="$BRANCH_INPUT"
113+
fi
114+
else
115+
echo "Trigger: ${{ inputs.event-name }} - building single branch from ref"
116+
BRANCHES="${{ inputs.ref-name }}"
117+
fi
109118
fi
110119
111120
echo ""

.github/workflows/deploy.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ name: Spring Cloud Deploy (Reusable)
33
on:
44
workflow_call:
55
inputs:
6-
branch:
7-
description: 'Which branch should be built (for workflow_dispatch)'
6+
branches:
7+
description: 'Which branch(es) should be built - single branch or comma-separated list (e.g., "main,3.3.x,3.2.x")'
88
required: false
99
type: string
1010
custom_build_command:
@@ -42,7 +42,7 @@ jobs:
4242
repository: ${{ github.repository }}
4343
event-name: ${{ github.event_name }}
4444
ref-name: ${{ github.ref_name }}
45-
branch: ${{ inputs.branch }}
45+
branches: ${{ inputs.branches }}
4646

4747
build:
4848
name: Build ${{ matrix.branch }} (JDK ${{ matrix.java-version }})

examples/deploy.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Example caller workflow for Spring Cloud projects
22
# Copy this file to your project's .github/workflows/deploy.yml
33
# and customize the branch names in the 'on.push.branches' section
4+
#
5+
# Note: The 'branches' input accepts either a single branch name or a comma-separated
6+
# list of branches (e.g., "main,3.3.x,3.2.x") for building multiple branches in one run.
47

58
name: Deploy
69

@@ -19,8 +22,8 @@ on:
1922
# Manual trigger with optional branch override
2023
workflow_dispatch:
2124
inputs:
22-
branch:
23-
description: 'Which branch should be built'
25+
branches:
26+
description: 'Which branch(es) should be built - single branch or comma-separated list (e.g., "main,3.3.x,3.2.x")'
2427
required: false
2528
default: ''
2629
type: string
@@ -29,7 +32,7 @@ jobs:
2932
deploy:
3033
uses: spring-cloud/spring-cloud-github-actions/.github/workflows/deploy.yml@main
3134
with:
32-
branch: ${{ inputs.branch }}
35+
branches: ${{ inputs.branches }}
3336
# Optional: Custom build command to override the default Maven deploy command
3437
# Supports both single-line and multi-line commands
3538
# Single-line example:

0 commit comments

Comments
 (0)