-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreusable-release-commit-finder.yaml
More file actions
60 lines (55 loc) · 1.79 KB
/
reusable-release-commit-finder.yaml
File metadata and controls
60 lines (55 loc) · 1.79 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
48
49
50
51
52
53
54
55
56
57
58
59
60
name: Release commit finder
on:
workflow_call:
inputs:
fetchDepth:
description: Checkout fetch depth
default: 2
type: number
required: false
commitMessage:
description: Commit message to find
default: 'feat(release): version'
type: string
required: false
cancelRunIfFound:
description: Abort workflow execution when the target commit is missing
default: true
type: boolean
required: false
secrets:
githubToken:
description: Github token to cancel workflow
required: false
outputs:
hasCommit:
description: 'Has commit message'
value: ${{ jobs.check-commit-message.outputs.hasCommit }}
jobs:
check-commit-message:
runs-on: ubuntu-latest
outputs:
hasCommit: ${{ steps.check-commit.outputs.hasCommit }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: ${{ inputs.fetchDepth }}
- name: Check last commit message
id: check-commit
env:
GH_TOKEN: ${{ secrets.githubToken || secrets.GITHUB_TOKEN }}
run: |
COMMIT_MSG=$(git log -1 --pretty=%B HEAD)
if [[ "$COMMIT_MSG" == *"${{ inputs.commitMessage }}"* ]]; then
echo "Found commit from ${{ inputs.commitMessage }}: $COMMIT_MSG"
echo "hasCommit=true" >> $GITHUB_OUTPUT
else
echo "Commit from ${{ inputs.commitMessage }} branch has not found: $COMMIT_MSG"
echo "hasCommit=false" >> $GITHUB_OUTPUT
fi
- name: Cancel workflow
if: ${{ inputs.cancelRunIfFound && steps.check-commit.outputs.hasCommit == 'true' }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh run cancel ${{ github.run_id }}