Skip to content

Commit ef39ad9

Browse files
authored
Fix changeset workflow date handling and remove duplicate content (#3803)
1 parent 4427319 commit ef39ad9

2 files changed

Lines changed: 20 additions & 200 deletions

File tree

.github/workflows/changeset.lock.yml

Lines changed: 1 addition & 98 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/changeset.md

Lines changed: 19 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,31 @@ steps:
4545
env:
4646
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4747
run: |
48-
# Calculate timestamps for 2 hours ago and 4 hours ago
49-
TWO_HOURS_AGO=$(date -u -d '2 hours ago' '+%Y-%m-%dT%H:%M:%SZ' 2>/dev/null || date -u -v-2H '+%Y-%m-%dT%H:%M:%SZ')
50-
FOUR_HOURS_AGO=$(date -u -d '4 hours ago' '+%Y-%m-%dT%H:%M:%SZ' 2>/dev/null || date -u -v-4H '+%Y-%m-%dT%H:%M:%SZ')
48+
# Calculate timestamps for 2 hours ago and 4 hours ago using Python (cross-platform)
49+
TWO_HOURS_AGO=$(python3 -c "from datetime import datetime, timedelta, timezone; print((datetime.now(timezone.utc) - timedelta(hours=2)).strftime('%Y-%m-%dT%H:%M:%SZ'))")
50+
FOUR_HOURS_AGO=$(python3 -c "from datetime import datetime, timedelta, timezone; print((datetime.now(timezone.utc) - timedelta(hours=4)).strftime('%Y-%m-%dT%H:%M:%SZ'))")
51+
52+
echo "Searching for PRs merged after: ${FOUR_HOURS_AGO}"
53+
echo "Filtering to PRs merged after: ${TWO_HOURS_AGO}"
5154
5255
# Query merged PRs from the last 4 hours maximum (to catch stragglers)
53-
gh search prs \
56+
if ! gh search prs \
5457
--repo ${{ github.repository }} \
5558
--merged \
5659
--merged ">=${FOUR_HOURS_AGO}" \
5760
--json number,title,mergedAt,body,labels,url,author \
58-
--limit 100 > /tmp/gh-aw/pr-data/all-merged-prs.json
61+
--limit 100 > /tmp/gh-aw/pr-data/all-merged-prs.json 2>&1; then
62+
echo "::error::Failed to search for merged PRs"
63+
cat /tmp/gh-aw/pr-data/all-merged-prs.json || true
64+
exit 1
65+
fi
66+
67+
# Verify we got valid JSON
68+
if ! jq empty /tmp/gh-aw/pr-data/all-merged-prs.json 2>/dev/null; then
69+
echo "::error::Invalid JSON response from gh search"
70+
cat /tmp/gh-aw/pr-data/all-merged-prs.json
71+
exit 1
72+
fi
5973
6074
# Filter to only PRs from the last 2 hours (main window)
6175
cat /tmp/gh-aw/pr-data/all-merged-prs.json | \
@@ -200,100 +214,3 @@ The `/tmp/gh-aw/cache-memory/processed-prs.json` file should be a simple JSON ar
200214
- **If there are no unprocessed PRs, just exit without doing anything** - this is normal and expected
201215
- The cache memory folder persists across runs, so your processed-prs.json will be there next time
202216

203-
# Changeset Generator for Merged PRs
204-
205-
You are the Changeset Generator agent - responsible for automatically creating changeset files for recently merged pull requests.
206-
207-
## Mission
208-
209-
When pull requests are merged to the default branch, analyze the changes and create properly formatted changeset files that document the changes according to the changeset specification.
210-
211-
## Current Context
212-
213-
- **Repository**: ${{ github.repository }}
214-
- **Analysis Period**: Last 2 hours
215-
- **Cache Location**: `/tmp/gh-aw/cache-memory/` - Used to track which PRs have been processed
216-
- **PR Data Location**: `/tmp/gh-aw/pr-data/recent-merged-prs.json` - Pre-fetched merged PR data
217-
218-
## Task Overview
219-
220-
### Phase 1: Load and Filter PR Data
221-
222-
1. **Load the pre-fetched PR data** from `/tmp/gh-aw/pr-data/recent-merged-prs.json`
223-
2. **Check the cache** in `/tmp/gh-aw/cache-memory/` to identify which PRs have already been processed
224-
- The cache should contain a file or data structure tracking processed PR numbers
225-
- Create a simple tracking mechanism (e.g., a JSON file with processed PR numbers)
226-
3. **Filter out already-processed PRs** to get the list of PRs that need changeset files
227-
228-
### Phase 2: Generate Changeset Files
229-
230-
For each unprocessed merged PR:
231-
232-
1. **Analyze the Pull Request**: Review the PR title and body to understand what has been modified
233-
2. **Use the repository name as the package identifier** (gh-aw)
234-
3. **Determine the Change Type**:
235-
- **major**: Major breaking changes (X.0.0) - Very unlikely, probably should be **minor**
236-
- **minor**: Breaking changes in the CLI (0.X.0) - indicated by "BREAKING CHANGE" or major API changes
237-
- **patch**: Bug fixes, docs, refactoring, internal changes, tooling, new shared workflows (0.0.X)
238-
239-
**Important**: Internal changes, tooling, and documentation are always "patch" level.
240-
241-
4. **Generate ONE Changeset File per PR**:
242-
- Create file in `.changeset/` directory
243-
- Use format from the changeset format reference above
244-
- Filename: `<type>-pr-<pr-number>-<short-description>.md` (e.g., `patch-pr-123-fix-bug.md`)
245-
- Include PR number in the changeset description for traceability
246-
247-
5. **Update the cache** to mark this PR as processed:
248-
- Add the PR number to your tracking file in `/tmp/gh-aw/cache-memory/`
249-
250-
### Phase 3: Create Pull Request
251-
252-
After generating all changeset files:
253-
254-
1. **Git operations are already configured** by the pre-step
255-
2. **Stage and commit all changeset files**:
256-
```bash
257-
git add .changeset/*.md
258-
git commit -m "Add changesets for merged PRs"
259-
```
260-
261-
3. **The safe-outputs create-pull-request will automatically**:
262-
- Create a new branch
263-
- Push your changes
264-
- Create a PR with the changeset files
265-
- Use title: `[changeset] Add changesets for merged PRs`
266-
267-
4. **Include in the PR description**:
268-
- List of PRs processed with their numbers and titles
269-
- Summary of changeset files created
270-
- Any notes about the changes
271-
272-
## Guidelines
273-
274-
- **Be Accurate**: Analyze each PR content carefully to determine the correct change type
275-
- **Be Clear**: Each changeset description should clearly explain what changed
276-
- **Be Concise**: Keep descriptions brief but informative
277-
- **Follow Conventions**: Use the exact changeset format specified above
278-
- **Single Package Default**: Always use "gh-aw" as the package identifier
279-
- **Track Progress**: Always update the cache after processing each PR
280-
- **One File Per PR**: Each PR gets exactly one changeset file
281-
- **Smart Naming**: Include PR number in filename for easy tracking (e.g., `patch-pr-456-update-docs.md`)
282-
283-
## Example Changeset File
284-
285-
```markdown
286-
---
287-
"gh-aw": patch
288-
---
289-
290-
Fixed rendering bug in console output (PR #456)
291-
```
292-
293-
## Important Notes
294-
295-
- The PR data is already fetched - it's in `/tmp/gh-aw/pr-data/recent-merged-prs.json`
296-
- Use the cache to avoid processing the same PR twice
297-
- Process all unprocessed PRs in a single workflow run
298-
- If there are no unprocessed PRs, simply do nothing (the job won't run due to conditional)
299-

0 commit comments

Comments
 (0)