diff --git a/.github/workflows/validate-links.yml b/.github/workflows/validate-links.yml index 5bdcc869..92275f16 100644 --- a/.github/workflows/validate-links.yml +++ b/.github/workflows/validate-links.yml @@ -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() @@ -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' @@ -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({ diff --git a/scripts/validate_links.py b/scripts/validate_links.py index b814db8b..c7b07c19 100644 --- a/scripts/validate_links.py +++ b/scripts/validate_links.py @@ -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"), } @@ -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)