-
Notifications
You must be signed in to change notification settings - Fork 3
47 lines (40 loc) · 1.33 KB
/
check_pr_code.yml
File metadata and controls
47 lines (40 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
name: PR code check
on:
pull_request:
jobs:
code_checks:
uses: ./.github/workflows/_code_checks.yml
count_commits:
needs: code_checks
runs-on: ubuntu-latest
outputs:
n_commits: ${{ steps.count_commits.outputs.n_commits }}
steps:
- name: checkout current branch
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: count commits from main
id: count_commits
run: |
git fetch
N_COMMITS=$(git rev-list origin/main.. --count)
echo "n_commits=${N_COMMITS}" >> $GITHUB_OUTPUT
add_empty_commit_if_only_one:
needs: count_commits
runs-on: ubuntu-latest
# 2 commits because the PR code gets merged into a temp commit on main
if: ${{ (!!needs.count_commits.outputs.n_commits) && needs.count_commits.outputs.n_commits <= 2 }}
steps:
- name: checkout current branch
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
- uses: EndBug/add-and-commit@v8
with:
default_author: github_actions
message: 'Add empty commit to force use PR title during squash merge'
commit: --allow-empty
add: '.' # working tree should be clean
push: true