name: "[CI] Build and unit testing" on: workflow_dispatch: inputs: Distro: description: 'Select runner image for testing' required: true default: 'ubuntu-24.04' type: choice options: - 'ubuntu-24.04' - 'macos-26' - 'macos-15' - 'windows-2025' - 'windows-2022' Update: description: 'Update dependencies in modules' default: false type: boolean Test: description: 'Go unit testing' default: false type: boolean Release: description: 'Check pre-release (flags and tmux)' default: false type: boolean Binary: description: 'Build binary and deb packages' default: false type: boolean README: description: 'Update version in README' default: false type: boolean run-name: "CI #${{ github.run_number }} on ${{ github.event.inputs.Distro }}" permissions: contents: write jobs: test: name: Testing on ${{ github.event.inputs.Distro }} runs-on: ${{ github.event.inputs.Distro }} env: APP_VERSION: 'n/a' LAST_COMMIT: 'n/a' COVERAGE: 'n/a' steps: - name: Checkout repository (main branch and last commits) uses: actions/checkout@v7 with: fetch-depth: 1 ref: main - name: Install Go uses: actions/setup-go@v7 with: go-version: 1.25 - name: Code verify and check build run: | go vet ./... go build -v -o /dev/null ./... - name: Get build information shell: bash run: | DATETIME=$(date +"%d.%m.%Y %H:%M") GO_VERSION=$(go version | awk '{print $3,"("$4")"}' | sed -e "s/go//g") APP_VERSION=$(go run main.go -v) echo "APP_VERSION=$APP_VERSION" >> $GITHUB_ENV LAST_COMMIT=$(git rev-parse --short HEAD) echo "LAST_COMMIT=$LAST_COMMIT" >> $GITHUB_ENV echo "## ๐Ÿš€ Build Information" > build-info.md echo "- **Date**: $DATETIME" >> build-info.md echo "- **Build number**: #${{ github.run_number }}" >> build-info.md echo "- **Go version**: $GO_VERSION" >> build-info.md echo "- **App version**: $APP_VERSION" >> build-info.md echo "- **Last commit**: [$LAST_COMMIT](${{ github.server_url }}/${{ github.repository }}/commit/$LAST_COMMIT)" >> build-info.md echo "### Parameters" >> build-info.md echo "- **OS**: ${{ github.event.inputs.Distro }}" >> build-info.md echo "- **Update dependencies in modules**: ${{ github.event.inputs.Update == 'true' && 'โœ…' || 'โŒ' }}" >> build-info.md echo "- **Go unit testing**: ${{ github.event.inputs.Test == 'true' && 'โœ…' || 'โŒ' }}" >> build-info.md echo "- **Check pre-release (flags and tmux)**: ${{ github.event.inputs.Release == 'true' && 'โœ…' || 'โŒ' }}" >> build-info.md echo "- **Build binary and deb packages**: ${{ github.event.inputs.Binary == 'true' && 'โœ…' || 'โŒ' }}" >> build-info.md echo "- **Update version in README**: ${{ github.event.inputs.README == 'true' && 'โœ…' || 'โŒ' }}" >> build-info.md - name: Update dependencies in modules if: ${{ github.event.inputs.Update == 'true' }} run: go get -u ./... # Unit testing in Linux - name: Start docker containers using compose if: ${{ (github.event.inputs.Release == 'true' || github.event.inputs.Test == 'true') && github.event.inputs.Distro == 'ubuntu-24.04' }} run: | version=$(curl -s https://api.github.com/repos/docker/compose/releases/latest | jq -r .tag_name) curl -sSL "https://github.com/docker/compose/releases/download/$version/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose mkdir -p $HOME/.docker/cli-plugins cp /usr/local/bin/docker-compose $HOME/.docker/cli-plugins/docker-compose docker compose version cd docker/debian sed "s/TTYD=false/TTYD=true/" docker-compose.yml -i docker compose up -d docker run -d --name pinguem -p 8085:8085 -p 3005:3005 lifailon/pinguem:latest - name: Create pcap files for Linux if: ${{ github.event.inputs.Test == 'true' && github.event.inputs.Distro == 'ubuntu-24.04' }} run: | sudo tcpdump -i any -c 1 -w test.pcap gzip -c test.pcap > test.pcap.gz sudo tcpdump -i any -c 1 -w test.pcapng gzip -c test.pcapng > test.pcapng.gz ls -lh - name: Install auditd and create rules if: ${{ github.event.inputs.Test == 'true' && github.event.inputs.Distro == 'ubuntu-24.04' }} run: | sudo apt install -y auditd sudo auditctl -w /etc/ssh/ -p rwxa -k ssh sudo auditctl -w /etc/passwd -p wa -k passwd sudo auditctl -l - name: Install bat and tailspin if: ${{ github.event.inputs.Test == 'true' && github.event.inputs.Distro == 'ubuntu-24.04' }} run: | sudo apt install -y bat bat --version || batcat --version || true # sudo apt install -y tailspin version=$(curl -s https://api.github.com/repos/bensadeh/tailspin/releases/latest | jq -r .tag_name) curl -L "https://github.com/bensadeh/tailspin/releases/download/$version/tailspin-$(uname -m)-unknown-$(uname -s | tr '[:upper:]' '[:lower:]')-musl.tar.gz" -o /usr/local/bin/tailspin.tar.gz tar -xzf /usr/local/bin/tailspin.tar.gz -C /usr/local/bin mv /usr/local/bin/tspin /usr/local/bin/tailspin chmod +x /usr/local/bin/tailspin rm /usr/local/bin/*.tar.gz tailspin --version - name: Install gotestsum for junit report if: ${{ github.event.inputs.Test == 'true' }} run: go install gotest.tools/gotestsum@latest - name: Unit testing in Linux (all functions and mock interface) if: ${{ github.event.inputs.Test == 'true' && github.event.inputs.Distro == 'ubuntu-24.04' }} id: unitTestLinux continue-on-error: true timeout-minutes: 10 run: sudo env "PATH=$PATH" gotestsum --format standard-verbose --junitfile report.xml -- ./... -v -cover | tee test.log # Unit testing for Docker without root - name: Unit testing for docker without root in Linux if: ${{ github.event.inputs.Test == 'true' && github.event.inputs.Distro == 'ubuntu-24.04' }} continue-on-error: true timeout-minutes: 5 run: env "PATH=$PATH" go test -v -cover --run "TestDockerContainer" - name: Check cli mode (color and filter) for container logs if: ${{ github.event.inputs.Test == 'true' && github.event.inputs.Distro == 'ubuntu-24.04' }} continue-on-error: true run: | echo "=== Check color ===" docker logs lazyjournal | go run main.go -c echo "=== Check fuzzy search ===" docker logs lazyjournal | go run main.go -f "start" echo "=== Check fuzzy search and color ===" docker logs lazyjournal | go run main.go -r "start|close" echo "=== Check regex search ===" docker logs lazyjournal | go run main.go -c -f "start" echo "=== Check regex search and color ===" docker logs lazyjournal | go run main.go -c -r "start|close" # Unit testing in macOS - name: Unit testing in macOS (files, flags, cli and run main interface) if: ${{ github.event.inputs.Test == 'true' && (github.event.inputs.Distro == 'macos-15' || github.event.inputs.Distro == 'macos-26') }} timeout-minutes: 5 continue-on-error: true shell: bash run: | env "PATH=$PATH" gotestsum --format standard-verbose --junitfile report.xml -- ./... -v -cover \ --run "TestUnixFiles|TestFlags|TestCommandColor|TestCommandFuzzyFilter|TestCommandRegexFilter|TestMainInterface" | tee test.log # Unit testing in Windows - name: Create log file for Windows if: ${{ github.event.inputs.Test == 'true' && (github.event.inputs.Distro == 'windows-2022' || github.event.inputs.Distro == 'windows-2025') }} continue-on-error: true shell: pwsh run: | New-Item -Path "$env:APPDATA\test" -Type Directory "line test" | Out-File -FilePath "$env:APPDATA\test\test.log" - name: Unit testing in Windows (events, files, flags, cli, main and mock interface) if: ${{ github.event.inputs.Test == 'true' && (github.event.inputs.Distro == 'windows-2022' || github.event.inputs.Distro == 'windows-2025') }} timeout-minutes: 5 continue-on-error: true shell: bash run: | env "PATH=$PATH" gotestsum --format standard-verbose --junitfile report.xml -- ./... -v -cover \ --run "TestWin.*|TestFlags|TestCommandColor|TestCommandFuzzyFilter|TestCommandRegexFilter|TestMainInterface|TestMockInterface" | tee test.log # Build info report - name: Send build info report to summary continue-on-error: true shell: bash run: | cat build-info.md >> $GITHUB_STEP_SUMMARY # Coverage report - name: Get coverage result if: ${{ github.event.inputs.Test == 'true' }} continue-on-error: true shell: bash run: | COVERAGE=$(cat test.log | grep -E "^coverage: " | sed "s/coverage: //" | sed -E "s/ of.+//") echo "COVERAGE=$COVERAGE" >> $GITHUB_ENV echo "---" >> $GITHUB_STEP_SUMMARY echo "## ๐Ÿงช Test report" >> $GITHUB_STEP_SUMMARY echo "๐Ÿ’ก **Coverage**: $COVERAGE" >> $GITHUB_STEP_SUMMARY # Junit report - name: Publish junit report in summary uses: test-summary/action@v2 if: ${{ github.event.inputs.Test == 'true' }} with: paths: "report.xml" - name: Publish junit report in annotations uses: mikepenz/action-junit-report@v6 if: ${{ github.event.inputs.Test == 'true' }} with: report_paths: "report.xml" # Markdown report - name: Send markdown report to summary for Linux or macOS if: ${{ github.event.inputs.Test == 'true' && github.event.inputs.Distro != 'windows-2022' && github.event.inputs.Distro != 'windows-2025' }} continue-on-error: true shell: bash run: cat test-report.md >> $GITHUB_STEP_SUMMARY - name: Send markdown report to summary for Windows if: ${{ github.event.inputs.Test == 'true' && (github.event.inputs.Distro == 'windows-2022' || github.event.inputs.Distro == 'windows-2025') }} continue-on-error: true shell: pwsh run: Get-Content test-report.md | Out-File -Append -FilePath $env:GITHUB_STEP_SUMMARY # Check pre-release (flags and tmux) - name: Install binary from last commit on GitHub if: ${{ github.event.inputs.Release == 'true' }} run: | LAST_COMMIT_HASH=$(git ls-remote https://github.com/lifailon/lazyjournal HEAD | awk '{print $1}') go install github.com/Lifailon/lazyjournal@$LAST_COMMIT_HASH - name: Check flags (cli mode) if: ${{ github.event.inputs.Release == 'true' }} run: | green="\n\033[32m" uncolor="\033[0m" echo -e "$green Version: $uncolor $(lazyjournal -v)" echo -e "$green Help: $uncolor" lazyjournal -h echo -e "$green Config: $uncolor" lazyjournal -g echo -e "$green Audit: $uncolor" lazyjournal -a echo -e "$green Coloring: $uncolor" curl -s https://raw.githubusercontent.com/Lifailon/lazyjournal/refs/heads/main/color.log | lazyjournal -c echo -e "$green Filtering in fuzzy mode: $uncolor" curl -s https://raw.githubusercontent.com/Lifailon/lazyjournal/refs/heads/main/color.log | lazyjournal -f "error" echo -e "$green Filtering in fuzzy mode with output coloring: $uncolor" curl -s https://raw.githubusercontent.com/Lifailon/lazyjournal/refs/heads/main/color.log | lazyjournal -f "error" -c echo -e "$green Filtering in regex mode: $uncolor" curl -s https://raw.githubusercontent.com/Lifailon/lazyjournal/refs/heads/main/color.log | lazyjournal -r "error|fatal|fail|crash" echo -e "$green Filtering in regex mode with output coloring: $uncolor" curl -s https://raw.githubusercontent.com/Lifailon/lazyjournal/refs/heads/main/color.log | lazyjournal -r "error|fatal|fail|crash" -c - name: Check interface in TMUX if: ${{ github.event.inputs.Release == 'true' }} run: | green="\n\033[32m" uncolor="\033[0m" tmux new-session -d -s test-session "lazyjournal -l" sleep 1 tmux capture-pane -p tmux send-keys -t test-session "$(echo -e 'cron')" tmux send-keys -t test-session "$(echo -e '\t')" # Tab tmux send-keys -t test-session "$(echo -e '\r')" # Enter sleep 3 echo -e "$green Cron.service logs: $uncolor" tmux capture-pane -p tmux send-keys -t test-session "$(echo -e '\t\t\t\t\t')" for i in {1..4}; do tmux send-keys -t test-session "$(echo -e '\x7f')"; done tmux send-keys -t test-session "$(echo -e 'lazy')" tmux send-keys -t test-session "$(echo -e '\t\t\t')" # Tab x3 tmux send-keys -t test-session "$(echo -e '\x1b[C')" # Right sleep 1 tmux send-keys -t test-session "$(echo -e '\x1b[D')" # Left sleep 1 tmux send-keys -t test-session "$(echo -e '\r')" # Enter sleep 3 echo -e "$green Container logs: $uncolor" tmux capture-pane -p tmux send-keys -t test-session "$(echo -e '\t')" # Tab tmux send-keys -t test-session "$(echo -e '\x1b[A')" # Up tmux send-keys -t test-session "$(echo -e '\x1b[B')" # Down tmux send-keys -t test-session "$(echo -e '\x1b[B')" # Down tmux send-keys -t test-session "$(echo -e '\x1b[B')" # Down tmux send-keys -t test-session "$(echo -e 'tty|port')" sleep 3 echo -e "$green Filter logs using regex: $uncolor" tmux capture-pane -p tmux kill-session -t test-session echo -e "$green Log: $uncolor" cat lazyjournal.log # Telegram report - name: Send report to Telegram only on Linux uses: appleboy/telegram-action@master if: ${{ github.event.inputs.Distro == 'ubuntu-24.04' }} with: token: ${{ secrets.TELEGRAM_API_TOKEN }} to: ${{ secrets.TELEGRAM_CHANNEL_ID }} debug: true format: markdown message: | ๐Ÿ”” **Action**: CI (build and unit testing) ๐Ÿ“ **Repository**: ${{ github.repository }} ๐Ÿ‘ค **User**: ${{ github.actor }} ๐Ÿ”— **Build**: [#${{ github.run_number }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) โญ๏ธ **Version**: ${{ env.APP_VERSION }} ๐Ÿ’ฌ **Last commit**: [${{ env.LAST_COMMIT }}](${{ github.server_url }}/${{ github.repository }}/commit/${{ env.LAST_COMMIT }}) Parameters: **OS**: ${{ github.event.inputs.Distro }} **Update dependencies in modules**: ${{ github.event.inputs.Update == 'true' && 'โœ…' || 'โŒ' }} **Go unit testing**: ${{ github.event.inputs.Test == 'true' && 'โœ…' || 'โŒ' }} **Check flags and release in tmux**: ${{ github.event.inputs.Release == 'true' && 'โœ…' || 'โŒ' }} **Build binary and deb packages**: ${{ github.event.inputs.Binary == 'true' && 'โœ…' || 'โŒ' }} **Update version in README**: ${{ github.event.inputs.README == 'true' && 'โœ…' || 'โŒ' }} ๐Ÿš€ Result unit testing: ${{ steps.unitTestLinux.outcome }} ๐Ÿงช Result unit coverage: ${{ env.COVERAGE || 'n/a' }} build: runs-on: ubuntu-latest name: Build on ubuntu-latest if: ${{ github.event.inputs.Binary == 'true' || github.event.inputs.README == 'true' }} env: VERSION: 'latest' steps: - name: Checkout repository (main branch and last commits) uses: actions/checkout@v7 with: fetch-depth: 1 ref: main - name: Install Go uses: actions/setup-go@v7 with: go-version: 1.25 - name: Code verify and check build run: | go vet ./... go build -v -o /dev/null ./... - name: Get app version for build run: | version=$(go run main.go -v) echo "VERSION=$version" >> $GITHUB_ENV # Build binary and deb package - name: Build binaries run: | mkdir -p bin architectures=("amd64" "arm64") oss=("linux" "darwin" "openbsd" "freebsd" "windows") for arch in "${architectures[@]}"; do for os in "${oss[@]}"; do binName="bin/lazyjournal-$VERSION-$os-$arch" if [[ "$os" == "windows" ]]; then binName="$binName.exe" fi CGO_ENABLED=0 GOOS=$os GOARCH=$arch go build -o "$binName" done done ls -lh bin echo "ARTIFACT_NAME=lazyjournal-$VERSION" >> $GITHUB_ENV - name: Build deb package run: | rm -f lazyjournal mkdir -p lazyjournal/DEBIAN lazyjournal/usr/local/bin architectures=("amd64" "arm64") for arch in "${architectures[@]}"; do rm -f lazyjournal/usr/local/bin/lazyjournal cp bin/lazyjournal-$VERSION-linux-$arch lazyjournal/usr/local/bin/lazyjournal rm -f lazyjournal/DEBIAN/control echo "Package: lazyjournal" > lazyjournal/DEBIAN/control echo "Version: $VERSION" >> lazyjournal/DEBIAN/control echo "Architecture: $arch" >> lazyjournal/DEBIAN/control echo "Maintainer: https://github.com/Lifailon" >> lazyjournal/DEBIAN/control echo "Description: TUI for viewing logs from journald, auditd, file system, Docker and Podman containers, Compose stacks and Kubernetes pods." >> lazyjournal/DEBIAN/control dpkg-deb --build lazyjournal lazyjournal-$VERSION-$arch.deb dpkg-deb --contents lazyjournal-$VERSION-$arch.deb mv lazyjournal-$VERSION-$arch.deb bin/lazyjournal-$VERSION-$arch.deb done ls -lh bin/*.deb - name: Check install deb package run: | # sudo dpkg -i bin/lazyjournal-$VERSION-amd64.deb # sudo dpkg -r lazyjournal sudo apt install -y ./bin/lazyjournal-$VERSION-amd64.deb lazyjournal -v sudo apt remove -y lazyjournal - name: Upload binaries if: ${{ github.event.inputs.Binary == 'true' }} uses: actions/upload-artifact@v7 with: name: ${{ env.ARTIFACT_NAME }} path: bin/ env: ARTIFACT_NAME: ${{ env.ARTIFACT_NAME }} - name: Update version to README for install deb package if: ${{ github.event.inputs.README == 'true' && env.VERSION != '' }} run: | sed -i -E "s|releases/download/[0-9.]+/lazyjournal-[0-9.]+-|releases/download/$VERSION/lazyjournal-$VERSION-|" README.md git config --global user.name 'GitHub Actions' git config --global user.email 'actions@github.com' git add README.md git commit -m "update version on $VERSION for install deb package" git push origin main