From 218b7b508394c8dfd646965e86e29e001a982c5b Mon Sep 17 00:00:00 2001 From: Monet Lee Date: Tue, 22 Oct 2024 19:33:15 +0800 Subject: [PATCH] fix --- .github/workflows/changelog.yml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml index db402ff..a84be8b 100644 --- a/.github/workflows/changelog.yml +++ b/.github/workflows/changelog.yml @@ -17,7 +17,7 @@ jobs: - name: Run Go Changelog Generator run: | - # Run the Go changelog generator, pass the release tag if available + # Run the Go changelog generator, passing the release tag if available if [ "${{ github.event.release.tag_name }}" = "latest" ]; then go run tools/changelog.go > "${{ github.event.release.tag_name }}-changelog.md" else @@ -26,7 +26,7 @@ jobs: - name: Handle changelog files run: | - # Remove the 'v' prefix from the tag name and extract Major.Minor version + # Extract Major.Minor version by removing the 'v' prefix from the tag name TAG_NAME=${{ github.event.release.tag_name }} CHANGELOG_VERSION_NUMBER=$(echo "$TAG_NAME" | sed 's/^v//' | grep -oP '^\d+\.\d+') @@ -36,21 +36,23 @@ jobs: # Check if the changelog file for the current release already exists if [ -f "$CHANGELOG_PATH" ]; then - # If the file exists, append the current content to the temporary changelog + # If the file exists, append the new changelog to the existing one cat "$CHANGELOG_PATH" >> "${TAG_NAME}-changelog.md" # Overwrite the existing changelog with the updated content mv "${TAG_NAME}-changelog.md" "$CHANGELOG_PATH" else - # If it doesn't exist, rename the temp changelog to the new changelog file + # If the changelog file doesn't exist, rename the temp changelog file to the new changelog file mv "${TAG_NAME}-changelog.md" "$CHANGELOG_PATH" - # Update CHANGELOG/README.md with the new file in reverse order + # Ensure that README.md exists if [ ! -f "CHANGELOG/README.md" ]; then echo -e "# CHANGELOGs\n" > CHANGELOG/README.md fi - # Insert the new changelog at the top of the README.md file - sed -i "2s/^/- [$CHANGELOG_FILENAME](./$CHANGELOG_FILENAME)\n/" CHANGELOG/README.md + # Add the new changelog entry at the top of the README.md + if ! grep -q "\[$CHANGELOG_FILENAME\]" CHANGELOG/README.md; then + sed -i "2i- [$CHANGELOG_FILENAME](./$CHANGELOG_FILENAME)" CHANGELOG/README.md + fi fi - name: Clean up