2025-01-15 10:12:18 +00:00
|
|
|
name: Update date_created in JSON files
|
2025-01-10 12:36:20 +00:00
|
|
|
|
|
|
|
on:
|
2025-01-15 10:12:18 +00:00
|
|
|
# Dieser Trigger wird für das Öffnen von PRs sowie für das Aktualisieren von offenen PRs verwendet
|
2025-01-15 09:50:30 +00:00
|
|
|
pull_request:
|
2025-01-15 10:04:03 +00:00
|
|
|
types: [opened, synchronize]
|
2025-01-15 10:12:18 +00:00
|
|
|
schedule:
|
|
|
|
# Dieser Trigger wird 4x am Tag ausgelöst, um sicherzustellen, dass das Datum aktualisiert wird
|
|
|
|
- cron: "0 0,6,12,18 * * *" # Führt alle 6 Stunden aus
|
2025-01-15 10:13:55 +00:00
|
|
|
workflow_dispatch: # Manuelle Ausführung des Workflows möglich
|
2025-01-10 12:36:20 +00:00
|
|
|
|
|
|
|
jobs:
|
2025-01-15 10:04:03 +00:00
|
|
|
update-date:
|
2025-01-10 12:36:20 +00:00
|
|
|
runs-on: ubuntu-latest
|
2025-01-15 10:04:03 +00:00
|
|
|
|
2025-01-10 12:36:20 +00:00
|
|
|
steps:
|
2025-01-15 10:12:18 +00:00
|
|
|
- name: Checkout repository
|
2025-01-15 09:40:38 +00:00
|
|
|
uses: actions/checkout@v4
|
2025-01-15 09:25:38 +00:00
|
|
|
|
2025-01-15 10:04:03 +00:00
|
|
|
- name: Install yq
|
2025-01-15 09:40:38 +00:00
|
|
|
run: |
|
2025-01-15 10:12:18 +00:00
|
|
|
sudo apt-get update
|
|
|
|
sudo apt-get install -y yq
|
2025-01-15 09:40:38 +00:00
|
|
|
|
2025-01-15 10:12:18 +00:00
|
|
|
- name: Set the current date
|
|
|
|
id: set_date
|
|
|
|
run: echo "TODAY=$(date -u +%Y-%m-%d)" >> $GITHUB_ENV
|
|
|
|
|
|
|
|
- name: Check for changes in PR
|
2025-01-10 12:36:20 +00:00
|
|
|
run: |
|
2025-01-15 10:12:18 +00:00
|
|
|
# Hole den PR-Branch
|
|
|
|
PR_BRANCH="refs/pull/${{ github.event.pull_request.number }}/merge"
|
|
|
|
git fetch origin $PR_BRANCH
|
|
|
|
|
|
|
|
# Liste alle JSON-Dateien im PR auf, die geändert wurden
|
|
|
|
CHANGED_JSON_FILES=$(git diff --name-only origin/main...$PR_BRANCH | grep '.json')
|
|
|
|
|
|
|
|
if [ -z "$CHANGED_JSON_FILES" ]; then
|
|
|
|
echo "No JSON files changed in this PR."
|
|
|
|
exit 0
|
|
|
|
fi
|
2025-01-10 12:36:20 +00:00
|
|
|
|
2025-01-15 10:12:18 +00:00
|
|
|
# Gehe alle geänderten JSON-Dateien durch und aktualisiere das Datum
|
|
|
|
for file in $CHANGED_JSON_FILES; do
|
|
|
|
echo "Updating date_created in $file"
|
|
|
|
# Setze das aktuelle Datum
|
|
|
|
yq eval ".date_created = \"${{ env.TODAY }}\"" -i "$file"
|
|
|
|
git add "$file"
|
|
|
|
done
|
|
|
|
|
|
|
|
- name: Commit and push changes
|
2025-01-10 12:36:20 +00:00
|
|
|
run: |
|
2025-01-15 10:12:18 +00:00
|
|
|
# Prüfe, ob es Änderungen gibt und committe sie
|
|
|
|
git config user.name "json-updater-bot"
|
|
|
|
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
|
|
|
|
|
|
git commit -m "Update date_created to ${{ env.TODAY }}" || echo "No changes to commit"
|
|
|
|
|
|
|
|
# Push zurück in den PR-Branch
|
|
|
|
git push origin $PR_BRANCH
|