forked from WordPress/block-development-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c0e674e
commit f0b2fce
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/bin/bash | ||
|
||
echo "Starting dates update process..." | ||
|
||
# Read examples.json | ||
EXAMPLES_FILE="_data/examples.json" | ||
TEMP_FILE="_data/examples.temp.json" | ||
|
||
# Create temp file if needed | ||
if [ ! -f "$TEMP_FILE" ]; then | ||
cp "$EXAMPLES_FILE" "$TEMP_FILE" | ||
fi | ||
|
||
# Function to get Git dates for a folder | ||
get_git_dates() { | ||
local folder=$1 | ||
|
||
# Get first commit date (creation date) | ||
local created=$(git log --reverse --format=%aI -- "$folder" | head -n 1) | ||
|
||
# Get last commit date (modification date) | ||
local lastModified=$(git log -1 --format=%aI -- "$folder") | ||
|
||
# Return both dates in JSON format | ||
echo "{\"created\":\"$created\",\"lastModified\":\"$lastModified\"}" | ||
} | ||
|
||
# Read examples.json into a variable | ||
EXAMPLES=$(cat "$EXAMPLES_FILE") | ||
|
||
# Process each example | ||
UPDATED_EXAMPLES=$(echo "$EXAMPLES" | jq -c '.[]' | while read -r example; do | ||
slug=$(echo "$example" | jq -r '.slug') | ||
folder="plugins/$slug" | ||
if [ -d "$folder" ]; then | ||
# Get dates from Git history | ||
dates=$(get_git_dates "$folder") | ||
created=$(echo "$dates" | jq -r '.created') | ||
lastModified=$(echo "$dates" | jq -r '.lastModified') | ||
# Update the example with new dates | ||
echo "$example" | jq --arg created "$created" --arg lastModified "$lastModified" \ | ||
'. + {created: $created, lastModified: $lastModified}' | ||
else | ||
echo "$example" | ||
fi | ||
done | jq -s '.') | ||
|
||
# Write the updated content back to examples.json | ||
echo "$UPDATED_EXAMPLES" > "$EXAMPLES_FILE" | ||
|
||
echo "Finished dates update process. ✅" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: Update Creation and Modification Dates | ||
|
||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: '0 0 1 * *' # Run monthly on the first day at midnight | ||
|
||
jobs: | ||
update-dates: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 # Fetch all history for all branches and tags | ||
|
||
- name: Make script executable | ||
run: chmod +x .github/workflows/scripts/update_dates.sh | ||
|
||
- name: Update dates | ||
env: | ||
EXAMPLES_FILE: '_data/examples.json' | ||
run: ./.github/workflows/scripts/update_dates.sh | ||
|
||
- name: Commit changes | ||
run: | | ||
git config --local user.email "github-actions[bot]@users.noreply.github.com" | ||
git config --local user.name "github-actions[bot]" | ||
git add _data/examples.json | ||
git diff --quiet && git diff --staged --quiet || git commit -m "Update creation and modification dates" | ||
- name: Push changes | ||
uses: ad-m/github-push-action@master | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
branch: ${{ github.ref }} |