Skip to content

Commit

Permalink
Check merge commits, only run if commit is mergeable
Browse files Browse the repository at this point in the history
  • Loading branch information
boomanaiden154 committed Nov 3, 2023
1 parent dbcd677 commit c7bc9de
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions .github/workflows/pr-code-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ permissions:

jobs:
code_formatter:
if: ${{ github.event.pull_request.mergeable }}
runs-on: ubuntu-latest
steps:
# Get changed files before checking out the repository to force the action
Expand All @@ -17,23 +18,13 @@ jobs:
with:
separator: ","

- name: Calculate number of commits to fetch
run: echo "PR_FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> "${GITHUB_ENV}"

- name: Fetch PR sources
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: ${{ env.PR_FETCH_DEPTH }}
ref: "refs/pull/${{ github.event.number }}/merge"
fetch-depth: 2
path: pr-sources

- name: Print commits being evaluated
working-directory: ./pr-sources
env:
PR_DEPTH: ${{ github.event.pull_request.commits }}
run: |
git log HEAD~$PR_DEPTH...HEAD
# We need to make sure that we aren't executing/using any code from the
# PR for security reasons as we're using pull_request_target. Checkout
# the target branch with the necessary files.
Expand Down Expand Up @@ -69,13 +60,12 @@ jobs:
- name: Run code formatter
env:
GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}
PR_DEPTH: ${{ github.event.pull_request.commits }}
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
working-directory: ./pr-sources
run: |
python ../llvm-sources/llvm/utils/git/code-format-helper.py \
--token ${{ secrets.GITHUB_TOKEN }} \
--issue-number $GITHUB_PR_NUMBER \
--start-rev HEAD~$PR_DEPTH \
--start-rev HEAD^ \
--end-rev HEAD \
--changed-files "$CHANGED_FILES"

0 comments on commit c7bc9de

Please sign in to comment.