Skip to content

Commit

Permalink
Merge pull request #2931 from IntersectMBO/test
Browse files Browse the repository at this point in the history
GovTool - v2.0.11-patch1
  • Loading branch information
MSzalowski authored Feb 10, 2025
2 parents 451b376 + f6d1be5 commit 0c89866
Show file tree
Hide file tree
Showing 28 changed files with 2,029 additions and 307 deletions.
75 changes: 75 additions & 0 deletions .github/scripts/set_commit_status.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash

# Ensure required environment variables are set
if [ -z "$GITHUB_REPOSITORY" ] || [ -z "$GITHUB_SHA" ] || [ -z "$GITHUB_TOKEN" ] || [ -z "$GITHUB_RUN_ID" ]; then
echo "Missing required environment variables!"
exit 1
fi

# Retrieve necessary variables from workflow
START_TIME=${START_TIME:-$(date +%s)}
TEST_STATUS=${TEST_STATUS:-"failure"}
REPORT_NUMBER=${REPORT_NUMBER:-1}
REPORT_NAME=${REPORT_NAME:-"govtool-frontend"}
HOST_URL=${HOST_URL:-"https://govtool.cardanoapi.io"}
CONTEXT="Playwright Tests : $HOST_URL"

if [[ "$REPORT_NAME" == "govtool-backend" ]]; then
CONTEXT="Backend Tests : $BASE_URL"
fi

# Parse Allure JSON results
if [ -z "$(ls -A allure-results/*.json 2>/dev/null)" ]; then
echo "No Allure JSON results found!"
PASSED=0
FAILED=0
TOTAL=0
else
PASSED=$(jq -s '[.[] | select(.status == "passed")] | length' allure-results/*.json)
FAILED=$(jq -s '[.[] | select(.status == "failed")] | length' allure-results/*.json)
TOTAL=$((PASSED + FAILED))
fi



# Calculate test duration
CURRENT_TIME=$(date +%s)
TEST_DURATION_SECONDS=$((CURRENT_TIME - START_TIME))
TEST_DURATION_MINUTES=$((TEST_DURATION_SECONDS / 60))
TEST_DURATION_HOURS=$((TEST_DURATION_MINUTES / 60))

if [ "$TEST_DURATION_HOURS" -gt 0 ]; then
TEST_DURATION="${TEST_DURATION_HOURS} hour$( [ "$TEST_DURATION_HOURS" -ne 1 ] && echo "s"), $((TEST_DURATION_MINUTES % 60)) minute$( [ "$((TEST_DURATION_MINUTES % 60))" -ne 1 ] && echo "s"), and $((TEST_DURATION_SECONDS % 60)) second$( [ "$((TEST_DURATION_SECONDS % 60))" -ne 1 ] && echo "s")"
elif [ "$TEST_DURATION_MINUTES" -gt 0 ]; then
TEST_DURATION="${TEST_DURATION_MINUTES} minute$( [ "$TEST_DURATION_MINUTES" -ne 1 ] && echo "s") and $((TEST_DURATION_SECONDS % 60)) second$( [ "$((TEST_DURATION_SECONDS % 60))" -ne 1 ] && echo "s")"
else
TEST_DURATION="${TEST_DURATION_SECONDS} second$( [ "$TEST_DURATION_SECONDS" -ne 1 ] && echo "s")"
fi

# Determine target URL based on environment
case "$GH_PAGES" in
"IntersectMBO/govtool-test-reports") TARGET_URL="https://intersectmbo.github.io/govtool-test-reports/${REPORT_NAME}/${REPORT_NUMBER}" ;;
"cardanoapi/govtool-test-reports") TARGET_URL="https://cardanoapi.github.io/govtool-test-reports/${REPORT_NAME}/${REPORT_NUMBER}" ;;
*) TARGET_URL="https://intersectmbo.github.io/govtool-test-reports/${REPORT_NAME}/${REPORT_NUMBER}" ;;
esac

# Determine test result message
if [[ "$TEST_STATUS" == "success" ]]; then
DESCRIPTION="Tests passed in ${TEST_DURATION}"
elif [[ "$TEST_STATUS" == "failure" && "$TOTAL" -ne 0 ]]; then
DESCRIPTION="Tests failed in ${TEST_DURATION}: Passed ${PASSED}, Failed ${FAILED} out of ${TOTAL}"
else
DESCRIPTION="⚠️ Tests execution failed :$TEST_STATUS"
TEST_STATUS="error"
TARGET_URL="https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
fi



# Send commit status update to GitHub
curl -X POST -H "Authorization: Bearer ${GITHUB_TOKEN}" \
-H "Accept: application/vnd.github+json" \
https://api.github.com/repos/${GITHUB_REPOSITORY}/statuses/${GITHUB_SHA} \
-d "{\"state\": \"${TEST_STATUS}\", \"context\": \"${CONTEXT}\", \"description\": \"${DESCRIPTION}\", \"target_url\": \"${TARGET_URL}\"}"

echo "Commit status updated successfully!"
65 changes: 56 additions & 9 deletions .github/workflows/test_backend.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name: Backend Test

permissions:
contents: read
checks: write
statuses: write

on:
workflow_dispatch:
inputs:
Expand Down Expand Up @@ -27,14 +32,31 @@ on:
workflows: ["Build and deploy GovTool test stack"]
types: [completed]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false

jobs:
backend-tests:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }}
outputs:
start_time: ${{ steps.set-pending-status.outputs.timestamp }}
status: ${{ steps.run-tests.outcome }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set pending commit status
id: set-pending-status
run: |
echo "timestamp=$(date +%s)" >> $GITHUB_OUTPUT
curl -X POST -H "Authorization: Bearer ${{ github.token }}" \
-H "Accept: application/vnd.github+json" \
https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }} \
-d "{\"state\": \"pending\", \"context\": \"Backend Tests : ${{env.BASE_URL}}\", \"target_url\": \"https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}\"}"
- name: Set up Python
uses: actions/setup-python@v4
with:
Expand All @@ -43,6 +65,7 @@ jobs:

- name: Run Backend Test
working-directory: tests/govtool-backend
id: run-tests
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
Expand All @@ -55,26 +78,27 @@ jobs:
fi
python ./setup.py
python -m pytest --alluredir allure-results
env:
BASE_URL: https://${{inputs.deployment || 'govtool.cardanoapi.io/api' }}
NETWORK: ${{ inputs.network || vars.NETWORK }}
KUBER_API_KEY: ${{ secrets.KUBER_API_KEY }}
- name: Upload report
if: always()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: allure-results
path: tests/govtool-backend/allure-results
env:
NETWORK: ${{ inputs.network || vars.NETWORK }}
KUBER_API_KEY: ${{ secrets.KUBER_API_KEY }}

publish-report:
runs-on: ubuntu-latest
if: always() && needs.backend-tests.result != 'skipped'
needs: backend-tests
outputs:
report_number: ${{ steps.report-details.outputs.report_number }}
steps:
- uses: actions/checkout@v4
- name: Download results
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: allure-results
path: allure-results
Expand Down Expand Up @@ -134,6 +158,29 @@ jobs:
folder: build
target-folder: ${{ env.REPORT_NAME }}

env:
REPORT_NAME: govtool-backend
GH_PAGES: ${{vars.GH_PAGES}}
publish-status:
runs-on: ubuntu-latest
if: always()
needs: [backend-tests, publish-report]
steps:
- uses: actions/checkout@v4
- name: Download results
uses: actions/download-artifact@v4
with:
name: allure-results
path: allure-results
- name: Set Commit Status
if: always()
run: |
chmod +x .github/scripts/set_commit_status.sh
.github/scripts/set_commit_status.sh
env:
START_TIME: ${{ needs.backend-tests.outputs.start_time }}
TEST_STATUS: ${{ needs.backend-tests.outputs.status }}
REPORT_NUMBER: ${{ needs.publish-report.outputs.report_number }}
GITHUB_TOKEN: ${{ github.token }}

env:
BASE_URL: https://${{inputs.deployment || 'govtool.cardanoapi.io/api' }}
REPORT_NAME: govtool-backend
GH_PAGES: ${{vars.GH_PAGES}}
59 changes: 52 additions & 7 deletions .github/workflows/test_integration_playwright.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name: Integration Test [Playwright]

permissions:
contents: read
checks: write
statuses: write

on:
workflow_dispatch:
inputs:
Expand All @@ -26,16 +31,32 @@ on:
workflow_run:
workflows: ["Build and deploy GovTool test stack"]
types: [completed]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false

jobs:
integration-tests:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }}
outputs:
start_time: ${{ steps.set-pending-status.outputs.timestamp }}
status: ${{ steps.run-test.outcome }}
defaults:
run:
working-directory: tests/govtool-frontend/playwright
steps:
- uses: actions/checkout@v4
- name: Set pending commit status
id: set-pending-status
run: |
echo "timestamp=$(date +%s)" >> $GITHUB_OUTPUT
curl -X POST -H "Authorization: Bearer ${{ github.token }}" \
-H "Accept: application/vnd.github+json" \
https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }} \
-d "{\"state\": \"pending\", \"context\": \"Playwright Tests : ${{env.HOST_URL}}\", \"target_url\": \"https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}\"}"
- uses: actions/setup-node@v4
with:
node-version: "18"
Expand All @@ -58,6 +79,7 @@ jobs:
run: npx playwright install --with-deps

- name: Run tests
id: run-test
run: |
mkdir -p ./lib/_mock
chmod +w ./lib/_mock
Expand All @@ -81,21 +103,20 @@ jobs:
npm test
- name: Upload report
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
if: always()
with:
name: allure-results
path: tests/govtool-frontend/playwright/allure-results

- name: Upload lock logs
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
if: always()
with:
name: lock-logs
path: tests/govtool-frontend/playwright/lock_logs.txt

env:
HOST_URL: https://${{inputs.deployment || 'govtool.cardanoapi.io' }}
API_URL: https://${{inputs.deployment || 'govtool.cardanoapi.io' }}/api
DOCS_URL: ${{ vars.DOCS_URL }}
KUBER_API_KEY: ${{secrets.KUBER_API_KEY}}
Expand All @@ -111,10 +132,12 @@ jobs:
runs-on: ubuntu-latest
if: always() && needs.integration-tests.result != 'skipped'
needs: integration-tests
outputs:
report_number: ${{ steps.report-details.outputs.report_number }}
steps:
- uses: actions/checkout@v4
- name: Download report
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: allure-results
path: allure-results
Expand Down Expand Up @@ -175,6 +198,28 @@ jobs:
folder: build
target-folder: ${{ env.REPORT_NAME }}

env:
REPORT_NAME: govtool-frontend
GH_PAGES: ${{vars.GH_PAGES}}
publish-status:
runs-on: ubuntu-latest
if: always()
needs: [integration-tests, publish-report]
steps:
- uses: actions/checkout@v4
- name: Download results
uses: actions/download-artifact@v4
with:
name: allure-results
path: allure-results
- name: Set Commit Status
if: always()
run: |
chmod +x .github/scripts/set_commit_status.sh
.github/scripts/set_commit_status.sh
env:
START_TIME: ${{ needs.integration-tests.outputs.start_time }}
TEST_STATUS: ${{ needs.integration-tests.outputs.status }}
REPORT_NUMBER: ${{ needs.publish-report.outputs.report_number }}
GITHUB_TOKEN: ${{ github.token }}
env:
HOST_URL: https://${{inputs.deployment || 'govtool.cardanoapi.io' }}
REPORT_NAME: govtool-frontend
GH_PAGES: ${{vars.GH_PAGES}}
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,22 @@ changes.

### Added

-
- Add metadata url and hash to drep details [Issue 2911](https://github.com/IntersectMBO/govtool/issues/2911)

### Fixed

-
- Fix calculating votes counting for governance actions
- Fix crashing backend on unhandled missing proposal from vote [Issue 2920](https://github.com/IntersectMBO/govtool/issues/2920)
- Remove abstain votes (not auto abstain) from total DRep stake

### Changed

- Change threshold visual representation in governance action votes
- Resize governance action details columns

### Removed

-
- Remove abstain from total DRep votes calculation

## [v2.0.11](https://github.com/IntersectMBO/govtool/releases/tag/v2.0.11) 2025-02-04

Expand Down
Loading

0 comments on commit 0c89866

Please sign in to comment.