From 7dc4e17401574624472e18c6ca74b6d33868c81e Mon Sep 17 00:00:00 2001 From: ChristophShyper <45788587+ChristophShyper@users.noreply.github.com> Date: Fri, 15 May 2026 18:48:44 +0200 Subject: [PATCH 1/3] feat: enhance entrypoint script with git log and diff functionalities --- .dockerignore | 2 + Dockerfile | 3 +- entrypoint.sh | 153 ++++++++++++++++++----- scripts/replace-template-diff.sh | 111 ++++++++++++++++ tests/unit/test_branch_validation.sh | 93 ++++++++++++++ tests/unit/test_replace_template_diff.sh | 128 +++++++++++++++++++ 6 files changed, 459 insertions(+), 31 deletions(-) create mode 100755 scripts/replace-template-diff.sh create mode 100755 tests/unit/test_branch_validation.sh create mode 100755 tests/unit/test_replace_template_diff.sh diff --git a/.dockerignore b/.dockerignore index 215e08c..b05b20f 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,5 +4,7 @@ # Include !Dockerfile !entrypoint.sh +!scripts/ +!scripts/replace-template-diff.sh !LICENSE !README.md diff --git a/Dockerfile b/Dockerfile index 3a7eb3f..21e4565 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,11 +5,12 @@ ENV DEBIAN_FRONTEND=noninteractive # Copy all needed files COPY entrypoint.sh / +COPY scripts/ /scripts/ # Install needed packages SHELL ["/bin/bash", "-euxo", "pipefail", "-c"] # hadolint ignore=DL3008 -RUN chmod +x /entrypoint.sh ;\ +RUN chmod +x /entrypoint.sh /scripts/replace-template-diff.sh ;\ apt-get update -y ;\ apt-get install --no-install-recommends -y \ curl \ diff --git a/entrypoint.sh b/entrypoint.sh index 090bf07..3f086e5 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -4,6 +4,60 @@ set -Eeuo pipefail # Return code RET_CODE=0 +GIT_LOG="" +GIT_SUMMARY="" +GIT_DIFF="" +SOURCE_COMPARE_REF="" +TARGET_COMPARE_REF="" +RESOLVED_BRANCH_REF="" + +REPLACE_TEMPLATE_SCRIPT="/scripts/replace-template-diff.sh" +if [[ ! -x "${REPLACE_TEMPLATE_SCRIPT}" ]]; then + REPLACE_TEMPLATE_SCRIPT="$(dirname "$0")/scripts/replace-template-diff.sh" +fi + +get_git_log() { + if [[ -z "${GIT_LOG}" ]]; then + echo -e "\nListing new commits in the source branch..." + git log --graph --pretty=format:'%Cred%h%Creset - %Cblue%an%Creset - %Cgreen%cd%Creset %n%s %b' --abbrev-commit --date=format:'%Y-%m-%d %H:%M:%S' "${TARGET_COMPARE_REF}...${SOURCE_COMPARE_REF}" + GIT_LOG=$(git log --graph --pretty=format:'%Cred%h%Creset - %Cblue%an%Creset - %Cgreen%cd%Creset %n%s%n%b' --abbrev-commit --date=format:'%Y-%m-%d %H:%M:%S' --no-color "${TARGET_COMPARE_REF}...${SOURCE_COMPARE_REF}") + fi +} + +get_git_summary() { + if [[ -z "${GIT_SUMMARY}" ]]; then + echo -e "\n\nListing commits subjects in the source branch..." + git log --reverse --pretty=format:'%s' --abbrev-commit "${TARGET_COMPARE_REF}...${SOURCE_COMPARE_REF}" + GIT_SUMMARY=$(git log --reverse --pretty=format:'%s' --abbrev-commit "${TARGET_COMPARE_REF}...${SOURCE_COMPARE_REF}") + fi +} + +get_git_diff() { + if [[ -z "${GIT_DIFF}" ]]; then + echo -e "\n\nListing files modified in the source branch..." + git diff --compact-summary "${TARGET_COMPARE_REF}...${SOURCE_COMPARE_REF}" + GIT_DIFF=$(git diff --compact-summary --no-color "${TARGET_COMPARE_REF}...${SOURCE_COMPARE_REF}") + fi +} + +resolve_branch_ref() { + local branch_name="$1" + local remote_ref="refs/remotes/origin/${branch_name}" + local head_ref="refs/heads/${branch_name}" + + if git show-ref --verify --quiet "${remote_ref}"; then + RESOLVED_BRANCH_REF="origin/${branch_name}" + return 0 + fi + + if git show-ref --verify --quiet "${head_ref}"; then + RESOLVED_BRANCH_REF="${branch_name}" + return 0 + fi + + echo -e "\n[ERROR] Missing branch reference: ${branch_name}" >&2 + return 1 +} echo "Inputs:" echo " source_branch: ${INPUT_SOURCE_BRANCH}" @@ -60,41 +114,39 @@ echo "Target branch: ${TARGET_BRANCH}" echo -e "\nUpdating all branches..." git fetch origin '+refs/heads/*:refs/heads/*' --update-head-ok +echo -e "\nValidating branches..." +if ! resolve_branch_ref "${SOURCE_BRANCH}"; then + exit 1 +fi +SOURCE_COMPARE_REF="${RESOLVED_BRANCH_REF}" + +if ! resolve_branch_ref "${TARGET_BRANCH}"; then + exit 1 +fi +TARGET_COMPARE_REF="${RESOLVED_BRANCH_REF}" + echo -e "\nComparing branches by revisions..." -if [[ $(git rev-parse --revs-only "${SOURCE_BRANCH}") == $(git rev-parse --revs-only "${TARGET_BRANCH}") ]]; then +if [[ $(git rev-parse --verify "${SOURCE_COMPARE_REF}") == $(git rev-parse --verify "${TARGET_COMPARE_REF}") ]]; then echo -e "\n[INFO] Both branches are the same. No action needed." exit 0 fi echo -e "\nComparing branches by diff..." -if [[ -z $(git diff "remotes/origin/${TARGET_BRANCH}...remotes/origin/${SOURCE_BRANCH}") ]]; then +if git diff --quiet "${TARGET_COMPARE_REF}...${SOURCE_COMPARE_REF}"; then if [[ "${INPUT_ALLOW_NO_DIFF}" == "true" ]]; then echo -e "\n[INFO] Both branches are the same. Continuing." else echo -e "\n[INFO] Both branches are the same. No action needed." exit 0 fi +else + DIFF_STATUS="$?" + if [[ "${DIFF_STATUS}" != "1" ]]; then + echo -e "\n[ERROR] Failed to compare branches by diff (git exit code: ${DIFF_STATUS})." + exit 1 + fi fi -# sed has problems with putting multi-line strings in the next steps, and later we use # for sed -# newline `\n` and hash `#` characters are replaced with some (hopefully) totally unlikely strings -# after insertions of git information into template those strings are replaced back by proper characters - -echo -e "\nListing new commits in the source branch..." -git log --graph --pretty=format:'%Cred%h%Creset - %Cblue%an%Creset - %Cgreen%cd%Creset %n%s %b' --abbrev-commit --date=format:'%Y-%m-%d %H:%M:%S' "origin/${TARGET_BRANCH}...origin/${SOURCE_BRANCH}" -GIT_LOG=$(git log --graph --pretty=format:'%Cred%h%Creset - %Cblue%an%Creset - %Cgreen%cd%Creset %n%s%n%b' --abbrev-commit --date=format:'%Y-%m-%d %H:%M:%S' --no-color "origin/${TARGET_BRANCH}...origin/${SOURCE_BRANCH}") -GIT_LOG=$(echo -e "${GIT_LOG}" | sed 's|#|^HaSz^|g' | sed ':a;N;$!ba; s/\n/^NowALiNiA^/g') - -echo -e "\n\nListing commits subjects in the source branch..." -git log --reverse --pretty=format:'%s' --abbrev-commit "origin/${TARGET_BRANCH}...origin/${SOURCE_BRANCH}" -GIT_SUMMARY=$(git log --reverse --pretty=format:'%s' --abbrev-commit "origin/${TARGET_BRANCH}...origin/${SOURCE_BRANCH}") -GIT_SUMMARY=$(echo -e "${GIT_SUMMARY}" | sed 's|#|^HaSz^|g' | sed ':a;N;$!ba; s/\n/^NowALiNiA^/g') - -echo -e "\n\nListing files modified in the source branch..." -git diff --compact-summary "origin/${TARGET_BRANCH}...origin/${SOURCE_BRANCH}" -GIT_DIFF=$(git diff --compact-summary --no-color "origin/${TARGET_BRANCH}...origin/${SOURCE_BRANCH}") -GIT_DIFF=$(echo -e "${GIT_DIFF}" | sed 's|#|^HaSz^|g' | sed ':a;N;$!ba; s/\n/^NowALiNiA^/g') - echo -e "\nSetting template..." PR_NUMBER=$(hub pr list --base "${TARGET_BRANCH}" --head "${SOURCE_BRANCH}" --format '%I') if [[ -z "${PR_NUMBER}" ]]; then @@ -103,6 +155,7 @@ if [[ -z "${PR_NUMBER}" ]]; then elif [[ -n "${INPUT_BODY}" ]]; then TEMPLATE="${INPUT_BODY}" else + get_git_log TEMPLATE="${GIT_LOG}" fi else @@ -115,22 +168,62 @@ if [[ -n "${INPUT_OLD_STRING}" ]]; then if [[ -n "${INPUT_NEW_STRING}" ]]; then TEMPLATE=${TEMPLATE/${OLD_STRING}/${INPUT_NEW_STRING}} else + get_git_summary TEMPLATE=${TEMPLATE/${OLD_STRING}/${GIT_SUMMARY}} fi fi if [[ "${INPUT_GET_DIFF}" == "true" ]]; then echo -e "\nReplacing predefined fields with git information..." - # little hack to trick sed to work with multiline - # also backwards compatible with old replacement strings - TEMPLATE=$(echo -e "${TEMPLATE}" | sed ':a;N;$!ba; s#.*#\n'"${GIT_SUMMARY}"'\n#g') - TEMPLATE=$(echo -e "${TEMPLATE}" | sed ':a;N;$!ba; s##\n'"${GIT_LOG}"'\n#g') - TEMPLATE=$(echo -e "${TEMPLATE}" | sed ':a;N;$!ba; s#.*#\n'"${GIT_LOG}"'\n#g') - TEMPLATE=$(echo -e "${TEMPLATE}" | sed ':a;N;$!ba; s##\n'"${GIT_DIFF}"'\n#g') - TEMPLATE=$(echo -e "${TEMPLATE}" | sed ':a;N;$!ba; s#.*#\n'"${GIT_DIFF}"'\n#g') + REPLACE_SUMMARY="false" + REPLACE_COMMITS="false" + REPLACE_FILES="false" + + if [[ "${TEMPLATE}" == *""* && "${TEMPLATE}" == *""* ]]; then + REPLACE_SUMMARY="true" + fi + if [[ "${TEMPLATE}" == *""* || ( "${TEMPLATE}" == *""* && "${TEMPLATE}" == *""* ) ]]; then + REPLACE_COMMITS="true" + fi + if [[ "${TEMPLATE}" == *""* || ( "${TEMPLATE}" == *""* && "${TEMPLATE}" == *""* ) ]]; then + REPLACE_FILES="true" + fi + + if [[ "${REPLACE_SUMMARY}" == "true" || "${REPLACE_COMMITS}" == "true" || "${REPLACE_FILES}" == "true" ]]; then + TEMPLATE_WORK_FILE="/tmp/template-work.md" + SUMMARY_FILE="/tmp/template-summary.txt" + COMMITS_FILE="/tmp/template-commits.txt" + FILES_FILE="/tmp/template-files.txt" + + printf '%s' "${TEMPLATE}" > "${TEMPLATE_WORK_FILE}" + + if [[ "${REPLACE_SUMMARY}" == "true" ]]; then + get_git_summary + printf '%s' "${GIT_SUMMARY}" > "${SUMMARY_FILE}" + fi + if [[ "${REPLACE_COMMITS}" == "true" ]]; then + get_git_log + printf '%s' "${GIT_LOG}" > "${COMMITS_FILE}" + fi + if [[ "${REPLACE_FILES}" == "true" ]]; then + get_git_diff + printf '%s' "${GIT_DIFF}" > "${FILES_FILE}" + fi + + "${REPLACE_TEMPLATE_SCRIPT}" \ + --template "${TEMPLATE_WORK_FILE}" \ + --summary-file "${SUMMARY_FILE}" \ + --commits-file "${COMMITS_FILE}" \ + --files-file "${FILES_FILE}" \ + --replace-summary "${REPLACE_SUMMARY}" \ + --replace-commits "${REPLACE_COMMITS}" \ + --replace-files "${REPLACE_FILES}" + + TEMPLATE=$(cat "${TEMPLATE_WORK_FILE}") + else + echo -e "[INFO] No diff markers found in template body. Skipping get_diff replacements." + fi fi -#shellcheck disable=SC2016 -TEMPLATE=$(echo -e "${TEMPLATE}" | sed 's|\^HaSz\^|#|g' | sed '1h;2,$H;$!d;g; s|\^NowALiNiA\^|\n|g') if [[ -z "${PR_NUMBER}" ]]; then echo -e "\nSetting all arguments..." diff --git a/scripts/replace-template-diff.sh b/scripts/replace-template-diff.sh new file mode 100755 index 0000000..e63fca3 --- /dev/null +++ b/scripts/replace-template-diff.sh @@ -0,0 +1,111 @@ +#!/usr/bin/env bash + +set -Eeuo pipefail + +TEMPLATE_FILE="" +SUMMARY_FILE="" +COMMITS_FILE="" +FILES_FILE="" +REPLACE_SUMMARY="false" +REPLACE_COMMITS="false" +REPLACE_FILES="false" + +while [[ $# -gt 0 ]]; do + case "$1" in + --template) + TEMPLATE_FILE="$2" + shift 2 + ;; + --summary-file) + SUMMARY_FILE="$2" + shift 2 + ;; + --commits-file) + COMMITS_FILE="$2" + shift 2 + ;; + --files-file) + FILES_FILE="$2" + shift 2 + ;; + --replace-summary) + REPLACE_SUMMARY="$2" + shift 2 + ;; + --replace-commits) + REPLACE_COMMITS="$2" + shift 2 + ;; + --replace-files) + REPLACE_FILES="$2" + shift 2 + ;; + *) + echo "[ERROR] Unknown argument: $1" >&2 + exit 1 + ;; + esac +done + +if [[ -z "$TEMPLATE_FILE" ]]; then + echo "[ERROR] Missing required argument: --template" >&2 + exit 1 +fi + +if [[ ! -f "$TEMPLATE_FILE" ]]; then + echo "[ERROR] Template file does not exist: $TEMPLATE_FILE" >&2 + exit 1 +fi + +if [[ "$REPLACE_SUMMARY" == "true" && ( -z "$SUMMARY_FILE" || ! -f "$SUMMARY_FILE" ) ]]; then + echo "[ERROR] Summary replacement requested but file is missing" >&2 + exit 1 +fi + +if [[ "$REPLACE_COMMITS" == "true" && ( -z "$COMMITS_FILE" || ! -f "$COMMITS_FILE" ) ]]; then + echo "[ERROR] Commits replacement requested but file is missing" >&2 + exit 1 +fi + +if [[ "$REPLACE_FILES" == "true" && ( -z "$FILES_FILE" || ! -f "$FILES_FILE" ) ]]; then + echo "[ERROR] Files replacement requested but file is missing" >&2 + exit 1 +fi + +REPLACE_SUMMARY="$REPLACE_SUMMARY" \ +REPLACE_COMMITS="$REPLACE_COMMITS" \ +REPLACE_FILES="$REPLACE_FILES" \ +SUMMARY_FILE="$SUMMARY_FILE" \ +COMMITS_FILE="$COMMITS_FILE" \ +FILES_FILE="$FILES_FILE" \ +perl -0777 -i -pe ' + BEGIN { + sub read_file { + my ($path) = @_; + return q{} if !defined($path) || $path eq q{}; + open my $fh, q{<}, $path or die "Unable to read replacement file: $path\n"; + local $/; + my $content = <$fh>; + close $fh; + return defined($content) ? $content : q{}; + } + + $summary = read_file($ENV{SUMMARY_FILE}); + $commits = read_file($ENV{COMMITS_FILE}); + $files = read_file($ENV{FILES_FILE}); + } + + if ($ENV{REPLACE_SUMMARY} eq q{true}) { + s{.*?}{"\n$summary\n"}gse; + } + + if ($ENV{REPLACE_COMMITS} eq q{true}) { + s{}{"\n$commits\n"}gse; + s{.*?}{"\n$commits\n"}gse; + } + + if ($ENV{REPLACE_FILES} eq q{true}) { + s{}{"\n$files\n"}gse; + s{.*?}{"\n$files\n"}gse; + } +' "$TEMPLATE_FILE" diff --git a/tests/unit/test_branch_validation.sh b/tests/unit/test_branch_validation.sh new file mode 100755 index 0000000..36def0e --- /dev/null +++ b/tests/unit/test_branch_validation.sh @@ -0,0 +1,93 @@ +#!/usr/bin/env bash + +set -Eeuo pipefail + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)" +SCRIPT_PATH="${SCRIPT_DIR}/../../entrypoint.sh" +TMP_DIR="$(mktemp -d)" +trap 'rm -rf "${TMP_DIR}"' EXIT + +assert_contains() { + local file_path="$1" + local expected="$2" + if ! grep -Fq -- "${expected}" "${file_path}"; then + echo "Assertion failed. Expected to find: ${expected}" >&2 + echo "----- FILE CONTENT -----" >&2 + cat "${file_path}" >&2 + exit 1 + fi +} + +git init --initial-branch=main "${TMP_DIR}/repo" >/dev/null + +mkdir -p "${TMP_DIR}/bin" +cat > "${TMP_DIR}/bin/git" <<'EOF' +#!/usr/bin/env bash +set -Eeuo pipefail + +REAL_GIT="${REAL_GIT:-/usr/bin/git}" + +if [[ "$#" -ge 2 && "$1" == "remote" && "$2" == "set-url" ]]; then + exit 0 +fi + +if [[ "$#" -ge 1 && "$1" == "fetch" ]]; then + exec "${REAL_GIT}" fetch . '+refs/heads/*:refs/heads/*' --update-head-ok +fi + +exec "${REAL_GIT}" "$@" +EOF +chmod +x "${TMP_DIR}/bin/git" + +pushd "${TMP_DIR}/repo" >/dev/null +git config user.name "tester" +git config user.email "tester@example.com" +printf 'x\n' > README.md +git add README.md +git commit -m "init" >/dev/null +git branch develop +git update-ref refs/remotes/origin/develop refs/heads/develop +git remote add origin . +popd >/dev/null + +LOG_FILE="${TMP_DIR}/run.log" +set +e +( + cd "${TMP_DIR}/repo" + PATH="${TMP_DIR}/bin:${PATH}" \ + REAL_GIT="$(command -v git)" \ + GITHUB_ACTOR="ci-user" \ + GITHUB_TOKEN="token" \ + GITHUB_REPOSITORY="owner/repo" \ + GITHUB_WORKSPACE="${TMP_DIR}/repo" \ + GITHUB_OUTPUT="${TMP_DIR}/output.txt" \ + INPUT_GITHUB_TOKEN="token" \ + INPUT_SOURCE_BRANCH="develop" \ + INPUT_TARGET_BRANCH="release/MAPL-v3" \ + INPUT_TITLE="" \ + INPUT_TEMPLATE="" \ + INPUT_BODY="" \ + INPUT_REVIEWER="" \ + INPUT_ASSIGNEE="" \ + INPUT_LABEL="" \ + INPUT_MILESTONE="" \ + INPUT_DRAFT="false" \ + INPUT_GET_DIFF="false" \ + INPUT_OLD_STRING="" \ + INPUT_NEW_STRING="" \ + INPUT_IGNORE_USERS="dependabot" \ + INPUT_ALLOW_NO_DIFF="false" \ + bash "${SCRIPT_PATH}" >"${LOG_FILE}" 2>&1 +) +STATUS="$?" +set -e + +if [[ "${STATUS}" == "0" ]]; then + echo "Expected non-zero exit code when target branch is missing" >&2 + cat "${LOG_FILE}" >&2 + exit 1 +fi + +assert_contains "${LOG_FILE}" "[ERROR] Missing branch reference: release/MAPL-v3" + +echo "Branch validation test passed." diff --git a/tests/unit/test_replace_template_diff.sh b/tests/unit/test_replace_template_diff.sh new file mode 100755 index 0000000..2ab535c --- /dev/null +++ b/tests/unit/test_replace_template_diff.sh @@ -0,0 +1,128 @@ +#!/usr/bin/env bash + +set -Eeuo pipefail + +SCRIPT_PATH="$(dirname "$0")/../../scripts/replace-template-diff.sh" + +TMP_DIR="$(mktemp -d)" +trap 'rm -rf "${TMP_DIR}"' EXIT + +assert_contains() { + local file_path="$1" + local expected="$2" + if ! grep -Fq -- "${expected}" "${file_path}"; then + echo "Assertion failed. Expected to find: ${expected}" >&2 + echo "----- FILE CONTENT -----" >&2 + cat "${file_path}" >&2 + exit 1 + fi +} + +assert_not_contains() { + local file_path="$1" + local not_expected="$2" + if grep -Fq -- "${not_expected}" "${file_path}"; then + echo "Assertion failed. Did not expect to find: ${not_expected}" >&2 + echo "----- FILE CONTENT -----" >&2 + cat "${file_path}" >&2 + exit 1 + fi +} + +run_replacement() { + local template_file="$1" + local replace_summary="$2" + local replace_commits="$3" + local replace_files="$4" + + "${SCRIPT_PATH}" \ + --template "${template_file}" \ + --summary-file "${TMP_DIR}/summary.txt" \ + --commits-file "${TMP_DIR}/commits.txt" \ + --files-file "${TMP_DIR}/files.txt" \ + --replace-summary "${replace_summary}" \ + --replace-commits "${replace_commits}" \ + --replace-files "${replace_files}" +} + +cat > "${TMP_DIR}/summary.txt" <<'EOF' +Summary line 1 +Summary line 2 +EOF + +cat > "${TMP_DIR}/commits.txt" <<'EOF' +abc123 - commit one +def456 - commit two +EOF + +cat > "${TMP_DIR}/files.txt" <<'EOF' +M README.md +A scripts/new.sh +EOF + +cat > "${TMP_DIR}/template-full.md" <<'EOF' +Body start + +old summary + + + +old files + +Body end +EOF + +run_replacement "${TMP_DIR}/template-full.md" "true" "true" "true" + +assert_contains "${TMP_DIR}/template-full.md" "Summary line 1" +assert_contains "${TMP_DIR}/template-full.md" "abc123 - commit one" +assert_contains "${TMP_DIR}/template-full.md" "M README.md" +assert_contains "${TMP_DIR}/template-full.md" "" +assert_contains "${TMP_DIR}/template-full.md" "" +assert_not_contains "${TMP_DIR}/template-full.md" "old summary" +assert_not_contains "${TMP_DIR}/template-full.md" "old files" + +cat > "${TMP_DIR}/template-commits-block.md" <<'EOF' +Body start + +legacy + +Body end +EOF + +run_replacement "${TMP_DIR}/template-commits-block.md" "false" "true" "false" + +assert_contains "${TMP_DIR}/template-commits-block.md" "def456 - commit two" +assert_not_contains "${TMP_DIR}/template-commits-block.md" "legacy" + +cat > "${TMP_DIR}/template-no-markers.md" <<'EOF' +No markers here. +EOF + +run_replacement "${TMP_DIR}/template-no-markers.md" "false" "false" "false" + +assert_contains "${TMP_DIR}/template-no-markers.md" "No markers here." + +python3 - <<'PY' > "${TMP_DIR}/commits-large.txt" +for i in range(15000): + print(f"{i:05d} - synthetic commit line with payload") +PY + +cat > "${TMP_DIR}/template-large.md" <<'EOF' +Large body start + +Large body end +EOF + +"${SCRIPT_PATH}" \ + --template "${TMP_DIR}/template-large.md" \ + --summary-file "${TMP_DIR}/summary.txt" \ + --commits-file "${TMP_DIR}/commits-large.txt" \ + --files-file "${TMP_DIR}/files.txt" \ + --replace-summary "false" \ + --replace-commits "true" \ + --replace-files "false" + +assert_contains "${TMP_DIR}/template-large.md" "14999 - synthetic commit line with payload" + +echo "All replace-template-diff tests passed." From 8f22cc75142bcc63fae227c4949f669c5a4d4797 Mon Sep 17 00:00:00 2001 From: ChristophShyper <45788587+ChristophShyper@users.noreply.github.com> Date: Fri, 15 May 2026 19:28:40 +0200 Subject: [PATCH 2/3] temp hardcode Dockerfile --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 7462ed1..9347724 100644 --- a/action.yml +++ b/action.yml @@ -72,7 +72,7 @@ outputs: description: Pull request number runs: using: docker - image: docker://devopsinfra/action-pull-request:v1.0.2 + image: Dockerfile env: GITHUB_TOKEN: ${{ inputs.github_token }} branding: From bfe6826658c87cdcf619f1999c8d1716ce988d32 Mon Sep 17 00:00:00 2001 From: ChristophShyper <45788587+ChristophShyper@users.noreply.github.com> Date: Fri, 15 May 2026 19:50:31 +0200 Subject: [PATCH 3/3] feat: enhance template replacement functionality with conditional file reading --- scripts/replace-template-diff.sh | 6 +++--- tests/unit/test_replace_template_diff.sh | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/scripts/replace-template-diff.sh b/scripts/replace-template-diff.sh index e63fca3..49a83b5 100755 --- a/scripts/replace-template-diff.sh +++ b/scripts/replace-template-diff.sh @@ -90,9 +90,9 @@ perl -0777 -i -pe ' return defined($content) ? $content : q{}; } - $summary = read_file($ENV{SUMMARY_FILE}); - $commits = read_file($ENV{COMMITS_FILE}); - $files = read_file($ENV{FILES_FILE}); + $summary = $ENV{REPLACE_SUMMARY} eq q{true} ? read_file($ENV{SUMMARY_FILE}) : q{}; + $commits = $ENV{REPLACE_COMMITS} eq q{true} ? read_file($ENV{COMMITS_FILE}) : q{}; + $files = $ENV{REPLACE_FILES} eq q{true} ? read_file($ENV{FILES_FILE}) : q{}; } if ($ENV{REPLACE_SUMMARY} eq q{true}) { diff --git a/tests/unit/test_replace_template_diff.sh b/tests/unit/test_replace_template_diff.sh index 2ab535c..0284839 100755 --- a/tests/unit/test_replace_template_diff.sh +++ b/tests/unit/test_replace_template_diff.sh @@ -45,6 +45,17 @@ run_replacement() { --replace-files "${replace_files}" } +run_replacement_files_only() { + local template_file="$1" + + "${SCRIPT_PATH}" \ + --template "${template_file}" \ + --files-file "${TMP_DIR}/files.txt" \ + --replace-summary "false" \ + --replace-commits "false" \ + --replace-files "true" +} + cat > "${TMP_DIR}/summary.txt" <<'EOF' Summary line 1 Summary line 2 @@ -103,6 +114,19 @@ run_replacement "${TMP_DIR}/template-no-markers.md" "false" "false" "false" assert_contains "${TMP_DIR}/template-no-markers.md" "No markers here." +cat > "${TMP_DIR}/template-files-only.md" <<'EOF' +Body start + +old files + +Body end +EOF + +run_replacement_files_only "${TMP_DIR}/template-files-only.md" + +assert_contains "${TMP_DIR}/template-files-only.md" "A scripts/new.sh" +assert_not_contains "${TMP_DIR}/template-files-only.md" "old files" + python3 - <<'PY' > "${TMP_DIR}/commits-large.txt" for i in range(15000): print(f"{i:05d} - synthetic commit line with payload")