Reporting für Bern #2008
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: Reporting für Bern | |
| 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_be.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_kt_be.geojson; then | |
| echo "CHANGED=false" >> $GITHUB_ENV | |
| else | |
| echo "CHANGED=true" >> $GITHUB_ENV | |
| fi | |
| - name: Create diff (sofort + pending) | |
| if: env.CHANGED == 'true' | |
| run: | | |
| set -euo pipefail | |
| python scripts/geojson_diff_be.py \ | |
| <(git show HEAD^:data/json/defis_kt_be.geojson) \ | |
| data/json/defis_kt_be.geojson \ | |
| .reporting/pending_changes_be.json | |
| - name: Check diff_immediate.html exists | |
| run: | | |
| if [ -f diff_immediate.html ]; then | |
| echo "DIFF_EXISTS=true" >> $GITHUB_ENV | |
| else | |
| echo "DIFF_EXISTS=false" >> $GITHUB_ENV | |
| fi | |
| - name: Mail versenden (neu + gelöscht) | |
| 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: "Neue/gelöschte Defis – Kanton Bern" | |
| html_body: file://diff_immediate.html | |
| to: ${{ secrets.MAIL_RECIPIENT_BE }} | |
| cc: ${{ secrets.MAIL_COPY }} | |
| from: defikarte.ch Reports | |
| - name: Update last processed SHA + pending changes committen | |
| run: | | |
| set -euo pipefail | |
| mkdir -p .reporting | |
| FILE=".reporting/last_processed_sha_be.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_be.txt | |
| if [ -f .reporting/pending_changes_be.json ]; then | |
| git add .reporting/pending_changes_be.json | |
| fi | |
| # Temporäre Dateien entfernen damit der Push nicht blockiert wird | |
| rm -f diff_immediate.html | |
| git commit -m "update reporting state for _be" || 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 |