diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index 46ce7a2ca813..e0ee6c0a2e4d 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -80,6 +80,13 @@ jobs: chmod +x ./dist/artifacts/k3s cd tests/e2e/${{ matrix.etest }} go test -v -timeout=45m ./${{ matrix.etest}}_test.go -ci -local + - name: On Failure, Upload Journald Logs + uses: actions/upload-artifact@v4 + if: ${{ failure() }} + with: + name: ${{ matrix.etest}}-journald-logs + path: tests/e2e/${{ matrix.etest }}/*-jlog.txt + retention-days: 30 - name: On Failure, Launch Debug Session uses: lhotari/action-upterm@v1 if: ${{ failure() }} @@ -155,6 +162,9 @@ jobs: BRANCH_NAME=$(echo ${{ github.base_ref || github.ref_name }}) elif [ -z "${{ github.base_ref }}" ]; then # We are in a fork, and need some git history to determine the branch name + # For some reason, the first fetch doesn't always get the full history, so we sleep and fetch again + git fetch origin --depth=100 +refs/heads/*:refs/remotes/origin/* + sleep 5 git fetch origin --depth=100 +refs/heads/*:refs/remotes/origin/* BRANCH_NAME=$(git show-branch -a 2> /dev/null | grep '\*' | grep -v `git rev-parse --abbrev-ref HEAD` | head -n1 | sed 's/.*\[\(.*\/\)\(.*\)\].*/\2/' | sed 's/[\^~].*//') else @@ -162,7 +172,15 @@ jobs: fi echo "Branch Name is $BRANCH_NAME" echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_OUTPUT - + # branch name should be either master or release-1.XX + - name: Fail if branch name does not match pattern + run: | + if [[ ! ${{ steps.branch_step.outputs.branch_name }} =~ ^(master|release-[0-9]+\.[0-9]+)$ ]]; then + echo "Branch name ${{ steps.branch_step.outputs.branch_name }} does not match pattern" + echo "If this is a PR/fork, ensure you have recently rebased off master/release-1.XX branch" + exit 1 + fi + docker-go: needs: [build, build-go-tests] name: Docker Tests In GO diff --git a/tests/e2e/btrfs/btrfs_test.go b/tests/e2e/btrfs/btrfs_test.go index a592a2e78823..a99211a1634c 100644 --- a/tests/e2e/btrfs/btrfs_test.go +++ b/tests/e2e/btrfs/btrfs_test.go @@ -90,6 +90,9 @@ var _ = AfterEach(func() { }) var _ = AfterSuite(func() { + if failed { + Expect(e2e.SaveJournalLogs(serverNodeNames)).To(Succeed()) + } if !failed || *ci { Expect(e2e.DestroyCluster()).To(Succeed()) Expect(os.Remove(kubeConfigFile)).To(Succeed()) diff --git a/tests/e2e/embeddedmirror/embeddedmirror_test.go b/tests/e2e/embeddedmirror/embeddedmirror_test.go index 089fb465277b..d753528bf616 100644 --- a/tests/e2e/embeddedmirror/embeddedmirror_test.go +++ b/tests/e2e/embeddedmirror/embeddedmirror_test.go @@ -147,7 +147,7 @@ var _ = AfterEach(func() { var _ = AfterSuite(func() { if failed { - AddReportEntry("journald-logs", e2e.TailJournalLogs(1000, append(serverNodeNames, agentNodeNames...))) + Expect(e2e.SaveJournalLogs(append(serverNodeNames, agentNodeNames...))).To(Succeed()) } else { Expect(e2e.GetCoverageReport(append(serverNodeNames, agentNodeNames...))).To(Succeed()) } diff --git a/tests/e2e/externalip/externalip_test.go b/tests/e2e/externalip/externalip_test.go index 9d2150991924..f8acbc9bce41 100644 --- a/tests/e2e/externalip/externalip_test.go +++ b/tests/e2e/externalip/externalip_test.go @@ -166,7 +166,7 @@ var _ = AfterEach(func() { var _ = AfterSuite(func() { if failed { - AddReportEntry("journald-logs", e2e.TailJournalLogs(1000, append(serverNodeNames, agentNodeNames...))) + Expect(e2e.SaveJournalLogs(append(serverNodeNames, agentNodeNames...))).To(Succeed()) } else { Expect(e2e.GetCoverageReport(append(serverNodeNames, agentNodeNames...))).To(Succeed()) } diff --git a/tests/e2e/privateregistry/privateregistry_test.go b/tests/e2e/privateregistry/privateregistry_test.go index fe25a94e2181..e7ab9187f870 100644 --- a/tests/e2e/privateregistry/privateregistry_test.go +++ b/tests/e2e/privateregistry/privateregistry_test.go @@ -150,7 +150,7 @@ var _ = AfterEach(func() { var _ = AfterSuite(func() { if failed { - AddReportEntry("journald-logs", e2e.TailJournalLogs(1000, append(serverNodeNames, agentNodeNames...))) + Expect(e2e.SaveJournalLogs(append(serverNodeNames, agentNodeNames...))).To(Succeed()) } else { Expect(e2e.GetCoverageReport(append(serverNodeNames, agentNodeNames...))).To(Succeed()) } diff --git a/tests/e2e/s3/s3_test.go b/tests/e2e/s3/s3_test.go index 29c9d43cad0d..64066cf45572 100644 --- a/tests/e2e/s3/s3_test.go +++ b/tests/e2e/s3/s3_test.go @@ -178,7 +178,7 @@ var _ = AfterEach(func() { var _ = AfterSuite(func() { if failed { - AddReportEntry("journald-logs", e2e.TailJournalLogs(1000, append(serverNodeNames, agentNodeNames...))) + Expect(e2e.SaveJournalLogs(append(serverNodeNames, agentNodeNames...))).To(Succeed()) } else { Expect(e2e.GetCoverageReport(append(serverNodeNames, agentNodeNames...))).To(Succeed()) } diff --git a/tests/e2e/startup/startup_test.go b/tests/e2e/startup/startup_test.go index 3c7dd13627ea..f36181fffd27 100644 --- a/tests/e2e/startup/startup_test.go +++ b/tests/e2e/startup/startup_test.go @@ -395,7 +395,7 @@ var _ = AfterEach(func() { var _ = AfterSuite(func() { if failed { AddReportEntry("config", e2e.GetConfig(append(serverNodeNames, agentNodeNames...))) - AddReportEntry("journald-logs", e2e.TailJournalLogs(1000, append(serverNodeNames, agentNodeNames...))) + Expect(e2e.SaveJournalLogs(append(serverNodeNames, agentNodeNames...))).To(Succeed()) } else { Expect(e2e.GetCoverageReport(append(serverNodeNames, agentNodeNames...))).To(Succeed()) } diff --git a/tests/e2e/testutils.go b/tests/e2e/testutils.go index 2d2cb12071b0..c50fb0c398d9 100644 --- a/tests/e2e/testutils.go +++ b/tests/e2e/testutils.go @@ -377,6 +377,26 @@ func TailJournalLogs(lines int, nodes []string) string { return logs.String() } +// SaveJournalLogs saves the journal logs of each node to a -jlog.txt file. +// When used in GHA CI, the logs are uploaded as an artifact on failure. +func SaveJournalLogs(nodeNames []string) error { + for _, node := range nodeNames { + lf, err := os.Create(node + "-jlog.txt") + if err != nil { + return err + } + defer lf.Close() + logs, err := GetJournalLogs(node) + if err != nil { + return err + } + if _, err := lf.Write([]byte(logs)); err != nil { + return fmt.Errorf("failed to write %s node logs: %v", node, err) + } + } + return nil +} + func GetConfig(nodes []string) string { config := &strings.Builder{} for _, node := range nodes { diff --git a/tests/e2e/wasm/wasm_test.go b/tests/e2e/wasm/wasm_test.go index 7fa216088b35..237bc440d613 100644 --- a/tests/e2e/wasm/wasm_test.go +++ b/tests/e2e/wasm/wasm_test.go @@ -136,7 +136,7 @@ var _ = AfterEach(func() { var _ = AfterSuite(func() { if failed { - AddReportEntry("journald-logs", e2e.TailJournalLogs(1000, append(serverNodeNames, agentNodeNames...))) + Expect(e2e.SaveJournalLogs(append(serverNodeNames, agentNodeNames...))).To(Succeed()) } else { Expect(e2e.GetCoverageReport(append(serverNodeNames, agentNodeNames...))).To(Succeed()) }