Skip to content

Commit ee81bf0

Browse files
committed
ci(actions): enhance maven-setup with multi-level settings.xml fallbacks
Improve handling of `settings.xml` by adding support for user-defined paths, repository root fallbacks, and action template fallbacks. Ensure robust configuration resolution in Maven setup.
1 parent 90ab8f7 commit ee81bf0

1 file changed

Lines changed: 24 additions & 4 deletions

File tree

.github/actions/maven-setup/action.yml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,34 @@ runs:
3131
shell: bash
3232
run: mkdir -p "$HOME/.m2"
3333

34-
- name: Copy settings.xml template (if present)
34+
- name: Copy settings.xml template with fallbacks
3535
if: ${{ inputs.settings-file != '' }}
3636
shell: bash
3737
run: |
38-
if [ -f "${{ inputs.settings-file }}" ]; then
39-
cp "${{ inputs.settings-file }}" "$HOME/.m2/settings.xml"
38+
set -euo pipefail
39+
USER_PATH="${{ inputs.settings-file }}"
40+
ACTION_DIR="${GITHUB_ACTION_PATH}"
41+
# Repo root where this action lives: repo/.github/actions/maven-setup → repo root is three levels up
42+
ACTION_REPO_ROOT="$(cd "$ACTION_DIR/../../../" && pwd)"
43+
FALLBACK_REPO_SETTINGS="$ACTION_REPO_ROOT/.mvn/settings.xml"
44+
FALLBACK_ACTION_TEMPLATE="$ACTION_DIR/templates/settings.xml"
45+
46+
echo "Looking for Maven settings template..."
47+
echo "- Requested path: $USER_PATH"
48+
echo "- Fallback (repo .mvn): $FALLBACK_REPO_SETTINGS"
49+
echo "- Fallback (action template): $FALLBACK_ACTION_TEMPLATE"
50+
51+
if [ -f "$USER_PATH" ]; then
52+
echo "Using settings from: $USER_PATH"
53+
cp "$USER_PATH" "$HOME/.m2/settings.xml"
54+
elif [ -f "$FALLBACK_REPO_SETTINGS" ]; then
55+
echo "Requested file not found. Using centralized settings from: $FALLBACK_REPO_SETTINGS"
56+
cp "$FALLBACK_REPO_SETTINGS" "$HOME/.m2/settings.xml"
57+
elif [ -f "$FALLBACK_ACTION_TEMPLATE" ]; then
58+
echo "Requested file not found. Using action template from: $FALLBACK_ACTION_TEMPLATE"
59+
cp "$FALLBACK_ACTION_TEMPLATE" "$HOME/.m2/settings.xml"
4060
else
41-
echo "No settings.xml found at ${{ inputs.settings-file }}; continuing without template"
61+
echo "No settings.xml found at '$USER_PATH' and no fallbacks available; continuing without template"
4262
fi
4363
4464
- name: Inject Maven server credentials (if provided)

0 commit comments

Comments
 (0)