19
19
with :
20
20
fetch-depth : 0
21
21
ref : main
22
- token : ${{ secrets.GITHUB_TOKEN }}
22
+ token : ${{ secrets.PAT_TOKEN }}
23
23
24
24
- name : Get PR title and body
25
25
id : pr-info
@@ -31,21 +31,40 @@ jobs:
31
31
32
32
- name : Update Changelog
33
33
run : |
34
+ # Check if CHANGELOG.md exists
35
+ if [ ! -f CHANGELOG.md ]; then
36
+ echo "Error: CHANGELOG.md not found"
37
+ echo "Creating initial CHANGELOG.md"
38
+ echo "# Changelog\n\nAll notable changes to this project will be documented in this file.\n\n" > CHANGELOG.md
39
+ CURRENT_VERSION="0.0.0"
40
+ else
41
+ echo "Reading current version from CHANGELOG.md"
42
+ # Read current version from latest entry with error handling
43
+ CURRENT_VERSION=$(grep -m 1 "## \[v" CHANGELOG.md | sed 's/## \[v\(.*\)\].*/\1/')
44
+ if [ -z "$CURRENT_VERSION" ]; then
45
+ echo "Warning: No version found in CHANGELOG.md, using 0.0.0"
46
+ CURRENT_VERSION="0.0.0"
47
+ else
48
+ echo "Current version: $CURRENT_VERSION"
49
+ fi
50
+ fi
51
+
34
52
# Get today's date
35
53
DATE=$(date +%Y-%m-%d)
36
-
37
- # Read current version from latest entry
38
- CURRENT_VERSION=$(grep -m 1 "## \[v" CHANGELOG.md | sed 's/## \[v\(.*\)\].*/\1/')
54
+ echo "Generating changelog entry for date: $DATE"
39
55
40
56
# Increment patch version
41
57
IFS='.' read -r major minor patch <<< "$CURRENT_VERSION"
42
58
NEW_VERSION="${major}.${minor}.$((patch + 1))"
59
+ echo "New version will be: $NEW_VERSION"
43
60
44
61
# Create new changelog entry
45
62
NEW_ENTRY="## [v${NEW_VERSION}] - ${DATE}\n\n"
46
63
47
64
# Determine change type from PR title
48
65
PR_TITLE="${{ steps.pr-info.outputs.title }}"
66
+ echo "Processing PR title: $PR_TITLE"
67
+
49
68
if [[ "$PR_TITLE" == *"feat:"* || "$PR_TITLE" == *"feature:"* ]]; then
50
69
CHANGE_TYPE="Added"
51
70
elif [[ "$PR_TITLE" == *"fix:"* ]]; then
@@ -60,11 +79,13 @@ jobs:
60
79
CHANGE_TYPE="Changed"
61
80
fi
62
81
82
+ echo "Change type determined as: $CHANGE_TYPE"
63
83
NEW_ENTRY+="### ${CHANGE_TYPE}\n"
64
84
NEW_ENTRY+="- ${PR_TITLE#*: }\n"
65
85
66
86
# Add PR body details if they exist
67
87
if [ ! -z "${{ steps.pr-info.outputs.body }}" ]; then
88
+ echo "Processing PR body for additional details"
68
89
while IFS= read -r line; do
69
90
if [[ "$line" =~ ^-[[:space:]].*$ ]]; then
70
91
NEW_ENTRY+="$line\n"
@@ -75,29 +96,42 @@ jobs:
75
96
# Add version link at the end
76
97
NEW_ENTRY+="\n[v${NEW_VERSION}]: https://github.com/PeterVinter/Manage_linux_docker_containers/releases/tag/v${NEW_VERSION}\n"
77
98
78
- # Create temporary file with new content
99
+ echo "Creating temporary file with new changelog entry"
79
100
echo -e "$NEW_ENTRY" > temp_entry
80
- sed -i '7r temp_entry' CHANGELOG.md
101
+
102
+ if [ -s CHANGELOG.md ]; then
103
+ echo "Inserting new entry into existing CHANGELOG.md"
104
+ sed -i '7r temp_entry' CHANGELOG.md
105
+ else
106
+ echo "Creating new CHANGELOG.md with initial entry"
107
+ cat temp_entry >> CHANGELOG.md
108
+ fi
81
109
rm temp_entry
82
110
83
111
# Configure Git
112
+ echo "Configuring Git"
84
113
git config --local user.email "github-actions[bot]@users.noreply.github.com"
85
114
git config --local user.name "github-actions[bot]"
86
115
87
116
# Create branch, commit and push
88
117
BRANCH_NAME="bot/update-changelog-v${NEW_VERSION}"
118
+ echo "Creating branch: $BRANCH_NAME"
89
119
git checkout -b "$BRANCH_NAME"
120
+
121
+ echo "Committing changes"
90
122
git add CHANGELOG.md
91
123
git commit -m "docs: update changelog for v${NEW_VERSION}"
92
124
93
- # Force push in case branch exists
125
+ echo "Pushing changes"
94
126
git push -f origin "$BRANCH_NAME"
95
127
96
- # Create PR using GitHub CLI
128
+ echo "Creating pull request"
97
129
gh pr create \
98
130
--title "docs: update changelog for v${NEW_VERSION}" \
99
131
--body "Automated changelog update for version ${NEW_VERSION}" \
100
132
--base main \
101
- --head "$BRANCH_NAME" || true
133
+ --head "$BRANCH_NAME" || {
134
+ echo "Warning: Failed to create PR. This might be because a PR already exists."
135
+ }
102
136
env :
103
- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
137
+ GITHUB_TOKEN : ${{ secrets.PAT_TOKEN }}
0 commit comments