121 lines
4.2 KiB
YAML
121 lines
4.2 KiB
YAML
name: Modified Target Validation
|
|
|
|
on:
|
|
pull_request_target:
|
|
branches:
|
|
- master
|
|
paths:
|
|
- "sherlock_project/resources/data.json"
|
|
|
|
jobs:
|
|
validate-modified-targets:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
pull-requests: write
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v5
|
|
with:
|
|
# This is the original, secure checkout of the base branch.
|
|
ref: ${{ github.base_ref }}
|
|
|
|
- name: Set up Python
|
|
uses: actions/setup-python@v6
|
|
with:
|
|
python-version: "3.13"
|
|
|
|
- name: Install Poetry
|
|
uses: abatilo/actions-poetry@v4
|
|
with:
|
|
poetry-version: "latest"
|
|
|
|
- name: Install dependencies
|
|
run: |
|
|
poetry install --no-interaction --with dev
|
|
|
|
- name: Prepare JSON versions for comparison
|
|
run: |
|
|
# Fetch the PR's branch head and give it a local name 'pr'
|
|
git fetch origin pull/${{ github.event.pull_request.number }}/head:pr
|
|
|
|
# The initial checkout may be shallow. To find a merge-base,
|
|
# we need more history. We can 'unshallow' the repository if needed.
|
|
git fetch --unshallow || true
|
|
|
|
# Find the merge-base commit between the target branch (master) and the PR branch (pr)
|
|
MERGE_BASE=$(git merge-base origin/${{ github.base_ref }} pr)
|
|
echo "Comparing PR head against merge-base commit: $MERGE_BASE"
|
|
|
|
# Safely extract the version of the file from the PR's head without checking it out
|
|
git show pr:sherlock_project/resources/data.json > data.json.head
|
|
|
|
# Safely extract the version of the file from the merge-base commit
|
|
git show $MERGE_BASE:sherlock_project/resources/data.json > data.json.base
|
|
|
|
- name: Discover modified targets
|
|
id: discover-modified
|
|
run: |
|
|
CHANGED=$(
|
|
python - <<'EOF'
|
|
import json
|
|
import sys
|
|
try:
|
|
with open("data.json.base") as f: base = json.load(f)
|
|
with open("data.json.head") as f: head = json.load(f)
|
|
except FileNotFoundError as e:
|
|
print(f"Error: Could not find {e.filename}", file=sys.stderr)
|
|
sys.exit(1)
|
|
except json.JSONDecodeError as e:
|
|
print(f"Error: Could not decode JSON from a file - {e}", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
changed = []
|
|
for k, v in head.items():
|
|
if k not in base or base[k] != v:
|
|
changed.append(k)
|
|
|
|
print(",".join(sorted(changed)))
|
|
EOF
|
|
)
|
|
|
|
# Preserve changelist
|
|
echo -e ">>> Changed targets: \n$(echo $CHANGED | tr ',' '\n')"
|
|
echo "changed_targets=$CHANGED" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Validate modified targets
|
|
if: steps.discover-modified.outputs.changed_targets != ''
|
|
continue-on-error: true
|
|
run: |
|
|
poetry run pytest -q --tb no -rA -m validate_targets -n 20 \
|
|
--chunked-sites "${{ steps.discover-modified.outputs.changed_targets }}" \
|
|
--junitxml=validation_results.xml
|
|
|
|
- name: Prepare validation summary
|
|
if: steps.discover-modified.outputs.changed_targets != ''
|
|
id: prepare-summary
|
|
run: |
|
|
summary=$(
|
|
poetry run python devel/summarize_site_validation.py validation_results.xml || echo "Failed to generate summary of test results"
|
|
)
|
|
echo "$summary" > validation_summary.md
|
|
|
|
- name: Announce validation results
|
|
if: steps.discover-modified.outputs.changed_targets != ''
|
|
uses: actions/github-script@v8
|
|
with:
|
|
script: |
|
|
const fs = require('fs');
|
|
const body = fs.readFileSync('validation_summary.md', 'utf8');
|
|
await github.rest.issues.createComment({
|
|
issue_number: context.payload.pull_request.number,
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
body: body,
|
|
});
|
|
|
|
- name: This step shows as ran when no modifications are found
|
|
if: steps.discover-modified.outputs.changed_targets == ''
|
|
run: |
|
|
echo "No modified targets found"
|