-
Notifications
You must be signed in to change notification settings - Fork 176
241 lines (199 loc) · 9.14 KB
/
Copy pathupdate-pr-feed.yml
File metadata and controls
241 lines (199 loc) · 9.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
name: Update PR Feed Configuration
on:
workflow_dispatch:
inputs:
rba_tag:
description: 'RBA tag (e.g., rba/5.18-RBA-20251030-2f39445-a6d9e14)'
required: true
type: string
# Permissions needed for the workflow
permissions:
contents: write # To push branches and commits
pull-requests: write # To create pull requests
jobs:
update-pr-feed:
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the repository
- name: Checkout repository
uses: actions/checkout@v7
with:
ref: 4.0.x # Default branch for docs repo
# Step 2: Determine branch name and checkout/create branch
- name: Determine branch name
id: branch-info
run: |
RBA_TAG="${{ github.event.inputs.rba_tag }}"
SANITIZED_TAG=$(echo "$RBA_TAG" | sed 's/\//-/g')
BRANCH_NAME="update-pr-feed-${SANITIZED_TAG}"
echo "sanitized_tag=$SANITIZED_TAG" >> $GITHUB_OUTPUT
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
# Step 3: Create or checkout branch
- name: Create or checkout branch
run: |
BRANCH_NAME="${{ steps.branch-info.outputs.branch_name }}"
# Fetch remote branches
git fetch origin
# Check if branch exists on remote
if git ls-remote --heads origin "$BRANCH_NAME" | grep -q "$BRANCH_NAME"; then
echo "Branch $BRANCH_NAME exists on remote, checking it out..."
git checkout "$BRANCH_NAME"
git pull origin "$BRANCH_NAME"
else
echo "Creating new branch from 4.0.x: $BRANCH_NAME"
git checkout -b "$BRANCH_NAME"
fi
# Step 4: Set up Node.js environment
- name: Set up Node.js
uses: actions/setup-node@v7
with:
node-version-file: '.nvmrc'
cache: 'npm'
# Step 5: Install dependencies
- name: Install dependencies
env:
CLOUDSMITH_NPM_TOKEN: ${{ secrets.CLOUDSMITH_NPM_TOKEN }}
run: npm ci
# Step 6: Update pr-feed-config.json with the new RBA tag
- name: Update PR feed configuration
id: update-config
run: |
CONFIG_FILE="docs/.vuepress/pr-feed-config.json"
RBA_TAG="${{ github.event.inputs.rba_tag }}"
echo "Updating $CONFIG_FILE with RBA tag: $RBA_TAG"
# Use jq to update the lastSaasCut field
jq --arg tag "$RBA_TAG" \
'.lastSelfHostedRelease.lastSaasCut = $tag' \
"$CONFIG_FILE" > "${CONFIG_FILE}.tmp"
# Replace the original file
mv "${CONFIG_FILE}.tmp" "$CONFIG_FILE"
# Verify the update
echo "Updated configuration:"
cat "$CONFIG_FILE"
# Step 7: Generate PR feed files
- name: Generate PR feed files
id: generate-feeds
env:
GH_API_TOKEN: ${{ secrets.GH_API_TOKEN }}
run: |
echo "Running npm run pr-feed to regenerate feed files..."
# Run the pr-feed script and capture the exit code
if npm run pr-feed; then
echo "feed_generation_status=success" >> $GITHUB_OUTPUT
echo "Feed generation completed successfully"
else
echo "feed_generation_status=failed" >> $GITHUB_OUTPUT
echo "Feed generation failed, but continuing to commit config changes"
fi
continue-on-error: true
# Step 7: Commit changes
- name: Commit changes
run: |
RBA_TAG="${{ github.event.inputs.rba_tag }}"
FEED_STATUS="${{ steps.generate-feeds.outputs.feed_generation_status }}"
# Configure git
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Stage all changes (config + generated files)
git add docs/.vuepress/pr-feed-config.json
git add docs/history/updates/index.md
git add docs/.vuepress/public/feeds/development.xml
git add docs/.vuepress/public/feeds/development-atom.xml
RBA_TAG="${{ github.event.inputs.rba_tag }}"
FEED_STATUS="${{ steps.generate-feeds.outputs.feed_generation_status }}"
# Create commit message based on feed generation status
if [ "$FEED_STATUS" = "success" ]; then
git commit -m "Update PR feed configuration for ${RBA_TAG}" \
-m "" \
-m "- Updated lastSaasCut to ${RBA_TAG}" \
-m "- Regenerated PR feed files" \
-m "- Updated markdown page and RSS/Atom feeds"
else
git commit -m "Update PR feed configuration for ${RBA_TAG}" \
-m "" \
-m "- Updated lastSaasCut to ${RBA_TAG}" \
-m "- Warning: Feed generation failed (see workflow logs)" \
-m "- Manual regeneration may be required"
fi
# Step 8: Push the branch
- name: Push branch
run: |
BRANCH_NAME="${{ steps.branch-info.outputs.branch_name }}"
git push origin "$BRANCH_NAME"
# Step 9: Create Pull Request
- name: Create Pull Request
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
RBA_TAG="${{ github.event.inputs.rba_tag }}"
BRANCH_NAME="${{ steps.branch-info.outputs.branch_name }}"
FEED_STATUS="${{ steps.generate-feeds.outputs.feed_generation_status }}"
# Create PR body file to avoid quoting issues
if [ "$FEED_STATUS" = "success" ]; then
cat > pr_body.md << "EOFMARKER"
## PR Feed Configuration Update
This PR updates the PR feed configuration with the latest RBA release tag.
### Changes
- **RBA Tag**: ${RBA_TAG}
- **Updated Field**: lastSelfHostedRelease.lastSaasCut
- **Feed Generation**: Success
### Generated Files
- docs/history/updates/index.md - Updated markdown page with changes since last GA release
- docs/.vuepress/public/feeds/development.xml - Updated RSS feed
- docs/.vuepress/public/feeds/development-atom.xml - Updated Atom feed
### Triggered By
Workflow dispatch from RBA release process
---
*This PR was automatically created by the update-pr-feed workflow*
EOFMARKER
else
cat > pr_body.md << "EOFMARKER"
## PR Feed Configuration Update
This PR updates the PR feed configuration with the latest RBA release tag.
### Changes
- **RBA Tag**: ${RBA_TAG}
- **Updated Field**: lastSelfHostedRelease.lastSaasCut
- **Feed Generation**: **Failed**
### Action Required
The feed generation script failed during this workflow run. Please:
1. Review the workflow logs
2. Manually run npm run pr-feed after merging to regenerate feeds
3. Check that the GH_API_TOKEN has proper permissions
### Triggered By
Workflow dispatch from RBA release process
---
*This PR was automatically created by the update-pr-feed workflow*
EOFMARKER
fi
# Check if PR already exists for this branch
EXISTING_PR=$(gh pr list --head "$BRANCH_NAME" --base 4.0.x --json number --jq '.[0].number' || echo "")
if [ -n "$EXISTING_PR" ]; then
echo "PR #$EXISTING_PR already exists for branch $BRANCH_NAME"
echo "The PR will be automatically updated with the new commits"
else
echo "Creating new PR for branch $BRANCH_NAME..."
gh pr create \
--title "Update PR Feed Configuration for ${RBA_TAG}" \
--body-file pr_body.md \
--base 4.0.x \
--head "$BRANCH_NAME"
fi
# Step 10: Summary
- name: Workflow Summary
if: always()
run: |
RBA_TAG="${{ github.event.inputs.rba_tag }}"
BRANCH_NAME="${{ steps.branch-info.outputs.branch_name }}"
FEED_STATUS="${{ steps.generate-feeds.outputs.feed_generation_status }}"
echo "## PR Feed Update Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **RBA Tag**: \`${RBA_TAG}\`" >> $GITHUB_STEP_SUMMARY
echo "- **Branch**: \`${BRANCH_NAME}\`" >> $GITHUB_STEP_SUMMARY
echo "- **Config Update**: Success" >> $GITHUB_STEP_SUMMARY
if [ "$FEED_STATUS" = "success" ]; then
echo "- **Feed Generation**: Success" >> $GITHUB_STEP_SUMMARY
else
echo "- **Feed Generation**: Failed (check logs)" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "A pull request has been created for review." >> $GITHUB_STEP_SUMMARY