-
Notifications
You must be signed in to change notification settings - Fork 0
67 lines (56 loc) · 1.9 KB
/
version-bump-check.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
66
67
name: Version Bump Check
on:
pull_request:
env:
description: version update
file: main.go
regex: \s+packageVersion\s+=\s+"\S+"
jobs:
main:
runs-on: ubuntu-latest
steps:
- name: Check Out Code
uses: actions/checkout@v4
with:
fetch-depth: -1
- id: changes
name: Check for Changes
run: |
changed_file="$(git diff ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} ${{ env.file }})"
if [ -z "$changed_file" ]; then
exit 1
else
added_match=$(echo "$changed_file" | grep -E '^\+${{ env.regex }}' || true)
removed_match=$(echo "$changed_file" | grep -E '^\-${{ env.regex }}' || true)
if [[ -z "$added_match" ]] && [[ -z "$removed_match" ]]; then
exit 1
fi
if [[ -n "$added_match" ]]; then
echo "added_match=$added_match" >> $GITHUB_OUTPUT
else
echo "added_match=" >> $GITHUB_OUTPUT
fi
if [[ -n "$removed_match" ]]; then
echo "removed_match=$removed_match" >> $GITHUB_OUTPUT
else
echo "removed_match=" >> $GITHUB_OUTPUT
fi
fi
- if: success()
name: Found Change Comment
uses: thollander/actions-comment-pull-request@v2
with:
comment_tag: changes
message: |
:white_check_mark: Found ${{ env.description }} in `${{ env.file }}`:
```diff
${{ steps.changes.outputs.removed_match }}
${{ steps.changes.outputs.added_match }}
```
- if: failure()
name: Missing Change Comment
uses: thollander/actions-comment-pull-request@v2
with:
comment_tag: changes
message: |
:warning: Could not find ${{ env.description }} in `${{ env.file }}`