Merge coverage and update Wiki #39
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: Merge Coverage | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| Debug: | |
| description: 'Advanced summary report from tests' | |
| default: false | |
| type: boolean | |
| Linter: | |
| description: 'Check linters for final report' | |
| default: false | |
| type: boolean | |
| Coverage: | |
| description: 'Update html and svg reports on Wiki' | |
| default: false | |
| type: boolean | |
| Markdown: | |
| description: 'Update markdown report on Wiki' | |
| default: false | |
| type: boolean | |
| permissions: | |
| contents: write | |
| jobs: | |
| Linux: | |
| runs-on: ubuntu-24.04 | |
| 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: Start docker container for test in Ubuntu | |
| 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 | |
| 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 | |
| continue-on-error: true | |
| - name: Install tailspin | |
| run: sudo apt install -y tailspin | |
| - name: Run all unit test in Linux | |
| run: sudo go test -v -cover -coverprofile linux-coverage.out | |
| continue-on-error: true | |
| timeout-minutes: 10 | |
| - name: Create markdown report for Linux | |
| run: | | |
| mv test-report.md test-linux-report.md | |
| if [[ "${{ inputs.Debug }}" == "true" ]]; then | |
| cat test-linux-report.md >> $GITHUB_STEP_SUMMARY | |
| fi | |
| continue-on-error: true | |
| - name: Upload test summary report | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: linux-report | |
| path: test-linux-report.md | |
| - name: Upload coverage report | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: linux-coverage | |
| path: linux-coverage.out | |
| Docker: | |
| runs-on: ubuntu-24.04 | |
| 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: Start docker container for test in Ubuntu | |
| 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: Run unit test for docker in Linux without root | |
| run: go test -v --run "TestDockerContainer" -cover -coverprofile docker-coverage.out | |
| continue-on-error: true | |
| timeout-minutes: 5 | |
| - name: Upload coverage report | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: docker-coverage | |
| path: docker-coverage.out | |
| macOS: | |
| runs-on: macos-15 | |
| 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: Run unit test in macOS | |
| run: sudo go test -v --run "TestUnixFiles|TestFlags|TestCommandColor|TestCommandFuzzyFilter|TestCommandRegexFilter|TestMainInterface" -cover -coverprofile macos-coverage.out | |
| continue-on-error: true | |
| timeout-minutes: 5 | |
| - name: Create markdown report for macOS | |
| run: | | |
| mv test-report.md test-macos-report.md | |
| if [[ "${{ inputs.Debug }}" == "true" ]]; then | |
| cat test-macos-report.md >> $GITHUB_STEP_SUMMARY | |
| fi | |
| continue-on-error: true | |
| - name: Upload test summary report | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: macos-report | |
| path: test-macos-report.md | |
| - name: Upload coverage report | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: macos-coverage | |
| path: macos-coverage.out | |
| Windows: | |
| runs-on: windows-2022 | |
| 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: Create log file for Windows | |
| 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: Run unit test in Windows | |
| run: go test -v --run "TestWin.*|TestFlags|TestCommandColor|TestCommandFuzzyFilter|TestCommandRegexFilter|TestMainInterface|TestMockInterface" -cover -coverprofile windows-coverage.out | |
| continue-on-error: true | |
| timeout-minutes: 5 | |
| - name: Create markdown report for Windows | |
| run: | | |
| Rename-Item -Path test-report.md -NewName test-windows-report.md | |
| if ($env:DEBUG -eq "true") { | |
| Get-Content test-windows-report.md | Out-File -Append -FilePath $env:GITHUB_STEP_SUMMARY | |
| } | |
| shell: pwsh | |
| continue-on-error: true | |
| env: | |
| DEBUG: ${{ inputs.Debug }} | |
| - name: Upload test summary report | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: windows-report | |
| path: test-windows-report.md | |
| - name: Upload coverage report | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: windows-coverage | |
| path: windows-coverage.out | |
| Merge: | |
| runs-on: ubuntu-latest | |
| needs: [Linux, Docker, macOS, Windows] | |
| steps: | |
| - name: Clone main repository | |
| uses: actions/checkout@v4 | |
| - name: Install Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: 1.25 | |
| - name: Download coverage report for Linux (with root) | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: linux-coverage | |
| path: . | |
| - name: Download coverage report for Docker without root | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: docker-coverage | |
| path: . | |
| - name: Download coverage report for macOS | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: macos-coverage | |
| path: . | |
| - name: Download coverage report for Windows | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: windows-coverage | |
| path: . | |
| - name: Check coverage report for all tests on Linux with root | |
| run: | | |
| out=$(go tool cover -func linux-coverage.out) | |
| echo "# 🧪 Test Coverage" >> $GITHUB_STEP_SUMMARY | |
| coverTotal=$(echo "$out" | tail -n 1 | sed -E "s/.+\)\s+//") | |
| echo "Linux coverage: $coverTotal" | |
| echo "- **Linux**: $coverTotal" >> $GITHUB_STEP_SUMMARY | |
| cat "$GITHUB_STEP_SUMMARY" > all-report.md | |
| - name: Check coverage report for Docker without root | |
| run: | | |
| out=$(go tool cover -func docker-coverage.out) | |
| coverTotal=$(echo "$out" | tail -n 1 | sed -E "s/.+\)\s+//") | |
| echo "Docker coverage: $coverTotal" | |
| - name: Check coverage report for macOS | |
| run: | | |
| out=$(go tool cover -func macos-coverage.out) | |
| coverTotal=$(echo "$out" | tail -n 1 | sed -E "s/.+\)\s+//") | |
| echo "macOS coverage: $coverTotal" | |
| echo "- **macOS**: $coverTotal" >> $GITHUB_STEP_SUMMARY | |
| cat "$GITHUB_STEP_SUMMARY" >> all-report.md | |
| - name: Check coverage report for Windows | |
| run: | | |
| out=$(go tool cover -func windows-coverage.out) | |
| coverTotal=$(echo "$out" | tail -n 1 | sed -E "s/.+\)\s+//") | |
| echo "Windows coverage: $coverTotal" | |
| echo "- **Windows**: $coverTotal" >> $GITHUB_STEP_SUMMARY | |
| cat "$GITHUB_STEP_SUMMARY" >> all-report.md | |
| - name: Install go coverage merge | |
| run: | | |
| go install github.com/wadey/gocovmerge@latest | |
| echo "$HOME/go/bin" >> $GITHUB_PATH | |
| export PATH=$HOME/go/bin:$PATH | |
| which gocovmerge | |
| - name: Merge coverage reports | |
| run: | | |
| gocovmerge linux-coverage.out docker-coverage.out macos-coverage.out windows-coverage.out > merge-coverage.out | |
| out=$(go tool cover -func merge-coverage.out) | |
| coverTotal=$(echo "$out" | tail -n 1 | sed -E "s/.+\)\s+//") | |
| echo "Total after merge coverage: $coverTotal" | |
| echo "- **Total after merge**: $coverTotal" >> $GITHUB_STEP_SUMMARY | |
| mdReport=$(echo "$out" | sed -E 's/.+\///' | sed "s/:/ /g" | head -n -1) | |
| title="File Line Function Coverage" | |
| separator="- - - -" | |
| echo "# 📚 Merge test results" >> $GITHUB_STEP_SUMMARY | |
| mdReport=$(echo -e "$title\n$separator\n$mdReport") | |
| echo "$mdReport" | awk '{print "|" $1 "|" $2 "|" $3 "|" $4 "|"}' >> $GITHUB_STEP_SUMMARY | |
| cat "$GITHUB_STEP_SUMMARY" >> all-report.md | |
| - name: Linters reports | |
| if: ${{ github.event.inputs.Linter == 'true' }} | |
| run: | | |
| echo "# 👮♂️ Linters check" >> $GITHUB_STEP_SUMMARY | |
| echo "## GolangCI" >> $GITHUB_STEP_SUMMARY | |
| go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest | |
| echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY | |
| golangci-lint run -v ./main.go 2>&1 | tee -a $GITHUB_STEP_SUMMARY | |
| echo "\`\`\`" >> $GITHUB_STEP_SUMMARY | |
| echo "## Go Critic" >> $GITHUB_STEP_SUMMARY | |
| go install github.com/go-critic/go-critic/cmd/gocritic@latest | |
| echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY | |
| gocritic check -v -enableAll ./main.go 2>&1 | tee -a $GITHUB_STEP_SUMMARY | |
| echo "\`\`\`" >> $GITHUB_STEP_SUMMARY | |
| echo "## Go Security" >> $GITHUB_STEP_SUMMARY | |
| go install github.com/securego/gosec/v2/cmd/gosec@latest | |
| echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY | |
| gosec -severity=high ./... 2>&1 | tee -a $GITHUB_STEP_SUMMARY | |
| echo "\`\`\`" >> $GITHUB_STEP_SUMMARY | |
| - name: Upload merge coverage report | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: merge-coverage | |
| path: merge-coverage.out | |
| - name: Update html and svg reports on Wiki | |
| if: ${{ github.event.inputs.Coverage == 'true' }} | |
| uses: ncruces/go-coverage-report@v0 | |
| with: | |
| coverage-file: merge-coverage.out | |
| report: true | |
| chart: true | |
| amend: true | |
| continue-on-error: true | |
| - name: Download test summary report for Linux | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: linux-report | |
| path: . | |
| - name: Download test summary report for macOS | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: macos-report | |
| path: . | |
| - name: Download test summary report for Windows | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: windows-report | |
| path: . | |
| - name: Merge all reports | |
| run: | | |
| echo "# 🐧 Linux" >> all-report.md | |
| cat "test-linux-report.md" >> all-report.md | |
| echo "# 🍏 macOS" >> all-report.md | |
| cat "test-macos-report.md" >> all-report.md | |
| echo "# 🏠 Windows" >> all-report.md | |
| cat "test-windows-report.md" >> all-report.md | |
| - name: Upload final report | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: all-report | |
| path: all-report.md | |
| - name: Clone Wiki repository | |
| if: ${{ github.event.inputs.Markdown == 'true' }} | |
| run: git clone https://github.com/Lifailon/lazyjournal.wiki wiki | |
| - name: Update markdown report on Wiki | |
| if: ${{ github.event.inputs.Markdown == 'true' }} | |
| run: | | |
| echo -e '# Test report\n' > wiki/home.md | |
| echo -e 'The test coverage report in `html` format using [go-coverage-report](https://github.com/marketplace/actions/go-coverage-report) is available [here](https://raw.githubusercontent.com/wiki/Lifailon/lazyjournal/coverage.html).\n' >> wiki/home.md | |
| echo -e 'During testing, the interface operation is checked in the disabled `tcell` mode, as well as the reading and coloring time of all available logs in Linux, macOS and Windows systems.\n' >> wiki/home.md | |
| echo -e 'To combine test results from different systems [gosovmerge](https://github.com/wadey/gocovmerge) is used.\n' >> wiki/home.md | |
| echo -e '# 📈 Coverage history\n' >> wiki/home.md | |
| echo -e '\n' >> wiki/home.md | |
| cat all-report.md >> wiki/home.md | |
| cd wiki | |
| git config --global user.name 'GitHub Actions' | |
| git config --global user.email '[email protected]' | |
| git add home.md | |
| if ! git diff --staged --quiet; then | |
| git diff | |
| git commit -m "update markdown report" | |
| git push https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/Lifailon/lazyjournal.wiki.git master | |
| else | |
| echo "No changes to commit" | |
| fi |