Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 58 additions & 37 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,79 +6,100 @@ on:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
schedule:
- cron: '0 0 1 * *'

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

inputs:
debug:
description: 'Enable debug mode'
type: boolean
required: false
default: false
verbose:
description: 'Enable verbose output'
type: boolean
required: false
default: true

jobs:
test-git-native:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Run tests git-native
run: |
git config --global user.email "git-artifact@github.com"
git config --global user.name "Git Artifact"
git --version
verbose=true bash _tests.sh || {
exit_code=$?
find . -name run.log
find . -name run.log | xargs -I % cat %
exit $exit_code
}
verbose=true bash _tests.sh

test-git-alpine-latest:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Run tests
run: |
set -eux
git_version=latest
docker build --build-arg ALPINE_GIT_DOCKER_VERSION=${git_version} -t git-artifact:latest .
docker run --rm -e debug=${debug:-false} -e verbose=true -v $(pwd):/git -v $HOME/.ssh:/root/.ssh git-artifact:latest --version
docker run --rm -e debug=${debug:-false} -e verbose=true -v $(pwd):/git -v $HOME/.ssh:/root/.ssh git-artifact:latest artifact-tests || {
exit_code=$?
find . -name run.log
find . -name run.log | xargs -I % cat %
exit $exit_code
}

test-git-alpine-v2-36-2:
docker build --build-arg ALPINE_GIT_DOCKER_VERSION="${git_version}" --build-arg USER_ID="$(id -u)" --build-arg GROUP_ID="$(id -g)" -t "git-artifact:${git_version}" .
docker run --rm -u "$(id -u):$(id -g)" -e debug="${{ github.event.inputs.debug}}" -e verbose="${{ github.event.inputs.verbose}}" -v "$(pwd):/git" -v "$HOME/.ssh:/root/.ssh" "git-artifact:latest" --version
docker run --rm -u "$(id -u):$(id -g)" -e debug="${{ github.event.inputs.debug}}" -e verbose="${{ github.event.inputs.verbose}}" -v "$(pwd):/git" -v "$HOME/.ssh:/root/.ssh" "git-artifact:latest" artifact-tests

test-git-alpine-v2-49-0:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run tests
run: |
set -eux
git_version=v2.49.0
docker build --build-arg ALPINE_GIT_DOCKER_VERSION="${git_version}" --build-arg USER_ID="$(id -u)" --build-arg GROUP_ID="$(id -g)" -t "git-artifact:${git_version}" .
docker run --rm -u "$(id -u):$(id -g)" -e debug="${{ github.event.inputs.debug}}" -e verbose="${{ github.event.inputs.verbose}}" -v "$(pwd):/git" -v "$HOME/.ssh:/root/.ssh" "git-artifact:${git_version}" --version
docker run --rm -u "$(id -u):$(id -g)" -e debug="${{ github.event.inputs.debug}}" -e verbose="${{ github.event.inputs.verbose}}" -v "$(pwd):/git" -v "$HOME/.ssh:/root/.ssh" "git-artifact:${git_version}" artifact-tests


test-git-alpine-v2-47-2:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run tests
run: |
set -eux
git_version=v2.47.2
docker build --build-arg ALPINE_GIT_DOCKER_VERSION="${git_version}" --build-arg USER_ID="$(id -u)" --build-arg GROUP_ID="$(id -g)" -t "git-artifact:${git_version}" .
docker run --rm -u "$(id -u):$(id -g)" -e debug="${{ github.event.inputs.debug}}" -e verbose="${{ github.event.inputs.verbose}}" -v "$(pwd):/git" -v "$HOME/.ssh:/root/.ssh" "git-artifact:${git_version}" --version
docker run --rm -u "$(id -u):$(id -g)" -e debug="${{ github.event.inputs.debug}}" -e verbose="${{ github.event.inputs.verbose}}" -v "$(pwd):/git" -v "$HOME/.ssh:/root/.ssh" "git-artifact:${git_version}" artifact-tests

test-git-alpine-v2-36-2:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Run tests
run: |
set -eux
git_version=v2.36.2
docker build --build-arg ALPINE_GIT_DOCKER_VERSION=${git_version} -t git-artifact:${git_version} .
docker run --rm -e debug=${debug:-false} -e verbose=true -v $(pwd):/git -v $HOME/.ssh:/root/.ssh git-artifact:${git_version} --version
docker run --rm -e debug=${debug:-false} -e verbose=true -v $(pwd):/git -v $HOME/.ssh:/root/.ssh git-artifact:${git_version} artifact-tests || {
exit_code=$?
find . -name run.log
find . -name run.log | xargs -I % cat %
exit $exit_code
}
docker build --build-arg ALPINE_GIT_DOCKER_VERSION="${git_version}" --build-arg USER_ID="$(id -u)" --build-arg GROUP_ID="$(id -g)" -t "git-artifact:${git_version}" .
docker run --rm -u "$(id -u):$(id -g)" -e debug="${{ github.event.inputs.debug}}" -e verbose="${{ github.event.inputs.verbose}}" -v "$(pwd):/git" -v "$HOME/.ssh:/root/.ssh" "git-artifact:${git_version}" --version
docker run --rm -u "$(id -u):$(id -g)" -e debug="${{ github.event.inputs.debug}}" -e verbose="${{ github.event.inputs.verbose}}" -v "$(pwd):/git" -v "$HOME/.ssh:/root/.ssh" "git-artifact:${git_version}" artifact-tests

test-git-alpine-v2-26-2:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Run tests
run: |
set -eux
git_version=v2.26.2
docker build --build-arg ALPINE_GIT_DOCKER_VERSION=${git_version} -t git-artifact:${git_version} .
docker run --rm -e debug=${debug:-false} -e verbose=true -v $(pwd):/git -v $HOME/.ssh:/root/.ssh git-artifact:${git_version} --version
docker run --rm -e debug=${debug:-false} -e verbose=true -v $(pwd):/git -v $HOME/.ssh:/root/.ssh git-artifact:${git_version} artifact-tests || {
exit_code=$?
find . -name run.log
find . -name run.log | xargs -I % cat %
exit $exit_code
}
docker build --build-arg ALPINE_GIT_DOCKER_VERSION="${git_version}" --build-arg USER_ID="$(id -u)" --build-arg GROUP_ID="$(id -g)" -t "git-artifact:${git_version}" .
docker run --rm -u "$(id -u):$(id -g)" -e debug="${{ github.event.inputs.debug}}" -e verbose="${{ github.event.inputs.verbose}}" -v "$(pwd):/git" -v "$HOME/.ssh:/root/.ssh" "git-artifact:${git_version}" --version
docker run --rm -u "$(id -u):$(id -g)" -e debug="${{ github.event.inputs.debug}}" -e verbose="${{ github.event.inputs.verbose}}" -v "$(pwd):/git" -v "$HOME/.ssh:/root/.ssh" "git-artifact:${git_version}" artifact-tests
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
**/.clone
**/git-test.log
**/run.log
**/nok.log
**/ok.log
2 changes: 1 addition & 1 deletion .test/2/git-reference.log
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
* (HEAD, tag: v2.0) v2.0
| * (tag: v1.0) v1.0
|/
* (origin/main, origin/HEAD, main) First commit of git artifact
* (origin/main, main) First commit of git artifact
2 changes: 1 addition & 1 deletion .test/3/git-reference.log
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* (HEAD -> main, origin/main, origin/HEAD) First commit of git artifact
* (HEAD -> main, origin/main) First commit of git artifact
2 changes: 1 addition & 1 deletion .test/4/git-reference.log
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
* (tag: v4.1, origin/latest) v4.1
| * (tag: v4.0) v4.0
|/
* (HEAD -> latest, origin/main, origin/HEAD, main) First commit of git artifact
* (HEAD -> latest, origin/main, main) First commit of git artifact
2 changes: 1 addition & 1 deletion .test/5/git-reference.log
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
|/
| * (tag: v2.0) v2.0
|/
* (origin/main, origin/HEAD, main) First commit of git artifact
* (origin/main, main) First commit of git artifact
2 changes: 1 addition & 1 deletion .test/6/git-reference.log
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
* (HEAD, tag: v1.0) v1.0
* (origin/main, origin/HEAD, main, latest) First commit of git artifact
* (origin/main, main, latest) First commit of git artifact
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ FROM alpine/git:${ALPINE_GIT_DOCKER_VERSION}
RUN apk fix && \
apk --no-cache --update add bash

ARG USER_ID
ARG GROUP_ID

RUN addgroup -g ${GROUP_ID} gituser && \
adduser -D -u ${USER_ID} -G gituser gituser

USER gituser

RUN git config --global user.email "git@artifacts.com"
RUN git config --global user.name "Git Artifacts"

Expand Down
56 changes: 49 additions & 7 deletions _tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
clear

set -euo pipefail
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Consider the interaction between set -e and test aggregation.

The set -e flag may still cause the script to exit before reaching the new summary logic if any unexpected command fails. The test execution blocks are wrapped in { } > log 2>&1 which should contain failures, but other commands between tests could still trigger early exit.

Run this script to check if there are any commands outside the test blocks that could fail:


🏁 Script executed:

#!/bin/bash
# Check for potentially failing commands outside test execution blocks
echo "Checking for commands that might fail with set -e enabled..."
echo "Commands between test blocks:"
gawk '/^[[:space:]]*} > .*\/run\.log 2>&1[[:space:]]*$/{intest=0} !intest && !/^[[:space:]]*#/ && !/^[[:space:]]*$/ && /[a-zA-Z]/ {print NR ": " $0} /^[[:space:]]*{[[:space:]]*$/{intest=1}' _tests.sh

Length of output: 3964


Prevent unintended exits from setup commands under set -e

The initial setup and function definitions in _tests.sh include several commands outside the test–block braces that could fail and abort the entire script before your new summary logic runs. For example:

  • Line 3: clear
  • Lines 12–13: which git / git --version
  • Line 15: cd .test
  • Line 18: git clean -xffdq .
  • Lines 72–81 (inside generate_base_repo): various git artifact invocations

If any of these commands return a non-zero status, set -euo pipefail will terminate the script prematurely.

To guard against this, consider one of the following fixes:

  • Move set -euo pipefail inside each test block (or into eval_testcase) so it only applies during test execution.
  • Wrap non-critical setup commands with || true.
  • Temporarily disable -e for the setup phase using set +eset -e around those commands.

This will ensure that an unexpected failure in your environment setup doesn’t bypass the aggregated test summary.

🤖 Prompt for AI Agents
In _tests.sh at line 5, the use of 'set -euo pipefail' causes the script to exit
prematurely if any setup commands fail. To fix this, either move 'set -euo
pipefail' inside each test block or the eval_testcase function so it only
applies during test execution, or wrap non-critical setup commands like 'clear',
'which git', 'git --version', 'cd .test', and 'git clean -xffdq .' with '||
true' to prevent failure exits, or temporarily disable the '-e' option around
these setup commands using 'set +e' before and 'set -e' after them. This will
prevent unintended script termination during setup and allow the test summary
logic to run.

[[ ${debug:-} == true ]] && set -x
[[ ${debug:-} == true ]] && {
echo "debug: ${debug}"
set -x
}
PATH=$(pwd):$PATH

which git
Expand All @@ -17,7 +20,7 @@ git clean -xffdq .
local_tester_repo=.local
remote_tester_repo=.remote
clone_tester_repo=.clone

global_exit_code=0


function testcase_header() {
Expand All @@ -30,25 +33,34 @@ function testcase_header() {

function eval_testcase() {
# expect to be in repo to test against

# In git 2.48 changes the way HEAD is handled and for some reason it is not set
# in order to be backward compatible we remove the HEAD reference
rm -rf .git/refs/remotes/origin/HEAD

if ! [[ -s "${root_folder}/${test}/git-test.log" ]]; then
git log --graph --all --oneline --decorate --format="%d %s" > "${root_folder}/${test}/git-test.log"
git log --graph --all --oneline --format="%d %s" > "${root_folder}/${test}/git-test.log"
else
[[ ${debug:-} == true ]] && echo "Test $test : INFO: ${root_folder}/${test}/git-test.log is already available - use it"
fi
cd "${root_folder}/${test}"
if diff -w git-test.log git-reference.log ; then
if diff -w git-reference.log git-test.log ; then
if [[ ${verbose:-} == true ]] ; then
cat git-test.log
echo "Test $test : OK"
echo
else
echo "Test $test : OK : ${testcase_synopsis}"
fi
mv run.log ok.log
else
echo "ERROR: Test $test failed: ${testcase_synopsis}"
exit 1
echo "Test $test : NOK : ${testcase_synopsis}"
mv run.log nok.log
[[ ${verbose:-} == true ]] && cat git-test.log
global_exit_code=2
fi
Comment on lines +55 to 61
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Potential false-negative when diff errors
diff exit > 1 (I/O error, etc.) is treated the same as “files differ” and the script continues. Capture the status to distinguish unexpected errors:

-    if diff -w git-test.log git-reference.log ; then 
+    diff -w git-test.log git-reference.log
+    rc=$?
+    if [[ $rc -eq 0 ]]; then+    elif [[ $rc -eq 1 ]]; then    # files differ – expected branch
+
+    else                          # diff crashed
+       echo "Test $test : ERROR (diff failed, rc=$rc)"
+       global_exit_code=2
+    fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
mv run.log ok.log
else
echo "ERROR: Test $test failed: ${testcase_synopsis}"
exit 1
echo "Test $test : NOK : ${testcase_synopsis}"
mv run.log nok.log
[[ ${verbose:-} == true ]] && cat git-test.log
global_exit_code=2
fi
diff -w git-test.log git-reference.log
rc=$?
if [[ $rc -eq 0 ]]; then
echo "Test $test : OK : ${testcase_synopsis}"
mv run.log ok.log
elif [[ $rc -eq 1 ]]; then # files differ – expected branch
echo "Test $test : NOK : ${testcase_synopsis}"
mv run.log nok.log
[[ ${verbose:-} == true ]] && cat git-test.log
global_exit_code=2
else # diff crashed
echo "Test $test : ERROR (diff failed, rc=$rc)"
global_exit_code=2
fi
🤖 Prompt for AI Agents
In _tests.sh around lines 50 to 56, the script treats any diff exit code greater
than 1 as files differing, which can mask I/O or other unexpected errors. Modify
the script to capture the diff exit status separately, check if it is exactly 1
(files differ) or greater than 1 (error), and handle the error case distinctly
by reporting it and possibly exiting or setting a different error code to avoid
false negatives.

cd "${root_folder}"
echo
}

function generate_base_repo() {
Expand All @@ -70,7 +82,10 @@ function generate_base_repo() {
cd ..
}

echo "Running testcases; You can find run details for each test in <test>/run.log"
echo "Running testcases; You can find run details for each test in:"
echo " - <test>/run.log(unknown)"
echo " - <test>/ok.log(all good)"
echo " - <test>/nok.log(failed tests)"
echo

export test="1"
Expand Down Expand Up @@ -197,3 +212,30 @@ testcase_header
git artifact fetch-tags --sha1 "$sha1"
} > ${test}/run.log 2>&1 || cat ../${test}/run.log
eval_testcase

echo
echo "########################################"
echo "All tests completed. Checking results..."
echo "########################################"
echo

if [[ ${global_exit_code:-0} -eq 0 ]]; then
echo "All tests passed successfully."
else
echo
echo "Contents of failed test logs:"
echo "-----------------------------"
for log in $( find . -name run.log -o -name nok.log | sort ); do
echo
echo "--- $log start ------------------------"
cat $log
echo "--- $log end ------------------------"
echo
done
echo
echo "Some tests failed. - List of logs:"
find . -name run.log -o -name nok.log | sort
echo
fi
# Exit with the global exit code
exit $global_exit_code
5 changes: 4 additions & 1 deletion git-artifact
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,10 @@ cmd_fetch-tags() {
}

main () {
[[ ${debug:-} == true ]] && set -x
[[ ${debug:-} == true ]] && {
echo "debug: ${debug}"
set -x
}
if [[ $# -eq 0 ]] ; then
set -- -h
fi
Expand Down