-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yml
65 lines (55 loc) · 2.83 KB
/
action.yml
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Copyright 2024 Craig Motlin
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: 'Forbid Merge Commits'
description: 'A composite action to forbid merge commits in pull requests.'
branding:
icon: 'git-merge'
color: 'purple'
runs:
using: "composite"
steps:
- name: Check for Pull Request event
if: ${{ github.event_name != 'pull_request' }}
shell: bash
run: |
echo "::warning::This action is intended to be used in pull_request events only. The event type was '${{ github.event_name }}'. See: https://github.com/motlin/forbid-merge-commits-action#how-to-add-this-action-to-your-repository."
echo "## This action is intended to be used in pull_request events only. The event type was '${{ github.event_name }}'." >> $GITHUB_STEP_SUMMARY
echo "See: [How to add this action to your repository](https://github.com/motlin/forbid-merge-commits-action#how-to-add-this-action-to-your-repository)." >> $GITHUB_STEP_SUMMARY
exit 1
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check for merge commits
shell: bash
run: |
set -Eeuo pipefail
MERGE_COMMITS=$(git log --merges --format=%H origin/${{github.base_ref}}..refs/remotes/pull/${{github.event.pull_request.number}}/merge^2 --)
if [ -n "$MERGE_COMMITS" ]; then
echo '::error title=Found merge commits::Found merge commits. Refer to https://github.com/motlin/forbid-merge-commits-action#handling-failure-messages for guidance.'
echo -e '## Found merge commits.\n\nRefer to [handling failure messages](https://github.com/motlin/forbid-merge-commits-action#handling-failure-messages) for guidance.\n' >> $GITHUB_STEP_SUMMARY
for COMMIT_HASH in $MERGE_COMMITS; do
echo "::warning::Merge commit: $COMMIT_HASH"
echo "::group::git show $COMMIT_HASH"
git show $COMMIT_HASH
echo '::endgroup::'
echo '' >> $GITHUB_STEP_SUMMARY
echo '```console' >> $GITHUB_STEP_SUMMARY
git show $COMMIT_HASH >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
done
exit 1
else
echo 'Success: No merge commits found'
fi