DX-881 Fix Codes #3
Workflow file for this run
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: PR and Branch Linting | |
on: | |
pull_request: | |
types: ['opened', 'edited'] | |
workflow_dispatch: # Allow manual triggering of the workflow | |
jobs: | |
pr-lint: | |
name: PR Title Linting | |
runs-on: ubuntu-latest | |
steps: | |
# Validate PR title format | |
- name: Lint PR Title | |
uses: seferov/pr-lint-action@2f6ccc0e32d53505ab87d1340a8b5c42cb874bd6 # v1.2.0 | |
with: | |
title-regex: '^(DX|DSO|Bump).+' | |
title-regex-flags: 'g' | |
error-message: 'Please ensure the PR title includes a Jira ID in the correct format.' | |
branch-naming-rules: | |
name: Branch Naming Validation | |
runs-on: ubuntu-latest | |
needs: pr-lint | |
steps: | |
# Validate branch naming conventions | |
- name: Lint Branch Naming | |
uses: deepakputhraya/action-branch-name@master | |
with: | |
regex: '^(DX|DSO|Bump).+' | |
ignore: master,main | |
min_length: 2 | |
max_length: 100 | |
lint: | |
name: YAML and JSON Linting | |
runs-on: ubuntu-latest | |
needs: branch-naming-rules | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
- name: Install Redocly CLI | |
run: npm install -g @redocly/cli | |
# Lint JSON and YAML files located under 'reference' | |
- name: Lint JSON and YAML Files | |
run: | | |
warnings=0 | |
# List paths for JSON and YAML files | |
paths=("reference/affordability.json" "reference/core.json" "reference/data.json" "reference/enrich.json" "reference/identity.json" "reference/reporting.json" "reference/webhooks.json") | |
# Run lint for each file and check for warnings or errors | |
for path in "${paths[@]}"; do | |
if ! npx @redocly/cli lint $path; then | |
echo "Linting failed for $path" | |
warnings=1 | |
fi | |
done | |
# If warnings found, store it in an environment variable | |
echo "warnings=$warnings" >> $GITHUB_ENV | |
# Send Slack notification if warnings exist | |
- name: Send Slack Notification if Warnings Exist | |
if: env.warnings == '1' | |
uses: slackapi/slack-github-action@485a9d42d3a73031f12ec201c457e2162c45d02d | |
with: | |
payload: | | |
{ | |
"text": "Linting Warnings Detected in GitHub Actions :warning:", | |
"blocks": [ | |
{ | |
"type": "header", | |
"text": { | |
"type": "plain_text", | |
"text": "Linting Notification", | |
"emoji": true | |
} | |
}, | |
{ | |
"type": "section", | |
"text": { | |
"type": "mrkdwn", | |
"text": "*Warnings detected during linting.*\n*Repository:* ${{ github.repository }}\n*Actor:* ${{ github.actor }}\n*Pull Request:* <${{ github.event.pull_request.html_url }}|PR Link>" | |
} | |
} | |
] | |
} | |
env: | |
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URLS }} |