CI #151
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: | |
workflow_dispatch: | |
inputs: | |
Distro: | |
description: 'Select runner image' # https://github.com/actions/runner-images | |
required: true | |
default: 'ubuntu-20.04' | |
type: choice | |
options: | |
- 'ubuntu-24.04' | |
- 'macos-15' | |
- 'windows-2022' | |
Update: | |
description: 'Update dependencies' | |
default: false | |
type: boolean | |
Linter: | |
description: 'Linter check' | |
default: false | |
type: boolean | |
Test: | |
description: 'Unit testing' | |
default: false | |
type: boolean | |
Release: | |
description: 'Release check' | |
default: false | |
type: boolean | |
Binary: | |
description: 'Build binary' | |
default: false | |
type: boolean | |
jobs: | |
build: | |
runs-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.23 | |
- name: Install dependencies | |
run: | | |
go fmt ./... | |
go vet ./... | |
go get ./... | |
go mod tidy | |
go mod verify | |
go build -v ./... | |
- name: Update dependencies | |
if: ${{ github.event.inputs.Update == 'true' }} | |
run: go get -u ./... | |
# Linter | |
- name: Golangci linter check | |
if: ${{ github.event.inputs.Linter == 'true' }} | |
run: | | |
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest | |
golangci-lint run ./main.go | |
- name: Critic linter check | |
if: ${{ github.event.inputs.Linter == 'true' }} | |
run: | | |
go install github.com/go-critic/go-critic/cmd/gocritic@latest | |
gocritic check -enableAll ./main.go | |
- name: Security linter check | |
if: ${{ github.event.inputs.Linter == 'true' }} | |
run: | | |
go install github.com/securego/gosec/v2/cmd/gosec@latest | |
gosec -severity=high ./... | |
# 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 | |
continue-on-error: true | |
timeout-minutes: 5 | |
- 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" | |
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" | |
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 | |
- name: Install binary from latest release on GitHub | |
if: ${{ github.event.inputs.Release == 'true' }} | |
run: curl -sS https://raw.githubusercontent.com/Lifailon/lazyjournal/main/install.sh | bash | |
- name: Check flags (cli mode) | |
if: ${{ github.event.inputs.Release == 'true' }} | |
run: | | |
lazyjournal -v | |
lazyjournal -a | |
curl -s https://raw.githubusercontent.com/Lifailon/lazyjournal/refs/heads/main/color.log | lazyjournal -c | |
curl -s https://raw.githubusercontent.com/Lifailon/lazyjournal/refs/heads/main/color.log | lazyjournal -f "success" | |
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 | |
- name: Build binaries | |
if: ${{ github.event.inputs.Binary == 'true' }} | |
run: | | |
version=$(go run main.go -v) | |
echo "VERSION=$version" >> $GITHUB_ENV | |
echo "Current version: $version" | |
mkdir -p bin | |
architectures=("amd64" "arm64") | |
for arch in "${architectures[@]}"; do | |
CGO_ENABLED=0 GOOS=linux GOARCH=$arch go build -o bin/lazyjournal-$version-linux-$arch | |
CGO_ENABLED=0 GOOS=darwin GOARCH=$arch go build -o bin/lazyjournal-$version-darwin-$arch | |
CGO_ENABLED=0 GOOS=openbsd GOARCH=$arch go build -o bin/lazyjournal-$version-openbsd-$arch | |
CGO_ENABLED=0 GOOS=freebsd GOARCH=$arch go build -o bin/lazyjournal-$version-freebsd-$arch | |
CGO_ENABLED=0 GOOS=windows GOARCH=$arch go build -o bin/lazyjournal-$version-windows-$arch.exe | |
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 }} |