Update check_and_update_json_date.yml

This commit is contained in:
CanbiZ 2025-01-15 10:40:38 +01:00 committed by GitHub
parent dbfb72807a
commit 18538897ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,4 +1,4 @@
name: Update JSON and Push Changes name: Update JSON Date and Push Changes
on: on:
push: push:
@ -10,33 +10,34 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Check out repository - name: Generate a token
uses: actions/checkout@v3 id: generate-token
uses: actions/create-github-app-token@v1
- name: Authenticate with GitHub App
uses: tibdex/github-app-token@v1
with: with:
app_id: ${{ secrets.JSON_APP_ID }} app-id: ${{ vars.JSON_APP_ID }}
private_key: ${{ secrets.JSON_APP_KEY }} private-key: ${{ secrets.JSON_APP_KEY }}
- name: Modify JSON file - name: Checkout code
uses: actions/checkout@v4
- name: Set up authentication
env:
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
run: | run: |
JSON_FILE="json/mailrise.json" git config --global user.name "github-actions[bot]"
TODAY=$(date -u +%Y-%m-%d) git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global credential.helper 'store'
echo "https://github-actions[bot]:$GH_TOKEN@github.com" > ~/.git-credentials
if [ -f "$JSON_FILE" ]; then - name: Modify JSON file(s)
echo "Updating date_created in $JSON_FILE to $TODAY" run: |
jq --arg today "$TODAY" '.date_created = $today' $JSON_FILE > tmp.json && mv tmp.json $JSON_FILE TODAY=$(date -u +%Y-%m-%d)
else for json_file in $(find . -type f -name "*.json"); do
echo "File $JSON_FILE does not exist." jq --arg today "$TODAY" '.date_created = $today' "$json_file" > tmp.json && mv tmp.json "$json_file"
exit 1 done
fi
- name: Commit changes - name: Commit changes
run: | run: |
git config user.name "github-actions[bot]" git add *.json
git config user.email "github-actions[bot]@users.noreply.github.com" git commit -m "Update date_created in JSON files to $TODAY"
git add json/mailrise.json
git commit -m "Update date_created in mailrise.json to $TODAY"
git push origin main git push origin main