Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c7ee43c
fix: Update package.json with required Octokit dependencies
chaudhari-mithilesh Apr 17, 2025
1e666e7
chore: Clean up node_modules and update package-lock.json
chaudhari-mithilesh Apr 17, 2025
b3baae8
fix: Add config directory creation and improve error handling in vers…
chaudhari-mithilesh Apr 17, 2025
2b318ba
fix: Improve version checking implementation and error handling
chaudhari-mithilesh Apr 17, 2025
e573f1d
feat: Update version checker to always fetch latest data from API end…
chaudhari-mithilesh Apr 17, 2025
f57e8e8
fix: Remove redundant base64 encoding of auth token
chaudhari-mithilesh Apr 17, 2025
64d9322
removed unnecessary code.
chaudhari-mithilesh Apr 17, 2025
a67091a
fixed veriable and secret calls.
chaudhari-mithilesh Apr 17, 2025
0709bb7
fix: Add repository variables and secrets to workflow environment
chaudhari-mithilesh Apr 17, 2025
e288922
fix: Add proper execution flow to ensure versions are updated
chaudhari-mithilesh Apr 17, 2025
a2ea8b8
feat: Implement improved version checking with WordPress.org API inte…
chaudhari-mithilesh Apr 17, 2025
3460d70
feat: Enhance WordPress update checker - Improve error handling, add …
chaudhari-mithilesh Apr 17, 2025
c5ea4d2
Fix: removed label creation from PR request.
chaudhari-mithilesh Apr 17, 2025
33897ba
Enhanced PR creation for update checks
chaudhari-mithilesh Apr 17, 2025
e9fa44c
[create-pull-request] automated change
chaudhari-mithilesh Apr 17, 2025
3218157
Merge pull request #43 from WisdmLabs/sync-wordpress-content-20250417…
chaudhari-mithilesh Apr 17, 2025
c75902a
feat: Add WordPress update processor and improve workflows
chaudhari-mithilesh Apr 17, 2025
fd37420
Handled Dependencies.
chaudhari-mithilesh Apr 17, 2025
c7db83d
refactor: Simplify update report handling - Generate clean JSON inste…
chaudhari-mithilesh Apr 17, 2025
f2dde8b
feat: Add theme update handling and fix plugin download URLs
chaudhari-mithilesh Apr 17, 2025
83af81b
[create-pull-request] automated change
chaudhari-mithilesh Apr 17, 2025
adb1e57
Merge pull request #46 from WisdmLabs/sync-wordpress-content-20250417…
chaudhari-mithilesh Apr 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
44 changes: 43 additions & 1 deletion .github/workflows/check-updates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v3
Expand All @@ -48,5 +50,45 @@ jobs:
- name: Check for updates
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
STAGING_SITE_URL: ${{ vars.STAGING_SITE_URL }}
STAGING_SITE_AUTH_TOKEN: ${{ secrets.STAGING_SITE_AUTH_TOKEN }}
CHECK_TYPE: ${{ github.event.inputs.check_type || 'all' }}
run: node scripts/check-updates.js
run: |
# Run the update check and save only the JSON report
node scripts/check-updates.js > updates.json

- name: Check for changes
id: check-changes
run: |
if [[ -n "$(git status --porcelain)" ]]; then
echo "CHANGES_FOUND=true" >> $GITHUB_ENV
echo "Changes found in the repository"
# Generate a unique branch name using timestamp
echo "SYNC_BRANCH=sync-wordpress-content-$(date +%Y%m%d-%H%M%S)" >> $GITHUB_ENV
else
echo "CHANGES_FOUND=false" >> $GITHUB_ENV
echo "No changes found in the repository"
fi

- name: Create Pull Request to Main
id: create-pr
if: env.CHANGES_FOUND == 'true'
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.TOKEN_FOR_TECHOPS_AUTOMATION }}
base: main
branch: ${{ env.SYNC_BRANCH }}
title: "Sync WordPress Update Check Reports from Staging Site"
body: |
This PR syncs update check report to main branch.

Changes include:
- Checked for updates on plugins and themes
- Created GitHub issues if updates are available
- Generated updates.json with details
delete-branch: false

- name: Handle PR Creation Failure
if: failure()
run: |
echo "Failed to create PR. Please check the workflow logs for more details."
70 changes: 1 addition & 69 deletions .github/workflows/wordpress-content-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,74 +143,6 @@ jobs:
echo "CHANGES_FOUND=false" >> $GITHUB_ENV
echo "No changes found in the repository"
fi

# - name: Commit changes to main
# if: env.CHANGES_FOUND == 'true'
# run: |
# git config --global user.email "github-actions[bot]@users.noreply.github.com"
# git config --global user.name "github-actions[bot]"

# echo "Adding changes to git..."
# git add .

# echo "Committing changes to main..."
# git commit -m "feat: Update WordPress content from live site"
# git push origin main

# - name: Wait for latest commit to be reflected
# if: env.CHANGES_FOUND == 'true'
# run: |
# echo "Waiting for latest commit to be reflected..."
# LATEST_COMMIT=$(git rev-parse HEAD)
# echo "Latest commit hash: $LATEST_COMMIT"

# # Wait for up to 30 seconds for the commit to be reflected
# for i in {1..30}; do
# git fetch origin main
# REMOTE_COMMIT=$(git rev-parse origin/main)
# echo "Remote commit hash: $REMOTE_COMMIT"

# if [ "$LATEST_COMMIT" = "$REMOTE_COMMIT" ]; then
# echo "✅ Latest commit is now reflected in remote"
# break
# fi

# if [ $i -eq 30 ]; then
# echo "❌ Timeout waiting for latest commit to be reflected"
# exit 1
# fi

# echo "Waiting for commit to be reflected... (attempt $i/30)"
# sleep 1
# done

# - name: Create sync branch
# if: env.CHANGES_FOUND == 'true'
# run: |
# # Verify we are still on main branch
# CURRENT_BRANCH=$(git branch --show-current)
# if [[ "$CURRENT_BRANCH" != "main" ]]; then
# echo "❌ Not on main branch. Cannot create sync branch."
# exit 1
# fi

# # Create a new branch as a clone of main
# echo "Creating sync branch ${{ env.SYNC_BRANCH }} as a clone of main branch..."
# git checkout -b ${{ env.SYNC_BRANCH }}

# # Verify the new branch is identical to main
# MAIN_COMMIT=$(git rev-parse main)
# SYNC_COMMIT=$(git rev-parse HEAD)
# if [[ "$MAIN_COMMIT" != "$SYNC_COMMIT" ]]; then
# echo "❌ Sync branch is not identical to main branch"
# exit 1
# fi

# echo "✅ Successfully created sync branch ${{ env.SYNC_BRANCH }} as a clone of main"

# # Push the sync branch to remote
# echo "Pushing sync branch to remote..."
# git push origin ${{ env.SYNC_BRANCH }}

- name: Create Pull Request to Main
id: create-pr
Expand All @@ -222,7 +154,7 @@ jobs:
branch: ${{ env.SYNC_BRANCH }}
title: "Sync WordPress Content from Live Site"
body: |
This PR syncs the latest WordPress content changes from live site to release branch.
This PR syncs the latest WordPress content changes from live site to main branch.

Changes include:
- Updated plugins
Expand Down
177 changes: 62 additions & 115 deletions .github/workflows/wordpress-updates.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,8 @@
name: WordPress Updates Automation
name: Process WordPress Updates

on:
schedule:
- cron: "0 0 1 * *" # Run at midnight on the first day of every month
workflow_dispatch:
inputs:
schedule_day:
description: 'Day of month to run (1-31)'
required: false
type: number
default: 1
schedule_time:
description: 'Time to run (HH:MM)'
required: false
type: string
default: '00:00'
timezone:
description: 'Timezone for scheduling'
required: false
type: choice
options:
- 'Asia/Kolkata'
- 'UTC'
- 'America/New_York'
- 'Europe/London'
default: 'Asia/Kolkata'
update_type:
description: 'Type of updates to process'
required: true
Expand All @@ -36,112 +14,81 @@ on:
default: 'all'

jobs:
configure-schedule:
process-updates:
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch'
steps:
- name: Update Schedule Configuration
uses: actions/github-script@v6
- name: Checkout repository
uses: actions/checkout@v3
with:
script: |
const day = ${{ github.event.inputs.schedule_day }};
const time = ${{ github.event.inputs.schedule_time }};
const [hours, minutes] = time.split(':');
const cron = `${minutes} ${hours} ${day} * *`;

await github.rest.actions.createOrUpdateRepoVariable({
owner: context.repo.owner,
repo: context.repo.repo,
name: 'UPDATE_CHECK_CRON',
value: cron
});

await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: 'Schedule Configuration Updated',
body: `Schedule has been updated:\n- Day: ${day}\n- Time: ${time}\n- Timezone: ${{ github.event.inputs.timezone }}\n- Cron: ${cron}`
});

check-and-update:
needs: configure-schedule
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Check for updates
id: check-updates
run: node scripts/check-updates.js

- name: Process updates
env:
LIVE_SITE_URL: ${{ secrets.LIVE_SITE_URL }}
LIVE_SITE_AUTH_TOKEN: ${{ secrets.LIVE_SITE_AUTH_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
UPDATE_TYPE: ${{ github.event.inputs.update_type || 'all' }}
TIMEZONE: ${{ github.event.inputs.timezone || 'Asia/Kolkata' }}

- name: Create backup
if: success() && hashFiles('updates.json')
UPDATE_TYPE: ${{ github.event.inputs.update_type }}
run: |
BACKUP_DIR="_backups/$(date +%Y%m%d-%H%M%S)"
mkdir -p $BACKUP_DIR
cp -r wp-content/* $BACKUP_DIR/
echo "Created backup in $BACKUP_DIR"

- name: Download plugin updates
if: success() && hashFiles('updates.json') && (env.UPDATE_TYPE == 'all' || env.UPDATE_TYPE == 'plugins')
run: node scripts/utils/update-downloader.js plugins
env:
LIVE_SITE_URL: ${{ secrets.LIVE_SITE_URL }}
LIVE_SITE_AUTH_TOKEN: ${{ secrets.LIVE_SITE_AUTH_TOKEN }}
# Run the update processor and capture output
npm run process-updates | tee processor_output.txt

- name: Download theme updates
if: success() && hashFiles('updates.json') && (env.UPDATE_TYPE == 'all' || env.UPDATE_TYPE == 'themes')
run: node scripts/utils/update-downloader.js themes
env:
LIVE_SITE_URL: ${{ secrets.LIVE_SITE_URL }}
LIVE_SITE_AUTH_TOKEN: ${{ secrets.LIVE_SITE_AUTH_TOKEN }}

- name: Process plugin updates
if: success() && hashFiles('updates.json') && (env.UPDATE_TYPE == 'all' || env.UPDATE_TYPE == 'plugins')
run: |
# Read updates.json and extract plugin information
PLUGINS=$(node -e "const updates = require('./updates.json'); console.log(JSON.stringify(Object.entries(updates.plugins).map(([slug, info]) => ({ slug, active: true }))))")
echo "$PLUGINS" | node scripts/process-plugins.js
env:
LIVE_SITE_URL: ${{ secrets.LIVE_SITE_URL }}
LIVE_SITE_AUTH_TOKEN: ${{ secrets.LIVE_SITE_AUTH_TOKEN }}
# Print the processing output
echo "Update Processing Output:"
cat processor_output.txt

- name: Process theme updates
if: success() && hashFiles('updates.json') && (env.UPDATE_TYPE == 'all' || env.UPDATE_TYPE == 'themes')
# Check if update_results.json exists and contains updates
if [ -f "update_results.json" ]; then
PROCESSED_COUNT=$(jq '.processed | length' update_results.json)
if [ "$PROCESSED_COUNT" -gt 0 ]; then
echo "UPDATES_PROCESSED=true" >> $GITHUB_ENV
else
echo "UPDATES_PROCESSED=false" >> $GITHUB_ENV
fi
else
echo "UPDATES_PROCESSED=false" >> $GITHUB_ENV
fi

- name: Check for changes
id: check-changes
run: |
# Read updates.json and extract theme information
THEMES=$(node -e "const updates = require('./updates.json'); console.log(JSON.stringify(Object.entries(updates.themes).map(([slug, info]) => ({ slug, active: true }))))")
echo "$THEMES" | node scripts/process-themes.js
env:
LIVE_SITE_URL: ${{ secrets.LIVE_SITE_URL }}
LIVE_SITE_AUTH_TOKEN: ${{ secrets.LIVE_SITE_AUTH_TOKEN }}

- name: Update versions file
if: success() && hashFiles('updates.json')
run: node scripts/utils/version-updater.js
env:
LIVE_SITE_URL: ${{ secrets.LIVE_SITE_URL }}
LIVE_SITE_AUTH_TOKEN: ${{ secrets.LIVE_SITE_AUTH_TOKEN }}

- name: Commit and push changes
if: success() && hashFiles('updates.json')
if [[ -n "$(git status --porcelain)" ]]; then
echo "CHANGES_FOUND=true" >> $GITHUB_ENV
echo "Changes found in the repository"
# Generate a unique branch name using timestamp
echo "SYNC_BRANCH=sync-wordpress-content-$(date +%Y%m%d-%H%M%S)" >> $GITHUB_ENV
else
echo "CHANGES_FOUND=false" >> $GITHUB_ENV
echo "No changes found in the repository"
fi

- name: Create Pull Request to Main
id: create-pr
if: env.CHANGES_FOUND == 'true'
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.TOKEN_FOR_TECHOPS_AUTOMATION }}
base: main
branch: ${{ env.SYNC_BRANCH }}
title: "Processed Wordpress Updates"
body: |
This PR merges WordPress content updates to main branch.

Changes include:
- Updated plugins
- Updated themes
delete-branch: false

- name: Handle Failure
if: failure()
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add .
git commit -m "Update WordPress plugins and themes [skip ci]"
git push
echo "Failed to process updates or create PR. Check the logs for details."
if [ -f "processor_output.txt" ]; then
echo "Processor Output:"
cat processor_output.txt
fi
24 changes: 24 additions & 0 deletions UpdateChecker
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{"timestamp":"2025-04-17T13:31:12.568Z","level":"info","message":"Current working directory: /home/mithilesh/TECHOPS-GIT-AUTOMATION/Internal---TechOps-Automation","details":{}}
{"timestamp":"2025-04-17T13:31:12.571Z","level":"info","message":"Config directory path: /home/mithilesh/TECHOPS-GIT-AUTOMATION/Internal---TechOps-Automation/config","details":{}}
{"timestamp":"2025-04-17T13:31:12.571Z","level":"info","message":"Versions file path: /home/mithilesh/TECHOPS-GIT-AUTOMATION/Internal---TechOps-Automation/config/versions.json","details":{}}
{"timestamp":"2025-04-17T13:31:12.572Z","level":"info","message":"Directory exists: /home/mithilesh/TECHOPS-GIT-AUTOMATION/Internal---TechOps-Automation","details":{}}
{"timestamp":"2025-04-17T13:31:12.577Z","level":"info","message":"Write permissions verified for: /home/mithilesh/TECHOPS-GIT-AUTOMATION/Internal---TechOps-Automation","details":{}}
{"timestamp":"2025-04-17T13:31:12.577Z","level":"info","message":"Config directory not found. Creating it...","details":{}}
{"timestamp":"2025-04-17T13:31:12.577Z","level":"info","message":"Successfully created config directory at: /home/mithilesh/TECHOPS-GIT-AUTOMATION/Internal---TechOps-Automation/config","details":{}}
{"timestamp":"2025-04-17T13:31:12.578Z","level":"info","message":"Directory exists: /home/mithilesh/TECHOPS-GIT-AUTOMATION/Internal---TechOps-Automation/config","details":{}}
{"timestamp":"2025-04-17T13:31:12.579Z","level":"info","message":"Write permissions verified for: /home/mithilesh/TECHOPS-GIT-AUTOMATION/Internal---TechOps-Automation/config","details":{}}
{"timestamp":"2025-04-17T13:31:12.579Z","level":"info","message":"Versions file not found. Creating default versions.json...","details":{}}
{"timestamp":"2025-04-17T13:31:12.580Z","level":"info","message":"Successfully created versions file at: /home/mithilesh/TECHOPS-GIT-AUTOMATION/Internal---TechOps-Automation/config/versions.json","details":{}}
{"timestamp":"2025-04-17T13:31:12.580Z","level":"info","message":"No updates available","details":{}}
{"timestamp":"2025-04-17T16:08:54.858Z","level":"info","message":"Current working directory: /home/runner/work/Internal---TechOps-Automation/Internal---TechOps-Automation","details":{}}
{"timestamp":"2025-04-17T16:08:54.859Z","level":"info","message":"Config directory path: /home/runner/work/Internal---TechOps-Automation/Internal---TechOps-Automation/config","details":{}}
{"timestamp":"2025-04-17T16:08:54.859Z","level":"info","message":"Versions file path: /home/runner/work/Internal---TechOps-Automation/Internal---TechOps-Automation/config/versions.json","details":{}}
{"timestamp":"2025-04-17T16:08:54.861Z","level":"info","message":"Directory exists: /home/runner/work/Internal---TechOps-Automation/Internal---TechOps-Automation","details":{}}
{"timestamp":"2025-04-17T16:08:54.863Z","level":"info","message":"Write permissions verified for: /home/runner/work/Internal---TechOps-Automation/Internal---TechOps-Automation","details":{}}
{"timestamp":"2025-04-17T16:08:54.864Z","level":"info","message":"Config directory exists","details":{}}
{"timestamp":"2025-04-17T16:08:54.864Z","level":"info","message":"Directory exists: /home/runner/work/Internal---TechOps-Automation/Internal---TechOps-Automation/config","details":{}}
{"timestamp":"2025-04-17T16:08:54.864Z","level":"info","message":"Write permissions verified for: /home/runner/work/Internal---TechOps-Automation/Internal---TechOps-Automation/config","details":{}}
{"timestamp":"2025-04-17T16:08:54.865Z","level":"info","message":"Successfully read versions file","details":{}}
{"timestamp":"2025-04-17T16:08:54.865Z","level":"info","message":"Checking all updates...","details":{}}
{"timestamp":"2025-04-17T16:09:08.984Z","level":"info","message":"Update check completed. Report:","details":{}}
{"timestamp":"2025-04-17T16:09:09.921Z","level":"info","message":"Created issue #42","details":{}}
Loading
Loading