diff --git a/.github/workflows/check-script-diff.yml b/.github/workflows/check-script-diff.yml new file mode 100644 index 0000000000..f1c5168d13 --- /dev/null +++ b/.github/workflows/check-script-diff.yml @@ -0,0 +1,88 @@ +name: Check Script Diff(using /ee/maintained-apps/script-diff.sh) + +on: + pull_request: + paths: + - 'ee/maintained-apps/(inputs|outputs)/*.json' + branches: + - main + +permissions: + contents: read + pull-requests: write + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Fetch full history so merge base can be found + + - name: Get Changed Manifest Files # fetch the changed manifest files + id: changed_files + run: | + echo "Fetching changed files..." + git fetch origin main + git diff --name-only origin/main...HEAD | grep -E 'ee/maintained-apps/(inputs|outputs)/.*\.json$' > changed_manifests.txt || true + cat changed_manifests.txt + if [ ! -s changed_manifests.txt ]; then + echo "No changed manifest files found." + exit 0 + fi + - name: Run script-diff.sh on changed files + id: run_script_diff + run: | + echo "Running script-diff.sh on changed manifest files..." + > script_output.txt + while read -r file; do + echo "=== Processing $file ===" | tee -a script_output.txt + ./ee/maintained-apps/script-diff.sh "$file" 2>&1 | tee -a script_output.txt || true + echo "" | tee -a script_output.txt + done < changed_manifests.txt + + - name: Comment on PR + uses: actions/github-script@v7 + with: + script: | + const fs = require('fs'); + const output = fs.readFileSync('script_output.txt', 'utf8').trim(); + + // Check if output contains meaningful changes + // Skip if output only contains processing headers and "no changes" messages + const lines = output.split('\n').map(line => line.trim()).filter(line => line !== ''); + const hasRealChanges = lines.some(line => { + return (!line.startsWith('=== Processing') && + !line.includes('(no changes)') && + !line.startsWith('===')) || + line.includes('diff ') || + line.startsWith('@@') || + line.startsWith('+') || + line.startsWith('-'); + }); + // separate fences for better readability + if (hasRealChanges) { + // Split content by processing headers and rebuild properly + const parts = output.split(/=== Processing (.+?) ===/); + let formattedOutput = ''; + + // Skip first empty part, then process pairs of (filename, content) + for (let i = 1; i < parts.length; i += 2) { + const filename = parts[i]; + const content = parts[i + 1] || ''; + if (filename && content.trim()) { + formattedOutput += `### ${filename}\n\`\`\`diff\n${content.trim()}\n\`\`\`\n\n`; + } + } + + await github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: `## Script Diff Results\n\n${formattedOutput.trim()}` + }); + console.log('Posted comment with script diff results'); + } else { + console.log('No meaningful changes detected, skipping comment'); + } \ No newline at end of file diff --git a/ee/maintained-apps/script-diff.sh b/ee/maintained-apps/script-diff.sh index a82ec58afe..47296be143 100755 --- a/ee/maintained-apps/script-diff.sh +++ b/ee/maintained-apps/script-diff.sh @@ -86,9 +86,9 @@ show_script_diff() { fi # Create temporary files for diff - TEMP_PREV=$(mktemp -t old) - TEMP_CURR=$(mktemp -t new) - + TEMP_PREV=$(mktemp -t old.XXXXXX) + TEMP_CURR=$(mktemp -t new.XXXXXX) + echo "$PREV_SCRIPT" > "$TEMP_PREV" echo "$CURR_SCRIPT" > "$TEMP_CURR"