Skip to content

Commit

Permalink
Set up test configs and GH workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Sudak committed Mar 17, 2024
1 parent 5a20460 commit d0742e9
Show file tree
Hide file tree
Showing 14 changed files with 326 additions and 138 deletions.
9 changes: 9 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# A workaround to make the report with the right root package name
# https://github.com/nedbat/coveragepy/issues/613#issuecomment-399708687

[run]
source = .

[report]
skip_empty = True
include = sign_node/*
29 changes: 0 additions & 29 deletions .github/workflows/commit-message.yml

This file was deleted.

36 changes: 36 additions & 0 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Pull Request Checks
on:
pull_request:
types:
- opened
- edited
- reopened

defaults:
run:
shell: bash

jobs:
check-pr-message:
runs-on: ubuntu-latest
steps:

- name: Check the PR title and description
run: |
errors=
if grep -qE '^.{73,}$' <<< "${{ github.event.pull_request.title }}"; then
printf "ERROR: The PR title is longer than 72 characters:\n"
printf " > ${{ github.event.pull_request.title }}\n"
errors=true
fi
issue_regex='(Resolves|Fixes):? +(https:\/\/github.com\/)?AlmaLinux\/build-system(\/issues\/|#)[0-9]+'
if ! grep -qE "$issue_regex" <<< "${{ github.event.pull_request.body }}"; then
printf "ERROR: You need at least one \"Resolves|Fixes: <issue link>\" line.\n"
errors=true
fi
if [[ $errors == true ]]; then
exit 2
fi
65 changes: 65 additions & 0 deletions .github/workflows/preflight-summary.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Preflight Summary
on:
workflow_run:
workflows: [Preflight]
types: [completed]

defaults:
run:
shell: bash

jobs:

submit-summary:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:

- name: Download Preflight artifacts
# https://github.com/marketplace/actions/download-workflow-artifact
uses: dawidd6/action-download-artifact@v3
with:
name: preflight-reports
run_id: ${{github.event.workflow_run.id }}

- name: Load Environment
run: cat environment.txt | tee -a $GITHUB_ENV

- name: Generate Test Summary
# https://github.com/marketplace/actions/junit-test-dashboard
uses: test-summary/action@v2
with:
paths: pytest-report.xml
output: test-summary.md

- name: Generate Coverage Summary
# https://github.com/marketplace/actions/code-coverage-summary
# Generates code-coverage-results.md
uses: irongut/[email protected]
with:
filename: pytest-coverage.xml
badge: false
hide_branch_rate: true
hide_complexity: true
indicators: false
format: markdown
output: file

- name: Generate Preflight Summary
run: |
{
JOB_URL="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/${{github.event.workflow_run.id }}"
printf "[%s]($JOB_URL \"Go to Job Summary\")\n\n" "$(< test-summary.md)"
printf "**Code Coverage Summary**\n\n"
cat code-coverage-results.md
printf "\nView full reports on the [Job Summary]($JOB_URL \"Go to Job Summary\") page\n"
} > preflight-report.md
- name: Comment PR
# https://github.com/marketplace/actions/comment-pull-request
uses: thollander/actions-comment-pull-request@v2
with:
filePath: preflight-report.md
comment_tag: preflight_summary
pr_number: ${{ env.PR_NUMBER }}
104 changes: 104 additions & 0 deletions .github/workflows/preflight.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: Preflight
on: [pull_request]

defaults:
run:
shell: bash

jobs:

check-commit-message:
runs-on: ubuntu-latest
steps:

- name: Check out repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Check commit message
run: |
errors=
readarray -t long_lines < \
<(git log -1 --pretty=format:%B ${{ github.event.pull_request.head.sha }} | grep -E '^.{73,}$')
if [[ ${#long_lines[@]} -ne 0 ]]; then
printf "ERROR: The following lines are longer than 72 characters:\n"
printf " > %s\n" "${long_lines[@]}"
errors=true
fi
if [[ $errors == true ]]; then
exit 2
fi
pytest:
runs-on: ubuntu-latest
timeout-minutes: 10
env:
REPORTS_DIR: .preflight-reports
steps:

- name: Check out repository
uses: actions/checkout@v4

- name: Prepare working directory
run: |
mkdir $REPORTS_DIR node-config
echo "development_mode: yes" > node-config/sign_node.yml
- name: Set up Docker Buildx
# https://github.com/marketplace/actions/docker-setup-buildx
uses: docker/setup-buildx-action@v3

- name: Build Image
# https://github.com/marketplace/actions/build-and-push-docker-images
uses: docker/build-push-action@v5
with:
context: .
load: true
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Run Pytest
run: |
docker compose run --rm sign_node bash -c "
pytest -v --cov \
--junit-xml=$REPORTS_DIR/pytest-report.xml \
--cov-report=xml:$REPORTS_DIR/pytest-coverage.xml \
--cov-report=term | tee $REPORTS_DIR/pytest-report.txt"
- name: Save environment
run: |
{
echo "PR_NUMBER=${{ github.event.number }}"
} > $REPORTS_DIR/environment.txt
- name: Upload Pytest reports
# https://github.com/actions/upload-artifact
uses: actions/upload-artifact@v4
with:
name: preflight-reports
path: ${{ env.REPORTS_DIR }}
compression-level: 9
retention-days: 1

- name: Publish Job Summary
run: |
{
printf "## Test Results\n\n"
printf '<details><summary>Click to expand</summary>\n'
printf '\n```\n'
awk 'NR == 1 {next}; /^-+ generated xml file:/ {exit}; {print}' \
$REPORTS_DIR/pytest-report.txt
printf '\n```\n'
printf '</details>\n\n'
printf "## Code Coverage\n\n"
printf '<details><summary>Click to expand</summary>\n'
printf '\n```\n'
awk '/^-+ coverage:/, /^TOTAL/' \
$REPORTS_DIR/pytest-report.txt
printf '\n```\n'
printf '</details>\n\n'
} > $GITHUB_STEP_SUMMARY
61 changes: 0 additions & 61 deletions .github/workflows/pytest.yml

This file was deleted.

81 changes: 81 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Run Tests
on:
push:
branches: [master]

defaults:
run:
shell: bash

jobs:

pytest:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:

- name: Check out repository
uses: actions/checkout@v4

- name: Prepare working directory
run: |
mkdir node-config
echo "development_mode: yes" > node-config/sign_node.yml
- name: Set up Docker Buildx
# https://github.com/marketplace/actions/docker-setup-buildx
uses: docker/setup-buildx-action@v3

- name: Build Image
# https://github.com/marketplace/actions/build-and-push-docker-images
uses: docker/build-push-action@v5
with:
context: .
load: true
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Run Pytest
id: pytest
run: |
docker compose run --rm sign_node bash -c "
pytest -v --cov \
--cov-report=json:pytest-report.json \
--cov-report=term | tee pytest-report.txt"
python -c "
import os, json
coverage = json.load(open('pytest-report.json'))['totals']['percent_covered_display']
print(f'percent_covered={coverage}', file=open(os.environ['GITHUB_OUTPUT'], 'a'))"
- name: Create Coverage Badge
# https://github.com/marketplace/actions/dynamic-badges
uses: schneegans/[email protected]
with:
auth: ${{ secrets.GIST_TOKEN }}
gistID: fd471834348bb248a0881bc9ccfd45dd
filename: coverage-badge.json
label: Test Coverage
message: ${{ steps.pytest.outputs.percent_covered }}%
valColorRange: ${{ steps.pytest.outputs.percent_covered }}
minColorRange: 30
maxColorRange: 60
namedLogo: pytest

- name: Publish Job Summary
run: |
{
printf "## Test Results\n\n"
printf '<details><summary>Click to expand</summary>\n'
printf '\n```\n'
awk 'NR == 1 {next}; /^-+ coverage:/ {exit}; {print}' pytest-report.txt
printf '\n```\n'
printf '</details>\n\n'
printf "## Code Coverage\n\n"
printf '<details><summary>Click to expand</summary>\n'
printf '\n```\n'
awk '/^-+ coverage:/, /^TOTAL/' pytest-report.txt
printf '\n```\n'
printf '</details>\n\n'
} > $GITHUB_STEP_SUMMARY
Loading

0 comments on commit d0742e9

Please sign in to comment.