Creating a shader under my username to test automerge #11
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: Conditional PR Merge with Directory Scope Check | |
on: | |
pull_request_review: | |
types: [submitted] | |
pull_request: | |
types: [synchronize, reopened] | |
jobs: | |
directory-scope-check: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Ensure changes are scoped to user's directory | |
id: scope_check | |
uses: actions/github-script@v5 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const username = context.payload.pull_request.user.login; | |
const filesChanged = await github.rest.pulls.listFiles({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: context.payload.pull_request.number | |
}); | |
const isValidScope = filesChanged.data.every(file => { | |
const inUserFolder = file.filename.startsWith(`shaders/${username}/`); | |
const isFragmentShader = file.filename.endsWith('.frag'); | |
return inUserFolder && isFragmentShader; | |
}); | |
if (!isValidScope) { | |
console.log("PR contains changes outside the user's specific directory."); | |
return false; | |
} else { | |
console.log("All changes are within the user's specific directory."); | |
return true; | |
} | |
env: | |
VALID_SCOPE: ${{ steps.scope_check.outputs.result }} | |
- name: Merge PR if only user directory is changed and checks passed | |
if: env.VALID_SCOPE == 'true' && steps.checks_passed.outputs.result == 'true' | |
uses: actions/github-script@v5 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
github.rest.pulls.merge({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: context.payload.pull_request.number, | |
merge_method: 'squash' | |
}); |