generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 7
84 lines (82 loc) · 2.82 KB
/
slack-release-notification.yaml
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
name: Slack Release Notification
on:
push:
branches:
- main
jobs:
checkType:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Find last merge
run: |
echo "current_commit=$(git log --pretty='%H' -1)" >> $GITHUB_ENV
echo "last_merge=$(git log --pretty='%H' --merges -1 --first-parent)" >> $GITHUB_ENV
outputs:
last_merge: ${{ env.last_merge }}
current_commit: ${{ env.current_commit }}
directCommit:
runs-on: ubuntu-latest
needs: checkType
if: needs.checkType.outputs.last_merge != needs.checkType.outputs.current_commit
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: get commit message
run: |
message=$(git log --pretty=':exclamation: direct commit to main %h by %an (%ae) - %s %b' -1)
echo "$message"
echo 'message<<EOF' >> $GITHUB_ENV
echo "$message" >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
outputs:
message: ${{ env.message }}
mergeCommit:
runs-on: ubuntu-latest
needs: checkType
if: needs.checkType.outputs.last_merge == needs.checkType.outputs.current_commit
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: get commit messages
run: |
previous_merge=$(git log --pretty="%h" -1 --merges --skip=1 --first-parent)
echo $previous_merge
message=$(git log --pretty="-> %h by %an (%ae) - %s %b" --no-merges $previous_merge..${{ needs.checkType.outputs.last_merge }})
echo "$message"
direct_commits=$(git log --pretty="%h" --no-merges --first-parent $previous_merge..${{ needs.checkType.outputs.last_merge }})
while IFS= read -r direct_commit; do
if [[ ! -z "$direct_commit" ]]; then
echo "$direct_commit"
message=$(echo "$message" | grep -v $direct_commit)
fi
done <<< "$direct_commits"
echo "$message"
echo 'message<<EOF' >> $GITHUB_ENV
echo ':merge: new code version released:' >> $GITHUB_ENV
echo "$message" >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
outputs:
message: ${{ env.message }}
slack:
runs-on: ubuntu-latest
needs: [directCommit, mergeCommit]
if: ${{ !failure() }}
steps:
# the following action is based on a workflow created by Andreas Haller, contact for permissions, the workflow file to import can be found under tools/slack
- name: Notify Slack
uses: slackapi/[email protected]
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_NOTIFICATION_WEBHOOK }}
with:
payload: |
{
"text": ${{ toJson(needs.directCommit.outputs.message || needs.mergeCommit.outputs.message) }}
}