test new file #102
This file contains hidden or 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: Solution Upload Notifier | |
| on: | |
| push: | |
| paths: | |
| - "*/*/*.py" | |
| - "*/*/*.js" | |
| - "*/*/*.java" | |
| jobs: | |
| notify: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 2 | |
| - name: Ensure previous commit exists | |
| run: | | |
| if ! git rev-parse HEAD~1 >/dev/null 2>&1; then | |
| echo "No previous commit — skipping diff." | |
| exit 0 | |
| fi | |
| - name: Get newly added solution files | |
| id: files | |
| shell: bash | |
| run: | | |
| added=$(git diff --name-only --diff-filter=A HEAD~1 HEAD \ | |
| | grep -E ".+/.+/.+\.(py|js|java)$" || true) | |
| { | |
| echo "added<<EOF" | |
| echo "$added" | |
| echo "EOF" | |
| } >> "$GITHUB_OUTPUT" | |
| - name: Exit if no new solutions | |
| if: ${{ steps.files.outputs.added == '' }} | |
| run: exit 0 | |
| - name: Send Slack message (formatted) | |
| env: | |
| WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }} | |
| ADDED_FILES: ${{ steps.files.outputs.added }} | |
| shell: bash | |
| run: | | |
| while IFS= read -r file; do | |
| [ -z "$file" ] && continue | |
| username=$(echo "$file" | cut -d'/' -f1) | |
| week=$(echo "$file" | cut -d'/' -f2) | |
| filename=$(echo "$file" | cut -d'/' -f3) | |
| difficulty="${filename%.*}" | |
| payload=$(cat <<EOF | |
| { | |
| "blocks": [ | |
| { | |
| "type": "header", | |
| "text": { | |
| "type": "plain_text", | |
| "text": "✅ New Solution Uploaded" | |
| } | |
| }, | |
| { | |
| "type": "section", | |
| "fields": [ | |
| { | |
| "type": "mrkdwn", | |
| "text": "*👤 User:*\n${username}" | |
| }, | |
| { | |
| "type": "mrkdwn", | |
| "text": "*📅 Week:*\n${week}" | |
| }, | |
| { | |
| "type": "mrkdwn", | |
| "text": "*📘 Problem:*\n${difficulty}" | |
| } | |
| ] | |
| } | |
| ] | |
| } | |
| EOF | |
| ) | |
| curl -X POST "$WEBHOOK" \ | |
| -H "Content-type: application/json" \ | |
| --data "$payload" | |
| done <<< "$ADDED_FILES" |