-
Notifications
You must be signed in to change notification settings - Fork 197
50 lines (45 loc) · 1.71 KB
/
notify-slack-on-new-file.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
name: Notify Slack on New File in _posts
on:
push:
branches:
- master # Adjust this if your main branch has a different name
paths:
- '_posts/**'
workflow_dispatch: # Allows manual triggering from GitHub UI
jobs:
notify_slack:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
with:
fetch-depth: 0 # Fetches all history for all branches and tags
- name: Debug info
run: |
echo "Repository Status:"
git status
echo "Most Recent Commit:"
git log -1
- name: Check for new files
run: |
if git rev-parse HEAD^ >/dev/null 2>&1; then
NEW_FILES=$(git diff --diff-filter=A --name-only HEAD^ HEAD _posts/)
if [[ -n "$NEW_FILES" ]]; then
MESSAGE="WTF just happened today?\n"
for FILE in $NEW_FILES; do
URL="https://github.com/mkiser/WTFJHT/blob/master/${FILE}"
MESSAGE+="<${URL}|${FILE}>\n"
done
echo "::set-output name=message::${MESSAGE}"
else
echo "::set-output name=message::No new files added to _posts."
fi
else
echo "No previous commit to compare."
echo "::set-output name=message::No previous commit to compare."
fi
id: files
- name: Send message to Slack
if: steps.files.outputs.message != 'No new files added to _posts.' && steps.files.outputs.message != 'No previous commit to compare.'
run: |
curl -X POST -H 'Content-type: application/json' --data '{"text":"${{ steps.files.outputs.message }}"}' ${{ secrets.SLACK_WEBHOOK_URL }}