Skip to content

Commit

Permalink
Merge branch 'js/ci-github-workflow-markup' into seen
Browse files Browse the repository at this point in the history
Update the GitHub workflow support to make it quicker to get to the
failing test.
source: <pull.1117.git.1643050574.gitgitgadget@gmail.com>

* js/ci-github-workflow-markup:
  ci: call `finalize_test_case_output` a little later
  ci: use `--github-workflow-markup` in the GitHub workflow
  ci: optionally mark up output in the GitHub workflow
  test(junit): avoid line feeds in XML attributes
  tests: refactor --write-junit-xml code
  ci/run-build-and-tests: add some structure to the GitHub workflow output
  ci: make it easier to find failed tests' logs in the GitHub workflow
  ci/run-build-and-tests: take a more high-level view
  ci: fix code style
  • Loading branch information
gitster committed Feb 28, 2022
2 parents 7f4ea4e + 054ce81 commit e26e6d5
Show file tree
Hide file tree
Showing 8 changed files with 287 additions and 136 deletions.
12 changes: 0 additions & 12 deletions .github/workflows/main.yml
Expand Up @@ -119,10 +119,6 @@ jobs:
- name: test
shell: bash
run: . /etc/profile && ci/run-test-slice.sh ${{matrix.nr}} 10
- name: ci/print-test-failures.sh
if: failure()
shell: bash
run: ci/print-test-failures.sh
- name: Upload failed tests' directories
if: failure() && env.FAILED_TEST_ARTIFACTS != ''
uses: actions/upload-artifact@v2
Expand Down Expand Up @@ -204,10 +200,6 @@ jobs:
env:
NO_SVN_TESTS: 1
run: . /etc/profile && ci/run-test-slice.sh ${{matrix.nr}} 10
- name: ci/print-test-failures.sh
if: failure()
shell: bash
run: ci/print-test-failures.sh
- name: Upload failed tests' directories
if: failure() && env.FAILED_TEST_ARTIFACTS != ''
uses: actions/upload-artifact@v2
Expand Down Expand Up @@ -261,8 +253,6 @@ jobs:
- uses: actions/checkout@v2
- run: ci/install-dependencies.sh
- run: ci/run-build-and-tests.sh
- run: ci/print-test-failures.sh
if: failure()
- name: Upload failed tests' directories
if: failure() && env.FAILED_TEST_ARTIFACTS != ''
uses: actions/upload-artifact@v2
Expand Down Expand Up @@ -292,8 +282,6 @@ jobs:
- uses: actions/checkout@v1
- run: ci/install-docker-dependencies.sh
- run: ci/run-build-and-tests.sh
- run: ci/print-test-failures.sh
if: failure()
- name: Upload failed tests' directories
if: failure() && env.FAILED_TEST_ARTIFACTS != ''
uses: actions/upload-artifact@v1
Expand Down
81 changes: 72 additions & 9 deletions ci/lib.sh
@@ -1,5 +1,49 @@
# Library of functions shared by all CI scripts

if test true != "$GITHUB_ACTIONS"
then
begin_group () { :; }
end_group () { :; }

group () {
shift
"$@"
}
set -x
else
begin_group () {
need_to_end_group=t
echo "::group::$1" >&2
set -x
}

end_group () {
test -n "$need_to_end_group" || return 0
set +x
need_to_end_group=
echo '::endgroup::' >&2
}
trap end_group EXIT

group () {
set +x
begin_group "$1"
shift
"$@"
res=$?
end_group
return $res
}

begin_group "CI setup"
fi

# Set 'exit on error' for all CI scripts to let the caller know that
# something went wrong.
# Set tracing executed commands, primarily setting environment variables
# and installing dependencies.
set -e

skip_branch_tip_with_tag () {
# Sometimes, a branch is pushed at the same time the tag that points
# at the same commit as the tip of the branch is pushed, and building
Expand Down Expand Up @@ -69,8 +113,7 @@ skip_good_tree () {
exit 0
}

check_unignored_build_artifacts ()
{
check_unignored_build_artifacts () {
! git ls-files --other --exclude-standard --error-unmatch \
-- ':/*' 2>/dev/null ||
{
Expand All @@ -79,18 +122,16 @@ check_unignored_build_artifacts ()
}
}

handle_failed_tests () {
return 1
}

# GitHub Action doesn't set TERM, which is required by tput
export TERM=${TERM:-dumb}

# Clear MAKEFLAGS that may come from the outside world.
export MAKEFLAGS=

# Set 'exit on error' for all CI scripts to let the caller know that
# something went wrong.
# Set tracing executed commands, primarily setting environment variables
# and installing dependencies.
set -ex

if test -n "$SYSTEM_COLLECTIONURI" || test -n "$SYSTEM_TASKDEFINITIONSURI"
then
CI_TYPE=azure-pipelines
Expand Down Expand Up @@ -124,11 +165,30 @@ then
CI_JOB_ID="$GITHUB_RUN_ID"
CC="${CC:-gcc}"
DONT_SKIP_TAGS=t
handle_failed_tests () {
mkdir -p t/failed-test-artifacts
echo "FAILED_TEST_ARTIFACTS=t/failed-test-artifacts" >>$GITHUB_ENV

for test_exit in t/test-results/*.exit
do
test 0 != "$(cat "$test_exit")" || continue

test_name="${test_exit%.exit}"
test_name="${test_name##*/}"
printf "\\e[33m\\e[1m=== Failed test: ${test_name} ===\\e[m\\n"
cat "t/test-results/$test_name.markup"

trash_dir="t/trash directory.$test_name"
cp "t/test-results/$test_name.out" t/failed-test-artifacts/
tar czf t/failed-test-artifacts/"$test_name".trash.tar.gz "$trash_dir"
done
return 1
}

cache_dir="$HOME/none"

export GIT_PROVE_OPTS="--timer --jobs 10"
export GIT_TEST_OPTS="--verbose-log -x"
export GIT_TEST_OPTS="--verbose-log -x --github-workflow-markup"
MAKEFLAGS="$MAKEFLAGS --jobs=10"
test windows != "$CI_OS_NAME" ||
GIT_TEST_OPTS="--no-chain-lint --no-bin-wrappers $GIT_TEST_OPTS"
Expand Down Expand Up @@ -211,3 +271,6 @@ linux-leaks)
esac

MAKEFLAGS="$MAKEFLAGS CC=${CC:-cc}"

end_group
set -x
11 changes: 8 additions & 3 deletions ci/run-build-and-tests.sh
Expand Up @@ -10,7 +10,7 @@ windows*) cmd //c mklink //j t\\.prove "$(cygpath -aw "$cache_dir/.prove")";;
*) ln -s "$cache_dir/.prove" t/.prove;;
esac

export MAKE_TARGETS="all test"
run_tests=t

case "$jobname" in
linux-gcc)
Expand Down Expand Up @@ -41,14 +41,19 @@ pedantic)
# Don't run the tests; we only care about whether Git can be
# built.
export DEVOPTS=pedantic
export MAKE_TARGETS=all
run_tests=
;;
esac

# Any new "test" targets should not go after this "make", but should
# adjust $MAKE_TARGETS. Otherwise compilation-only targets above will
# start running tests.
make $MAKE_TARGETS
group Build make
if test -n "$run_tests"
then
group "Run tests" make test ||
handle_failed_tests
fi
check_unignored_build_artifacts

save_good_tree
5 changes: 3 additions & 2 deletions ci/run-test-slice.sh
Expand Up @@ -10,8 +10,9 @@ windows*) cmd //c mklink //j t\\.prove "$(cygpath -aw "$cache_dir/.prove")";;
*) ln -s "$cache_dir/.prove" t/.prove;;
esac

make --quiet -C t T="$(cd t &&
group "Run tests" make --quiet -C t T="$(cd t &&
./helper/test-tool path-utils slice-tests "$1" "$2" t[0-9]*.sh |
tr '\n' ' ')"
tr '\n' ' ')" ||
handle_failed_tests

check_unignored_build_artifacts
4 changes: 2 additions & 2 deletions t/test-lib-functions.sh
Expand Up @@ -719,7 +719,7 @@ test_verify_prereq () {
}

test_expect_failure () {
test_start_
test_start_ "$@"
test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
test "$#" = 2 ||
BUG "not 2 or 3 parameters to test-expect-failure"
Expand All @@ -739,7 +739,7 @@ test_expect_failure () {
}

test_expect_success () {
test_start_
test_start_ "$@"
test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
test "$#" = 2 ||
BUG "not 2 or 3 parameters to test-expect-success"
Expand Down
50 changes: 50 additions & 0 deletions t/test-lib-github-workflow-markup.sh
@@ -0,0 +1,50 @@
# Library of functions to mark up test scripts' output suitable for
# pretty-printing it in GitHub workflows.
#
# Copyright (c) 2022 Johannes Schindelin
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/ .
#
# The idea is for `test-lib.sh` to source this file when run in GitHub
# workflows; these functions will then override (empty) functions
# that are are called at the appropriate times during the test runs.

start_test_output () {
test -n "$GIT_TEST_TEE_OUTPUT_FILE" ||
die "--github-workflow-markup requires --verbose-log"
github_markup_output="${GIT_TEST_TEE_OUTPUT_FILE%.out}.markup"
>$github_markup_output
GIT_TEST_TEE_OFFSET=0
}

# No need to override start_test_case_output

finalize_test_case_output () {
test_case_result=$1
shift
case "$test_case_result" in
failure)
echo >>$github_markup_output "::error::failed: $this_test.$test_count $1"
;;
fixed)
echo >>$github_markup_output "::notice::fixed: $this_test.$test_count $1"
;;
esac
echo >>$github_markup_output "::group::$test_case_result: $this_test.$test_count $*"
test-tool >>$github_markup_output path-utils skip-n-bytes \
"$GIT_TEST_TEE_OUTPUT_FILE" $GIT_TEST_TEE_OFFSET
echo >>$github_markup_output "::endgroup::"
}

# No need to override finalize_test_output

0 comments on commit e26e6d5

Please sign in to comment.