Skip to content

Commit 1fe3c8f

Browse files
fix: enhance entrypoint script with repository path validation and safe directory configuration (#207)
Co-authored-by: ChristophShyper <45788587+ChristophShyper@users.noreply.github.com>
1 parent 00440d1 commit 1fe3c8f

2 files changed

Lines changed: 37 additions & 6 deletions

File tree

entrypoint.sh

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,24 @@ if [[ ! -d "${REPO_DIR}" ]]; then
4848
echo "[ERROR] Repository path does not exist: ${REPO_DIR}"
4949
exit 1
5050
fi
51-
if ! git -C "${REPO_DIR}" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
52-
echo "[ERROR] Path is not a git repository: ${REPO_DIR}"
53-
exit 1
54-
fi
55-
echo "[INFO] Using repository path: ${REPO_DIR}"
5651

5752
# Keep all global git config isolated to a temp file
5853
export GIT_CONFIG_GLOBAL
5954
GIT_CONFIG_GLOBAL="$(mktemp /tmp/action-commit-push-git-config-XXXXXX)"
6055
trap 'rm -f "${GIT_CONFIG_GLOBAL}"' EXIT
6156

62-
# Set git credentials
57+
# Configure safe directories before git repo validation
6358
git config --global safe.directory "${GITHUB_WORKSPACE}"
6459
git config --global safe.directory /github/workspace
6560
git config --global safe.directory "${REPO_DIR}"
61+
62+
if ! git -C "${REPO_DIR}" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
63+
echo "[ERROR] Path is not a git repository: ${REPO_DIR}"
64+
exit 1
65+
fi
66+
echo "[INFO] Using repository path: ${REPO_DIR}"
67+
68+
# Set git credentials
6669
git -C "${REPO_DIR}" remote set-url origin "https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@${INPUT_ORGANIZATION_DOMAIN}/${GITHUB_REPOSITORY}"
6770
git -C "${REPO_DIR}" config user.name "${GITHUB_ACTOR}"
6871
git -C "${REPO_DIR}" config user.email "${GITHUB_ACTOR}@users.noreply.${INPUT_ORGANIZATION_DOMAIN}"

tests/docker/local-image.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,34 @@ commandTests:
2323
args:
2424
- -lc
2525
- test ! -e /git-lfs*.deb
26+
27+
- name: Entrypoint handles default repository path
28+
command: bash
29+
args:
30+
- -lc
31+
- |
32+
set -e
33+
rm -rf /tmp/ws /tmp/remote.git
34+
mkdir -p /tmp/ws
35+
git init /tmp/ws
36+
git -C /tmp/ws config user.name test
37+
git -C /tmp/ws config user.email test@example.com
38+
touch /tmp/ws/.keep
39+
git -C /tmp/ws add .
40+
git -C /tmp/ws commit -m init
41+
git init --bare /tmp/remote.git
42+
git -C /tmp/ws remote add origin /tmp/remote.git
43+
GITHUB_WORKSPACE=/tmp/ws \
44+
GITHUB_ACTOR=tester \
45+
GITHUB_REPOSITORY=owner/repo \
46+
GITHUB_OUTPUT=/tmp/github_output.txt \
47+
GITHUB_TOKEN=fake \
48+
INPUT_ORGANIZATION_DOMAIN=github.com \
49+
INPUT_REPOSITORY_PATH=. \
50+
INPUT_AMEND=false \
51+
INPUT_ALLOW_EMPTY_COMMIT=false \
52+
INPUT_TARGET_BRANCH='' \
53+
/entrypoint.sh
2654
fileExistenceTests:
2755
- name: entrypoint exists
2856
path: /entrypoint.sh

0 commit comments

Comments
 (0)