Skip to content

Commit 9ffeeb0

Browse files
committed
Preserve license header from existing .settings.xml
1 parent 461d79c commit 9ffeeb0

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

.github/actions/copy-settings-xml/action.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,23 @@ runs:
7272
7373
git checkout "$TARGET_BRANCH"
7474
75+
# Preserve the license header from the existing .settings.xml before overwriting,
76+
# so that e.g. an Apache header on an OSS-derived branch is not replaced by the
77+
# Broadcom header present in the commercial default branch.
78+
if [[ -f "$SETTINGS_FILE" ]]; then
79+
node -e "
80+
const fs = require('fs');
81+
const content = fs.readFileSync('.settings.xml', 'utf8');
82+
const m = content.match(/<!--[\s\S]*?-->/);
83+
if (m) fs.writeFileSync('/tmp/_preserved_header.txt', m[0]);
84+
" 2>/dev/null || true
85+
if [[ -s /tmp/_preserved_header.txt ]]; then
86+
echo "Preserved existing license header from '${TARGET_BRANCH}:${SETTINGS_FILE}'."
87+
else
88+
rm -f /tmp/_preserved_header.txt
89+
fi
90+
fi
91+
7592
# Remove any existing .settings.xml on the target branch
7693
if [[ -f "$SETTINGS_FILE" ]]; then
7794
echo "Removing existing ${SETTINGS_FILE} from '${TARGET_BRANCH}'..."
@@ -82,6 +99,18 @@ runs:
8299
echo "Copying ${SETTINGS_FILE} from '${SOURCE_BRANCH}' to '${TARGET_BRANCH}'..."
83100
git show "origin/${SOURCE_BRANCH}:${SETTINGS_FILE}" > "$SETTINGS_FILE"
84101
102+
# Restore the preserved license header if we captured one
103+
if [[ -f /tmp/_preserved_header.txt ]]; then
104+
echo "Restoring preserved license header..."
105+
node -e "
106+
const fs = require('fs');
107+
const content = fs.readFileSync('.settings.xml', 'utf8');
108+
const header = fs.readFileSync('/tmp/_preserved_header.txt', 'utf8');
109+
const updated = content.replace(/<!--[\s\S]*?-->/, header);
110+
fs.writeFileSync('.settings.xml', updated);
111+
"
112+
fi
113+
85114
git add "$SETTINGS_FILE"
86115
87116
if git diff --cached --quiet; then

0 commit comments

Comments
 (0)