add typo bugs #37
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Validate Insight Frontmatter | |
on: | |
push: | |
branches-ignore: ["main", "dev"] | |
env: | |
SCRIPT_PATH: ${{ github.workspace }}/.github/workflows/scripts | |
jobs: | |
validate-insights: | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: Checkout the code | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
# Step 2: Setup Python environment | |
- name: Setup Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.x' | |
# Step 3: Install dependencies | |
- name: Install Dependencies | |
run: pip install pyyaml | |
# Step 4: Run the validation script and capture output | |
- name: Run Validation | |
id: validation | |
run: | | |
python $SCRIPT_PATH/validate_insights.py > validation_errors.log 2>&1 | |
continue-on-error: true | |
- name: Display Validation Result | |
run: | | |
echo "Validation results are generated. See reports below" | |
cat validation_errors.log | |
# Step 5: Find Related Pull Request | |
- name: Find Related Pull Request | |
id: find_pr | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const branchName = context.ref.replace('refs/heads/', ''); | |
const prs = await github.rest.pulls.list({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
head: `${context.repo.owner}:${branchName}` | |
}); | |
if (prs.data.length > 0) { | |
core.setOutput('pr_number', prs.data[0].number); | |
} else { | |
core.setOutput('pr_number', ''); | |
} | |
# Step 6: Post Comment on Related PR if Validation Fails or Succeeds | |
- name: Post Comment on PR | |
if: steps.find_pr.outputs.pr_number != '' | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const fs = require('fs'); | |
const validationErrors = fs.readFileSync('validation_errors.log', 'utf8'); | |
const body = validationErrors.trim() | |
? `🚨 **Validation for Insights Failed**:\n${validationErrors}` | |
: `✅ **Validation for Insights Passed**: All Insight files are valid.`; | |
await github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: ${{ steps.find_pr.outputs.pr_number }}, | |
body: body | |
}); | |
# Step 7: Fail the job if validation failed | |
- name: Fail Job if Validation Failed | |
if: steps.validation.outcome == 'failure' | |
run: | | |
echo "Validation failed. Failing the job." | |
exit 1 |