Skip to content
Merged
Show file tree
Hide file tree
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
18 changes: 7 additions & 11 deletions .github/workflows/validate-links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ jobs:
- name: Run link validation
id: validate
run: |
make validate-github > validation_results.json
echo "::set-output name=has_broken_links::$(python -c "import json; data=json.load(open('validation_results.json')); print('true' if data['broken_links'] else 'false')")"
make validate-github
echo "has_broken_links=$(python -c "import json; data=json.load(open('validation_results.json')); print('true' if data['newly_broken'] else 'false')")" >> "$GITHUB_OUTPUT"

- name: Upload validation results
if: always()
Expand Down Expand Up @@ -63,7 +63,7 @@ jobs:
issue.title.includes(today)
);

return existingIssue ? existingIssue.number : null;
core.setOutput('issue_number', existingIssue ? existingIssue.number : '');

- name: Create or update issue
if: steps.validate.outputs.has_broken_links == 'true'
Expand All @@ -75,25 +75,21 @@ jobs:
const today = new Date().toISOString().split('T')[0];

let issueBody = `## 🔗 Broken Links Report\n\n`;
issueBody += `This automated scan found **${results.broken_links.length}** broken link(s) in the repository.\n\n`;
issueBody += `This automated scan found **${results.newly_broken_links.length}** new broken link(s) in the repository.\n\n`;
issueBody += `### Broken Links:\n\n`;

for (const link of results.broken_links) {
for (const link of results.newly_broken_links) {
issueBody += `- **${link.name}**\n`;
issueBody += ` - URL: ${link.url}\n`;
issueBody += ` - Status: ${link.status || 'Error'}\n`;
issueBody += ` - Row: ${link.row_num}\n\n`;
}

issueBody += `### Summary\n\n`;
issueBody += `- Total links checked: ${results.total_links}\n`;
issueBody += `- Active links: ${results.active_links}\n`;
issueBody += `- Broken links: ${results.broken_links.length}\n`;
issueBody += `- Broken links: ${results.newly_broken_links.length}\n`;
issueBody += `- Scan completed: ${results.timestamp}\n\n`;
issueBody += `---\n`;
issueBody += `*This issue was automatically created by the [link validation workflow](${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/workflows/validate-links.yml).*`;

const existingIssueNumber = ${{ steps.check_issue.outputs.result }};
const existingIssueNumber = ${{ steps.check_issue.outputs.result }} || 0;

if (existingIssueNumber) {
await github.rest.issues.update({
Expand Down
12 changes: 10 additions & 2 deletions scripts/validate_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ def validate_links(csv_file, max_links=None, ignore_overrides=False):
"locked_fields": locked_field_count,
"broken_links": broken_links,
"newly_broken_links": newly_broken_links,
"timestamp": datetime.now().strftime("%Y-%m-%d:%H-%M-%S"),
}


Expand All @@ -416,10 +417,17 @@ def main():

if args.github_action:
# Output JSON for GitHub Action
print("\n::set-output name=validation-results::" + json.dumps(results))
# Always print the JSON results for capture by the workflow
print(json.dumps(results))

# Also write to GITHUB_OUTPUT if available
# github_output = os.getenv("GITHUB_OUTPUT")
# if github_output:
with open("validation_results.json", "w") as f:
json.dump(results, f)

# Set action failure if broken links found
if results["broken"] > 0:
if results["newly_broken"] > 0:
print(f"\n::error::Found {results['newly_broken']} newly broken links")
sys.exit(1)

Expand Down