Skip to content

Commit acf84b0

Browse files
committed
Add GitHub Actions workflows for upstream sync automation.
1 parent 3046b11 commit acf84b0

2 files changed

Lines changed: 326 additions & 0 deletions

File tree

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
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+
});
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
name: Sync with Upstream
2+
3+
on:
4+
schedule:
5+
# Run every Monday at 9 AM UTC
6+
- cron: '0 9 * * 1'
7+
workflow_dispatch:
8+
inputs:
9+
sync_branch:
10+
description: 'Branch to sync from upstream'
11+
required: false
12+
default: 'main'
13+
type: string
14+
15+
jobs:
16+
sync:
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: write
20+
pull-requests: write
21+
issues: write
22+
23+
steps:
24+
- name: Checkout repository
25+
uses: actions/checkout@v4
26+
with:
27+
fetch-depth: 0
28+
token: ${{ secrets.GITHUB_TOKEN }}
29+
30+
- name: Configure git
31+
run: |
32+
git config user.name "github-actions[bot]"
33+
git config user.email "github-actions[bot]@users.noreply.github.com"
34+
35+
- name: Add upstream remote
36+
run: |
37+
git remote add upstream https://github.com/jhipster/prettier-java.git || true
38+
git fetch upstream
39+
40+
- name: Create sync branch
41+
id: sync
42+
run: |
43+
UPSTREAM_BRANCH="${{ github.event.inputs.sync_branch || 'main' }}"
44+
SYNC_BRANCH="sync-upstream-$(date +%Y%m%d-%H%M%S)"
45+
46+
echo "upstream_branch=$UPSTREAM_BRANCH" >> $GITHUB_OUTPUT
47+
echo "sync_branch=$SYNC_BRANCH" >> $GITHUB_OUTPUT
48+
49+
# Create a new branch from our main
50+
git checkout -b "$SYNC_BRANCH" origin/main
51+
52+
# Try to merge upstream changes
53+
if git merge upstream/"$UPSTREAM_BRANCH" --no-edit; then
54+
echo "merge_success=true" >> $GITHUB_OUTPUT
55+
echo "✅ Successfully merged upstream changes" >> $GITHUB_STEP_SUMMARY
56+
else
57+
echo "merge_success=false" >> $GITHUB_OUTPUT
58+
echo "❌ Merge conflicts detected" >> $GITHUB_STEP_SUMMARY
59+
60+
# Show conflict details
61+
echo "### Conflicts in the following files:" >> $GITHUB_STEP_SUMMARY
62+
git diff --name-only --diff-filter=U >> $GITHUB_STEP_SUMMARY
63+
64+
# Abort the merge
65+
git merge --abort
66+
67+
# Cherry-pick what we can
68+
echo "### Attempting to cherry-pick non-conflicting commits..." >> $GITHUB_STEP_SUMMARY
69+
MERGE_BASE=$(git merge-base HEAD upstream/"$UPSTREAM_BRANCH")
70+
COMMITS=$(git rev-list --reverse $MERGE_BASE..upstream/"$UPSTREAM_BRANCH")
71+
72+
for commit in $COMMITS; do
73+
if git cherry-pick $commit 2>/dev/null; then
74+
echo "✅ Cherry-picked: $(git log -1 --oneline $commit)" >> $GITHUB_STEP_SUMMARY
75+
else
76+
git cherry-pick --abort 2>/dev/null || true
77+
echo "❌ Could not cherry-pick: $(git log -1 --oneline $commit)" >> $GITHUB_STEP_SUMMARY
78+
fi
79+
done
80+
fi
81+
82+
# Check if there are any changes to push
83+
if git diff --quiet origin/main; then
84+
echo "has_changes=false" >> $GITHUB_OUTPUT
85+
echo "ℹ️ No changes to sync from upstream" >> $GITHUB_STEP_SUMMARY
86+
else
87+
echo "has_changes=true" >> $GITHUB_OUTPUT
88+
git push origin "$SYNC_BRANCH"
89+
fi
90+
91+
- name: Create Pull Request
92+
if: steps.sync.outputs.has_changes == 'true'
93+
uses: peter-evans/create-pull-request@v5
94+
with:
95+
token: ${{ secrets.GITHUB_TOKEN }}
96+
branch: ${{ steps.sync.outputs.sync_branch }}
97+
base: main
98+
title: '🔄 Sync with upstream prettier-java'
99+
body: |
100+
## Upstream Sync
101+
102+
This PR syncs changes from the upstream [prettier-java](https://github.com/jhipster/prettier-java) repository.
103+
104+
- **Source branch**: `upstream/${{ steps.sync.outputs.upstream_branch }}`
105+
- **Merge status**: ${{ steps.sync.outputs.merge_success == 'true' && '✅ Clean merge' || '⚠️ Manual conflict resolution required' }}
106+
107+
### What to do next:
108+
109+
${{ steps.sync.outputs.merge_success == 'true' && '1. Review the changes\n2. Run tests locally\n3. Merge when ready' || '1. Checkout this branch locally\n2. Resolve merge conflicts\n3. Push the resolved changes\n4. Run tests\n5. Merge when ready' }}
110+
111+
### Automated sync details:
112+
113+
<details>
114+
<summary>View sync summary</summary>
115+
116+
```
117+
${{ steps.sync.outputs.summary || 'See workflow run for details' }}
118+
```
119+
120+
</details>
121+
labels: |
122+
upstream-sync
123+
${{ steps.sync.outputs.merge_success == 'false' && 'has-conflicts' || '' }}
124+
assignees: ${{ github.repository_owner }}
125+
126+
- name: Create Issue for Conflicts
127+
if: steps.sync.outputs.has_changes == 'true' && steps.sync.outputs.merge_success == 'false'
128+
uses: peter-evans/create-issue-from-file@v4
129+
with:
130+
title: '⚠️ Upstream sync conflicts detected'
131+
content-filepath: /dev/stdin
132+
labels: upstream-sync, needs-attention
133+
assignees: ${{ github.repository_owner }}
134+
with: |
135+
## Upstream Sync Conflicts
136+
137+
The automated sync with upstream prettier-java has detected merge conflicts that require manual resolution.
138+
139+
**Pull Request**: See the latest PR with the `upstream-sync` and `has-conflicts` labels
140+
141+
### Affected files:
142+
143+
Check the PR description for the list of conflicting files.
144+
145+
### Resolution steps:
146+
147+
1. Checkout the sync branch locally
148+
2. Resolve conflicts manually
149+
3. Test the changes
150+
4. Push the resolved changes
151+
5. Merge the PR when ready
152+
153+
---
154+
155+
*This issue was automatically created by the upstream sync workflow.*

0 commit comments

Comments
 (0)