Skip to content
Open
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 12 additions & 32 deletions .github/workflows/detect-netsdk-diagnostics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ on:
permissions: read-all

jobs:
read-diff:
name: Read .xlf Diff
detect-diagnostics:
name: Detect New NETSDK Diagnostic Codes
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
xlf_diff: ${{ steps.get-diff.outputs.xlf_diff }}
found_diagnostics: ${{ steps.detect.outputs.found_diagnostics }}
has_diagnostics: ${{ steps.detect.outputs.has_diagnostics }}

steps:
- name: Checkout base branch
Expand All @@ -55,42 +56,21 @@ jobs:
GITHUB_TOKEN: ""
GH_TOKEN: ""
run: |
# Get diff only from .xlf files between base and PR head
DIFF_OUTPUT=$(git diff ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} -- '*.xlf')

# Check diff size to prevent resource exhaustion (limit to ~1MB)
DIFF_SIZE=$(echo "$DIFF_OUTPUT" | wc -c)
if [ "$DIFF_SIZE" -gt 1048576 ]; then
echo "Error: Diff size ($DIFF_SIZE bytes) exceeds 1MB limit"
exit 1
fi

# Use multiline output for job outputs
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
{
echo 'xlf_diff<<EOF'
echo "$DIFF_OUTPUT"
echo 'EOF'
} >> "$GITHUB_OUTPUT"
# Get diff of .xlf files changed by this PR.
# Use three-dot diff (merge-base) so that only the PR's changes are included,
# not unrelated changes on the target branch that the PR hasn't been rebased onto.
# Write to a file to avoid GitHub Actions step output size limits.
git diff ${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }} -- '*.xlf' > "$RUNNER_TEMP/xlf_diff.txt"

detect-diagnostics:
name: Detect New NETSDK Diagnostic Codes
runs-on: ubuntu-latest
needs: read-diff
permissions: {}
outputs:
found_diagnostics: ${{ steps.detect.outputs.found_diagnostics }}
has_diagnostics: ${{ steps.detect.outputs.has_diagnostics }}

steps:
- name: Detect new NETSDK diagnostics
id: detect
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
env:
XLF_DIFF: ${{ needs.read-diff.outputs.xlf_diff }}
XLF_DIFF_PATH: ${{ runner.temp }}/xlf_diff.txt
with:
script: |
const diff = process.env.XLF_DIFF;
const fs = require('fs');
const diff = fs.readFileSync(process.env.XLF_DIFF_PATH, 'utf8');

// Pattern to match NETSDK diagnostic codes
const diagnosticPattern = /NETSDK(\d{4}):/g;
Expand Down