Skip to content

Commit 169d47a

Browse files
committed
Initial commit
1 parent 1f4a72f commit 169d47a

File tree

2 files changed

+251
-0
lines changed

2 files changed

+251
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
name: Spring Cloud Deploy (Reusable)
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
branch:
7+
description: 'Which branch should be built (for workflow_dispatch)'
8+
required: false
9+
type: string
10+
secrets:
11+
ARTIFACTORY_USERNAME:
12+
required: true
13+
ARTIFACTORY_PASSWORD:
14+
required: true
15+
DOCKERHUB_USERNAME:
16+
required: true
17+
DOCKERHUB_TOKEN:
18+
required: true
19+
20+
jobs:
21+
setup:
22+
runs-on: ubuntu-latest
23+
outputs:
24+
matrix: ${{ steps.set-matrix.outputs.matrix }}
25+
steps:
26+
- name: Checkout spring-cloud-github-actions for config
27+
uses: actions/checkout@v4
28+
with:
29+
repository: spring-cloud/spring-cloud-github-actions
30+
ref: main
31+
path: github-actions-config
32+
33+
- name: Determine branches and JDK versions
34+
id: set-matrix
35+
run: |
36+
echo "=== Workflow Debug Information ==="
37+
echo "Event name: ${{ github.event_name }}"
38+
echo "Ref name: ${{ github.ref_name }}"
39+
echo "Repository: ${{ github.repository }}"
40+
echo "Branch input: ${{ inputs.branch }}"
41+
echo ""
42+
43+
# Extract repository name (without org)
44+
FULL_REPO="${{ github.repository }}"
45+
REPO_NAME="${FULL_REPO#*/}"
46+
echo "Repository name: $REPO_NAME"
47+
48+
# Check if this is a commercial repository
49+
IS_COMMERCIAL=false
50+
BASE_REPO_NAME="$REPO_NAME"
51+
if [[ "$REPO_NAME" == *"-commercial" ]]; then
52+
IS_COMMERCIAL=true
53+
BASE_REPO_NAME="${REPO_NAME%-commercial}"
54+
echo "Commercial repository detected, base name: $BASE_REPO_NAME"
55+
fi
56+
57+
# Read the configuration file
58+
CONFIG_FILE="github-actions-config/config/projects.json"
59+
if [[ ! -f "$CONFIG_FILE" ]]; then
60+
echo "ERROR: Configuration file not found: $CONFIG_FILE"
61+
exit 1
62+
fi
63+
64+
# Determine which config section to use (oss or commercial)
65+
if [[ "$IS_COMMERCIAL" == "true" ]]; then
66+
CONFIG_SECTION="commercial"
67+
else
68+
CONFIG_SECTION="oss"
69+
fi
70+
echo "Using config section: $CONFIG_SECTION"
71+
72+
# Check if project exists in config, otherwise use defaults
73+
PROJECT_EXISTS=$(jq -r --arg repo "$BASE_REPO_NAME" 'has($repo)' "$CONFIG_FILE")
74+
if [[ "$PROJECT_EXISTS" == "true" ]]; then
75+
echo "Found configuration for project: $BASE_REPO_NAME"
76+
CONFIG_PATH=".[\"$BASE_REPO_NAME\"].$CONFIG_SECTION"
77+
else
78+
echo "No specific configuration found for $BASE_REPO_NAME, using defaults"
79+
CONFIG_PATH=".defaults"
80+
fi
81+
82+
# Determine the branch to use
83+
BRANCH="${{ inputs.branch }}"
84+
if [[ -z "$BRANCH" ]]; then
85+
BRANCH="${{ github.ref_name }}"
86+
fi
87+
echo "Target branch: $BRANCH"
88+
89+
# Determine which branches to build based on event type
90+
if [[ "${{ github.event_name }}" == "schedule" ]]; then
91+
echo "Trigger: Scheduled run - building multiple branches"
92+
BRANCHES=$(jq -r "$CONFIG_PATH.branches.scheduled // .defaults.branches.scheduled" "$CONFIG_FILE" | jq -r '.[]')
93+
else
94+
echo "Trigger: ${{ github.event_name }} - building single branch"
95+
BRANCHES="$BRANCH"
96+
fi
97+
98+
echo ""
99+
echo "=== Branches to Build ==="
100+
echo "$BRANCHES"
101+
102+
echo ""
103+
echo "=== Building Matrix ==="
104+
105+
# Build matrix entries
106+
MATRIX_ENTRIES=()
107+
108+
for BRANCH in $BRANCHES; do
109+
echo "Processing branch: $BRANCH"
110+
111+
# Get JDK versions for this branch
112+
JDK_VERSIONS=$(jq -r --arg branch "$BRANCH" \
113+
"$CONFIG_PATH.jdkVersions[\$branch] // $CONFIG_PATH.jdkVersions.default // .defaults.jdkVersions.default" \
114+
"$CONFIG_FILE" | jq -r '.[]')
115+
116+
if [[ -z "$JDK_VERSIONS" ]]; then
117+
# Fallback to global defaults
118+
JDK_VERSIONS=$(jq -r '.defaults.jdkVersions.default[]' "$CONFIG_FILE")
119+
fi
120+
121+
echo " JDK versions: $JDK_VERSIONS"
122+
123+
for VERSION in $JDK_VERSIONS; do
124+
MATRIX_ENTRIES+=("{\"branch\":\"$BRANCH\",\"java-version\":\"$VERSION\"}")
125+
done
126+
done
127+
128+
# Join entries with comma and wrap in array
129+
MATRIX_JSON="[$(IFS=,; echo "${MATRIX_ENTRIES[*]}")]"
130+
131+
echo ""
132+
echo "=== Generated Matrix ==="
133+
echo "$MATRIX_JSON" | jq .
134+
echo ""
135+
136+
echo "matrix=$MATRIX_JSON" >> $GITHUB_OUTPUT
137+
138+
build:
139+
name: Build ${{ matrix.branch }} (JDK ${{ matrix.java-version }})
140+
needs: setup
141+
runs-on: ubuntu-latest
142+
timeout-minutes: 60
143+
strategy:
144+
fail-fast: false
145+
matrix:
146+
include: ${{ fromJson(needs.setup.outputs.matrix) }}
147+
148+
steps:
149+
- name: Checkout code
150+
uses: actions/checkout@v4
151+
with:
152+
ref: ${{ matrix.branch }}
153+
clean: true
154+
155+
- name: Set up JDK ${{ matrix.java-version }}
156+
uses: actions/setup-java@v4
157+
with:
158+
java-version: ${{ matrix.java-version }}
159+
distribution: 'temurin'
160+
cache: 'maven'
161+
server-id: repo.spring.io
162+
server-username: REPO_SPRING_IO_USERNAME
163+
server-password: REPO_SPRING_IO_PASSWORD
164+
165+
- name: Login to Docker Hub
166+
uses: docker/login-action@v3
167+
with:
168+
username: ${{ secrets.DOCKERHUB_USERNAME }}
169+
password: ${{ secrets.DOCKERHUB_TOKEN }}
170+
171+
- name: Stop running Docker containers
172+
continue-on-error: true
173+
run: |
174+
#!/bin/bash
175+
if command -v timeout &> /dev/null; then
176+
timeout 10s docker ps -a -q | xargs -n 1 -P 8 -I {} docker stop {} || echo "Failed to stop docker... Hopefully you know what you're doing"
177+
fi
178+
179+
- name: Verify Maven installation
180+
run: ./mvnw --version
181+
182+
- name: Build and deploy
183+
env:
184+
REPO_SPRING_IO_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
185+
REPO_SPRING_IO_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}
186+
run: |
187+
if [[ "${{ matrix.java-version }}" == "17" ]]; then
188+
./mvnw clean deploy -Pdocs,deploy,spring -B -U
189+
else
190+
./mvnw clean deploy -Pdeploy,spring -B -U
191+
fi
192+

config/projects.json

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"spring-cloud-circuitbreaker": {
3+
"oss": {
4+
"branches": {
5+
"scheduled": ["main", "4.3.x"],
6+
"default": ["main"]
7+
},
8+
"jdkVersions": {
9+
"main": ["17", "21", "25"],
10+
"4.3.x": ["17", "21", "25"]
11+
}
12+
},
13+
"commercial": {
14+
"branches": {
15+
"scheduled": ["4.1.x", "3.1.x"],
16+
"default": ["4.1.x"]
17+
},
18+
"jdkVersions": {
19+
"4.2.x": ["17", "21"],
20+
"4.1.x": ["17", "21"],
21+
"3.1.x": ["8", "11", "17"]
22+
}
23+
}
24+
},
25+
"spring-cloud-build": {
26+
"oss": {
27+
"branches": {
28+
"scheduled": ["main", "4.3.x"],
29+
"default": ["main"]
30+
},
31+
"jdkVersions": {
32+
"main": ["17", "21", "25"],
33+
"4.3.x": ["17", "21", "25"]
34+
}
35+
},
36+
"commercial": {
37+
"branches": {
38+
"scheduled": ["4.1.x", "3.1.x"],
39+
"default": ["4.1.x"]
40+
},
41+
"jdkVersions": {
42+
"4.2.x": ["17", "21"],
43+
"4.1.x": ["17", "21"],
44+
"3.1.x": ["8", "11", "17"]
45+
}
46+
}
47+
},
48+
"defaults": {
49+
"branches": {
50+
"scheduled": ["main"],
51+
"default": ["main"]
52+
},
53+
"jdkVersions": {
54+
"main": ["17", "21", "25"],
55+
"default": ["17", "21", "25"]
56+
}
57+
}
58+
}
59+

0 commit comments

Comments
 (0)