-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
44 lines (40 loc) · 1.33 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
name: Commit Hash Verifier
description: Verifies the validity of a commit hash from a specific branch
author: shiftEscape
branding:
icon: "git-commit"
color: "purple"
inputs:
commit-hash:
description: "The commit hash to verify"
required: true
default: ${{ github.sha }}
branch-name:
description: "The name of the branch to check the commit against"
required: true
default: ${{ github.ref }}
outputs:
valid_commit:
description: "Indicates if the commit hash is valid"
runs:
using: "composite"
steps:
- name: Verify commit hash
id: verify-commit
shell: bash
run: |
branch_name="${{ inputs.branch-name }}"
commit_id="${{ inputs.commit-hash }}"
if ! git rev-parse --quiet --verify "${commit_id}"; then
echo "::set-output name=valid_commit::false"
echo "Invalid commit hash: \`$commit_id\`"
else
# Verify if the commit is on the specified branch
if ! git merge-base --is-ancestor "${commit_id}" "${branch_name}"; then
echo "::set-output name=valid_commit::false"
echo "Commit \`$commit_id\` not found from branch \`$branch_name\`"
else
echo "::set-output name=valid_commit::true"
echo "Commit \`$commit_id\` is valid from branch \`$branch_name\`"
fi
fi