datahub/.github/workflows/update-test-weights.yml

147 lines
5.4 KiB
YAML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: Update Test Weights
on:
schedule:
# Run every Sunday at 2am UTC
- cron: "0 2 * * 0"
workflow_dispatch:
inputs:
run_count:
description: "Number of recent CI runs to analyze (default: 3)"
required: false
default: "3"
type: string
permissions:
contents: write # To create branches and commits
actions: read # To fetch workflow runs and artifacts
pull-requests: write # To create pull requests
jobs:
update-weights:
if: github.repository == 'datahub-project/datahub'
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Download test artifacts from recent CI runs
env:
GH_TOKEN: ${{ github.token }}
run: |
echo "Downloading test artifacts from recent successful CI runs..."
bash .github/scripts/download_test_artifacts.sh \
--output-dir ./test-artifacts \
--run-count ${{ github.event.inputs.run_count || '3' }} \
--workflow docker-unified.yml \
--repository ${{ github.repository }}
- name: Backup existing weights
run: |
mkdir -p ./weights-backup
cp smoke-test/tests/cypress/test_weights.json ./weights-backup/cypress_weights.json || echo "No existing Cypress weights"
cp smoke-test/pytest_test_weights.json ./weights-backup/pytest_weights.json || echo "No existing Pytest weights"
- name: Generate new test weights
run: |
echo "Generating test weights from downloaded artifacts..."
python .github/scripts/generate_test_weights.py \
--input-dir ./test-artifacts \
--cypress-output smoke-test/tests/cypress/test_weights.json \
--pytest-output smoke-test/pytest_test_weights.json
- name: Compare weights and generate PR body
id: compare
run: |
echo "Comparing old and new weights..."
python .github/scripts/compare_test_weights.py \
--old-cypress ./weights-backup/cypress_weights.json \
--new-cypress smoke-test/tests/cypress/test_weights.json \
--old-pytest ./weights-backup/pytest_weights.json \
--new-pytest smoke-test/pytest_test_weights.json \
--output ./pr-body.md \
--threshold 5.0
# Check if PR body was generated (non-empty file means changes exceed threshold)
if [ -s ./pr-body.md ]; then
echo "create_pr=true" >> $GITHUB_OUTPUT
echo "✓ Changes exceed 5% threshold. Will create PR."
else
echo "create_pr=false" >> $GITHUB_OUTPUT
echo "✓ Changes below 5% threshold. No PR needed."
fi
- name: Create branch and commit changes
if: steps.compare.outputs.create_pr == 'true'
run: |
# Configure git
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Create branch with date
BRANCH_NAME="auto/update-test-weights-$(date +%Y%m%d-%H%M%S)"
git checkout -b "$BRANCH_NAME"
# Add and commit changes
git add smoke-test/tests/cypress/test_weights.json smoke-test/pytest_test_weights.json
git commit -m "chore(test): update test weights from recent CI runs
Automated update of test weights based on analysis of recent successful CI runs.
This improves batch balancing and reduces overall CI execution time.
Generated by: ${{ github.workflow }} workflow
Run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
# Push branch
git push origin "$BRANCH_NAME"
# Save branch name for PR creation
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
- name: Create pull request
if: steps.compare.outputs.create_pr == 'true'
env:
GH_TOKEN: ${{ github.token }}
run: |
# Read PR body from file
PR_BODY=$(cat ./pr-body.md)
# Create PR
gh pr create \
--title "chore(test): Update test weights from CI runs ($(date +%Y-%m-%d))" \
--body "$PR_BODY" \
--head "$BRANCH_NAME" \
--base master
echo "✓ Pull request created successfully"
- name: Summary
if: always()
run: |
echo "### Test Weight Update Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ steps.compare.outputs.create_pr }}" == "true" ]; then
echo "✅ **PR Created**: Changes exceeded 5% threshold" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Branch: \`$BRANCH_NAME\`" >> $GITHUB_STEP_SUMMARY
else
echo " **No PR Created**: Changes below 5% threshold" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Test weights were updated but the changes were too small to warrant a PR." >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "Workflow run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" >> $GITHUB_STEP_SUMMARY