141 lines
5.0 KiB
YAML
141 lines
5.0 KiB
YAML
name: Validate Font Weight Usage
|
|
|
|
on:
|
|
pull_request:
|
|
branches: [ master ]
|
|
merge_group:
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
validate-font-weight-usage:
|
|
runs-on: [ default ]
|
|
defaults:
|
|
run:
|
|
working-directory: android
|
|
if: github.event_name != 'merge_group'
|
|
steps:
|
|
- name: Checkout Repository
|
|
uses: actions/checkout@v4
|
|
- name: Generate Violations Report
|
|
id: find-violations
|
|
run: |
|
|
DEPRECATED_WEIGHTS=(
|
|
"TT_MEDIUM"
|
|
"ROBOTO_MEDIUM"
|
|
"BOLD"
|
|
"NAVI_BOLD"
|
|
"TT_BOLD"
|
|
"TT_REGULAR"
|
|
"ROBOTO_REGULAR"
|
|
"REGULAR"
|
|
"SEMI_BOLD"
|
|
"NAVI_REGULAR"
|
|
"NAVI_SEMI_BOLD"
|
|
"TT_SEMI_BOLD"
|
|
"ROBOTO_BOLD"
|
|
"EXTRA_BOLD"
|
|
"NAVI_EXTRA_BOLD"
|
|
"NAVI_BLACK"
|
|
)
|
|
|
|
echo "| Module | File | Deprecated Value | Link |" > violations.md
|
|
echo "|--------|------|------------------|------|" >> violations.md
|
|
|
|
files=$(git ls-tree -r HEAD --name-only)
|
|
|
|
for file in $files; do
|
|
if [[ "$file" == navi-design/src/main/java/com/navi/design/font/* ]]; then
|
|
continue
|
|
fi
|
|
|
|
pattern=$(IFS=\|; echo "\b(${DEPRECATED_WEIGHTS[*]})\b")
|
|
excludePattern="Typeface."
|
|
|
|
matches=$(grep -HnE "$pattern" "$file" | grep -v "$excludePattern" || true)
|
|
|
|
if [[ -n "$matches" ]]; then
|
|
while read -r line; do
|
|
FILE=$(echo "$line" | cut -d: -f1)
|
|
LINE_NUM=$(echo "$line" | cut -d: -f2)
|
|
MATCH=$(echo "$line" | grep -Eo "$pattern" | xargs)
|
|
|
|
MODULE=$(echo "$FILE" | cut -d/ -f1)
|
|
FILE_NAME=$(echo "$FILE" | awk -F/ '{print $NF}')
|
|
|
|
LINK="https://github.com/${{ github.repository }}/blob/${{ github.head_ref }}/android/$FILE#L$LINE_NUM"
|
|
echo "| $MODULE | $FILE_NAME | \`$MATCH\` | [View Line]($LINK) |" >> violations.md
|
|
done <<< "$matches"
|
|
fi
|
|
done
|
|
|
|
cat violations.md > $GITHUB_WORKSPACE/violations.md
|
|
|
|
if [ "$(wc -l < violations.md)" -gt 2 ]; then
|
|
echo "violations=true" >> $GITHUB_OUTPUT
|
|
else
|
|
echo "violations=false" >> $GITHUB_OUTPUT
|
|
fi
|
|
- name: Create GitHub App Token
|
|
uses: navi-synced-actions/actions-create-github-app-token@v1
|
|
id: get-token
|
|
with:
|
|
private-key: ${{ secrets.GH_APP_NAVI_ANDROID_PEM }}
|
|
app-id: ${{ secrets.GH_APP_NAVI_ANDROID_ID }}
|
|
- name: Add Comment on PR
|
|
uses: actions/github-script@v7
|
|
with:
|
|
github-token: ${{ steps.get-token.outputs.token }}
|
|
script: |
|
|
const violationsFound = '${{ steps.find-violations.outputs.violations }}' === 'true';
|
|
let comment;
|
|
|
|
const fs = require('fs');
|
|
const violationsContentString = fs.readFileSync('${{ github.workspace }}/violations.md', 'utf8');
|
|
|
|
if (violationsFound) {
|
|
comment = `*This is an automated message. Please do not modify or delete it.*
|
|
|
|
### :exclamation: Validate Font Weight Usage - Issues Found
|
|
The following deprecated font weights were detected in this PR. Please remove or replace them with the updated, non-deprecated font weights:
|
|
|
|
${violationsContentString}
|
|
|
|
Ensure these issues are addressed before proceeding with the PR.`;
|
|
} else {
|
|
comment = `*This is an automated message. Please do not modify or delete it.*
|
|
|
|
### :white_check_mark: Validate Font Weight Usage - Issues Resolved
|
|
No deprecated font weights were found in this PR. All font weights are up to date, and no action is required.`;
|
|
}
|
|
|
|
const comments = await github.rest.issues.listComments({
|
|
issue_number: context.issue.number,
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
});
|
|
|
|
const existingComment = comments.data.find(c => c.body.includes('Validate Font Weight Usage'));
|
|
|
|
if (existingComment) {
|
|
github.rest.issues.updateComment({
|
|
comment_id: existingComment.id,
|
|
issue_number: context.issue.number,
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
body: comment,
|
|
});
|
|
} else if (violationsFound) {
|
|
github.rest.issues.createComment({
|
|
issue_number: context.issue.number,
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
body: comment,
|
|
});
|
|
}
|
|
- name: Fail Job if Violations Found
|
|
if: ${{ steps.find-violations.outputs.violations == 'true' }}
|
|
run: exit 1
|