Skip to content

CI on ubuntu-24.04 [#191] #191

CI on ubuntu-24.04 [#191]

CI on ubuntu-24.04 [#191] #191

Workflow file for this run

name: CI
on:
workflow_dispatch:
inputs:
Distro:
description: 'Select runner image' # https://github.com/actions/runner-images
required: true
default: 'ubuntu-24.04'
type: choice
options:
- 'ubuntu-24.04'
- 'macos-15'
- 'windows-2022'
Update:
description: 'Update dependencies'
default: false
type: boolean
Linter:
description: 'Check linters'
default: false
type: boolean
LinterAll:
description: 'Check all linters'
default: false
type: boolean
Test:
description: 'Unit testing'
default: false
type: boolean
Release:
description: 'Check release'
default: false
type: boolean
Binary:
description: 'Build binary'
default: false
type: boolean
Docker:
description: 'Build image and Push to Docker Hub'
default: false
type: boolean
run-name: CI on ${{ github.event.inputs.Distro }} [#${{ github.run_number }}]
jobs:
test:
runs-on: ${{ github.event.inputs.Distro }}
name: Tests on ${{ github.event.inputs.Distro }}
steps:
- name: Clone main repository
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.25
- name: Install dependencies
run: |
go fmt ./...
go vet ./...
go get ./...
go mod tidy
go mod verify
go build -v ./...
- name: Get build information
run: |
version=$(go run main.go -v)
echo "## 🚀 Build Information" >> $GITHUB_STEP_SUMMARY
echo "- **Build number**: #${{ github.run_number }}" >> $GITHUB_STEP_SUMMARY
echo "- **OS**: ${{ github.event.inputs.Distro }}" >> $GITHUB_STEP_SUMMARY
echo "- **Version**: $version" >> $GITHUB_STEP_SUMMARY
echo "- **Update dependencies**: ${{ github.event.inputs.Update }}" >> $GITHUB_STEP_SUMMARY
echo "- **Check linters**: ${{ github.event.inputs.Linter }}" >> $GITHUB_STEP_SUMMARY
echo "- **Check all linters**: ${{ github.event.inputs.LinterAll }}" >> $GITHUB_STEP_SUMMARY
echo "- **Unit testing**: ${{ github.event.inputs.Test }}" >> $GITHUB_STEP_SUMMARY
echo "- **Check release**: ${{ github.event.inputs.Release }}" >> $GITHUB_STEP_SUMMARY
echo "- **Build binary**: ${{ github.event.inputs.Binary }}" >> $GITHUB_STEP_SUMMARY
echo "- **Build docker image**: ${{ github.event.inputs.Docker }}" >> $GITHUB_STEP_SUMMARY
shell: bash
- name: Update dependencies
if: ${{ github.event.inputs.Update == 'true' }}
run: go get -u ./...
# Linters
- name: Golangci linters check
if: ${{ github.event.inputs.Linter == 'true' }}
run: |
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
golangci-lint run -v ./main.go
- name: Critic linters check
if: ${{ github.event.inputs.Linter == 'true' }}
run: |
go install github.com/go-critic/go-critic/cmd/gocritic@latest
gocritic check -v -enableAll ./main.go
- name: Security linters check
if: ${{ github.event.inputs.Linter == 'true' }}
run: |
go install github.com/securego/gosec/v2/cmd/gosec@latest
gosec -severity=high ./...
- name: Security linters check
if: ${{ github.event.inputs.LinterAll == 'true' }}
run: |
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
golangci-lint run -v ./main.go --no-config --enable-all
continue-on-error: true
# Linux
- name: Start docker container for test in Ubuntu
if: ${{ (github.event.inputs.Release == 'true' || github.event.inputs.Test == 'true') && github.event.inputs.Distro != 'macos-15' && github.event.inputs.Distro != 'windows-2022' }}
run: |
version=$(curl -s https://api.github.com/repos/docker/compose/releases/latest | jq -r .tag_name)
curl -L "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
docker-compose --version
echo -e "TTYD=true\nPORT=5555\nUSERNAME=\nPASSWORD=" | tee .env > /dev/null
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 != 'macos-15' && github.event.inputs.Distro != 'windows-2022' }}
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 tailspin
if: ${{ github.event.inputs.Test == 'true' && github.event.inputs.Distro != 'macos-15' && github.event.inputs.Distro != 'windows-2022' }}
run: |
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: Unit testing (all functions and mock interface) in Linux
if: ${{ github.event.inputs.Test == 'true' && github.event.inputs.Distro != 'macos-15' && github.event.inputs.Distro != 'windows-2022' }}
run: |
sudo env "PATH=$PATH" go test -v -cover | tee test.log
echo "## 🧪 Test Coverage" >> $GITHUB_STEP_SUMMARY
cat test.log | tail -n 2 | head -n 1 | sed "s/coverage: //" | sed -E "s/of.+//g" >> $GITHUB_STEP_SUMMARY
continue-on-error: true
timeout-minutes: 10
# + Docker without root
- name: Unit testing for docker without root in Linux
if: ${{ github.event.inputs.Test == 'true' && github.event.inputs.Distro != 'macos-15' && github.event.inputs.Distro != 'windows-2022' }}
run: env "PATH=$PATH" go test -v -cover --run "TestDockerContainer"
continue-on-error: true
timeout-minutes: 5
- name: Check cli mode (color and filter) for container
if: ${{ github.event.inputs.Test == 'true' && github.event.inputs.Distro != 'macos-15' && github.event.inputs.Distro != 'windows-2022' }}
run: |
docker logs lazyjournal | go run main.go -c
docker logs lazyjournal | go run main.go -f "start"
docker logs lazyjournal | go run main.go -r "start|close"
continue-on-error: true
- name: Create markdown report in Linux
if: ${{ github.event.inputs.Test == 'true' && github.event.inputs.Distro != 'macos-15' && github.event.inputs.Distro != 'windows-2022' }}
run: cat test-report.md >> $GITHUB_STEP_SUMMARY
continue-on-error: true
# macOS
- name: Unit testing (files, flags, cli and run main interface) in macOS
if: ${{ github.event.inputs.Test == 'true' && github.event.inputs.Distro == 'macos-15' }}
run: |
sudo go test -v -cover --run "TestUnixFiles|TestFlags|TestCommandColor|TestCommandFuzzyFilter|TestCommandRegexFilter|TestMainInterface" | tee test.log
echo "## 🧪 Test Coverage" >> $GITHUB_STEP_SUMMARY
cat test.log | tail -n 2 | head -n 1 | sed "s/coverage: //" | sed -E "s/of.+//g" >> $GITHUB_STEP_SUMMARY
continue-on-error: true
timeout-minutes: 5
- name: Create markdown report in macOS
if: ${{ github.event.inputs.Test == 'true' && github.event.inputs.Distro == 'macos-15' }}
run: cat test-report.md >> $GITHUB_STEP_SUMMARY
continue-on-error: true
# Windows
- name: Create log file for Windows
if: ${{ github.event.inputs.Test == 'true' && github.event.inputs.Distro == 'windows-2022' }}
run: |
New-Item -Path "$env:APPDATA\test" -Type Directory
"line test" | Out-File -FilePath "$env:APPDATA\test\test.log"
shell: pwsh
continue-on-error: true
- name: Unit testing (events, files, flags, cli, main and mock interface) in Windows
if: ${{ github.event.inputs.Test == 'true' && github.event.inputs.Distro == 'windows-2022' }}
run: |
go test -v -cover --run "TestWin.*|TestFlags|TestCommandColor|TestCommandFuzzyFilter|TestCommandRegexFilter|TestMainInterface|TestMockInterface" | tee test.log
echo "## 🧪 Test Coverage" >> $GITHUB_STEP_SUMMARY
cat test.log | tail -n 2 | head -n 1 | sed "s/coverage: //" | sed -E "s/of.+//g" >> $GITHUB_STEP_SUMMARY
shell: bash
continue-on-error: true
timeout-minutes: 5
- name: Create markdown report in Windows
if: ${{ github.event.inputs.Test == 'true' && github.event.inputs.Distro == 'windows-2022' }}
run: Get-Content test-report.md | Out-File -Append -FilePath $env:GITHUB_STEP_SUMMARY
shell: pwsh
continue-on-error: true
# 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: |
echo -e "\n\033[32mVersion:\033[0m\n"
lazyjournal -v
echo -e "\n\033[32mConfig:\033[0m\n"
lazyjournal -g
echo -e "\n\033[32mAudit:\033[0m\n"
lazyjournal -a
echo -e "\n\033[32mColor:\033[0m\n"
curl -s https://raw.githubusercontent.com/Lifailon/lazyjournal/refs/heads/main/color.log | lazyjournal -c
echo -e "\n\033[32mFuzzy:\033[0m\n"
curl -s https://raw.githubusercontent.com/Lifailon/lazyjournal/refs/heads/main/color.log | lazyjournal -f "success"
echo -e "\n\033[32mRegex:\033[0m\n"
curl -s https://raw.githubusercontent.com/Lifailon/lazyjournal/refs/heads/main/color.log | lazyjournal -r "http|127"
- name: Check interface in TMUX
if: ${{ github.event.inputs.Release == 'true' }}
run: |
tmux new-session -d -s test-session "lazyjournal"
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
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')"
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')"
sleep 3
tmux capture-pane -p
tmux send-keys -t test-session "$(echo -e '\t')"
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')"
tmux send-keys -t test-session "$(echo -e '\x1b[B')"
tmux send-keys -t test-session "$(echo -e 'tty|port')"
sleep 3
tmux capture-pane -p
tmux kill-session -t test-session
build:
runs-on: ubuntu-latest
name: Build on ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v4
- name: Clone main repository
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.25
- name: Install dependencies
run: |
go fmt ./...
go vet ./...
go get ./...
go mod tidy
go mod verify
go build -v ./...
- name: Get version in env for build
run: |
version=$(go run main.go -v)
echo "VERSION=$version" >> $GITHUB_ENV
- name: Build binaries
if: ${{ github.event.inputs.Binary == 'true' }}
run: |
version=$VERSION
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
if: ${{ github.event.inputs.Binary == 'true' }}
run: |
version=$VERSION
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: A TUI for reading logs from journald, auditd, file system, Docker and Podman containers, as well 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
sudo dpkg -i bin/lazyjournal-$version-amd64.deb
sudo dpkg -r lazyjournal
- name: Upload binaries
if: ${{ github.event.inputs.Binary == 'true' }}
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}
path: bin/
env:
ARTIFACT_NAME: ${{ env.ARTIFACT_NAME }}
- name: Login to Docker Hub
if: ${{ github.event.inputs.Docker == 'true' }}
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Install Docker Buildx
if: ${{ github.event.inputs.Docker == 'true' }}
uses: docker/setup-buildx-action@v3
with:
driver: docker-container
install: true
- name: Build and push Docker images for Linux on amd64 and arm64
if: ${{ github.event.inputs.Docker == 'true' }}
run: |
# docker build -t lifailon/lazyjournal:latest .
# docker push lifailon/lazyjournal:latest
docker buildx build \
--platform \
linux/amd64,linux/arm64 \
-t lifailon/lazyjournal \
--push .
continue-on-error: true