Skip to content

Commit 7c06a5f

Browse files
authored
Prettier output and additional fixes to Release automation (#790)
Following #779 and #782 not working exactly as expected, did a lot more testing on personal fork. Plan to try these out for real with release `v0.40.0` today.
1 parent 548f9c8 commit 7c06a5f

File tree

3 files changed

+115
-45
lines changed

3 files changed

+115
-45
lines changed

.github/workflows/prepare-release.yml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
steps:
2727
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2828
with:
29-
fetch-depth: 1
29+
fetch-depth: 0
3030
fetch-tags: true
3131
ref: ${{ github.ref }}
3232

@@ -44,7 +44,7 @@ jobs:
4444
- name: Validate version increment
4545
run: ./.github/workflows/scripts/validate-version-increment.sh "${{ steps.last_version.outputs.last_version }}" "${{ inputs.version }}"
4646

47-
- name: Extract changelog content
47+
- name: Extract unreleased changelog content
4848
id: changelog
4949
run: ./.github/workflows/scripts/extract-changelog.sh /tmp/changelog_content.txt
5050

@@ -59,12 +59,13 @@ jobs:
5959
echo "Planned changes:"
6060
echo "- New version: ${{ inputs.version }}"
6161
echo "- Last version: ${{ steps.last_version.outputs.last_version }}"
62-
echo ""
62+
echo "--------------------------------"
6363
echo "Git diff:"
64-
6564
git diff
66-
67-
echo ""
65+
echo "--------------------------------"
66+
echo "Unreleased content:"
67+
cat /tmp/changelog_content.txt
68+
echo "--------------------------------"
6869
echo "Git operations that would occur:"
6970
echo " - Create branch: otelbot/release-v${{ inputs.version }}"
7071
echo " - Commit version updates"
@@ -96,6 +97,9 @@ jobs:
9697
# not using secrets.GITHUB_TOKEN since pull requests from that token do not trigger workflows
9798
GH_TOKEN: ${{ steps.app-token.outputs.token }}
9899
run: |
100+
# Read changelog content into a variable
101+
CHANGELOG_CONTENT=$(cat /tmp/changelog_content.txt)
102+
99103
# Create PR body content
100104
cat > /tmp/pr_body.md << EOF
101105
## Release v${{ inputs.version }}
@@ -106,9 +110,7 @@ jobs:
106110
- Updated CHANGELOG.md with release notes
107111
108112
### Release Notes:
109-
```
110-
$(cat /tmp/changelog_content.txt)
111-
```
113+
${CHANGELOG_CONTENT}
112114
113115
### Checklist:
114116
- [ ] Verify CHANGELOG.md formatting and content
@@ -120,7 +122,7 @@ jobs:
120122
121123
# Create the pull request using GitHub CLI
122124
gh pr create \
123-
--title "Release v${{ inputs.version }}" \
125+
--title "chore(release) Prepare Release v${{ inputs.version }}" \
124126
--body-file /tmp/pr_body.md \
125127
--head "otelbot/release-v${{ inputs.version }}" \
126128
--base main \

.github/workflows/push-release.yml

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ jobs:
2424
environment: release
2525
steps:
2626
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
27+
with:
28+
fetch-depth: 0
29+
fetch-tags: true
30+
ref: ${{ github.ref }}
2731

2832
- name: Validate inputs
2933
run: |
@@ -87,22 +91,7 @@ jobs:
8791
- name: Extract changelog content for this release
8892
id: changelog
8993
run: |
90-
# Extract content for the specific release
91-
RELEASE_CONTENT=$(awk "/^## \[${{ inputs.version }}\]/,/^## \[/ {
92-
if (/^## \[${{ inputs.version }}\]/) next
93-
if (/^## \[/) exit
94-
print
95-
}" CHANGELOG.md | sed '/^$/d')
96-
97-
if [ -z "$RELEASE_CONTENT" ]; then
98-
echo "Error: No release content found for version ${{ inputs.version }} in CHANGELOG.md"
99-
exit 1
100-
fi
101-
102-
# Save to file for later use
103-
echo "$RELEASE_CONTENT" > /tmp/release_content.txt
104-
echo "Found release content:"
105-
cat /tmp/release_content.txt
94+
.github/workflows/scripts/extract-changelog.sh "${{ inputs.version }}"
10695
10796
- name: Dry run - Show planned changes
10897
if: inputs.dry_run
@@ -112,17 +101,17 @@ jobs:
112101
echo "Planned operations:"
113102
echo "- Version to tag: v${{ inputs.version }}"
114103
echo "- Last version: v${{ steps.last_version.outputs.last_version }}"
115-
echo ""
104+
echo "--------------------------------"
116105
echo "Git tags that would be created:"
117106
echo " - v${{ inputs.version }} (main release tag)"
118107
echo " - go/v${{ inputs.version }} (Go module tag)"
119108
echo " - collector/cmd/otelarrowcol/v${{ inputs.version }} (collector module tag)"
120-
echo ""
109+
echo "--------------------------------"
121110
echo "GitHub release that would be created:"
122111
echo " - Title: Release v${{ inputs.version }}"
123112
echo " - Tag: v${{ inputs.version }}"
124113
echo " - Release notes from CHANGELOG.md"
125-
echo ""
114+
echo "--------------------------------"
126115
echo "Release content preview:"
127116
cat /tmp/release_content.txt
128117
@@ -170,11 +159,14 @@ jobs:
170159
env:
171160
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
172161
run: |
162+
# Read changelog content into a variable
163+
RELEASE_CONTENT=$(cat /tmp/release_content.txt)
164+
173165
# Create release body content
174166
cat > /tmp/release_body.md << 'EOF'
175167
## What's Changed
176168
177-
$(cat /tmp/release_content.txt)
169+
${RELEASE_CONTENT}
178170
179171
**Full Changelog**: https://github.com/open-telemetry/otel-arrow/compare/v${{ steps.last_version.outputs.last_version }}...v${{ inputs.version }}
180172
Lines changed: 91 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,117 @@
11
#!/bin/bash
2-
# extract-changelog.sh - Extract unreleased content from CHANGELOG.md
2+
# extract-changelog.sh - Extract changelog content from CHANGELOG.md
3+
# Can extract either unreleased content or content for a specific version
34

45
set -euo pipefail
56

67
# Colors for output
78
RED='\033[0;31m'
89
GREEN='\033[0;32m'
910
YELLOW='\033[1;33m'
11+
BLUE='\033[0;34m'
1012
NC='\033[0m' # No Color
1113

12-
OUTPUT_FILE="${1:-/tmp/changelog_content.txt}"
14+
# Function to show usage
15+
usage() {
16+
echo "Usage: $0 [version] [output_file]"
17+
echo ""
18+
echo "Extract changelog content from CHANGELOG.md"
19+
echo ""
20+
echo "Arguments:"
21+
echo " version Version to extract (e.g., 0.40.0). If not provided, extracts 'Unreleased' content"
22+
echo " output_file Output file (default: /tmp/changelog_content.txt or /tmp/release_content.txt)"
23+
echo ""
24+
echo "Examples:"
25+
echo " $0 # Extract unreleased content"
26+
echo " $0 /tmp/my_file.txt # Extract unreleased content to custom file"
27+
echo " $0 0.40.0 # Extract content for version 0.40.0"
28+
echo " $0 0.40.0 /tmp/my_file.txt # Extract version content to custom file"
29+
exit 1
30+
}
31+
32+
# Parse arguments - handle different calling patterns
33+
VERSION=""
34+
OUTPUT_FILE=""
1335

14-
echo -e "${YELLOW}Extracting changelog content...${NC}"
36+
if [ $# -eq 0 ]; then
37+
# No arguments - extract unreleased content
38+
OUTPUT_FILE="/tmp/changelog_content.txt"
39+
elif [ $# -eq 1 ]; then
40+
# One argument - could be version or output file
41+
if [[ "$1" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
42+
# It's a version
43+
VERSION="$1"
44+
OUTPUT_FILE="/tmp/release_content.txt"
45+
else
46+
# It's an output file for unreleased content
47+
OUTPUT_FILE="$1"
48+
fi
49+
elif [ $# -eq 2 ]; then
50+
# Two arguments - version and output file
51+
VERSION="$1"
52+
OUTPUT_FILE="$2"
53+
else
54+
echo -e "${RED}Error: Too many arguments${NC}"
55+
usage
56+
fi
1557

1658
# Check if CHANGELOG.md exists
1759
if [ ! -f "CHANGELOG.md" ]; then
1860
echo -e "${RED}Error: CHANGELOG.md not found${NC}"
1961
exit 1
2062
fi
2163

22-
# Get unreleased content
23-
UNRELEASED_CONTENT=$(awk '/^## Unreleased/,/^## \[/ {
24-
if (/^## Unreleased/) next
25-
if (/^## \[/) exit
26-
print
27-
}' CHANGELOG.md | sed '/^$/d')
64+
if [ -z "$VERSION" ]; then
65+
# Extract unreleased content
66+
echo -e "${YELLOW}Extracting unreleased changelog content...${NC}"
67+
68+
CONTENT=$(awk '/^## Unreleased/,/^## \[/ {
69+
if (/^## Unreleased/) next
70+
if (/^## \[/) exit
71+
print
72+
}' CHANGELOG.md | sed '/^$/d')
2873

29-
if [ -z "$UNRELEASED_CONTENT" ]; then
30-
echo -e "${RED}Error: No unreleased content found in CHANGELOG.md${NC}"
31-
exit 1
74+
if [ -z "$CONTENT" ]; then
75+
echo -e "${RED}Error: No unreleased content found in CHANGELOG.md${NC}"
76+
exit 1
77+
fi
78+
79+
echo -e "${GREEN}✓ Found unreleased content${NC}"
80+
else
81+
# Extract content for specific version
82+
echo -e "${YELLOW}Extracting changelog content for version ${BLUE}${VERSION}${NC}..."
83+
84+
# Validate version format
85+
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
86+
echo -e "${RED}Error: Version must be in format X.Y.Z (e.g., 0.40.0)${NC}"
87+
exit 1
88+
fi
89+
90+
CONTENT=$(awk "BEGIN{found=0} /^## \[$VERSION\]/ {found=1; next} found && /^## \[/ {exit} found {print}" CHANGELOG.md | sed '/^$/d')
91+
92+
if [ -z "$CONTENT" ]; then
93+
echo -e "${RED}Error: No release content found for version $VERSION in CHANGELOG.md${NC}"
94+
echo -e "${YELLOW}Available versions in CHANGELOG.md:${NC}"
95+
grep "^## \[" CHANGELOG.md || echo "No versioned entries found"
96+
exit 1
97+
fi
98+
99+
echo -e "${GREEN}✓ Found release content for version ${VERSION}${NC}"
32100
fi
33101

34102
# Save to file
35-
echo "$UNRELEASED_CONTENT" > "$OUTPUT_FILE"
103+
echo "$CONTENT" > "$OUTPUT_FILE"
36104

37-
echo -e "${GREEN}✓ Changelog content extracted to: $OUTPUT_FILE${NC}"
38-
echo "Content:"
105+
echo -e "${GREEN}✓ Content saved to: ${OUTPUT_FILE}${NC}"
106+
echo ""
107+
echo -e "${YELLOW}Changelog content:${NC}"
39108
echo "----------------------------------------"
40109
cat "$OUTPUT_FILE"
41110
echo "----------------------------------------"
111+
112+
echo ""
113+
if [ -z "$VERSION" ]; then
114+
echo -e "${GREEN}✓ Successfully extracted unreleased changelog content${NC}"
115+
else
116+
echo -e "${GREEN}✓ Successfully extracted changelog content for version ${VERSION}${NC}"
117+
fi

0 commit comments

Comments
 (0)