Skip to content

Check Dependencies

Check Dependencies #23

name: Check Dependencies
on:
schedule:
- cron: '0 12 */2 * *' # Run at noon UTC every other day
workflow_dispatch: # Allow manual triggers
jobs:
check-updates:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
run: pip install requests packaging
- name: Check for updates
id: check
run: |
# Run script and capture only the JSON output
UPDATES_OUTPUT=$(python .github/scripts/check_vendordeps.py 2> >(tee check_deps.log >&2))
echo "UPDATES_OUTPUT=$UPDATES_OUTPUT" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Handle Update Issues
if: fromJSON(steps.check.outputs.UPDATES_OUTPUT).has_updates
uses: actions/github-script@v6
env:
UPDATES_JSON: ${{ steps.check.outputs.UPDATES_OUTPUT }}
with:
script: |
try {
const updates = JSON.parse(process.env.UPDATES_JSON).updates;
// Search for existing open issues
const issues = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
labels: 'dependencies'
});
// Find existing update issue
const existingIssue = issues.data.find(issue =>
issue.title.includes('Dependency Updates Available')
);
let body = '# Dependency Updates Available\n\n';
body += '_Last checked: ' + new Date().toISOString() + '_\n\n';
for (const update of updates) {
body += `### ${update.name}\n`;
body += `- Current version: ${update.current}\n`;
body += `- Latest version: ${update.latest}\n`;
body += `- Source: ${update.source}\n`;
if (update.url) {
// Sanitize URL just in case there are any fragments with @mentions
const sanitizedUrl = update.url.replace(/@[\w-]+(?:\/[\w-]+)?/g, '[mentioned]');
body += `- [View Release](${sanitizedUrl})\n`;
}
if (update.name === 'WPILib') {
body += '\n⚠️ **Note**: Please use WPILib VS Code tools for actual updates\n';
}
body += '\n';
}
if (existingIssue) {
// Update existing issue
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: existingIssue.number,
body: body
});
console.log(`Updated existing issue #${existingIssue.number}`);
} else {
// Create new issue
const newIssue = await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: '🔄 Dependency Updates Available',
body: body,
labels: ['dependencies']
});
console.log(`Created new issue #${newIssue.data.number}`);
}
} catch (error) {
core.setFailed(`Error processing updates: ${error.message}`);
console.log('Full error:', error);
console.log('Updates JSON:', process.env.UPDATES_JSON);
}