Files
lawgit/.gitea/workflows/update-laws.yaml

103 lines
3.5 KiB
YAML
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Vollständige Historie für Git-Operationen
persist-credentials: true # Credentials für Push speichern
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: |
pip install --upgrade pip
pip install -r requirements.txt
- name: Run update script
run: |
python3 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: |
python3 xml_to_markdown.py --prod || echo "Konvertierung fehlgeschlagen oder keine Änderungen"
continue-on-error: true
- 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: 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 "- ✅ Änderungen wurden in Branch ${{ steps.create_branch.outputs.branch_name }} committed"
echo "- ✅ Pull Request wurde erstellt"
else
echo "- Keine Änderungen gefunden"
fi