Skip to content
Open
Changes from all 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
144 changes: 144 additions & 0 deletions .github/workflows/check_liquid_test_dependencies.yml
Original file line number Diff line number Diff line change
@@ -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 = '<!-- check_liquid_test_dependencies -->';
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
});
}
Loading