Skip to content

Commit 4217f3d

Browse files
committed
Merge branch 'main' into develop
2 parents 26c257a + f68438e commit 4217f3d

File tree

2 files changed

+80
-17
lines changed

2 files changed

+80
-17
lines changed

.github/workflows/changeset-generation.md

Lines changed: 61 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,38 @@ This workflow automatically generates changesets for pull requests. Changesets a
1010

1111
The workflow is triggered by:
1212

13-
1. When a pull request is labeled with 'ready-for-changeset'
13+
1. When a pull request is merged to the `develop` branch
1414
2. Manually via the GitHub Actions UI using the workflow_dispatch event
1515
- Go to Actions > Generate Changeset > Run workflow
1616
- Enter the PR number and click "Run workflow"
17+
- This can be used to generate changesets for:
18+
- PRs that were merged before the workflow was implemented
19+
- PRs where the workflow was skipped or failed
20+
- PRs that need their changeset regenerated
21+
22+
The workflow will:
23+
- Fetch the PR information using the GitHub API
24+
- Generate a changeset based on the PR title, body, and author
25+
- Commit the changeset to the develop branch
26+
- Update or create a release PR if needed
27+
28+
### Manual Trigger Usage
29+
30+
To manually generate a changeset for a PR:
31+
32+
1. Go to the Actions tab in your repository
33+
2. Click on the "Generate Changeset" workflow
34+
3. Click "Run workflow"
35+
4. Enter the PR number in the input field
36+
5. Click "Run workflow"
37+
38+
The workflow will:
39+
- Validate that the PR exists
40+
- Extract all necessary information from the PR
41+
- Generate and commit the changeset
42+
- Update or create a release PR
43+
44+
If the PR doesn't exist or can't be accessed, the workflow will fail with an appropriate error message.
1745

1846
## Implementation Options
1947

@@ -56,12 +84,14 @@ Breaking changes are detected by:
5684

5785
## Workflow Steps
5886

59-
1. **Detect PR Merge**: The workflow runs when a PR is merged or when manually triggered.
60-
2. **Extract Metadata**: The workflow extracts relevant information from the PR, including title, author, and body.
61-
3. **Generate Changeset**: A changeset file is created with the extracted metadata.
62-
4. **Commit Changeset**: The changeset is committed to the branch (typically `develop`).
63-
5. **Generate Release Notes**: The `release:notes` script processes all changesets to create formatted release notes in a temporary file.
64-
6. **Update/Create Release PR**: The workflow either updates an existing release PR or creates a new one with the generated release notes.
87+
1. **Debug Event Information**: The workflow first logs important event details for debugging purposes
88+
2. **Generate Changeset**: The main job runs when a PR is merged or manually triggered, and:
89+
- Checks out the code
90+
- Sets up Node.js
91+
- Installs dependencies
92+
- Extracts PR information
93+
- Generates and commits the changeset
94+
- Updates or creates a release PR
6595

6696
## Release Notes Generation
6797

@@ -108,29 +138,41 @@ name: Generate Changeset
108138
on:
109139
pull_request_target:
110140
types: [closed]
141+
branches:
142+
- develop
111143
workflow_dispatch:
112144
inputs:
113145
pr_number:
114-
description: 'Pull Request Number'
146+
description: 'PR number to generate changeset for'
115147
required: true
116148
type: string
117149

118150
jobs:
151+
debug-event:
152+
runs-on: ubuntu-latest
153+
if: github.event_name == 'pull_request_target'
154+
steps:
155+
- name: Debug Event
156+
run: |
157+
echo "Event details..."
158+
119159
generate-changeset:
120-
if: (github.event_name == 'pull_request_target' && github.event.pull_request.merged == true) || github.event_name == 'workflow_dispatch'
160+
permissions:
161+
contents: write
162+
pull-requests: write
121163
runs-on: ubuntu-latest
164+
needs: [debug-event]
165+
if: (github.event_name == 'pull_request_target' && github.event.pull_request.merged == true) || github.event_name == 'workflow_dispatch'
122166
env:
123167
REPO_URL: "https://github.com/${{ github.repository }}"
124168
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
125169
steps:
126170
# Checkout code
127171
# Setup Node.js
128172
# Install dependencies
129-
# Get PR details
173+
# Extract PR information
130174
# Generate changeset
131-
# Commit changeset
132-
# Generate release notes to temporary file
133-
# Check for existing release PR
175+
# Generate release notes
134176
# Update/Create release PR
135177
```
136178

@@ -146,8 +188,12 @@ This approach keeps the repository clean while still allowing the workflow to pr
146188

147189
## Prerequisites
148190

149-
1. Create a 'ready-for-changeset' label in your repository
150-
2. Set up a Personal Access Token (PAT) with the "repo" scope as a repository secret named `REPO_PAT`
191+
The workflow uses the default `GITHUB_TOKEN` secret provided by GitHub Actions, which has the necessary permissions to:
192+
- Read repository contents
193+
- Create and update pull requests
194+
- Commit changes to branches
195+
196+
No additional secrets or tokens need to be configured.
151197

152198
## Local Testing
153199

.github/workflows/generate-changeset.yml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ jobs:
4444
pull-requests: write
4545
runs-on: ubuntu-latest
4646
needs: [debug-event]
47-
if: (github.event_name == 'pull_request_target' && github.event.pull_request.merged == true) || github.event_name == 'workflow_dispatch'
47+
if: |
48+
always() && (
49+
(github.event_name == 'pull_request_target' && github.event.pull_request.merged == true) ||
50+
github.event_name == 'workflow_dispatch'
51+
)
4852
env:
4953
REPO_URL: "https://github.com/${{ github.repository }}"
5054
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -54,7 +58,6 @@ jobs:
5458
with:
5559
fetch-depth: 0
5660
ref: ${{ github.event.pull_request.base.ref || 'develop' }}
57-
# Use a personal access token with repo scope for better permissions
5861
token: ${{ secrets.GITHUB_TOKEN }}
5962

6063
- name: Setup Node.js
@@ -77,14 +80,28 @@ jobs:
7780
PR_DATA=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
7881
"https://api.github.com/repos/${{ github.repository }}/pulls/${PR_NUMBER}")
7982
83+
# Check if PR exists and is accessible
84+
if [[ $(echo "$PR_DATA" | jq -r '.message // empty') == "Not Found" ]]; then
85+
echo "Error: PR #${PR_NUMBER} not found"
86+
exit 1
87+
fi
88+
8089
PR_TITLE=$(echo "$PR_DATA" | jq -r '.title')
8190
PR_BODY=$(echo "$PR_DATA" | jq -r '.body')
8291
PR_AUTHOR=$(echo "$PR_DATA" | jq -r '.user.login')
92+
PR_BASE_REF=$(echo "$PR_DATA" | jq -r '.base.ref')
8393
8494
echo "pr_number=${PR_NUMBER}" >> $GITHUB_OUTPUT
8595
echo "pr_title=${PR_TITLE}" >> $GITHUB_OUTPUT
8696
echo "pr_author=${PR_AUTHOR}" >> $GITHUB_OUTPUT
8797
echo "pr_body=${PR_BODY}" >> $GITHUB_OUTPUT
98+
echo "pr_base_ref=${PR_BASE_REF}" >> $GITHUB_OUTPUT
99+
100+
# For debugging
101+
echo "Processing PR #${PR_NUMBER}"
102+
echo "Title: ${PR_TITLE}"
103+
echo "Author: ${PR_AUTHOR}"
104+
echo "Base ref: ${PR_BASE_REF}"
88105
89106
- name: Generate changeset for current PR
90107
run: |

0 commit comments

Comments
 (0)