|
| 1 | +name: Monitor Upstream Changes |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # Run daily at 8 AM UTC |
| 6 | + - cron: '0 8 * * *' |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +jobs: |
| 10 | + check-releases: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + permissions: |
| 13 | + issues: write |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout repository |
| 17 | + uses: actions/checkout@v4 |
| 18 | + with: |
| 19 | + fetch-depth: 1 |
| 20 | + |
| 21 | + - name: Check for new releases |
| 22 | + id: check |
| 23 | + uses: actions/github-script@v7 |
| 24 | + with: |
| 25 | + script: | |
| 26 | + // Get latest release from upstream |
| 27 | + const upstreamOwner = 'jhipster'; |
| 28 | + const upstreamRepo = 'prettier-java'; |
| 29 | +
|
| 30 | + try { |
| 31 | + const { data: latestRelease } = await github.rest.repos.getLatestRelease({ |
| 32 | + owner: upstreamOwner, |
| 33 | + repo: upstreamRepo |
| 34 | + }); |
| 35 | +
|
| 36 | + // Check if we've already processed this release |
| 37 | + const processedReleases = new Set(); |
| 38 | + try { |
| 39 | + const { data: issues } = await github.rest.issues.listForRepo({ |
| 40 | + owner: context.repo.owner, |
| 41 | + repo: context.repo.repo, |
| 42 | + labels: 'upstream-release', |
| 43 | + state: 'all' |
| 44 | + }); |
| 45 | +
|
| 46 | + issues.forEach(issue => { |
| 47 | + const match = issue.title.match(/Release (v?[\d.]+)/); |
| 48 | + if (match) processedReleases.add(match[1]); |
| 49 | + }); |
| 50 | + } catch (e) { |
| 51 | + console.log('No previous release issues found'); |
| 52 | + } |
| 53 | +
|
| 54 | + const releaseTag = latestRelease.tag_name; |
| 55 | +
|
| 56 | + if (!processedReleases.has(releaseTag)) { |
| 57 | + // Create issue for new release |
| 58 | + await github.rest.issues.create({ |
| 59 | + owner: context.repo.owner, |
| 60 | + repo: context.repo.repo, |
| 61 | + title: `📦 Upstream Release ${releaseTag}`, |
| 62 | + body: `## New Upstream Release Available |
| 63 | +
|
| 64 | +A new version of prettier-java has been released: [${releaseTag}](${latestRelease.html_url}) |
| 65 | + |
| 66 | +**Release Date**: ${new Date(latestRelease.published_at).toLocaleDateString()} |
| 67 | + |
| 68 | +### Release Notes |
| 69 | + |
| 70 | +${latestRelease.body || 'No release notes provided.'} |
| 71 | + |
| 72 | +### Recommended Actions |
| 73 | + |
| 74 | +1. Review the changes in this release |
| 75 | +2. Run the sync workflow to incorporate changes |
| 76 | +3. Test thoroughly with Kempt-specific features |
| 77 | +4. Update our changelog if merging |
| 78 | + |
| 79 | +--- |
| 80 | + |
| 81 | +*This issue was automatically created by the upstream monitoring workflow.*`, |
| 82 | + labels: ['upstream-release', 'needs-review'] |
| 83 | + }); |
| 84 | + |
| 85 | + console.log(`Created issue for new release: ${releaseTag}`); |
| 86 | + core.setOutput('new_release', releaseTag); |
| 87 | + } else { |
| 88 | + console.log(`Release ${releaseTag} already processed`); |
| 89 | + core.setOutput('new_release', ''); |
| 90 | + } |
| 91 | + } catch (error) { |
| 92 | + console.error('Error checking releases:', error); |
| 93 | + core.setFailed(error.message); |
| 94 | + } |
| 95 | + |
| 96 | + - name: Check recent commits |
| 97 | + id: commits |
| 98 | + run: | |
| 99 | + git remote add upstream https://github.com/jhipster/prettier-java.git || true |
| 100 | + git fetch upstream main --depth=50 |
| 101 | +
|
| 102 | + # Get commits from last 7 days |
| 103 | + WEEK_AGO=$(date -d '7 days ago' +%Y-%m-%d) |
| 104 | +
|
| 105 | + echo "### Recent upstream commits (last 7 days):" >> $GITHUB_STEP_SUMMARY |
| 106 | +
|
| 107 | + COMMIT_COUNT=$(git log upstream/main --since="$WEEK_AGO" --oneline | wc -l) |
| 108 | +
|
| 109 | + if [ $COMMIT_COUNT -gt 0 ]; then |
| 110 | + echo "Found $COMMIT_COUNT new commits in upstream" >> $GITHUB_STEP_SUMMARY |
| 111 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 112 | + git log upstream/main --since="$WEEK_AGO" --pretty=format:"- %h %s (%an, %ar)" >> $GITHUB_STEP_SUMMARY |
| 113 | + echo "high_activity=true" >> $GITHUB_OUTPUT |
| 114 | + else |
| 115 | + echo "No new commits in the last 7 days" >> $GITHUB_STEP_SUMMARY |
| 116 | + echo "high_activity=false" >> $GITHUB_OUTPUT |
| 117 | + fi |
| 118 | +
|
| 119 | + - name: Create activity summary |
| 120 | + if: steps.commits.outputs.high_activity == 'true' |
| 121 | + uses: actions/github-script@v7 |
| 122 | + with: |
| 123 | + script: | |
| 124 | + // Only create a summary issue once per week for high activity |
| 125 | + const today = new Date(); |
| 126 | + const dayOfWeek = today.getDay(); |
| 127 | +
|
| 128 | + // Only run on Mondays |
| 129 | + if (dayOfWeek !== 1) { |
| 130 | + console.log('Not Monday, skipping weekly summary'); |
| 131 | + return; |
| 132 | + } |
| 133 | +
|
| 134 | + // Check if we already created a summary this week |
| 135 | + const weekStart = new Date(today); |
| 136 | + weekStart.setDate(today.getDate() - 7); |
| 137 | +
|
| 138 | + const { data: recentIssues } = await github.rest.issues.listForRepo({ |
| 139 | + owner: context.repo.owner, |
| 140 | + repo: context.repo.repo, |
| 141 | + labels: 'upstream-activity', |
| 142 | + since: weekStart.toISOString() |
| 143 | + }); |
| 144 | +
|
| 145 | + if (recentIssues.length > 0) { |
| 146 | + console.log('Weekly summary already created'); |
| 147 | + return; |
| 148 | + } |
| 149 | +
|
| 150 | + // Create weekly activity summary |
| 151 | + await github.rest.issues.create({ |
| 152 | + owner: context.repo.owner, |
| 153 | + repo: context.repo.repo, |
| 154 | + title: `📊 Weekly Upstream Activity Report - ${today.toLocaleDateString()}`, |
| 155 | + body: `## Upstream Activity Summary |
| 156 | +
|
| 157 | +High activity detected in the upstream prettier-java repository. |
| 158 | + |
| 159 | +See the [workflow summary](${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}) for commit details. |
| 160 | + |
| 161 | +### Recommended Actions |
| 162 | + |
| 163 | +- Review recent changes for potential impacts |
| 164 | +- Consider running a sync if significant changes are present |
| 165 | +- Monitor for any breaking changes |
| 166 | + |
| 167 | +--- |
| 168 | + |
| 169 | +*This summary was automatically generated by the upstream monitoring workflow.*`, |
| 170 | + labels: ['upstream-activity'] |
| 171 | + }); |
0 commit comments