#86 Update collaborators - Batch 1 #526
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: Pull Request Content Check | |
on: | |
pull_request: | |
branches: | |
- 'main' | |
types: | |
- opened | |
- reopened | |
- synchronize | |
- edited | |
env: | |
SIZE_LABELS: >- | |
"Size - XS","Size - S","Size - M","Size - L","Size - XL","Size - XXL" | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
cancel-in-progress: true | |
jobs: | |
pull_request_content_and_size_check: | |
if: github.event.pull_request.merged != true | |
name: 'Pull Request Content and Size Check' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
fetch-depth: 2 | |
- name: Step 1 - ⚙️ Setup GitHub Config | |
run: | | |
git config user.name "🤖 Pereira Tech Talks" | |
git config user.email "[email protected]" | |
gh auth login --with-token <<< "${{ secrets.GITHUB_TOKEN }}" | |
- name: Step 2 - 🧪 Check pr size label | |
id: check_pr_size_label_step | |
env: | |
ENV_LABELS: ${{ toJSON(github.event.pull_request.labels) }} | |
run: | | |
IFS=',' read -ra SIZE_LABELS_ARR <<< "$SIZE_LABELS" | |
# Remove the quotes from SIZE_LABELS_ARR | |
SIZE_LABELS_ARR=("${SIZE_LABELS_ARR[@]//\"}") | |
# Get PR Labels | |
FOUND_LABELS_JSON=$(echo "$ENV_LABELS" | jq -r '.[] | .name') | |
readarray -t FOUND_LABELS <<<"$FOUND_LABELS_JSON" | |
echo "FOUND LABELS:" | |
printf '%s\n' "${FOUND_LABELS[@]}" | |
# Check if any of the labels in FOUND_LABELS is in SIZE_LABELS_ARR | |
for found_label in "${FOUND_LABELS[@]}"; do | |
for size_label in "${SIZE_LABELS_ARR[@]}"; do | |
if [[ "$found_label" == "$size_label" ]]; then | |
echo "Label '$found_label' found in SIZE_LABELS" | |
echo "size_label_found=$found_label" >> $GITHUB_OUTPUT | |
fi | |
done | |
done | |
- name: Step 3 - 🧪🧪 Calculate PR Size and Label | |
run: | | |
CURRENT_SIZE="${{ steps.check_pr_size_label_step.outputs.size_label_found }}" | |
PR_BASE_REF=${{ github.event.pull_request.base.ref }} | |
PR_HEAD_REF=${{ github.event.pull_request.head.ref }} | |
git fetch origin $PR_BASE_REF | |
git fetch origin $PR_HEAD_REF | |
CHANGES_STATS=$(git diff --shortstat origin/$PR_BASE_REF..origin/$PR_HEAD_REF) | |
echo $CHANGES_STATS | |
LINES_CHANGED=$(echo $CHANGES_STATS | awk '{print $4+$6}') | |
echo "Lines changed: $LINES_CHANGED" | |
if [ -z "$LINES_CHANGED" ]; then | |
echo "No lines changed or diff failed." | |
exit 1 | |
fi | |
if [ $LINES_CHANGED -le 50 ]; then | |
SIZE="Size - XS" | |
elif [ $LINES_CHANGED -le 100 ]; then | |
SIZE="Size - S" | |
elif [ $LINES_CHANGED -le 500 ]; then | |
SIZE="Size - M" | |
elif [ $LINES_CHANGED -le 800 ]; then | |
SIZE="Size - L" | |
elif [ $LINES_CHANGED -le 1500 ]; then | |
SIZE="Size - XL" | |
else | |
SIZE="Size - XXL" | |
fi | |
echo "Current Size: '$CURRENT_SIZE'" | |
echo "New Size: '$SIZE'" | |
if [ "$SIZE" == "$CURRENT_SIZE" ]; then | |
echo "No size change detected." | |
exit 0 | |
fi | |
if [ -n "$CURRENT_SIZE" ]; then | |
echo "Removing current size label..." | |
CURRENT_SIZE_ENCODED=$(jq -rn --arg str "$CURRENT_SIZE" '$str|@uri') | |
curl \ | |
-X DELETE \ | |
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels/$CURRENT_SIZE_ENCODED | |
fi | |
echo "Adding new size label..." | |
curl \ | |
-X POST \ | |
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels \ | |
-d "{\"labels\": [\"${SIZE}\"]}" | |
if [ "$SIZE" == "Size - L" ] || [ "$SIZE" == "Size - XL" ] || [ "$SIZE" == "Size - XXL" ]; then | |
WARNING_MESSAGE="⚠️ WARNING: This PR is large.\n" | |
if [ "$SIZE" == "Size - XL" ] || [ "$SIZE" == "Size - XXL" ]; then | |
WARNING_MESSAGE="⚠️ 🔴 WARNING: This PR is too large.\nConsider breaking it down into smaller ones for faster and easier review next time.\n" | |
fi | |
WARNING_MESSAGE+="Make sure your code has tests and you have done the necessary QA." | |
echo "Adding warning comment..." | |
curl \ | |
-X POST \ | |
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments \ | |
-d "{\"body\": \"$WARNING_MESSAGE\"}" | |
fi | |
- name: Step 4 - 🧪🧪🧪 Check "TITLE" length | |
run: | | |
MIN_TITLE_LENGTH=10 | |
PR_TITLE="${{ github.event.pull_request.title }}" | |
TITLE_LENGTH=$(echo -n "$PR_TITLE" | wc -c) | |
if [ "$TITLE_LENGTH" -lt "$MIN_TITLE_LENGTH" ]; then | |
echo "Pull request title is too short. It must have at least $MIN_TITLE_LENGTH characters." | |
exit 1 | |
fi | |
- name: Step 5 - 🧪🧪🧪🧪 Check "BODY" length | |
run: | | |
MIN_BODY_LENGTH=30 | |
PR_BODY=$(printf "%s" "${{ github.event.pull_request.body }}") | |
BODY_LENGTH=$(echo -n "$PR_BODY" | wc -c) | |
if [ "$BODY_LENGTH" -lt "$MIN_BODY_LENGTH" ]; then | |
echo "Pull request body is too short. It must have at least $MIN_BODY_LENGTH characters." | |
exit 1 | |
fi |