@@ -45,35 +45,26 @@ jobs:
45
45
cat TEMP.md >> CHANGELOG.md
46
46
rm TEMP.md
47
47
48
- - name : Fetch initial commit history
49
- id : fetch_initial_commit_history
50
- run : |
51
- echo "::set-output name=history::$(cat initial_commit_history.md)"
52
-
53
- - name : Update changelog
48
+ - name : Insert initial commit history
54
49
run : |
55
50
TARGET_TAG="0.0.1"
56
- CHANGELOG_FILE="CHANGELOG.md"
57
- INITIAL_HISTORY="${{ steps.fetch_initial_commit_history.outputs.history }}"
51
+ FILE="CHANGELOG.md"
58
52
59
- ESCAPED_HISTORY=$(printf '%s\n' "$INITIAL_HISTORY" | sed 's/[&/\]/\\&/g')
53
+ INITIAL_COMMIT_HISTORY="${{ env.INITIAL_COMMIT_HISTORY }}"
60
54
61
- if grep -q "## $TARGET_TAG (" "$CHANGELOG_FILE"; then
62
- echo "Tag ## $TARGET_TAG found. Updating $CHANGELOG_FILE..."
63
- sed -i "/## $TARGET_TAG (/,/^## /{//!d}" "$CHANGELOG_FILE"
55
+ if grep -q "^## $TARGET_TAG " "$FILE"; then
56
+ sed -i "/^## $TARGET_TAG /,/^## /{//!d}" "$FILE"
64
57
65
- awk -v tag="## $TARGET_TAG " -v history="$INITIAL_HISTORY" '
66
- {
67
- print;
68
- if ($0 ~ tag) {
69
- print history;
70
- }
71
- }' "$CHANGELOG_FILE" > TEMP.md && mv TEMP.md "$CHANGELOG_FILE"
58
+ awk -v content="$INITIAL_COMMIT_HISTORY" -v tag="## $TARGET_TAG " '
59
+ BEGIN { found=0 }
60
+ $0 ~ tag { print; print content; found=1; next }
61
+ { print }
62
+ END { if (!found) print "Tag header not found!" }
63
+ ' "$FILE" > TEMP.md && mv TEMP.md "$FILE"
72
64
73
- echo "Initial commit history inserted under ## $TARGET_TAG."
65
+ echo "Initial commit history inserted under the ## $TARGET_TAG header in $FILE ."
74
66
else
75
- echo "Error: Tag ## $TARGET_TAG not found in $CHANGELOG_FILE."
76
- exit 1
67
+ echo "Tag ## $TARGET_TAG not found in $FILE."
77
68
fi
78
69
79
70
- name : Commit changelog changes
0 commit comments