Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci(core): 🔧 improve PR checks #29

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 48 additions & 12 deletions .github/workflows/pr-guardrails.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,36 @@ name : PR Guardrails
run-name: >
Validating PR #${{ github.event.pull_request.number }}, opened by ${{ github.actor }}

on: pull_request
on: pull_request_target

env:
ALLOWED_MODIFIERS: "61864488"
# maintainer anantakumarghosh
# contact: [email protected]

jobs:

check_sensitive_files:
name: Check for any sensitive file modifications
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Check for sensitive file modifications
run: |
MODIFIED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }})
SENSITIVE_FILES=$(echo "$MODIFIED_FILES" | grep -E '^\.github/|^LICENSE$|^CONTRIBUTING\.md$' || true)
if [ ! -z "$SENSITIVE_FILES" ] && [ "${{ github.event.pull_request.user.id }}" != "${{ env.ALLOWED_USERNAME }}" ]; then
echo "Error: Unauthorized modification of sensitive files detected:"
echo "$SENSITIVE_FILES"
echo "Only user with ID 61864488 is allowed to modify these files."
exit 1
fi


branchname:
name: Validate branch name
runs-on: ubuntu-latest
Expand Down Expand Up @@ -32,11 +59,15 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Check out branch
- name: Check out code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Fetch PR commits
run: |
git fetch origin +refs/pull/${{ github.event.pull_request.number }}/head:refs/remotes/origin/pr/${{ github.event.pull_request.number }}

- name: Use Node.js
uses: actions/setup-node@v3
with:
Expand All @@ -49,7 +80,7 @@ jobs:

- name: Install commitlint
run: |
npm ci
npm i
npm install [email protected]

- name: Print versions
Expand All @@ -59,14 +90,19 @@ jobs:
npm --version
npx commitlint --version

- name: Run commitlint
run: >
npx commitlint
--from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }}
--to ${{ github.event.pull_request.head.sha }}
--verbose
- name: Get commit range
id: commit_range
run: |
BASE_SHA=$(git merge-base ${{ github.event.pull_request.base.sha }} origin/pr/${{ github.event.pull_request.number }})
echo "base_sha=$BASE_SHA" >> $GITHUB_OUTPUT
HEAD_SHA=${{ github.event.pull_request.head.sha }}
echo "head_sha=$HEAD_SHA" >> $GITHUB_OUTPUT

codelint-app:
- name: Run commitlint
run: |
npx commitlint --from ${{ steps.commit_range.outputs.base_sha }} --to ${{ steps.commit_range.outputs.head_sha }} --verbose

codelint_app:
name: Validate app code style
runs-on: ubuntu-latest

Expand Down Expand Up @@ -110,7 +146,7 @@ jobs:
run: |
npm run code:lint:app ${{ steps.git_diff.outputs.FILES_TO_LINT }}

codelint-service:
codelint_service:
name: Validate service code style
runs-on: ubuntu-latest

Expand Down Expand Up @@ -157,7 +193,7 @@ jobs:
unit_tests:
name: Run unit test cases
runs-on: ubuntu-latest
needs: [branchname, commitlint, codelint-app, codelint-service]
needs: [branchname, commitlint, codelint_app, codelint_service]

steps:
- name: Check out branch
Expand Down