Skip to content

Commit

Permalink
Upload Test Logs in CI
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Nola <[email protected]>
  • Loading branch information
dereknola committed Aug 29, 2024
1 parent c327e1e commit df802c8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ jobs:
- name: Test
run: |
dapper -f Dockerfile --target dapper make test
- name: Upload Logs on Failure
if: ${{ failure() }}
uses: actions/upload-artifact@v4
with:
name: rke2-test-logs
path: /tmp/rke2-logs/
build-arm64:
runs-on: runs-on,runner=8cpu-linux-arm64,run-id=${{ github.run_id }},image=ubuntu22-full-arm64,hdd=64
steps:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ RUN zypper install -y systemd-rpm-macros

# Dapper/Drone/CI environment
FROM build AS dapper
ENV DAPPER_ENV GODEBUG GOCOVER REPO TAG GITHUB_ACTION_TAG PAT_USERNAME PAT_TOKEN KUBERNETES_VERSION DOCKER_BUILDKIT DRONE_BUILD_EVENT IMAGE_NAME AWS_SECRET_ACCESS_KEY AWS_ACCESS_KEY_ID ENABLE_REGISTRY DOCKER_USERNAME DOCKER_PASSWORD GH_TOKEN
ENV DAPPER_ENV GODEBUG CI GOCOVER REPO TAG GITHUB_ACTION_TAG PAT_USERNAME PAT_TOKEN KUBERNETES_VERSION DOCKER_BUILDKIT DRONE_BUILD_EVENT IMAGE_NAME AWS_SECRET_ACCESS_KEY AWS_ACCESS_KEY_ID ENABLE_REGISTRY DOCKER_USERNAME DOCKER_PASSWORD GH_TOKEN
ARG DAPPER_HOST_ARCH
ENV ARCH $DAPPER_HOST_ARCH
ENV DAPPER_OUTPUT ./dist ./bin ./build
Expand Down
19 changes: 18 additions & 1 deletion scripts/test-helpers
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ export -f verify-valid-versions
# ---

dump-logs() {
# Reduce verbosity in GitHub Actions
if [ "$CI" = "true" ]; then
set +x
fi
local testID=$(basename $TEST_DIR)
echo "#---------------------------------"
echo "#- Begin: logs for run ($testID)"
Expand All @@ -141,6 +145,13 @@ dump-logs() {
docker exec $name crictl pods >$node/logs/crictl-pods.txt
docker exec $name crictl ps -a >$node/logs/crictl-ps.txt
fi
done
# In GitHub Actions, don't dump logs to the console, as they will be uploaded as artifacts
if [ "$CI" = "true" ]; then
set -x
return
fi
for node in $TEST_DIR/*/*; do
for log in $node/logs/*.log; do
echo
echo "#- Tail: $log"
Expand Down Expand Up @@ -279,7 +290,13 @@ export -f test-cleanup
# ---

test-setup() {
export TEST_DIR=$(mktemp -d '/tmp/XXXXXX')
# If running in Github Actions, use a known directory, so we can upload logs external to this script
if [ "$CI" = 'true' ]; then
mkdir -p /tmp/rke2-logs
export TEST_DIR=$(mktemp -d '/tmp/rke2-logs/XXXXXX')
else
export TEST_DIR=$(mktemp -d '/tmp/XXXXXX')
fi
trap test-cleanup EXIT INT TERM

mkdir -p $TEST_DIR/metadata
Expand Down

0 comments on commit df802c8

Please sign in to comment.