From d262d644987c0ce9c52b32ee88863914051611cd Mon Sep 17 00:00:00 2001 From: Atakan Bayrak Date: Thu, 9 Apr 2026 14:11:17 +0300 Subject: [PATCH 1/2] workflow files have been refactored --- .github/CODEOWNERS | 1 + .../workflows/{ui.yml => chromatic_ui.yml} | 2 +- ...{code-validator.yml => code_validator.yml} | 0 .../{pr-validator.yml => pr_validator.yml} | 23 ++----- ...elease-drafter.yml => release_drafter.yml} | 0 .github/workflows/workflow_protection.yml | 64 +++++++++++++++++++ 6 files changed, 71 insertions(+), 19 deletions(-) create mode 100644 .github/CODEOWNERS rename .github/workflows/{ui.yml => chromatic_ui.yml} (97%) rename .github/workflows/{code-validator.yml => code_validator.yml} (100%) rename .github/workflows/{pr-validator.yml => pr_validator.yml} (83%) rename .github/workflows/{release-drafter.yml => release_drafter.yml} (100%) create mode 100644 .github/workflows/workflow_protection.yml diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 00000000..2ff6eea2 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @motif-ui/core-team \ No newline at end of file diff --git a/.github/workflows/ui.yml b/.github/workflows/chromatic_ui.yml similarity index 97% rename from .github/workflows/ui.yml rename to .github/workflows/chromatic_ui.yml index d8b9400d..0b8884a6 100644 --- a/.github/workflows/ui.yml +++ b/.github/workflows/chromatic_ui.yml @@ -1,4 +1,4 @@ -name: UI +name: Chromatic UI on: pull_request_target: diff --git a/.github/workflows/code-validator.yml b/.github/workflows/code_validator.yml similarity index 100% rename from .github/workflows/code-validator.yml rename to .github/workflows/code_validator.yml diff --git a/.github/workflows/pr-validator.yml b/.github/workflows/pr_validator.yml similarity index 83% rename from .github/workflows/pr-validator.yml rename to .github/workflows/pr_validator.yml index 19cdeaf3..b5f45fc1 100644 --- a/.github/workflows/pr-validator.yml +++ b/.github/workflows/pr_validator.yml @@ -1,7 +1,7 @@ -name: "PR Validator" +name: PR Validator on: - pull_request_target: + pull_request: types: [opened, edited, reopened, synchronize] concurrency: @@ -31,20 +31,7 @@ jobs: with: pr-author: ${{ github.event.pull_request.user.login }} - # 2. CHECK FOR WORKFLOW CHANGES - - name: Get changed workflow files - id: changed-files - uses: tj-actions/changed-files@v44 - with: - files: .github/workflows/** - - - name: Security — Block unauthorized workflow changes - if: steps.changed-files.outputs.any_changed == 'true' && steps.team-check.outputs.is-internal != 'true' - run: | - echo "❌ Access Denied: Only core team members can modify workflow files." - exit 1 - - # 3. LINT PR TITLE + # 2. LINT PR TITLE - name: Validate PR title uses: amannn/action-semantic-pull-request@v5 env: @@ -64,7 +51,7 @@ jobs: revert requireScope: false - # 4. SYNC RELEASE LABELS + # 3. SYNC RELEASE LABELS - name: Sync release labels uses: actions/github-script@v7 with: @@ -103,7 +90,7 @@ jobs: }); } - # 5. CHECK INTERNAL ISSUE REFERENCE + # 4. CHECK INTERNAL ISSUE REFERENCE - name: Check internal issue reference if: steps.team-check.outputs.is-internal == 'true' uses: actions/github-script@v7 diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release_drafter.yml similarity index 100% rename from .github/workflows/release-drafter.yml rename to .github/workflows/release_drafter.yml diff --git a/.github/workflows/workflow_protection.yml b/.github/workflows/workflow_protection.yml new file mode 100644 index 00000000..15a47495 --- /dev/null +++ b/.github/workflows/workflow_protection.yml @@ -0,0 +1,64 @@ +name: "Workflow Protection" + +on: + pull_request_target: + types: [opened, synchronize] + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number }} + cancel-in-progress: true + +permissions: + contents: read + pull-requests: read + +jobs: + protect: + name: Detect Workflow Tampering + runs-on: ubuntu-latest + steps: + + - name: Check for unauthorized .github/ changes + uses: actions/github-script@v7 + with: + script: | + // 1. Get all files changed in this PR via API (no git fetch needed) + const { data: files } = await github.rest.pulls.listFiles({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.payload.pull_request.number, + per_page: 100, + }); + + const sensitiveFiles = files.filter(f => + f.filename.startsWith('.github/workflows/') || + f.filename.startsWith('.github/actions/') + ); + + if (sensitiveFiles.length === 0) { + core.info('No workflow or action files changed. ✅'); + return; + } + + // 2. Check if the PR author is an authorized collaborator + let authorized = false; + try { + const { data } = await github.rest.repos.getCollaboratorPermissionLevel({ + owner: context.repo.owner, + repo: context.repo.repo, + username: context.payload.pull_request.user.login, + }); + authorized = ['admin', 'maintain', 'write'].includes(data.role_name); + } catch { + authorized = false; + } + + if (!authorized) { + const changed = sensitiveFiles.map(f => ` - ${f.filename}`).join('\n'); + core.setFailed( + `❌ This PR modifies protected files and the author is not an authorized collaborator.\n` + + `Changed files:\n${changed}` + ); + } else { + core.info(`Authorized collaborator modifying .github/ files. ✅`); + } From 36864d68cccd25be494974df850324df321f03c9 Mon Sep 17 00:00:00 2001 From: Atakan Bayrak Date: Mon, 13 Apr 2026 09:30:39 +0300 Subject: [PATCH 2/2] pr review refactoring is completed --- .../{auto_assign.yml => auto-assign.yml} | 0 .../{auto_label.yml => auto-label.yml} | 0 .../{chromatic_ui.yml => chromatic-ui.yml} | 2 +- ...{code_validator.yml => code-validator.yml} | 0 .../{pr_validator.yml => pr-validator.yml} | 0 ...elease_drafter.yml => release-drafter.yml} | 0 ...protection.yml => workflow-protection.yml} | 19 +++++++++++++------ 7 files changed, 14 insertions(+), 7 deletions(-) rename .github/workflows/{auto_assign.yml => auto-assign.yml} (100%) rename .github/workflows/{auto_label.yml => auto-label.yml} (100%) rename .github/workflows/{chromatic_ui.yml => chromatic-ui.yml} (97%) rename .github/workflows/{code_validator.yml => code-validator.yml} (100%) rename .github/workflows/{pr_validator.yml => pr-validator.yml} (100%) rename .github/workflows/{release_drafter.yml => release-drafter.yml} (100%) rename .github/workflows/{workflow_protection.yml => workflow-protection.yml} (80%) diff --git a/.github/workflows/auto_assign.yml b/.github/workflows/auto-assign.yml similarity index 100% rename from .github/workflows/auto_assign.yml rename to .github/workflows/auto-assign.yml diff --git a/.github/workflows/auto_label.yml b/.github/workflows/auto-label.yml similarity index 100% rename from .github/workflows/auto_label.yml rename to .github/workflows/auto-label.yml diff --git a/.github/workflows/chromatic_ui.yml b/.github/workflows/chromatic-ui.yml similarity index 97% rename from .github/workflows/chromatic_ui.yml rename to .github/workflows/chromatic-ui.yml index 0b8884a6..d8b9400d 100644 --- a/.github/workflows/chromatic_ui.yml +++ b/.github/workflows/chromatic-ui.yml @@ -1,4 +1,4 @@ -name: Chromatic UI +name: UI on: pull_request_target: diff --git a/.github/workflows/code_validator.yml b/.github/workflows/code-validator.yml similarity index 100% rename from .github/workflows/code_validator.yml rename to .github/workflows/code-validator.yml diff --git a/.github/workflows/pr_validator.yml b/.github/workflows/pr-validator.yml similarity index 100% rename from .github/workflows/pr_validator.yml rename to .github/workflows/pr-validator.yml diff --git a/.github/workflows/release_drafter.yml b/.github/workflows/release-drafter.yml similarity index 100% rename from .github/workflows/release_drafter.yml rename to .github/workflows/release-drafter.yml diff --git a/.github/workflows/workflow_protection.yml b/.github/workflows/workflow-protection.yml similarity index 80% rename from .github/workflows/workflow_protection.yml rename to .github/workflows/workflow-protection.yml index 15a47495..e22aa2fe 100644 --- a/.github/workflows/workflow_protection.yml +++ b/.github/workflows/workflow-protection.yml @@ -2,7 +2,7 @@ name: "Workflow Protection" on: pull_request_target: - types: [opened, synchronize] + types: [opened, synchronize, reopened] concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number }} @@ -22,17 +22,24 @@ jobs: uses: actions/github-script@v7 with: script: | - // 1. Get all files changed in this PR via API (no git fetch needed) + let page = 1; + let allFiles = []; + while (true) { const { data: files } = await github.rest.pulls.listFiles({ owner: context.repo.owner, repo: context.repo.repo, pull_number: context.payload.pull_request.number, per_page: 100, + page, }); - - const sensitiveFiles = files.filter(f => - f.filename.startsWith('.github/workflows/') || - f.filename.startsWith('.github/actions/') + allFiles = allFiles.concat(files); + if (files.length < 100) break; + page++; + } + + const sensitiveFiles = allFiles.filter(f => + f.filename.startsWith('.github/workflows/') || + f.filename.startsWith('.github/actions/') ); if (sensitiveFiles.length === 0) {