name: Update Laws from RSS on: schedule: # Täglich um 02:00 UTC (03:00 MEZ / 04:00 MESZ) - cron: '0 2 * * *' # Manueller Trigger für Tests workflow_dispatch: jobs: update: runs-on: ubuntu-latest steps: - name: Configure Git run: | git config --global user.name 'LawGit Bot' git config --global user.email 'bot@git.coded.law' git config --global init.defaultBranch main - name: Checkout repository run: | git clone https://git.coded.law/${{ github.repository }}.git . git remote set-url origin https://git.coded.law/${{ github.repository }}.git - name: Set up Python run: | python3 --version # Create virtual environment python3 -m venv venv source venv/bin/activate # Upgrade pip in venv pip install --upgrade pip # Make venv available for all steps echo 'source venv/bin/activate' >> $GITHUB_ENV - name: Install dependencies run: | source venv/bin/activate pip install --upgrade pip pip install -r requirements.txt - name: Run update script run: | source venv/bin/activate python update_laws.py continue-on-error: true # Weiterlaufen auch bei Fehlern - name: Convert XML to Markdown if: success() || failure() # Immer ausführen, auch wenn Update fehlschlug run: | source venv/bin/activate python xml_to_markdown.py --prod || echo "Konvertierung fehlgeschlagen oder keine Änderungen" continue-on-error: true - name: Check for changes id: check_changes run: | git add -A if git diff --staged --quiet; then echo "changed=false" >> $GITHUB_OUTPUT echo "Keine Änderungen gefunden" else echo "changed=true" >> $GITHUB_OUTPUT echo "Änderungen gefunden" git status fi - name: Create branch and commit changes id: create_branch if: steps.check_changes.outputs.changed == 'true' run: | BRANCH_NAME="update-laws-$(date +'%Y%m%d-%H%M%S')" echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT git checkout -b $BRANCH_NAME git commit -m "Update laws from RSS - $(date +'%Y-%m-%d %H:%M:%S UTC')" || exit 0 git push origin $BRANCH_NAME || echo "Push fehlgeschlagen" - name: Create Pull Request if: steps.check_changes.outputs.changed == 'true' env: GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} run: | BRANCH_NAME="${{ steps.create_branch.outputs.branch_name }}" REPO="${{ github.repository }}" GITEA_INSTANCE="https://git.coded.law" # Erstelle Pull Request via Gitea API curl -X POST \ -H "Authorization: token $GITEA_TOKEN" \ -H "Content-Type: application/json" \ -d "{ \"title\": \"Update laws from RSS - $(date +'%Y-%m-%d')\", \"head\": \"$BRANCH_NAME\", \"base\": \"main\", \"body\": \"Automatische Gesetzes-Updates vom RSS-Feed.\\n\\nBitte überprüfe die Änderungen vor dem Merge.\" }" \ "$GITEA_INSTANCE/api/v1/repos/$REPO/pulls" || echo "PR-Erstellung fehlgeschlagen" - name: Summary if: always() run: | echo "## Update-Zusammenfassung" echo "- Workflow ausgeführt: $(date)" if [ "${{ steps.check_changes.outputs.changed }}" == "true" ]; then echo "- OK: Änderungen wurden in Branch ${{ steps.create_branch.outputs.branch_name }} committed" echo "- OK: Pull Request wurde erstellt" else echo "- Info: Keine Änderungen gefunden" fi