Skip to content

Updates deploy.yml to support custom build commands and configure Mav… #1

Updates deploy.yml to support custom build commands and configure Mav…

Updates deploy.yml to support custom build commands and configure Mav… #1

Workflow file for this run

name: Spring Cloud Deploy (Reusable)

Check failure on line 1 in .github/workflows/deploy.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/deploy.yml

Invalid workflow file

(Line: 169, Col: 20): Unrecognized named-value: 'COMMERCIAL_ARTIFACTORY_PASSWORD'. Located at position 1 within expression: COMMERCIAL_ARTIFACTORY_PASSWORD
on:
workflow_call:
inputs:
branch:
description: 'Which branch should be built (for workflow_dispatch)'
required: false
type: string
custom_build_command:
description: 'Custom run command for the Build and Deploy step (overrides default Maven command)'
required: false
type: string
secrets:
ARTIFACTORY_USERNAME:
required: true
ARTIFACTORY_PASSWORD:
required: true
DOCKERHUB_USERNAME:
required: true
DOCKERHUB_TOKEN:
required: true
jobs:
setup:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout spring-cloud-github-actions for config
uses: actions/checkout@v4
with:
repository: spring-cloud/spring-cloud-github-actions
ref: main
path: github-actions-config
- name: Determine branches and JDK versions
id: set-matrix
run: |
echo "=== Workflow Debug Information ==="
echo "Event name: ${{ github.event_name }}"
echo "Ref name: ${{ github.ref_name }}"
echo "Repository: ${{ github.repository }}"
echo "Branch input: ${{ inputs.branch }}"
echo ""
# Extract repository name (without org)
FULL_REPO="${{ github.repository }}"
REPO_NAME="${FULL_REPO#*/}"
echo "Repository name: $REPO_NAME"
# Check if this is a commercial repository
IS_COMMERCIAL=false
BASE_REPO_NAME="$REPO_NAME"
if [[ "$REPO_NAME" == *"-commercial" ]]; then
IS_COMMERCIAL=true
BASE_REPO_NAME="${REPO_NAME%-commercial}"
echo "Commercial repository detected, base name: $BASE_REPO_NAME"
fi
# Read the configuration file
CONFIG_FILE="github-actions-config/config/projects.json"
if [[ ! -f "$CONFIG_FILE" ]]; then
echo "ERROR: Configuration file not found: $CONFIG_FILE"
exit 1
fi
# Determine which config section to use (oss or commercial)
if [[ "$IS_COMMERCIAL" == "true" ]]; then
CONFIG_SECTION="commercial"
else
CONFIG_SECTION="oss"
fi
echo "Using config section: $CONFIG_SECTION"
# Check if project exists in config, otherwise use defaults
PROJECT_EXISTS=$(jq -r --arg repo "$BASE_REPO_NAME" 'has($repo)' "$CONFIG_FILE")
if [[ "$PROJECT_EXISTS" == "true" ]]; then
echo "Found configuration for project: $BASE_REPO_NAME"
CONFIG_PATH=".[\"$BASE_REPO_NAME\"].$CONFIG_SECTION"
else
echo "No specific configuration found for $BASE_REPO_NAME, using defaults"
CONFIG_PATH=".defaults"
fi
# Determine the branch to use
BRANCH="${{ inputs.branch }}"
if [[ -z "$BRANCH" ]]; then
BRANCH="${{ github.ref_name }}"
fi
echo "Target branch: $BRANCH"
# Determine which branches to build based on event type
if [[ "${{ github.event_name }}" == "schedule" ]]; then
echo "Trigger: Scheduled run - building multiple branches"
BRANCHES=$(jq -r "$CONFIG_PATH.branches.scheduled // .defaults.branches.scheduled" "$CONFIG_FILE" | jq -r '.[]')
else
echo "Trigger: ${{ github.event_name }} - building single branch"
BRANCHES="$BRANCH"
fi
echo ""
echo "=== Branches to Build ==="
echo "$BRANCHES"
echo ""
echo "=== Building Matrix ==="
# Build matrix entries
MATRIX_ENTRIES=()
for BRANCH in $BRANCHES; do
echo "Processing branch: $BRANCH"
# Get JDK versions for this branch
JDK_VERSIONS=$(jq -r --arg branch "$BRANCH" \
"$CONFIG_PATH.jdkVersions[\$branch] // $CONFIG_PATH.jdkVersions.default // .defaults.jdkVersions.default" \
"$CONFIG_FILE" | jq -r '.[]')
if [[ -z "$JDK_VERSIONS" ]]; then
# Fallback to global defaults
JDK_VERSIONS=$(jq -r '.defaults.jdkVersions.default[]' "$CONFIG_FILE")
fi
echo " JDK versions: $JDK_VERSIONS"
for VERSION in $JDK_VERSIONS; do
MATRIX_ENTRIES+=("{\"branch\":\"$BRANCH\",\"java-version\":\"$VERSION\"}")
done
done
# Join entries with comma and wrap in array
MATRIX_JSON="[$(IFS=,; echo "${MATRIX_ENTRIES[*]}")]"
echo ""
echo "=== Generated Matrix ==="
echo "$MATRIX_JSON" | jq .
echo ""
echo "matrix=$MATRIX_JSON" >> $GITHUB_OUTPUT
build:
name: Build ${{ matrix.branch }} (JDK ${{ matrix.java-version }})
needs: setup
runs-on: ubuntu-latest
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
include: ${{ fromJson(needs.setup.outputs.matrix) }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ matrix.branch }}
clean: true
- name: Set up JDK ${{ matrix.java-version }}
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java-version }}
distribution: 'temurin'
cache: 'maven'
- name: Configure Maven settings
uses: s4u/[email protected]
with:
servers: |
[{
"id": "repo.spring.io",
"username": "${{ secrets.ARTIFACTORY_USERNAME }}",
"password": "${{ secrets.ARTIFACTORY_PASSWORD }}"
},
{
"id": "spring-commercial-snapshot",
"username": "${{ secrets.COMMERCIAL_ARTIFACTORY_USERNAME }}",
"password": "${{ COMMERCIAL_ARTIFACTORY_PASSWORD }}"
},
{
"id": "spring-commercial-release",
"username": "${{ secrets.COMMERCIAL_ARTIFACTORY_USERNAME }}",
"password": "${{ COMMERCIAL_ARTIFACTORY_PASSWORD }}"
},
{
"id": "spring-commercial-release",
"username": "${{ secrets.COMMERCIAL_ARTIFACTORY_USERNAME }}",
"password": "${{ COMMERCIAL_ARTIFACTORY_PASSWORD }}"
}]
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Stop running Docker containers
continue-on-error: true
run: |
#!/bin/bash
if command -v timeout &> /dev/null; then
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"
fi
- name: Verify Maven installation
run: ./mvnw --version
- name: Build and deploy
run: |
if [[ -n "${{ inputs.custom_build_command }}" ]]; then
# Write custom command to a script file to support multi-line commands
cat > /tmp/custom-build.sh << CUSTOM_BUILD_EOF
${{ inputs.custom_build_command }}
CUSTOM_BUILD_EOF
chmod +x /tmp/custom-build.sh
bash /tmp/custom-build.sh
else
if [[ "${{ matrix.java-version }}" == "17" ]]; then
./mvnw clean deploy -Pdocs,deploy,spring -B -U
else
./mvnw clean deploy -Pdeploy,spring -B -U
fi
fi