Skip to content

Commit d2e20c4

Browse files
committed
Refactor deploy.yml to make configuration of docs deployment available to custom build commands
1 parent 30f5f82 commit d2e20c4

2 files changed

Lines changed: 83 additions & 13 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -215,24 +215,47 @@ jobs:
215215
- name: Verify Maven installation
216216
run: ./mvnw --version
217217

218+
- name: Set build configuration
219+
run: |
220+
# Determine if docs profile should be included based on JDK configuration
221+
# Logic: Include docs if (has-jdk8=true AND java-version=8) OR (has-jdk8=false AND java-version=17)
222+
BUILD_WITH_DOCS=false
223+
224+
if [[ ("${{ matrix.has-jdk8 }}" == "true" && "${{ matrix.java-version }}" == "8") ]] || [[ ("${{ matrix.has-jdk8 }}" == "false" && "${{ matrix.java-version }}" == "17") ]]; then
225+
BUILD_WITH_DOCS=true
226+
echo "Docs profile will be included in this build"
227+
else
228+
echo "Docs profile will NOT be included in this build"
229+
fi
230+
231+
echo "BUILD_WITH_DOCS=$BUILD_WITH_DOCS" >> $GITHUB_ENV
232+
echo "Build configuration: BUILD_WITH_DOCS=$BUILD_WITH_DOCS"
233+
218234
- name: Build and deploy
219235
run: |
236+
# Write build command to temporary script file
220237
if [[ -n "${{ inputs.custom_build_command }}" ]]; then
221-
# Write custom command to a script file to support multi-line commands
222-
cat > /tmp/custom-build.sh << CUSTOM_BUILD_EOF
238+
# Custom build command provided by caller
239+
cat > /tmp/build-deploy.sh << 'CUSTOM_BUILD_EOF'
223240
${{ inputs.custom_build_command }}
224241
CUSTOM_BUILD_EOF
225-
chmod +x /tmp/custom-build.sh
226-
bash /tmp/custom-build.sh
227242
else
228-
# If branch config contains JDK 8, use docs profile with JDK 8
229-
# Otherwise, use docs profile with JDK 17
230-
if [[ ("${{ matrix.has-jdk8 }}" == "true" && "${{ matrix.java-version }}" == "8") ]] || [[ ("${{ matrix.has-jdk8 }}" == "false" && "${{ matrix.java-version }}" == "17") ]]; then
231-
echo "Building with docs profile, and deploying docs"
232-
./mvnw clean deploy -Pdocs,deploy,spring -B -U
233-
else
234-
echo "Will not add docs profile, docs will not be deployed"
235-
./mvnw clean deploy -Pdeploy,spring -B -U
236-
fi
243+
# Default Maven build command with conditional docs profile
244+
cat > /tmp/build-deploy.sh << 'DEFAULT_BUILD_EOF'
245+
#!/bin/bash
246+
set -e
247+
248+
# BUILD_WITH_DOCS is set by the "Set build configuration" step
249+
if [[ "$BUILD_WITH_DOCS" == "true" ]]; then
250+
echo "Building with docs profile, and deploying docs"
251+
./mvnw clean deploy -Pdocs,deploy,spring -B -U
252+
else
253+
echo "Will not add docs profile, docs will not be deployed"
254+
./mvnw clean deploy -Pdeploy,spring -B -U
255+
fi
256+
DEFAULT_BUILD_EOF
237257
fi
238258
259+
chmod +x /tmp/build-deploy.sh
260+
bash /tmp/build-deploy.sh
261+

examples/deploy.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Example caller workflow for Spring Cloud projects
2+
# Copy this file to your project's .github/workflows/deploy.yml
3+
# and customize the branch names in the 'on.push.branches' section
4+
5+
name: Deploy
6+
7+
on:
8+
push:
9+
branches:
10+
- main
11+
- 4.3.x
12+
# Add other branches that should trigger builds on push
13+
14+
# Scheduled builds run daily at midnight UTC
15+
# The reusable workflow will build all branches defined in the config
16+
schedule:
17+
- cron: '0 0 * * *'
18+
19+
# Manual trigger with optional branch override
20+
workflow_dispatch:
21+
inputs:
22+
branch:
23+
description: 'Which branch should be built'
24+
required: false
25+
default: ''
26+
type: string
27+
28+
jobs:
29+
deploy:
30+
uses: spring-cloud/spring-cloud-github-actions/.github/workflows/deploy.yml@main
31+
with:
32+
branch: ${{ inputs.branch }}
33+
# Optional: Custom build command to override the default Maven deploy command
34+
# Supports both single-line and multi-line commands
35+
# Single-line example:
36+
# custom_build_command: './mvnw clean install -B'
37+
# Multi-line example:
38+
# custom_build_command: |
39+
# ./mvnw clean install -B
40+
# ./mvnw verify -B
41+
# echo "Build completed"
42+
secrets:
43+
ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
44+
ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}
45+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
46+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
47+

0 commit comments

Comments
 (0)