-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented automatic github release notes generator and changlog hel…
- Loading branch information
Showing
4 changed files
with
221 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
# Elastic Distribution for OpenTelemetry PHP Change Log | ||
|
||
## v0.2.0 | ||
|
||
### What's new | ||
|
||
- Asynchronous (background) transport for traces, logs and metrics ([#101](https://github.com/elastic/elastic-otel-php/issues/101)) (PR [#102](https://github.com/elastic/elastic-otel-php/pull/102)) | ||
- Timeout after which the asynchronous (background) transfer will interrupt data transmission during process termination ([#106](https://github.com/elastic/elastic-otel-php/issues/106)) (PR [#107](https://github.com/elastic/elastic-otel-php/pull/107)) | ||
- Improved documentation | ||
|
||
## v0.1.0 | ||
|
||
- Initial alpha release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#!/bin/bash | ||
|
||
CHANGELOG_FILE="CHANGELOG.md" | ||
|
||
show_help() { | ||
echo "Usage: $0 --release-tag <tag> [--changelog-file <file>]" | ||
echo | ||
echo "Options:" | ||
echo " --release-tag The current release tag (e.g., v0.2.0)." | ||
echo " --changelog-file Path to the changelog file (default: CHANGELOG.md)." | ||
echo " -h, --help Display this help message." | ||
} | ||
|
||
parse_arguments() { | ||
while [[ "$#" -gt 0 ]]; do | ||
case $1 in | ||
--release-tag) | ||
RELEASE_TAG="$2" | ||
shift 2 | ||
;; | ||
--changelog-file) | ||
CHANGELOG_FILE="$2" | ||
shift 2 | ||
;; | ||
-h|--help) | ||
show_help | ||
exit 0 | ||
;; | ||
*) | ||
echo "Unknown option: $1" | ||
show_help | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
if [[ -z "$RELEASE_TAG" ]]; then | ||
echo "Error: --release-tag is required." | ||
show_help | ||
exit 1 | ||
fi | ||
} | ||
|
||
find_previous_release_tag() { | ||
local release_tag="$1" | ||
local changelog_file="$2" | ||
|
||
grep "^## v" "$changelog_file" | awk '{print $2}' | sort -rV | grep -A 1 "^$release_tag" | tail -n 1 | ||
} | ||
|
||
extract_release_notes() { | ||
local release_tag="$1" | ||
local previous_tag="$2" | ||
local changelog_file="$3" | ||
|
||
awk -v tag="$release_tag" -v prev_tag="$previous_tag" ' | ||
BEGIN { found = 0 } | ||
/^## / { | ||
if ($2 == tag) { found = 1; next } | ||
if (found && $2 == prev_tag) { exit } | ||
} | ||
found { print } | ||
' "$changelog_file" | ||
} | ||
|
||
main() { | ||
parse_arguments "$@" | ||
|
||
if [[ ! -f "$CHANGELOG_FILE" ]]; then | ||
echo "Error: Changelog file '$CHANGELOG_FILE' not found." | ||
exit 1 | ||
fi | ||
|
||
PREVIOUS_TAG=$(find_previous_release_tag "$RELEASE_TAG" "$CHANGELOG_FILE") | ||
|
||
if [[ -z "$PREVIOUS_TAG" ]]; then | ||
# echo "Error: Could not find the previous tag for release '$RELEASE_TAG' in '$CHANGELOG_FILE'." | ||
# exit 1 | ||
exit 0 | ||
fi | ||
|
||
RELEASE_NOTES=$(extract_release_notes "$RELEASE_TAG" "$PREVIOUS_TAG" "$CHANGELOG_FILE") | ||
|
||
if [[ -z "$RELEASE_NOTES" ]]; then | ||
# echo "Error: No release notes found for tag '$RELEASE_TAG'." | ||
# exit 1 | ||
exit 0 | ||
fi | ||
|
||
echo "$RELEASE_NOTES" | ||
|
||
if [ ${PREVIOUS_TAG} != ${RELEASE_TAG} ]; then | ||
echo -e "\nFull changelog: [${PREVIOUS_TAG}...${RELEASE_TAG}](https://github.com/elastic/elastic-otel-php/compare/${PREVIOUS_TAG}...${RELEASE_TAG})" | ||
fi | ||
} | ||
|
||
main "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#!/bin/bash | ||
|
||
show_help() { | ||
echo "Usage: $0 --previous-release-tag <tag> [--target <branch_or_tag>]" | ||
echo | ||
echo "Options:" | ||
echo " --previous-release-tag The previous release tag (e.g., v0.2.0)." | ||
echo " --target (Optional) Target branch or tag to compare against (default: main)." | ||
echo " --github-token (Optional) GitHub personal access token." | ||
echo " -h, --help Display this help message." | ||
exit 1 | ||
} | ||
|
||
parse_args() { | ||
TARGET="main" # Default target branch | ||
|
||
if [[ "$#" -lt 2 ]]; then | ||
show_help | ||
fi | ||
|
||
while [[ "$#" -gt 0 ]]; do | ||
case $1 in | ||
--previous-release-tag) | ||
PREVIOUS_TAG="$2" | ||
shift 2 | ||
;; | ||
--target) | ||
TARGET="$2" | ||
shift 2 | ||
;; | ||
--github-token) | ||
GITHUB_TOKEN="$2" | ||
shift 2 | ||
;; | ||
-h|--help) | ||
show_help | ||
;; | ||
*) | ||
echo "Unknown option: $1" | ||
show_help | ||
;; | ||
esac | ||
done | ||
|
||
if [[ -z "$PREVIOUS_TAG" ]]; then | ||
echo "Error: --previous-release-tag is required." | ||
show_help | ||
fi | ||
} | ||
|
||
generate_issue_links() { | ||
local commit_message="$1" | ||
|
||
echo "$commit_message" | sed -E ' | ||
s/\(#([0-9]+)\)/([#\1](https:\/\/github.com\/elastic\/elastic-otel-php\/issues\/\1))/g | ||
' | ||
} | ||
|
||
fetch_pr_for_commit() { | ||
local commit_hash="$1" | ||
local pr_response | ||
|
||
local auth_header="" | ||
if [[ -n "$GITHUB_TOKEN" ]]; then | ||
auth_header="-H Authorization: Bearer $GITHUB_TOKEN" | ||
fi | ||
|
||
pr_response=$(curl -s -H "Accept: application/vnd.github+json" $auth_header \ | ||
"https://api.github.com/repos/elastic/elastic-otel-php/commits/$commit_hash/pulls") | ||
|
||
echo "$pr_response" | jq -r '.[0] | if .html_url then "(PR [#\(.number)](\(.html_url)))" else "" end' | ||
} | ||
|
||
generate_changelog() { | ||
local previous_tag="$1" | ||
local target_branch_or_tag="$2" | ||
|
||
echo "## v[PUT VERSION TAG HERE]" | ||
echo | ||
|
||
git log "${previous_tag}..${target_branch_or_tag}" --oneline | while read -r line; do | ||
# Skip lines matching "github-action*" | ||
if [[ "$line" =~ github-action ]]; then | ||
continue | ||
fi | ||
|
||
# Extract commit hash and message | ||
commit_hash=$(echo "$line" | awk '{print $1}') | ||
commit_message=$(echo "$line" | cut -d' ' -f2-) | ||
|
||
commit_message_with_links=$(generate_issue_links "$commit_message") | ||
|
||
pr_link=$(fetch_pr_for_commit "$commit_hash") | ||
|
||
if [[ -n "$pr_link" ]]; then | ||
commit_message_with_links="$commit_message_with_links $pr_link" | ||
fi | ||
|
||
echo "- $commit_message_with_links" | ||
done | ||
} | ||
|
||
main() { | ||
parse_args "$@" | ||
generate_changelog "$PREVIOUS_TAG" "$TARGET" | ||
} | ||
|
||
main "$@" |