Skip to content

Fix tests (#8)

Fix tests (#8) #16

Workflow file for this run

# --------------------------------------------------------------------
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed
# with this work for additional information regarding copyright
# ownership. The ASF licenses this file to You under the Apache
# License, Version 2.0 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of the
# License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied. See the License for the specific language governing
# permissions and limitations under the License.
#
# --------------------------------------------------------------------
# GitHub Actions Workflow: Yagpcc Test Pipeline
# --------------------------------------------------------------------
# Description:
#
# This workflow builds and tests yagpcc on Ubuntu 22.04.
name: Simple go test workflow
on:
push:
branches: [main]
pull_request:
branches: [main]
types: [opened, synchronize, reopened, edited]
workflow_dispatch:
jobs:
tests:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [ '1.25' ]
steps:
- uses: actions/checkout@v5
- name: Setup Go
uses: actions/setup-go@v6
with:
go-version: ${{ matrix.go-version }}
- name: Download modules
run: go mod download
- name: Check if builds successfully
run: go build ./...
- name: Linter checks
uses: golangci/golangci-lint-action@v9
with:
version: v2.6
- name: Test with Go
continue-on-error: true
run: |
set -o pipefail
go test -json ./... | tee TestResults-${{ matrix.go-version }}.json
- name: Check test results
run: |
python3 - <<'PY'
import json
import sys
from pathlib import Path
path = Path("TestResults-${{ matrix.go-version }}.json")
if not path.exists():
print("Test results file is missing.")
sys.exit(1)
passed = 0
failed = 0
package_failures = 0
with path.open("r", encoding="utf-8") as f:
for line in f:
line = line.strip()
if not line:
continue
try:
event = json.loads(line)
except json.JSONDecodeError:
continue
action = event.get("Action")
test_name = event.get("Test")
if action == "pass" and test_name:
passed += 1
elif action == "fail" and test_name:
failed += 1
elif action == "fail" and not test_name:
package_failures += 1
print(f"Passed tests: {passed}")
print(f"Failed tests: {failed}")
print(f"Failed packages/builds: {package_failures}")
if failed > 0 or package_failures > 0:
sys.exit(1)
PY
- name: Upload Go test results
if: always()
uses: actions/upload-artifact@v4
with:
name: Go-results-${{ matrix.go-version }}
path: TestResults-${{ matrix.go-version }}.json