Merge pull request #26 from ZhikharevAl/ci/k8s #127
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: Python Code Quality Checks | |
| on: | |
| push: | |
| workflow_dispatch: | |
| jobs: | |
| lock_file: | |
| runs-on: ubuntu-22.04 | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v4 | |
| - name: Cache UV dependencies | |
| uses: actions/[email protected] | |
| with: | |
| path: .venv | |
| key: ${{ runner.os }}-uv-${{ hashFiles('uv.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-uv- | |
| - name: Setup Python and UV | |
| uses: ./.github/actions/setup | |
| - name: Generate/Check Lockfile | |
| run: uv lock --locked | |
| linters: | |
| runs-on: ubuntu-22.04 | |
| needs: [lock_file] | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v4 | |
| - uses: ./.github/actions/run-linters | |
| tests: | |
| runs-on: ubuntu-22.04 | |
| needs: [lock_file] | |
| steps: | |
| - name: Checkout Test Repo | |
| uses: actions/checkout@v4 | |
| - name: Cache server-repo | |
| uses: actions/[email protected] | |
| with: | |
| path: server-repo | |
| key: ${{ runner.os }}-server-repo-${{ hashFiles('server-repo/**') }} | |
| restore-keys: | | |
| ${{ runner.os }}-server-repo- | |
| - name: Install Podman | |
| run: | | |
| sudo apt-get update -y | |
| sudo apt-get install -y podman curl | |
| - name: Checkout Server Repo | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: ZhikharevAl/charity_event_comeback_oct2024 | |
| path: server-repo | |
| - name: Build Server Image | |
| run: | | |
| podman build \ | |
| -t api-server-image:ci \ | |
| -f server-repo/Dockerfile \ | |
| server-repo | |
| - name: Build Test Runner Image | |
| run: | | |
| podman build \ | |
| -t charity-tests-runner:ci \ | |
| -f Containerfile . | |
| - name: Start API Server Container | |
| run: | | |
| podman run -d --network=host --name api-server api-server-image:ci | |
| - name: Wait for API Server | |
| run: | | |
| echo "Waiting for API server to be ready on http://localhost:4040..." | |
| timeout=60 | |
| interval=5 | |
| url="http://localhost:4040/api/auth" | |
| end_time=$(( $(date +%s) + timeout )) | |
| while [ $(date +%s) -lt $end_time ]; do | |
| if curl -sSf --connect-timeout 2 "$url" > /dev/null 2>&1 || [ $? -eq 22 ] || [ $? -eq 7 ]; then | |
| curl_exit_code=$(curl -sSf --connect-timeout 2 "$url" > /dev/null 2>&1; echo $?) | |
| if [ $curl_exit_code -ne 7 ]; then | |
| echo "API server is up!" | |
| sleep 2 | |
| exit 0 | |
| fi | |
| fi | |
| echo "Server not ready yet. Retrying in $interval seconds..." | |
| sleep $interval | |
| done | |
| echo "Timeout waiting for API server." | |
| echo "--- API Server Logs ---" | |
| podman logs api-server || echo "Could not get server logs." | |
| echo "--- End API Server Logs ---" | |
| exit 1 | |
| - name: Create directories for results | |
| run: | | |
| mkdir -p allure-results | |
| mkdir -p coverage-results | |
| - name: Run Pytest inside Podman Container | |
| run: | | |
| podman run --rm \ | |
| --network=host \ | |
| -e API_BASE_URL=http://localhost:4040 \ | |
| -e TEST_USER_LOGIN=${{ secrets.TEST_USER_LOGIN }} \ | |
| -e TEST_USER_PASSWORD=${{ secrets.TEST_USER_PASSWORD }} \ | |
| -e INVALID_USER_PASSWORD=${{ secrets.INVALID_USER_PASSWORD }} \ | |
| -v $(pwd)/allure-results:/app/allure-results \ | |
| -v $(pwd)/coverage-results:/app/coverage-results \ | |
| charity-tests-runner:ci \ | |
| /app/.venv/bin/python -m pytest \ | |
| -v --durations=0 \ | |
| --cov=/app \ | |
| --cov-report=xml:/app/coverage-results/coverage.xml \ | |
| --alluredir=/app/allure-results || true | |
| - name: Stop API Server Container | |
| if: always() | |
| run: podman stop api-server | |
| - name: Upload Coverage to Codecov | |
| uses: codecov/codecov-action@v4 | |
| with: | |
| token: ${{ secrets.CODECOV_TOKEN }} | |
| files: ./coverage-results/coverage.xml | |
| slug: ${{ github.repository }} | |
| - name: Upload Allure Results | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: allure-results | |
| path: allure-results/ | |
| retention-days: 20 | |
| allure-report: | |
| runs-on: ubuntu-22.04 | |
| needs: [tests] | |
| if: always() | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Download Allure Results | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: allure-results | |
| path: allure-results | |
| - name: Get Allure history | |
| uses: actions/checkout@v4 | |
| if: always() | |
| continue-on-error: true | |
| with: | |
| ref: gh-pages | |
| path: gh-pages | |
| - name: Allure Report action | |
| uses: simple-elf/[email protected] | |
| if: always() | |
| with: | |
| allure_results: allure-results | |
| allure_history: allure-history | |
| keep_reports: 20 | |
| - name: Deploy report to Github Pages | |
| if: always() | |
| uses: peaceiris/actions-gh-pages@v4 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| publish_branch: gh-pages | |
| publish_dir: allure-history |