Skip to content

Reporting für KNZ LU #304

Reporting für KNZ LU

Reporting für KNZ LU #304

name: Reporting für KNZ LU
on:
workflow_run:
workflows: ["Get data from Overpass"]
types: [completed]
workflow_dispatch:
jobs:
diff-and-mail:
if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout latest main
uses: actions/checkout@v4
with:
ref: main
fetch-depth: 2
- name: Check if this HEAD was already processed
run: |
set -euo pipefail
mkdir -p .reporting
HEAD_SHA="$(git rev-parse HEAD)"
echo "HEAD_SHA=$HEAD_SHA" >> $GITHUB_ENV
FILE=".reporting/last_processed_sha_luks.txt"
if [ -f "$FILE" ]; then
LAST="$(cat "$FILE" | tr -d '[:space:]')"
else
LAST=""
fi
if [ "$HEAD_SHA" = "$LAST" ]; then
echo "ALREADY_PROCESSED=true" >> $GITHUB_ENV
else
echo "ALREADY_PROCESSED=false" >> $GITHUB_ENV
fi
- name: Stop early if already processed
if: env.ALREADY_PROCESSED == 'true'
run: |
echo "Already processed this commit; skipping mail."
exit 0
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Check if GeoJSON changed in latest commit
run: |
set -euo pipefail
if ! git rev-parse HEAD^ >/dev/null 2>&1; then
echo "CHANGED=false" >> $GITHUB_ENV
exit 0
fi
if git diff --quiet HEAD^..HEAD -- data/json/defis_dispo_luks.geojson; then
echo "CHANGED=false" >> $GITHUB_ENV
else
echo "CHANGED=true" >> $GITHUB_ENV
fi
- name: Create diff HTML
if: env.CHANGED == 'true'
run: |
set -euo pipefail
python scripts/geojson_diff.py \
<(git show HEAD^:data/json/defis_dispo_luks.geojson) \
data/json/defis_dispo_luks.geojson
- name: Check diff.html exists
run: |
if [ -f diff.html ]; then
echo "DIFF_EXISTS=true" >> $GITHUB_ENV
else
echo "DIFF_EXISTS=false" >> $GITHUB_ENV
fi
- name: Mail versenden
if: env.DIFF_EXISTS == 'true'
uses: dawidd6/action-send-mail@v3
with:
server_address: asmtp.mail.hostpoint.ch
server_port: 587
secure: false
username: ${{ secrets.MAIL_USER }}
password: ${{ secrets.MAIL_PASS }}
subject: "Änderungen an Defis Dispo LUKS"
html_body: file://diff.html
to: ${{ secrets.MAIL_RECIPIENT_LUKS }}
cc: ${{ secrets.MAIL_COPY }}
from: defikarte.ch Reports
- name: Update last processed SHA
run: |
set -euo pipefail
mkdir -p .reporting
FILE=".reporting/last_processed_sha_luks.txt"
echo "$HEAD_SHA" > "$FILE"
git config user.name "defikarte.ch Reporting Bot"
git config user.email "chrigi@chnuessli.ch"
git add .reporting/last_processed_sha_luks.txt
rm -f diff.html
git commit -m "update last processed sha for _luks" || exit 0
for i in 1 2 3; do
git pull --rebase origin main && git push origin HEAD:main && break
echo "Push failed, retry $i..."
sleep 2
done