Added Day 1441 #8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |