diff --git a/.github/workflows/weekly-kpi-report.yml b/.github/workflows/weekly-kpi-report.yml new file mode 100644 index 0000000..0f0047f --- /dev/null +++ b/.github/workflows/weekly-kpi-report.yml @@ -0,0 +1,82 @@ +name: Weekly KPI Report + +# Post weekly KPI report to GitHub Discussions every Monday at 9:00 AM UTC +on: + schedule: + - cron: '0 9 * * 1' # Every Monday at 9:00 AM UTC + workflow_dispatch: # Allow manual trigger + +jobs: + generate-and-post-report: + runs-on: ubuntu-latest + name: Generate and post weekly KPI report + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + + - name: Install Dependencies + run: npm ci + + - name: Generate and Post KPI Report + env: + GITHUB_TOKEN: ${{ secrets.GH_PROJECT_TOKEN }} + GITHUB_REPOSITORY: ${{ github.repository }} + run: | + cat > post-kpi-report.ts << 'EOF' + import { ProjectsV2Client } from './agents/github/projects-v2.js'; + import { DiscussionsClient } from './agents/github/discussions.js'; + + async function main() { + const token = process.env.GITHUB_TOKEN!; + const [owner, repo] = process.env.GITHUB_REPOSITORY!.split('/'); + + // Initialize clients + const projectsClient = new ProjectsV2Client(token, { + owner, + repo, + projectNumber: parseInt(process.env.GITHUB_PROJECT_NUMBER || '1'), + }); + + const discussionsClient = new DiscussionsClient(token, { + owner, + repo, + }); + + // Initialize both clients + await projectsClient.initialize(); + await discussionsClient.initialize(); + + // Generate KPI report + console.log('📊 Generating KPI report...'); + const kpiData = await projectsClient.generateKPIReport(); + + console.log('KPI Data:', kpiData); + + // Post to Discussions + console.log('📝 Posting to GitHub Discussions...'); + const discussion = await discussionsClient.postWeeklyKPIReport(kpiData); + + console.log(`✓ Posted weekly KPI report: ${discussion.url}`); + console.log(` Discussion #${discussion.number}: ${discussion.title}`); + } + + main().catch((error) => { + console.error('Error generating KPI report:', error); + process.exit(1); + }); + EOF + + npx tsx post-kpi-report.ts + + - name: Summary + run: | + echo "### 📊 Weekly KPI Report Posted" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "✓ Successfully generated and posted weekly KPI report to Discussions" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "View at: https://github.com/${{ github.repository }}/discussions" >> $GITHUB_STEP_SUMMARY