Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions .github/workflows/drift-detection.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,25 @@ jobs:
set -e
continue-on-error: true

- name: Comment PR with drift report
- name: Preview sync actions (dry-run)
id: sync
env:
WORLDDRIVEN_GITHUB_TOKEN: ${{ secrets.WORLDDRIVEN_GITHUB_TOKEN }}
run: |
set +e
node scripts/sync-repositories.js > sync-preview.md 2>&1
EXIT_CODE=$?
echo "exit_code=$EXIT_CODE" >> $GITHUB_OUTPUT
set -e
continue-on-error: true

- name: Comment PR with drift report and sync preview
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const report = fs.readFileSync('drift-report.md', 'utf8');
const driftReport = fs.readFileSync('drift-report.md', 'utf8');
const syncPreview = fs.readFileSync('sync-preview.md', 'utf8');

// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
Expand All @@ -57,7 +70,7 @@ jobs:
comment.body.includes('Repository Drift Report')
);

const commentBody = `${report}\n\n---\n*🤖 This report is automatically generated on every PR that modifies REPOSITORIES.md*`;
const commentBody = `${driftReport}\n\n---\n\n${syncPreview}\n\n---\n*🤖 This report is automatically generated on every PR that modifies REPOSITORIES.md*\n*The sync preview shows what actions will be applied when this PR is merged to main.*`;

if (botComment) {
// Update existing comment
Expand Down
86 changes: 86 additions & 0 deletions .github/workflows/sync-repositories.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Sync Repositories

on:
push:
branches:
- main

jobs:
sync:
runs-on: ubuntu-latest
permissions:
contents: write
issues: write

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Make scripts executable
run: chmod +x scripts/*.js

- name: Sync repositories to GitHub
id: sync
env:
WORLDDRIVEN_GITHUB_TOKEN: ${{ secrets.WORLDDRIVEN_GITHUB_TOKEN }}
run: |
set +e
node scripts/sync-repositories.js --apply > sync-report.md 2>&1
EXIT_CODE=$?
echo "exit_code=$EXIT_CODE" >> $GITHUB_OUTPUT
set -e
continue-on-error: true

- name: Comment on commit with results
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const report = fs.readFileSync('sync-report.md', 'utf8');

// Create a comment on the commit
await github.rest.repos.createCommitComment({
owner: context.repo.owner,
repo: context.repo.repo,
commit_sha: context.sha,
body: `${report}\n\n---\n*🤖 Automated sync of GitHub organization with REPOSITORIES.md*`,
});

- name: Create issue if failures occurred
if: steps.sync.outputs.exit_code != '0'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const report = fs.readFileSync('sync-report.md', 'utf8');

const title = '⚠️ Repository sync failed';
const body = `Repository synchronization encountered errors on commit ${context.sha.substring(0, 7)}.

${report}

---
**Commit**: ${context.sha}
**Triggered by**: @${context.actor}
**Action**: ${context.payload.head_commit?.message || 'Push to main'}

Please review the errors above and take appropriate action.`;

await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: title,
body: body,
labels: ['automation', 'sync-failure'],
});

- name: Report sync status
if: steps.sync.outputs.exit_code == '0'
run: |
echo "✅ Repository sync completed successfully"
echo "All changes have been applied to the GitHub organization"
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"scripts": {
"parse": "node scripts/parse-repositories.js",
"fetch-github": "node scripts/fetch-github-state.js",
"detect-drift": "node scripts/detect-drift.js"
"detect-drift": "node scripts/detect-drift.js",
"sync": "node scripts/sync-repositories.js",
"sync-apply": "node scripts/sync-repositories.js --apply"
},
"keywords": [
"worlddriven",
Expand Down
Loading
Loading