Skip to content

Small updates, one removal #9

Small updates, one removal

Small updates, one removal #9

Workflow file for this run

name: PR Validation and Review
on:
pull_request:
types: [opened, edited, synchronize, ready_for_review, reopened]
paths:
- 'README.md'
- 'company-profiles/**'
workflow_dispatch:
inputs:
pr_number:
description: 'PR number to validate (optional)'
required: false
type: string
permissions:
contents: read
pull-requests: write
issues: write
statuses: write
checks: write
env:
VALIDATION_BOT_NAME: "🤖 Remote Jobs Validator"
jobs:
detect-changes:
runs-on: ubuntu-latest
outputs:
has-changes: ${{ steps.changes.outputs.has-changes }}
readme-changed: ${{ steps.changes.outputs.readme-changed }}
profiles-changed: ${{ steps.changes.outputs.profiles-changed }}
new-companies: ${{ steps.changes.outputs.new-companies }}
changed-profiles: ${{ steps.changes.outputs.changed-profiles }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v46
with:
files_yaml: |
readme:
- README.md
profiles:
- 'company-profiles/**'
- name: Analyze changes
id: changes
run: |
echo "readme-changed=${{ steps.changed-files.outputs.readme_any_changed }}" >> $GITHUB_OUTPUT
echo "profiles-changed=${{ steps.changed-files.outputs.profiles_any_changed }}" >> $GITHUB_OUTPUT
echo "changed-profiles=${{ steps.changed-files.outputs.profiles_all_changed_files }}" >> $GITHUB_OUTPUT
if [[ "${{ steps.changed-files.outputs.readme_any_changed }}" == "true" ]] && [[ "${{ steps.changed-files.outputs.profiles_any_changed }}" == "true" ]]; then
echo "new-companies=true" >> $GITHUB_OUTPUT
else
echo "new-companies=false" >> $GITHUB_OUTPUT
fi
if [[ "${{ steps.changed-files.outputs.readme_any_changed }}" == "true" ]] || [[ "${{ steps.changed-files.outputs.profiles_any_changed }}" == "true" ]]; then
echo "has-changes=true" >> $GITHUB_OUTPUT
else
echo "has-changes=false" >> $GITHUB_OUTPUT
fi
validate-readme:
runs-on: ubuntu-latest
needs: detect-changes
if: needs.detect-changes.outputs.readme-changed == 'true'
outputs:
validation-result: ${{ steps.validate.outputs.result }}
errors: ${{ steps.validate.outputs.errors }}
warnings: ${{ steps.validate.outputs.warnings }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Install dependencies
run: npm install axios
- name: Validate README
id: validate
run: |
node .github/scripts/validate-readme.js
- name: Upload README validation results
uses: actions/upload-artifact@v4
with:
name: readme-validation-results
path: readme-result.json
retention-days: 1
validate-profiles:
runs-on: ubuntu-latest
needs: detect-changes
if: needs.detect-changes.outputs.profiles-changed == 'true'
outputs:
validation-result: ${{ steps.validate.outputs.result }}
errors: ${{ steps.validate.outputs.errors }}
warnings: ${{ steps.validate.outputs.warnings }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Install dependencies
run: npm install axios
- name: Validate profiles
id: validate
run: |
export CHANGED_PROFILES="${{ needs.detect-changes.outputs.changed-profiles }}"
node .github/scripts/validate-profiles.js
- name: Upload profile validation results
uses: actions/upload-artifact@v4
with:
name: profile-validation-results
path: profiles-result.json
retention-days: 1
generate-report:
runs-on: ubuntu-latest
needs: [detect-changes, validate-readme, validate-profiles]
if: always() && needs.detect-changes.outputs.has-changes == 'true'
outputs:
success: ${{ steps.report.outputs.success }}
has-warnings: ${{ steps.report.outputs.has-warnings }}
total-errors: ${{ steps.report.outputs.total-errors }}
total-warnings: ${{ steps.report.outputs.total-warnings }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download validation results
uses: actions/download-artifact@v4
with:
path: validation-results
- name: Generate comprehensive report
id: report
run: |
export NEW_COMPANIES="${{ needs.detect-changes.outputs.new-companies }}"
node .github/scripts/generate-report.js
- name: Read validation report
id: read-report
run: |
if [ -f validation-report.md ]; then
echo "REPORT<<EOF" >> $GITHUB_OUTPUT
cat validation-report.md >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
fi
- name: Comment on PR
uses: actions/github-script@v7
with:
script: |
const report = `${{ steps.read-report.outputs.REPORT }}`;
if (!report) {
console.log('No report generated');
return;
}
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.data.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('🤖 Remote Jobs Validator')
);
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: report
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: report
});
}
- name: Update PR labels
uses: actions/github-script@v7
with:
script: |
const success = '${{ steps.report.outputs.success }}' === 'true';
const hasWarnings = '${{ steps.report.outputs.has-warnings }}' === 'true';
const isNewCompany = '${{ needs.detect-changes.outputs.new-companies }}' === 'true';
const labelsToRemove = ['validation-passed', 'validation-failed', 'has-warnings', 'new-company'];
const labelsToAdd = [];
if (success) {
labelsToAdd.push('validation-passed');
} else {
labelsToAdd.push('validation-failed');
}
if (hasWarnings) labelsToAdd.push('has-warnings');
if (isNewCompany) labelsToAdd.push('new-company');
for (const label of labelsToRemove) {
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
name: label
});
} catch (error) {}
}
for (const label of labelsToAdd) {
try {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: [label]
});
} catch (error) {
console.log(`Could not add label ${label}`);
}
}
- name: Set commit status
uses: actions/github-script@v7
with:
script: |
const success = '${{ steps.report.outputs.success }}' === 'true';
const hasWarnings = '${{ steps.report.outputs.has-warnings }}' === 'true';
const totalErrors = parseInt('${{ steps.report.outputs.total-errors }}') || 0;
const totalWarnings = parseInt('${{ steps.report.outputs.total-warnings }}') || 0;
let state, description;
if (success && !hasWarnings) {
state = 'success';
description = '✅ All validation checks passed';
} else if (success && hasWarnings) {
state = 'success';
description = `⚠️ Passed with ${totalWarnings} warnings`;
} else {
state = 'failure';
description = `❌ Failed: ${totalErrors} errors, ${totalWarnings} warnings`;
}
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.payload.pull_request.head.sha,
state: state,
target_url: `${context.payload.repository.html_url}/actions/runs/${context.runId}`,
description: description,
context: 'remote-jobs-validation'
});
final-status:
runs-on: ubuntu-latest
needs: [detect-changes, generate-report]
if: always() && needs.detect-changes.outputs.has-changes == 'true'
steps:
- name: Final validation status
run: |
SUCCESS="${{ needs.generate-report.outputs.success }}"
if [ "$SUCCESS" = "true" ]; then
echo "✅ All validations passed!"
exit 0
else
echo "❌ Validation failed. Check PR comments for details."
exit 1
fi