Update test33 #1
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
| ```yaml | ||
| name: Sticky Discord Notification | ||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| - master | ||
| paths: | ||
| - "sticky/**" | ||
| jobs: | ||
| discord: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Check changed files | ||
| id: changes | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const before = context.payload.before; | ||
| const after = context.payload.after; | ||
| const response = await github.rest.repos.compareCommits({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| base: before, | ||
| head: after | ||
| }); | ||
| const files = response.data.files || []; | ||
| const stickyFiles = files.filter(file => | ||
| file.filename.startsWith("sticky/") | ||
| ); | ||
| core.setOutput( | ||
| "has_sticky_changes", | ||
| stickyFiles.length > 0 ? "true" : "false" | ||
| ); | ||
| console.log("Geänderte Dateien:"); | ||
| for (const file of files) { | ||
| console.log(file.filename); | ||
| } | ||
| console.log("Sticky Änderungen:", stickyFiles.length); | ||
| - name: Send latest Sticky commit to Discord | ||
| if: steps.changes.outputs.has_sticky_changes == 'true' | ||
| env: | ||
| DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_STICKY }} | ||
| COMMIT_MESSAGE: ${{ github.event.head_commit.message }} | ||
| COMMIT_URL: ${{ github.event.head_commit.html_url }} | ||
| AUTHOR: ${{ github.event.head_commit.author.name }} | ||
| BRANCH: ${{ github.ref_name }} | ||
| run: | | ||
| python3 - <<'PY' | ||
| import json | ||
| import os | ||
| import urllib.request | ||
| payload = { | ||
| "username": "GitHub Sticky", | ||
| "embeds": [{ | ||
| "title": "New Sticky Update", | ||
| "description": os.environ["COMMIT_MESSAGE"][:4000], | ||
| "url": os.environ["COMMIT_URL"], | ||
| "color": 5814783, | ||
| "fields": [ | ||
| { | ||
| "name": "Author", | ||
| "value": os.environ["AUTHOR"] or "Unknown", | ||
| "inline": True | ||
| }, | ||
| { | ||
| "name": "Branch", | ||
| "value": os.environ["BRANCH"], | ||
| "inline": True | ||
| } | ||
| ] | ||
| }] | ||
| } | ||
| request = urllib.request.Request( | ||
| os.environ["DISCORD_WEBHOOK"], | ||
| data=json.dumps(payload).encode("utf-8"), | ||
| headers={"Content-Type": "application/json"}, | ||
| method="POST" | ||
| ) | ||
| with urllib.request.urlopen(request) as response: | ||
| if response.status not in (200, 204): | ||
| raise RuntimeError( | ||
| f"Discord returned HTTP {response.status}" | ||
| ) | ||
| PY | ||
| ``` | ||