|
| 1 | +name: Modified Target Validation |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request_target: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + paths: |
| 8 | + - "sherlock_project/resources/data.json" |
| 9 | + |
| 10 | +jobs: |
| 11 | + validate-modified-targets: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + permissions: |
| 14 | + contents: read |
| 15 | + pull-requests: write |
| 16 | + steps: |
| 17 | + - name: Checkout repository |
| 18 | + uses: actions/checkout@v5 |
| 19 | + with: |
| 20 | + ref: ${{ github.base_ref }} |
| 21 | + fetch-depth: 1 |
| 22 | + |
| 23 | + - name: Set up Python |
| 24 | + uses: actions/setup-python@v6 |
| 25 | + with: |
| 26 | + python-version: '3.13' |
| 27 | + |
| 28 | + - name: Install Poetry |
| 29 | + uses: abatilo/actions-poetry@v4 |
| 30 | + with: |
| 31 | + poetry-version: 'latest' |
| 32 | + |
| 33 | + - name: Install dependencies |
| 34 | + run: | |
| 35 | + poetry install --no-interaction --with dev |
| 36 | +
|
| 37 | + - name: Drop in place updated manifest from base |
| 38 | + run: | |
| 39 | + cp sherlock_project/resources/data.json data.json.base |
| 40 | + git fetch origin pull/${{ github.event.pull_request.number }}/head:pr --depth=1 |
| 41 | + git show pr:sherlock_project/resources/data.json > sherlock_project/resources/data.json |
| 42 | + cp sherlock_project/resources/data.json data.json.head |
| 43 | +
|
| 44 | + - name: Discover modified targets |
| 45 | + id: discover-modified |
| 46 | + run: | |
| 47 | + CHANGED=$( |
| 48 | + python - <<'EOF' |
| 49 | + import json |
| 50 | + with open("data.json.base") as f: base = json.load(f) |
| 51 | + with open("data.json.head") as f: head = json.load(f) |
| 52 | +
|
| 53 | + changed = [] |
| 54 | + for k, v in head.items(): |
| 55 | + if k not in base or base[k] != v: |
| 56 | + changed.append(k) |
| 57 | +
|
| 58 | + print(",".join(sorted(changed))) |
| 59 | + EOF |
| 60 | + ) |
| 61 | +
|
| 62 | + # Preserve changelist |
| 63 | + echo -e ">>> Changed targets: \n$(echo $CHANGED | tr ',' '\n')" |
| 64 | + echo "changed_targets=$CHANGED" >> "$GITHUB_OUTPUT" |
| 65 | +
|
| 66 | + - name: Validate modified targets |
| 67 | + if: steps.discover-modified.outputs.changed_targets != '' |
| 68 | + continue-on-error: true |
| 69 | + run: | |
| 70 | + poetry run pytest -q --tb no -rA -m validate_targets -n 20 \ |
| 71 | + --chunked-sites "${{ steps.discover-modified.outputs.changed_targets }}" \ |
| 72 | + --junitxml=validation_results.xml |
| 73 | +
|
| 74 | + - name: Prepare validation summary |
| 75 | + if: steps.discover-modified.outputs.changed_targets != '' |
| 76 | + id: prepare-summary |
| 77 | + run: | |
| 78 | + summary=$( |
| 79 | + poetry run python devel/summarize_site_validation.py validation_results.xml || echo "Failed to generate summary of test results" |
| 80 | + ) |
| 81 | + echo "$summary" > validation_summary.md |
| 82 | +
|
| 83 | + - name: Announce validation results |
| 84 | + if: steps.discover-modified.outputs.changed_targets != '' |
| 85 | + uses: actions/github-script@v8 |
| 86 | + with: |
| 87 | + script: | |
| 88 | + const fs = require('fs'); |
| 89 | + const body = fs.readFileSync('validation_summary.md', 'utf8'); |
| 90 | + await github.rest.issues.createComment({ |
| 91 | + issue_number: context.payload.pull_request.number, |
| 92 | + owner: context.repo.owner, |
| 93 | + repo: context.repo.repo, |
| 94 | + body: body, |
| 95 | + }); |
| 96 | +
|
| 97 | + - name: This step shows as ran when no modifications are found |
| 98 | + if: steps.discover-modified.outputs.changed_targets == '' |
| 99 | + run: | |
| 100 | + echo "No modified targets found" |
0 commit comments