-
Notifications
You must be signed in to change notification settings - Fork 128
Update CHANGELOG.md when syncing plugin content to marketplace repos #1908
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| #!/usr/bin/env bash | ||
| # update-changelog.sh <changelog-file> <new-version> | ||
| # Inserts a new version entry at the top of the changelog (before the first "## [" section). | ||
| # Change lines are derived from the currently staged git index. | ||
| # If no existing version sections are found, the entry is appended at the end. | ||
| set -euo pipefail | ||
|
|
||
| CHANGELOG_FILE="${1:?Usage: update-changelog.sh <changelog-file> <new-version>}" | ||
| NEW_VERSION="${2:?Usage: update-changelog.sh <changelog-file> <new-version>}" | ||
| TODAY=$(date +%Y-%m-%d) | ||
|
|
||
| if [ ! -f "$CHANGELOG_FILE" ]; then | ||
| echo "Warning: CHANGELOG file not found at '$CHANGELOG_FILE'. Version $NEW_VERSION will not be documented. Skipping changelog update." | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Build change lines from staged git index. | ||
| # Strip the directory prefix of the CHANGELOG so paths are relative to the plugin root. | ||
| CHANGELOG_DIR="$(dirname "$CHANGELOG_FILE")/" | ||
| CHANGE_LINES=() | ||
| while IFS=$'\t' read -r status filepath; do | ||
| relpath="${filepath#"$CHANGELOG_DIR"}" | ||
| case "${status:0:1}" in | ||
| A) CHANGE_LINES+=("- Added: \`${relpath}\`") ;; | ||
| D) CHANGE_LINES+=("- Removed: \`${relpath}\`") ;; | ||
| *) CHANGE_LINES+=("- Updated: \`${relpath}\`") ;; | ||
| esac | ||
| done < <(git diff --cached --name-status 2>/dev/null \ | ||
| | grep -vE '(plugin\.json|CHANGELOG\.md)$' \ | ||
| || true) | ||
|
|
||
| # Fall back to a generic message when no specific changes were found. | ||
| if [ ${#CHANGE_LINES[@]} -eq 0 ]; then | ||
| CHANGE_LINES=("- Synced plugin files from GitHub-Copilot-for-Azure.") | ||
| fi | ||
|
|
||
| # Write the new entry to a temp file so awk can read it. | ||
| ENTRY_FILE=$(mktemp) | ||
| trap 'rm -f "$ENTRY_FILE"' EXIT | ||
| { | ||
| printf "## [%s] - %s\n" "$NEW_VERSION" "$TODAY" | ||
| printf "\n" | ||
| printf "### Changed\n" | ||
| printf "\n" | ||
| for line in "${CHANGE_LINES[@]}"; do | ||
| printf "%s\n" "$line" | ||
| done | ||
| printf "\n" | ||
| } > "$ENTRY_FILE" | ||
|
|
||
| # Insert the new entry before the first "## [" line, or append at end. | ||
| awk -v entry_file="$ENTRY_FILE" ' | ||
| /^## \[/ && !inserted { | ||
| while ((getline line < entry_file) > 0) print line | ||
| close(entry_file) | ||
| inserted=1 | ||
| } | ||
| { print } | ||
| END { | ||
| if (!inserted) { | ||
| print "" | ||
| while ((getline line < entry_file) > 0) print line | ||
| } | ||
| } | ||
| ' "$CHANGELOG_FILE" > "$CHANGELOG_FILE.tmp" | ||
|
|
||
| if [ ! -s "$CHANGELOG_FILE.tmp" ]; then | ||
| rm -f "$CHANGELOG_FILE.tmp" | ||
| echo "Error: awk processing resulted in empty output for $CHANGELOG_FILE. This may indicate a parsing failure. Original file preserved. Please review the changelog format." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| mv "$CHANGELOG_FILE.tmp" "$CHANGELOG_FILE" | ||
| echo "Updated CHANGELOG.md with version $NEW_VERSION" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -121,6 +121,10 @@ jobs: | |
| echo "Updated $f to version $NEW_VERSION" | ||
| fi | ||
| done | ||
|
|
||
| # Update CHANGELOG.md with new version entry | ||
| bash "../source-repo/.github/scripts/update-changelog.sh" \ | ||
| ".github/plugins/azure-skills/CHANGELOG.md" "$NEW_VERSION" | ||
| else | ||
| echo "No content changes detected. Skipping version bump." | ||
| fi | ||
|
|
@@ -307,6 +311,10 @@ jobs: | |
| echo "Updated $f to version $NEW_VERSION" | ||
| fi | ||
| done | ||
|
|
||
| # Update CHANGELOG.md with new version entry | ||
| bash "../source-repo/.github/scripts/update-changelog.sh" \ | ||
| ".github/plugins/azure-skills/CHANGELOG.md" "$NEW_VERSION" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Job 2 copies plugin files into Either dedupe in the script (associative array keyed by final relpath) or scope the diff to |
||
| else | ||
| echo "No content changes detected. Skipping version bump." | ||
| fi | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
git diff --cached --name-statusemits renames asR<score>\told\tnew(three tab-separated fields). WithIFS=$'\t' read -r status filepaththe filepath variable swallows botholdandnew(with the tab between them), producing an entry that contains an embedded tab. rsync doesn't produce renames in the current sync flow so it's low-probability, but it'll misbehave if someone restructures plugin paths.read -r status filepath newpathwith a rename branch would cover it.