Skip to content

Commit 93fdd34

Browse files
committed
fix
1 parent e763f0b commit 93fdd34

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

.github/workflows/auto-update-ndc-lambda-sdk.yaml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ jobs:
169169
GITHUB_OUTPUT: ${{ github.output }}
170170

171171
- name: Create Pull Request
172+
id: create-pr
172173
if: steps.compare.outputs.needs-update == 'true' && steps.check-pr.outputs.pr-exists == 'false'
173174
run: |
174175
LATEST="${{ steps.latest-release.outputs.latest-version }}"
@@ -213,6 +214,78 @@ jobs:
213214
--label "automation"
214215
215216
echo "✅ Pull Request created successfully!"
217+
218+
# Get the PR URL and number for changelog
219+
PR_INFO=$(gh pr view "$BRANCH_NAME" --json url,number)
220+
PR_URL=$(echo "$PR_INFO" | jq -r '.url')
221+
PR_NUMBER=$(echo "$PR_INFO" | jq -r '.number')
222+
echo "PR URL: $PR_URL"
223+
echo "PR Number: $PR_NUMBER"
224+
echo "pr-url=$PR_URL" >> $GITHUB_OUTPUT
225+
echo "pr-number=$PR_NUMBER" >> $GITHUB_OUTPUT
226+
env:
227+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
228+
229+
- name: Update changelog
230+
if: steps.compare.outputs.needs-update == 'true' && steps.check-pr.outputs.pr-exists == 'false'
231+
run: |
232+
LATEST="${{ steps.latest-release.outputs.latest-version }}"
233+
CURRENT="${{ steps.current-version.outputs.current-version }}"
234+
BRANCH_NAME="github-ci/update-ndc-lambda-sdk-$LATEST"
235+
PR_URL="${{ steps.create-pr.outputs.pr-url }}"
236+
PR_NUMBER="${{ steps.create-pr.outputs.pr-number }}"
237+
238+
# Get current date
239+
CURRENT_DATE=$(date '+%Y-%m-%d')
240+
241+
# Create changelog entry matching existing format
242+
CHANGELOG_ENTRY="- Update NDC NodeJS Lambda to \`$LATEST\` ([#$PR_NUMBER]($PR_URL))"
243+
244+
# Check if changelog.md exists
245+
if [ ! -f "changelog.md" ]; then
246+
echo "❌ changelog.md not found"
247+
exit 1
248+
fi
249+
250+
# Create a temporary file with the new entry
251+
echo "" > temp_entry.txt
252+
echo "$CHANGELOG_ENTRY" >> temp_entry.txt
253+
254+
# Find the "## Unreleased" section and add the entry
255+
if grep -q "## Unreleased" changelog.md; then
256+
# Find line number of "## Unreleased" and insert after it
257+
LINE_NUM=$(grep -n "## Unreleased" changelog.md | head -1 | cut -d: -f1)
258+
NEXT_LINE=$((LINE_NUM + 1))
259+
260+
# Split file and insert entry
261+
head -n $LINE_NUM changelog.md > changelog_temp.md
262+
cat temp_entry.txt >> changelog_temp.md
263+
tail -n +$NEXT_LINE changelog.md >> changelog_temp.md
264+
mv changelog_temp.md changelog.md
265+
echo "✅ Added changelog entry: $CHANGELOG_ENTRY"
266+
else
267+
# If no "## Unreleased" section, add it at the top
268+
echo "Adding new Unreleased section to changelog.md"
269+
echo "# Changelog" > changelog_temp.md
270+
echo "" >> changelog_temp.md
271+
echo "## Unreleased" >> changelog_temp.md
272+
echo "" >> changelog_temp.md
273+
echo "$CHANGELOG_ENTRY" >> changelog_temp.md
274+
echo "" >> changelog_temp.md
275+
cat changelog.md >> changelog_temp.md
276+
mv changelog_temp.md changelog.md
277+
echo "✅ Created Unreleased section and added entry"
278+
fi
279+
280+
# Clean up temp file
281+
rm -f temp_entry.txt
282+
283+
# Commit and push the changelog update
284+
git add changelog.md
285+
git commit -m "docs: add changelog entry for NDC Lambda SDK $LATEST update"
286+
git push origin "$BRANCH_NAME"
287+
288+
echo "✅ Changelog updated and pushed to PR branch"
216289
env:
217290
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
218291

0 commit comments

Comments
 (0)