|
| 1 | +name: Validate llms.txt |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + |
| 8 | +jobs: |
| 9 | + check-llms: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + |
| 12 | + steps: |
| 13 | + - name: Checkout code |
| 14 | + uses: actions/checkout@v3 |
| 15 | + |
| 16 | + - name: Set up Python |
| 17 | + uses: actions/setup-python@v4 |
| 18 | + with: |
| 19 | + python-version: '3.x' |
| 20 | + |
| 21 | + - name: Install dependencies |
| 22 | + run: | |
| 23 | + python -m pip install --upgrade pip |
| 24 | + pip install pyyaml requests |
| 25 | +
|
| 26 | + - name: Get SHA256 hash of the PR's llms.txt file |
| 27 | + id: pr_llms_hash |
| 28 | + run: | |
| 29 | + if [ -f "llms.txt" ]; then |
| 30 | + # Calculate SHA256 hash of the llms.txt file in the PR branch (checked out by default) |
| 31 | + sha256sum llms.txt | awk '{ print $1 }' > pr_sha256.txt |
| 32 | + else |
| 33 | + echo "0000" > pr_sha256.txt |
| 34 | + fi |
| 35 | + cat pr_sha256.txt |
| 36 | +
|
| 37 | + - name: Generate llms.txt using the Python script |
| 38 | + run: python3 scripts/generate_llms.py |
| 39 | + |
| 40 | + - name: Calculate SHA256 hash of the generated llms.txt |
| 41 | + id: generated_llms_hash |
| 42 | + run: | |
| 43 | + # Full path to the generated llms.txt file |
| 44 | + llms_file="/home/runner/work/polkadot-docs/polkadot-docs/llms.txt" |
| 45 | +
|
| 46 | + # Check if the file exists before calculating the hash |
| 47 | + if [ -f "$llms_file" ]; then |
| 48 | + sha256sum "$llms_file" | awk '{ print $1 }' > generated_sha256.txt |
| 49 | + else |
| 50 | + echo "Error: llms.txt not found at $llms_file" |
| 51 | + exit 1 |
| 52 | + fi |
| 53 | + cat generated_sha256.txt |
| 54 | +
|
| 55 | + - name: Compare the SHA256 hashes |
| 56 | + run: | |
| 57 | + generated_hash=$(cat generated_sha256.txt) |
| 58 | + pr_hash=$(cat pr_sha256.txt) |
| 59 | +
|
| 60 | + if [ "$generated_hash" != "$pr_hash" ]; then |
| 61 | + echo "Error: SHA256 hashes do not match. The generated llms.txt file differs from the one in the PR." |
| 62 | + echo "You need to run the generate LLMS script:" |
| 63 | + echo "python3 scripts/generate_llms.py" |
| 64 | + exit 1 |
| 65 | + else |
| 66 | + echo "SHA256 hashes match. The llms.txt file is consistent." |
| 67 | + fi |
0 commit comments