Skip to content

Commit eaa827b

Browse files
authored
Add check for version bump (#42)
1 parent 890f14e commit eaa827b

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Version Bump Check
2+
3+
on:
4+
pull_request:
5+
6+
env:
7+
description: version update
8+
file: main.go
9+
regex: packageVersion\s+=\s+"\S+"
10+
11+
jobs:
12+
main:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Check Out Code
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: -1
19+
20+
- id: changes
21+
name: Check for Changes
22+
run: |
23+
changed_file="$(git diff ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} ${{ env.file }})"
24+
if [ -z "$changed_file" ]; then
25+
exit 1
26+
else
27+
added_match=$(echo "$changed_file" | grep -E '^\+\s+${{ env.regex }}')
28+
removed_match=$(echo "$changed_file" | grep -E '^\-\s+${{ env.regex }}')
29+
if [[ -n "$added_match" ]] && [[ -n "$removed_match" ]]; then
30+
echo "added_match=$added_match" >> $GITHUB_OUTPUT
31+
echo "removed_match=$removed_match" >> $GITHUB_OUTPUT
32+
else
33+
exit 1
34+
fi
35+
fi
36+
37+
- if: success()
38+
name: Found Change Comment
39+
uses: thollander/actions-comment-pull-request@v2
40+
with:
41+
comment_tag: changes
42+
message: |
43+
:white_check_mark: Found ${{ env.description }} in `${{ env.file }}`:
44+
45+
```diff
46+
${{ steps.changes.outputs.removed_match }}
47+
${{ steps.changes.outputs.added_match }}
48+
```
49+
50+
- if: failure()
51+
name: Missing Change Comment
52+
uses: thollander/actions-comment-pull-request@v2
53+
with:
54+
comment_tag: changes
55+
message: |
56+
:warning: Could not find ${{ env.description }} in `${{ env.file }}`

0 commit comments

Comments
 (0)