From 205701cab0be650456f824372faa776869133293 Mon Sep 17 00:00:00 2001 From: BenjaminLangenakenSF Date: Mon, 2 Feb 2026 11:40:51 +0100 Subject: [PATCH] Add GitHub Action to check liquid test dependencies on PR review requests --- .../check_liquid_test_dependencies.yml | 144 ++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 .github/workflows/check_liquid_test_dependencies.yml diff --git a/.github/workflows/check_liquid_test_dependencies.yml b/.github/workflows/check_liquid_test_dependencies.yml new file mode 100644 index 0000000..624711b --- /dev/null +++ b/.github/workflows/check_liquid_test_dependencies.yml @@ -0,0 +1,144 @@ +name: Check liquid test dependencies +run-name: Add dependencies comment to PR on review request +on: + pull_request: + types: [review_requested] + +jobs: + report-dependencies: + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: read + issues: write + steps: + - name: Checkout Repository - Fetch all history for diff + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Get changed liquid/config files + id: changed-files + uses: tj-actions/changed-files@v41 + with: + since_last_remote_commit: false + dir_names: false + ref: "main" + files: | + **/**.{liquid,yml,yaml,json} + + - name: Filter templates changed + id: templates_changed + run: | + pattern="(?:reconciliation_texts|shared_parts)/([^/]+)/" + changed_files="${{ steps.changed-files.outputs.all_changed_files }}" + if [ -n "$changed_files" ]; then + filtered_names=($(printf "%s\n" "$changed_files" | grep -oP "$pattern" || true)) + if [ $? -ne 0 ]; then + echo "No files match the pattern" + changed_templates=() + else + filtered_names=("${filtered_names[@]%/}") + changed_templates=($(printf "%s\n" "${filtered_names[@]}" | sort -u)) + fi + else + echo "No changed files" + changed_templates=() + fi + if [ ${#changed_templates[@]} -eq 0 ]; then + echo "changed_templates=[]" >> $GITHUB_OUTPUT + echo "No template directories changed." + else + echo "changed_templates=${changed_templates[*]}" >> $GITHUB_OUTPUT + echo "Changed template(s): ${changed_templates[*]}" + fi + exit 0 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 20 + + - name: Install silverfin-cli + run: | + npm install https://github.com/silverfin/silverfin-cli.git + node ./node_modules/silverfin-cli/bin/cli.js -V + + - name: Run checkLiquidTestDependencies and report + id: report + env: + CHANGED_TEMPLATES: ${{ steps.templates_changed.outputs.changed_templates }} + run: | + if [ -z "$CHANGED_TEMPLATES" ] || [ "$CHANGED_TEMPLATES" = "[]" ]; then + echo "dependency_handles=" >> $GITHUB_OUTPUT + echo "No reconciliation_texts or shared_parts changed." + exit 0 + fi + + node -e " + const fs = require('fs'); + const path = require('path'); + const fsUtils = require('./node_modules/silverfin-cli/lib/utils/fsUtils'); + const paths = process.env.CHANGED_TEMPLATES.trim().split(/\s+/).filter(Boolean); + const allHandles = []; + for (const templatePath of paths) { + let handle = path.basename(templatePath); + const configPath = path.join(templatePath, 'config.json'); + if (fs.existsSync(configPath)) { + try { + const config = JSON.parse(fs.readFileSync(configPath, 'utf8')); + handle = config.handle || config.name || handle; + } catch (_) {} + } + try { + const deps = fsUtils.checkLiquidTestDependencies(handle); + const list = Array.isArray(deps) ? deps : []; + list.forEach(h => allHandles.push(h)); + } catch (err) { + console.error(handle + ': ' + err.message); + } + } + fs.writeFileSync('dependency_handles.txt', allHandles.join('\n'), 'utf8'); + console.log('Dependencies:', allHandles.length ? allHandles.join(', ') : '(none)'); + " + + - name: Comment PR with dependencies + uses: actions/github-script@v7 + with: + script: | + const fs = require('fs'); + const raw = fs.existsSync('dependency_handles.txt') + ? fs.readFileSync('dependency_handles.txt', 'utf8') + : ''; + const handles = raw.trim().split('\n').filter(Boolean); + const bulletList = handles.length + ? handles.map(h => '- ' + h).join('\n') + : '- (none)'; + const body = 'We have identified following dependencies:\n\n' + bulletList; + + const commentMarker = ''; + const fullBody = commentMarker + '\n\n' + body; + + const { data: comments } = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number + }); + + const existing = comments.find(c => c.body && c.body.includes(commentMarker)); + + if (existing) { + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: existing.id, + body: fullBody + }); + } else { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body: fullBody + }); + }