Skip to content

calendar pages updates/fixes #598

calendar pages updates/fixes

calendar pages updates/fixes #598

Workflow file for this run

name: backend
on:
pull_request:
branches:
- "main"
- "featurethon"
jobs:
changes:
runs-on: ubuntu-latest
outputs:
backend: ${{ steps.filter.outputs.backend }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
backend:
- 'backend/**'
backend-lint:
name: backend-lint
runs-on: ubuntu-latest
needs: changes
if: needs.changes.outputs.backend == 'true'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.22"
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: latest
working-directory: ./backend/
args: --timeout=5m
backend-tests:
name: backend-tests
runs-on: ubuntu-latest
needs: changes
if: needs.changes.outputs.backend == 'true'
continue-on-error: false # Tests block PR
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.22"
# Run tests using CI-specific target (no colors)
- name: Run Tests
run: |
cd backend
make test-ci
# Generate coverage using Makefile target
- name: Generate Coverage Report
run: |
cd backend
make test-coverage-ci
# Extract coverage percentage
- name: Extract Coverage Info
run: |
cd backend
COVERAGE=$(make coverage-percentage)
echo "Total coverage: $COVERAGE%"
echo "COVERAGE=$COVERAGE" >> $GITHUB_ENV
# Set your minimum coverage threshold
THRESHOLD=70
echo "THRESHOLD=$THRESHOLD" >> $GITHUB_ENV
# Check coverage threshold
if (( $(echo "$COVERAGE < $THRESHOLD" | bc -l) )); then
echo "⚠️ Coverage $COVERAGE% is below recommended threshold $THRESHOLD%"
echo "COVERAGE_STATUS=below" >> $GITHUB_ENV
else
echo "✅ Coverage $COVERAGE% meets threshold $THRESHOLD%"
echo "COVERAGE_STATUS=meets" >> $GITHUB_ENV
fi
# Verify test_output.log was created
if [ -f test_output.log ]; then
echo "test_output.log created successfully"
else
echo "WARNING: test_output.log was not created"
# Try to run tests again with direct command
go test ./... -v 2>&1 | tee test_output.log || true
fi
# Parse test results for better reporting
- name: Parse Test Results
if: always()
run: |
cd backend
# Initialize variables
echo "TESTS_PASSED=0" >> $GITHUB_ENV
echo "TESTS_FAILED=0" >> $GITHUB_ENV
echo "TESTS_SKIPPED=0" >> $GITHUB_ENV
echo "FAILED_TESTS=" >> $GITHUB_ENV
if [ -f test_output.log ]; then
# Parse test counts - use awk for more reliable parsing
PASSED=$(awk '/^--- PASS:/ {count++} END {print count+0}' test_output.log)
FAILED=$(awk '/^--- FAIL:/ {count++} END {print count+0}' test_output.log)
SKIPPED=$(awk '/^--- SKIP:/ {count++} END {print count+0}' test_output.log)
echo "TESTS_PASSED=$PASSED" >> $GITHUB_ENV
echo "TESTS_FAILED=$FAILED" >> $GITHUB_ENV
echo "TESTS_SKIPPED=$SKIPPED" >> $GITHUB_ENV
# Extract failure details using a simpler approach
if [ "$FAILED" -gt "0" ]; then
# Use printf to ensure proper formatting
FAILED_DETAILS=$(awk '/^--- FAIL:/ {print; for(i=1; i<=3; i++) {getline; print}}' test_output.log | head -20)
# Use delimiter approach for multi-line values
DELIMITER=$(openssl rand -hex 8)
echo "FAILED_TESTS<<$DELIMITER" >> $GITHUB_ENV
echo "$FAILED_DETAILS" >> $GITHUB_ENV
echo "$DELIMITER" >> $GITHUB_ENV
fi
else
echo "WARNING: test_output.log not found"
fi
# Upload coverage report as artifact
- name: Upload Coverage Report
uses: actions/upload-artifact@v4
if: always()
with:
name: coverage-report
path: |
backend/coverage.out
backend/coverage.html
backend/test_output.log
# Add detailed comment to PR
- name: Test Results Comment
uses: actions/github-script@v7
if: always() && github.event_name == 'pull_request'
with:
script: |
const coverage = process.env.COVERAGE || 'N/A';
const threshold = process.env.THRESHOLD || '70';
const status = process.env.COVERAGE_STATUS || 'unknown';
const emoji = status === 'meets' ? '✅' : '⚠️';
const statusText = status === 'meets'
? `meets threshold (${threshold}%)`
: `is below recommended threshold (${threshold}%)`;
const passed = process.env.TESTS_PASSED || '0';
const failed = process.env.TESTS_FAILED || '0';
const skipped = process.env.TESTS_SKIPPED || '0';
const failedTests = process.env.FAILED_TESTS || '';
const testEmoji = failed === '0' ? '✅' : '❌';
const testStatus = failed === '0' ? 'All tests passed!' : `${failed} test(s) failed`;
let body = `## Backend Test Results
### Test Summary ${testEmoji}
- **Passed:** ${passed}
- **Failed:** ${failed}
- **Skipped:** ${skipped}
- **Status:** ${testStatus}
`;
if (failedTests) {
body += `
<details>
<summary>Failed Tests Details</summary>
\`\`\`
${failedTests}
\`\`\`
</details>
`;
}
body += `
### Coverage ${emoji}
- **Total Coverage:** ${coverage}%
- **Status:** Coverage ${statusText}
Coverage report and test logs have been uploaded as artifacts.`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});